Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
laziness, impatience, and hubris
 
PerlMonks  

Re: Append Next Line To Current Line

by Jim (Curate)
on Jul 02, 2012 at 18:19 UTC ( #979488=note: print w/ replies, xml ) Need Help??


in reply to Append Next Line To Current Line

Rename the array variable @data to @lines for the sake of clarity.

Alternatively, don't slurp the entire file into an array in the first place. Simply process the file line by line, which is easily done in Perl.

If you process the file line by line, then you'll need to delay printing every line until after you've read the next line and made whatever changes you need to make to the previous line:

my $previous_line; LINE: while (my $line = <>) { next LINE if $line =~ m/disregard this line/; chomp $line; # Here's where you implement your algorithm # to compare the value on line $line with the # value on line $previous_line and print the # appropriate ouput line $previous_line = $line; } # Here's where you print the last line # modified as appropriate given that # there is no next line

You asked for concepts, I gave you concepts.


Comment on Re: Append Next Line To Current Line
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (14)
As of 2014-04-16 10:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (424 votes), past polls