Because this is Perl, There Is More Than One Way To Do It:
use strict;
use warnings;
my $file = "/home/test.txt";
# Store the list of desired names in a hash, with a true value for each.
my %list = map { $_ => 1 } qw{ Anls core route };
open my $fh, '<', $file or die "Failed to open $file: $!";
while ( <$fh> ) {
# Use split() to break $_ on slashes. Save only first two parts.
my ( $x, $version ) = split /\//;
# Print if hash entry {$x} contains a true value. Non-existing entries are false.
print "$x: version $version\n" if $list{$x};
}
close $fh;
In reply to Re: Pattern matching in perl
by Anonymous Monk
in thread Pattern matching in perl
by noviceuser
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |