Rob Dixon wrote:
> Scott R. Godin wrote:
>> John W. Krahn wrote:
>> >
>> > Yes, there is. :-)
>> >
>> > my %hash = do { local $/; <FH> =~ /[^\n,]+/g };
>>
>> Holy Handgrenades, Batman!
>>
>> but where's the implicit split of key and value there? forgive me for
>> asking, but I just don't see it. is there some magic going on here?
>
> Hi Scott.
>
> May the apprentice answer for the master?
>
> The %hash = puts /[^\n,]+/g into list context, which therefore
> returns a list of all the matches. The regex matches all contiguous
> strings of characters excluding comma and newline, so will
> effectively split at both and return two fields per file record.
> local $/, of course, enable slurp mode and reads the entire
> file into a single string.
>
> Did I pass?
>
> Rob
Indeed. this construct is one I've rarely seen, which accounts for much of
my surprise. I was already aware of 'slurp mode', but had not seen the
localized use of do in this manner, where the filehandle was bound to a
regex <FH> =~ /matchthis/;
list context explains much here, but the usage was still surprising to me.
I'll definitely have to remember this for future reference.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]