Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
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


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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2014-08-31 10:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls