Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^4: chomp question

by Jenda (Abbot)
on Aug 08, 2012 at 10:57 UTC ( #986222=note: print w/replies, xml ) Need Help??


in reply to Re^3: chomp question
in thread chomp question

while (<>) { chomp if /^CLI\b/; print; } # or without all those default variables while (my $line = <$FILEHANDLE>) { chomp($line) if $line =~ /^CLI\b/; print $line; }

Probably not exactly what you had in mind, right? In either case you either want to check whether the line starts with "CLI" and chomp() it if it does or remember the last line (or whether it started with CLI) and append the text you read instead of adding a new element into the array.

my @lines; my $last_line_was_CLI = 0; while (<>) { chomp; if ($last_line_was_CLI) { $lines[-1] .= $_; $last_line_was_CLI = 0; } elsif (/^CLI\b/) { $last_line_was_CLI = 1; push @lines, $_; } else { push @lines, $_; } }

Jenda
Enoch was right!
Enjoy the last years of Rome.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://986222]
help
Chatterbox?
[TCLion]: I guess it makes sense but trying to take out key info to make it general was a bit difficult in the tiny window, it just doesnt look right... but I understand

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (13)
As of 2017-03-23 19:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (294 votes). Check out past polls.