Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: while modifier

by stefp (Vicar)
on Sep 21, 2001 at 01:27 UTC ( #113713=note: print w/replies, xml ) Need Help??


in reply to while modifier

I don't think that while as a modifier can set $_.
nope the problem is not there. the following line works as expected
 perl -e 'print $_ while <>'

The problem must be with peculiarities of lexical declared with a modifier in the same statement.

Anyway you could write:

#!/usr/bin/perl -w use strict; my $foo_text; while ( <DATA> ) { $foo_text .= $_; } print "$foo_text\n"; __DATA__ foo wears foo shoes at the foo store
or
#!/usr/bin/perl -w use strict; my $foo_text; { local $/; undef $/; # see perlvar $foot_text = <DATA>; # slurps contents after __DATA_ } print "$foo_text\n"; __DATA__ foo wears foo shoes at the foo store

-- stefp

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2022-08-13 00:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?