[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Question on Perl regular expression

Posted on 2006-03-22
3
Medium Priority
?
361 Views
Last Modified: 2010-04-17
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;
 }
0
Comment
Question by:AlexKhaw
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
thenonymous earned 2000 total points
ID: 16266508
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
 

Author Comment

by:AlexKhaw
ID: 16278253
Thanks it's working as required!!!
0
 
LVL 1

Expert Comment

by:thenonymous
ID: 16280896
No problem. :)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Introduction to Processes

826 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question