By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,773 Members | 1,710 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,773 IT Pros & Developers. It's quick & easy.


P: 36
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.     {    
  6.         if ($val =~ /\Q$patternph\E/)
  7.         {
  8.             $phcount++;
  9.         }elsif($val =~ /\Q$patternsip\E/)
  10.         {
  11.             $sicount++;                
  12.         }
  14.     }
@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
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
Share this Question
Share on Google+
3 Replies

Expert Mod 2.5K+
P: 3,503
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.


Jul 23 '08 #2

Expert 100+
P: 410
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

Expert 2.5K+
P: 4,059
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.