Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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

by Laurent_R (Prior)
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 rifling through the Monastery: (7)
As of 2015-07-07 06:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (87 votes), past polls