perl problem
hi all.......
i am trying to match a pattern like alphanumeric. example 123. ab3. 73aae. here . should be at the end of the pattern .... $mystring = "hello.World"; if($mystring =~ m/[a-zA-Z0-9]+\. /) { print "Yes"; } this is not working and also how to get the matched pattern in a variable... can anyone please help me... Thanks in advance.... |
put a $ after the \.
|
You just have an extra space between '.' and the final '/', delete it, and your pattern will be right, this may due to your carelessness I think.
BTW, if you use '/' as the delimiter, 'm' before the first '/' is unnecessary. |
Quote:
if($mystring =~ m/[a-zA-Z0-9]+\.$ /) { print "Yes"; } this is what you are telling right... it outputs nothing ..it should print yes if the pattern matches... please help me....... |
Quote:
|
Oh! Sorry, I forgot to answer that question.
You can write your code like this: $mystring = "hello.World"; if ($mystring =~ /([a-zA-Z0-9]+\.)/) { print $1, "\n"; print "Yes"; } and you'll see "hello." on the screen. Notice that I put parentheses around the patten, and every time you do this, Perl will automatically put the matched part of the string into internal variables like $1, $2, ... and there are as many of these variables as pairs of parentheses |
Quote:
|
Just call perldoc perlrequick and perldoc perlretut - it's all there. :)
|
|
Quote:
|
All times are GMT -5. The time now is 10:00 PM. |