perlDevsWorld has asked for the wisdom of the Perl Monks concerning the following question:
I'm running into issue while reading a file and matching the pattern
File content ============ 1: Recturing Svc 2: Finance : : 9: Payments : : 19: Mobile : : 29: Bankers
My Code looks like this
open(INPUTFILE,"<$conf_file") or die("unable to open text file"); foreach (<INPUTFILE>) { print "$_"; } close INPUTFILE ; print "Please choose a number from the list above: "; chop($input=<STDIN>); $input=trim($input); print "Your Choice was: $input \n"; $TEMP="$input:"; open(INPUTFILE,"<$conf_file") or die("unable to open text file for com +parision"); foreach $line(<INPUTFILE>) { if($line =~ /$TEMP/) { print " exact match: $& \n" ; print " after match: $' \n" ; $svc = $'; print "ServiceL $svc \n"; } } close INPUTFILE ;
As said it is matching multiple ones for example 9: and 19: and 29: when I select i.e. enter 9
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: pattern string match while reading from the file
by kennethk (Abbot) on Apr 09, 2015 at 19:45 UTC | |
|
Re: pattern string match while reading from the file
by AnomalousMonk (Archbishop) on Apr 09, 2015 at 21:03 UTC | |
by Laurent_R (Canon) on Apr 10, 2015 at 17:50 UTC | |
|
Re: pattern string match while reading from the file
by pme (Monsignor) on Apr 09, 2015 at 19:15 UTC | |
|
Re: pattern string match while reading from the file
by CountZero (Bishop) on Apr 09, 2015 at 20:30 UTC | |
|
Re: pattern string match while reading from the file
by hdb (Monsignor) on Apr 09, 2015 at 20:18 UTC | |
|
Re: pattern string match while reading from the file
by gpapkala (Acolyte) on Apr 09, 2015 at 20:03 UTC |