homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

groups perl pattern matching question

 3:10 pm on Aug 11, 2009 (gmt 0)


I have the code below. I also am thankful someone in this forum told me about expresso so I can build regular expressions quite easily. Unfortunately, some things don't move over to perl without issue. I saw some example code that said what I'm doing is possible in perl, but when I write it, it doesn't give me what I want. I'm just trying to get the results of the first matched group in the code below as $1 but it's not doing it. There must be a simple explanation but I can't see it.

#!/usr/bin/perl -w

my $msline ="";
my $dataline ="";
my $msnumtext ="MSNumbers=";

$msline = "<TD CLASS=\"shared\"><a href=http://www.mydomain.com/aac/index.php?Action=sm_hot&amp;MSNumbers=316030>316030</a></TD>";

if ($msline =~ /$msnumtext(\d)+/) {
print "Msline is: $msline\n";
$dataline = $1;
print "Dataline value is: $dataline \n";
print "msnumtext is: $msnumtext \n";

What I'm trying to accomplish here is simply to get the digits after the MSNumbers= so in this example it would be "316030"

Thanks in advance.



 6:33 pm on Aug 11, 2009 (gmt 0)

it's not doing it

what result are you getting?
have you checked any of the Perl Regular Expressions resources linked in the Perl Server Side CGI Scripting forum Charter [webmasterworld.com]?


 7:28 pm on Aug 11, 2009 (gmt 0)

From my previous post: "I saw some sample code..." --> not from the reference you suggested, but now, yes, here is a snippet from the reference you suggested which is basically telling me the same thing from the example I was looking at elsewhere. So I take it you are saying that my code looks good and you don't see a problem with it?

Example doing basically the same thing from the link reference you gave:
1. $x = "cat dog house"; # 3 words
2. while ($x =~ /(\w+)/g) {
3. print "Word is $1, ends at position ", pos $x, "\n";
4. }

What is the result I'm getting? Right here:

Msline is: <TD CLASS="shared"><a href=http://www.mydomain.com/aac/index.php?Action=sm_hot&amp;MSNumbers=316030>316030</a></TD>
Dataline value is: 0
msnumtext is: MSNumbers=

So...value is zero. I would think the value would be 316030

Anyone else who may know why I'm getting zero instead of 316030?


 10:19 pm on Aug 11, 2009 (gmt 0)

In the first code you posted all you need do is move the + quantifier to inside the parentheses:



 11:25 pm on Aug 11, 2009 (gmt 0)

No way. That was it. Thanks perl_diver. You're the man.


 5:08 am on Aug 12, 2009 (gmt 0)

Yes way ;)

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved