Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2018-02-18 07:52 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (251 votes). Check out past polls.