Re: How to filter out lines from a variable that has multi-lines?
am 29.09.2007 03:25:10 von Narthring
On Sep 28, 8:09 pm, mike wrote:
> suppose a variable $a has multi-lines, e.g.
>
> happy
> new
> new password
> year
> get password of micky
> LOL
>
> What is best way to filter out lines that have "password" involved?
> Thanks in advance
One way would be to split on newlines and use a regular expression to
filter out 'password':
use strict;
use warnings;
my $text = '
happy
new
new password
year
get password of micky
LOL';
my (@array) = split(/\n/, $text);
my ($result);
foreach my $line (@array){
$result .= "$line\n" unless ($line =~ m/password/);
}
print "$result";
Re: How to filter out lines from a variable that has multi-lines?
am 29.09.2007 03:47:08 von Tad McClellan
mike wrote:
> suppose a variable $a has multi-lines, e.g.
>
> happy
> new
> new password
> year
> get password of micky
> LOL
>
> What is best way to filter out lines that have "password" involved?
$a =~ s/.*password.*\n//g;
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"