CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Weird problem

 



ggnagarkar
New User

Apr 11, 2008, 3:55 AM

Post #1 of 2 (600 views)
Weird problem Can't Post

I am trying the below script in an eval. It works fine for a long time (6-7) days and then all of a sudden it fails to behave as expected... it goes into the else part. Not able to find any reason/solution. Please help.

my $val = "[1234567] SERVICE";

my $ivalue = "/^\[(.*)\]\sSERVICE$/";

my @fields = ($val =~ \$ivalue\)

if(@fields){ print "Success"}

else { print "Failed"}

---------------------

Regards

GG

(This post was edited by ggnagarkar on Apr 11, 2008, 3:58 AM)


KevinR
Veteran


Apr 11, 2008, 2:47 PM

Post #2 of 2 (594 views)
Re: [ggnagarkar] Weird problem [In reply to] Can't Post

I have no idea why the code would work and then not work, it sure would not work as you posted it because at minimum the third line of code has no semi-colon on the end. I would also change the backslashes in the regexp to forward slashes as that just seems like a bad idea. So correcting the code to this:


Code
my $val = "[1234567] SERVICE"; 

my $ivalue = "/^\[(.*)\]\sSERVICE$/";

my @fields = ($val =~ /$ivalue/);

if(@fields){ print "Success"}

else { print "Failed"}


I now get:

Unrecognized escape \s passed through at test.pl line 3. test.pl syntax OK

which is this line:

my $ivalue = "/^\[(.*)\]\sSERVICE$/";

the \s is not a valid meta sequence in a double-quoted string like it is in a regexp. What ytou really want to do is use the qr operator to quote the regexp, here is the corrected code:


Code
my $val = "[1234567] SERVICE"; 

my $ivalue = qr{^\[(.*)\]\sSERVICE$};

my @fields = ($val =~ /$ivalue/);

if(@fields){ print "Success: @fields"}

else { print "Failed"}

-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives