Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

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.



Comment on Re^2: Modify a txt file
Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2016-04-28 22:27 GMT
Find Nodes?
    Voting Booth?
    :nehw tseb si esrever ni gnitirW

    Results (437 votes). Check out past polls.