Regx

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jain236
    New Member
    • Jul 2007
    • 36

    Regx

    Hi all

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

    here is the code
    Code:
    $ver = 1.92 (i get it dynamically)
     my $patternph = 'Configuration file '. "\"phone1\.cfg\"" ." is from template phone1\.cfg, revision "."$phver" ;
    foreach my $val (@output)
    	{	
    		
    		if ($val =~ /\Q$patternph\E/)
    		{
    			$phcount++;
    		}elsif($val =~ /\Q$patternsip\E/)
    		{
    			$sicount++;				
    		}
    		
    	}
    @output contains lot of data the in which i am looking is as follows
    Code:
     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?
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    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

    Comment

    • nithinpes
      Recognized Expert Contributor
      • Dec 2007
      • 410

      #3
      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.

      Comment

      • KevinADC
        Recognized Expert Specialist
        • Jan 2007
        • 4092

        #4
        side note, use quoting operators to make your perl code more readable, instead of this monstrosity of a construct:

        Code:
        my $patternph = 'Configuration file '. "\"phone1\.cfg\"" ." is from template phone1\.cfg, revision "."$phver" ;
        You can do this:

        Code:
        my $patternph = qq{Configuration file "phone1.cfg" is from template phone1.cfg, revision $ver} ;
        perldoc: Quote Like Operators

        Comment

        Working...