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

question on cook book example

From:
Kipp, James
Date:
January 4, 2002 10:11
Subject:
question on cook book example
Message ID:
63C950B21B25D511960500508B122351F394DF@xexwlm05.mbnainternational.com
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);
--
 




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About