Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Perl: how to insert words at the end of each line and open the file?

by Laurent_R (Parson)
on Oct 31, 2013 at 18:20 UTC ( #1060618=note: print w/ replies, xml ) Need Help??


in reply to Perl: how to insert words at the end of each line and open the file?

In this part of your code:

while (@arr2 = <CF>){ foreach $line (@arr2) {

you are doing two nested loops, whereas you really need only one. And the first loop is actually faulty. You either want to do this:

my @arr2 = <CF>; foreach $line (@arr2) { # ...

or that:

while (my $line = <CF>) { # ...

The second solution is simpler, slightly faster and, in my view, cleaner.


Comment on Re: Perl: how to insert words at the end of each line and open the file?
Select or Download Code
Re^2: Perl: how to insert words at the end of each line and open the file?
by WWq (Novice) on Nov 01, 2013 at 02:42 UTC
    Yes, thank you for your guidance. =)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2014-12-20 18:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (97 votes), past polls