Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2016-10-24 22:34 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (310 votes). Check out past polls.