On Sat, Jan 10, 2009 at 09:26, Jenda Krynicky <je...@krynicky.cz> wrote:
> From: Mike McClain <mmccl...@nethere.com>
>> On Fri, Jan 09, 2009 at 05:52:45PM -0500, Chas. Owens wrote:
>> <snip>
>> > You seem to be under the impression that the argument to
>> > Digest::MD5::md5_hex is a file name.  The argument is a scalar holding
>> > the data to perform md5 on.  So Digest::MD5::md5_hex("foo") will give
>> > you the MD5 of the data "foo".  When you say
>> > Digest::MD5->md5_hex("foo") you are really saying
>> > Digest::MD5::md5_hex("Digest::MD5", "foo") so you will get the MD5 of
>> > the string "Digest::MD5" concatenated with the string "foo".
>>
>> When you said, "Module::method('Module', $arg)" I saw the second 'Module'
>> as file not string.
>> I guess I've still got a lot to learn.
>>
>> I see that
>>     Digest::MD5->md5_hex()
>>     "Digest::MD5"->md5_hex()
>>     Digest::MD5::md5_hex("Digest::MD5")     all return the same result.
>>     "Mud"->md5_hex()                        is an error.
>>
>> But after I read all the references in the index of 'Programming Perl'
>> about '->' the arrow operator I'm no where nearer to understanding
>> what's going on. At least thanks to your help I know what's going on
>> even if I don't yet understand it. It's been long enough since I picked
>> up a new language to have forgotten this particular frustration.
>> Cest la vie.
>
> The Class::Name->method(...) is a class method call. Perl will find
> the method in the clas hierarchy and call the method and pass the
> 'Class::Name' as the first parameter.
>
>>
>> <snip>
>>
>> > seek DATA, 0, 0;
>> > my $data = join '', <DATA>;
>>
>> This is interesting.
>> The 'join' causes the whole file to be slurped in by forcing list context?
>
> Yes. But it's inefficient. This forces perl to first split the file
> into lines and then merge them back.
>
> my $data = do {local $/; <DATA>};
>
> is more efficient.
>
> The "local $/" clears the "line separator for reading" and thus
> forces the <> (diamond operator) to return the whole file contents as
> a single scalar.
snip

I wasn't particularly interested in efficiency there because reading
the whole file into memory is the wrong solution anyway.  The right
solution is to use the OO interface and pass in a filehandle (that way
the file gets processed in blocks).

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to