Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: Modify a txt file

by johngg (Abbot)
on Oct 20, 2011 at 22:39 UTC ( #932774=note: print w/replies, xml ) Need Help??


in reply to Re: Modify a txt file
in thread Modify a txt file

You can dispense with the need for an input scalar by opening a filehandle on a reference to a HEREDOC. Also, there's no need to initialise your output scalar to the empty string as any previous content will be clobbered by the '>' in the open.

knoppix@Microknoppix:~$ perl -e ' > open my $inFH, q{<}, \ <<EOD or die qq{open: << HEREDOC: > $!\n}; > line 1 > line 2 > line 3 > EOD > > my $out = qq{some rubbish here\n}; > open $outFH, q{>}, \ $out or die qq{open: > scalar: $!\n}; > > while ( <$inFH> ) > { > print $outFH uc; > } > > print $out;' LINE 1 LINE 2 LINE 3 knoppix@Microknoppix:~$

I hope this is of interest.

Cheers,

JohnGG

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://932774]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (10)
As of 2016-12-06 20:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (117 votes). Check out past polls.