develooper Front page | perl.beginners | Postings from January 2002

question on cook book example

Kipp, James
January 4, 2002 10:11
question on cook book example
Message ID:
I understand how this works:
$sum = 0;
foreach $ascval (unpack("C*", $string)) {
    $sum += $ascval;
print "sum is $sum\n";
# prints "1248" if $string was "an apple a day"

buy not exactly sure how this is working. tried looking at perldoc pack
but no luck. explanation is appreciated.

This does the same thing, but much faster:
$sum = unpack("%32C*", $string);
-- Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About