in reply to pattern string match while reading from the file
Also, as you are taking an arbitrary string as input, you might want to use quotemeta to escape special characters.
if($line =~ /\b\Q$TEMP\E\b/) {
Other nice additions might include three-argument open, indirect file handles, and the strict pragma.
!/usr/bin/perl use strict; use warnings; my $conf_file = 'something'; open(my $in,'<', $conf_file) or die("unable to open $conf_file"); my @lines = <$in>; print @lines; print "Please choose a number from the list above: "; chomp(my $input = <STDIN>); # $input=trim($input); print "Your Choice was: $input \n"; for my $line (@lines) { if ($line =~ /\b\Q$input:\E\b/) { print " exact match: $& \n" ; print " after match: $' \n" ; my $svc = $'; print "ServiceL $svc \n"; } }
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
|
|---|