How to filter out lines from a variable that has multi-lines?

M

mike

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
 
N

Narthring

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";
 
T

Tad McClellan

mike said:
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;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top