Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Perl Idioms Explained - my $string = do { local $/; <FILEHANDLE> };

by wirrwarr (Monk)
on Aug 29, 2003 at 22:31 UTC ( #287848=note: print w/ replies, xml ) Need Help??


in reply to Perl Idioms Explained - my $string = do { local $/; <FILEHANDLE> };

Nice explanation, just one remark about

Because we are inside a do block when we use local, the value of $/ is temporarily changed, and we can rest assured that it will not affect code outside of our block (or scope).
This "(or scope)" should probably be worded more carefully. If you call another function from the block,then you are outside the scope of the block, but the value if $/ is still undef inside that function. This is one of the "features" of local that's hard to grasp, and information about it should therefore be not misleading.
$/ = 'uga';sub a { print ":$/:\n"; } a(); { local $/; a(); } a();

The rest is, as already said, well done!

daniel.


Comment on Re: Perl Idioms Explained - my $string = do { local $/; <FILEHANDLE> };

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://287848]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (12)
As of 2015-07-31 09:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (276 votes), past polls