noviceuser has asked for the wisdom of the Perl Monks concerning the following question:
i am writing a code where i have to find version associated with the name from a file. i am trying below code but the pattern match is not working. the file /home/test.txt contains multiple entries like below:
Anls/01.00/windows abc/02.00/windows core/03.00/windows route/04.00/windows . . .
my $file = "/home/test.txt"; if (-e $file) { my @list = ("Anls", "core", "route"); open(FH, '<', $file) or die $!; foreach my $x (@list) { while(<FH>){ my $pattern; if (defined($pattern) && ($pattern =~ /$x\/(.*)\/(.* +)/)) { my $version = $1; print "$x: $version\n"; } } } close(FH); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Pattern matching in perl
by hv (Prior) on Jun 30, 2022 at 15:31 UTC | |
by choroba (Cardinal) on Jun 30, 2022 at 16:50 UTC | |
by AnomalousMonk (Archbishop) on Jun 30, 2022 at 23:01 UTC | |
|
Re: Pattern matching in perl [short-circuit and declared vs. defined]
by kcott (Archbishop) on Jun 30, 2022 at 18:30 UTC | |
|
Re: Pattern matching in perl
by Anonymous Monk on Jul 01, 2022 at 15:11 UTC | |
by Fletch (Bishop) on Jul 01, 2022 at 15:18 UTC | |
by Anonymous Monk on Jul 02, 2022 at 17:32 UTC |