greenmoss has asked for the wisdom of the Perl Monks concerning the following question:
This works fine. However, I want to parse each line of a supposed aliases file into an array, then make sure all of the elements of the array look like they belong in a unix aliases file:sub remove_pattern_from_array { my $pattern = shift (@_); my @holder_array = qw//; foreach my $line (@_){ unless ($line =~ /$pattern/){ push (@holder_array, $line); } } return @holder_array; }
should pass the test, whereasusername: me@you.com
should fail the test and thus get kicked out of the arraygarbagetest#$^#$^#$%^#$
The first two alternatives get rid of blank lines and comment lines, but the last part of the pattern isn't picking out only the alias-style lines.@aliases_array = remove_pattern_from_array ( "^\$|^#|!(^.+?:\\s+.+\$)", @aliases_array);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: looking for aliases(5)-style entries in a text file
by athomason (Curate) on Aug 17, 2000 at 08:42 UTC | |
|
Re: looking for aliases(5)-style entries in a text file
by BlueLines (Hermit) on Aug 17, 2000 at 03:46 UTC |