467,179 Members | 1,299 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,179 developers. It's quick & easy.

Regx

Hi all

i am facing problem in the regex when is substitute a variable in the text.

here is the code
Expand|Select|Wrap|Line Numbers
  1. $ver = 1.92 (i get it dynamically)
  2.  my $patternph = 'Configuration file '. "\"phone1\.cfg\"" ." is from template phone1\.cfg, revision "."$phver" ;
  3. foreach my $val (@output)
  4.     {    
  5.  
  6.         if ($val =~ /\Q$patternph\E/)
  7.         {
  8.             $phcount++;
  9.         }elsif($val =~ /\Q$patternsip\E/)
  10.         {
  11.             $sicount++;                
  12.         }
  13.  
  14.     }
  15.  
@output contains lot of data the in which i am looking is as follows
Expand|Select|Wrap|Line Numbers
  1.  69|0723111807|cfg  |*|02|Prm|Configuration file "phone1.cfg" is from template phone1.cfg, revision 1.92
  2.  
  3.  
i am not why it is failing, if i dont append the $phver in the last then it is finding.

can some one help in this regards?
Jul 23 '08 #1
  • viewed: 976
Share:
3 Replies
numberwhun
Expert Mod 2GB
Have you tried removing the double quotes from around $phver and see if that works?

I would make sure that the variable $patternph is getting set right by testing it with print statements so you can see it.

Regards,

Jeff
Jul 23 '08 #2
nithinpes
Expert 256MB
You have assigned the version number to $ver variable, why have you used $phver in your pattern?
Also, if you are getting $ver dynamically from file or through STDIN, do remember to strip newline using chomp.
Apart from that, I don't see anything wrong in th regex.
Jul 23 '08 #3
KevinADC
Expert 2GB
side note, use quoting operators to make your perl code more readable, instead of this monstrosity of a construct:

Expand|Select|Wrap|Line Numbers
  1. my $patternph = 'Configuration file '. "\"phone1\.cfg\"" ." is from template phone1\.cfg, revision "."$phver" ;
You can do this:

Expand|Select|Wrap|Line Numbers
  1. my $patternph = qq{Configuration file "phone1.cfg" is from template phone1.cfg, revision $ver} ;
perldoc: Quote Like Operators
Jul 23 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Glenn Wilson | last post: by
2 posts views Thread by Holger | last post: by
4 posts views Thread by oldyork90 | last post: by
1 post views Thread by jain236 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.