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



On Sep 28, 8:09 pm, mike <needpass...@xxxxxxxxx> 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";

.



Relevant Pages

  • Re: How to filter out lines from a variable that has multi-lines?
    ... mike wrote: ... get password of micky ... What is best way to filter out lines that have "password" involved? ... Tad McClellan ...
    (comp.lang.perl.misc)
  • Re: foreach with options?
    ... foreach(object o in myClassIntances) ... public FilterFunction Filter; ... public bool Contains{return Parent.Contains&& ... public IDictionary<TKey, TValue> Parent; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: backreferneces in search pattern
    ... Unless you control the layout of the HTML, you would be much better off ... > I am labouring since a long while already on this filter. ... because of the additional control over the warnings it affords. ... The uninitialized value might have come from a capturing parentheses ...
    (comp.lang.perl.misc)
  • Re: Population running for extended period
    ... After applying a filter for Warnings in addition to Errors I see a ton ... The Gatherer property mapping file cannot be opened. ... I know that I need to move the catalogs on the short drives so I've ...
    (microsoft.public.sqlserver.fulltext)
  • Re: Filtering strongly-typed datasets
    ... foreach (DataRowView row in dv) {//... ... SQL-esque query or somesuch? ... I have wanted filter a dataset I have obtained from a generic method and pull out the rows I am actually interested in. ...
    (microsoft.public.dotnet.framework)