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

Re: if elsif elsif prints all three.

by hexcoder (Curate)
on Feb 27, 2008 at 22:26 UTC ( [id://670776]=note: print w/replies, xml ) Need Help??


in reply to if elsif elsif prints all three.

while ($line = <SH>){ if($line =~ m/$agent/){ $line = $collect; #this line will be replaced by the $collect line in the file OUT } elsif ( $line =~ m/best1collect/) { next; #this line will NOT appear in the file OUT, because you #don't reach the print command. If you want this line in #the OUT file, I suggest, you use a continue block. See at #the end. } elsif ($line =~ m/'syslogd'\)/){ my $newline = $. + 3; $newline = $bgs; print OUT "$newline\n"; # this line will appear in the OUT file , but have the # bgs line inserted before. } # all other lines will be copied. print OUT $line; print $line; }
Here is the version that does not omit lines. The statements in the continue block are executed always at the end of each loop.
while ($line = <SH>){ if($line =~ m/$agent/){ $line = $collect; } elsif ( $line =~ m/best1collect/) { next; } elsif ($line =~ m/'syslogd'\)/){ my $newline = $. + 3; $newline = $bgs; print OUT "$newline\n"; } } continue { print OUT $line; print $line; }

Replies are listed 'Best First'.
Re^2: if elsif elsif prints all three.
by wcj75019 (Acolyte) on Feb 27, 2008 at 23:20 UTC
    Ok, it doesn't remove that line and if the $line isn't there. It put the $ +bgs here doc there. But, if it has the wrong $line. if($line =~ m/$agent/){ $line = $collect; It fixes it and also adds the $bgs here. same with if the $line is right. It doesn't remove the line anymore. + But, it adds the $bgs here to that file too. Thanks!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2024-04-16 19:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found