Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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.



Log In?

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2017-02-28 00:53 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (394 votes). Check out past polls.