Question on Perl regular expression

Hi Experts,
I'm trying to do is - The program will prompt for enter string and user will enter string. After that it will compare the inputed string with the contain in 'str.tbl'.
'str.tbl' contains list of charather with numbers. The program will exit if the inputed chrather/numbers matches with the contain in 'str.tbl'.

The problem i'm having is this coding does not recognise charathers... it only recognise number...

ex:
'str.tbl' contain
wn7892
dk654
42893
890211
q35672
s123


The coding can only recognise "890211" and "42893".

Any suggestion on the right regular expression to make all contain in 'str.tbl' to be recognised by this program?




#!/usr/local/bin/perl -w

$str = "";
$file = "strfile.bat";

while ()
 {
  print 'Enter String : ';
  ($str = <STDIN>);
 
open(F, "str.tbl") || die "can't open str.tbl $!";
   while(<F>)
   {
   if((/^$str/) && ($str != ""))
      {
        print "Creating String\n";
        open(SRC, ">$file") || die "Unable to open strfile.bat: ($!)\n";
           print SRC "set string=$str\n";
          close(SRC);
      }
   }
   close F;


  last;
 }
AlexKhawAsked:
Who is Participating?
 
thenonymousCommented:
I do not know much Perl, so I am not really sure, but I think this should solve the problem.

Remember that, in the second inner condition, you are comparing strings, so instead of:

> if((/^$str/) && ($str != ""))

use

> if ((/^$str$/) && !($str =~ /^$/))

Hope this helps. :)
0
 
AlexKhawAuthor Commented:
Thanks it's working as required!!!
0
 
thenonymousCommented:
No problem. :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.