473,406 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Regx

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.     {    
  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
3 1192
numberwhun
3,509 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
410 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
4,059 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

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

Similar topics

4
by: McKirahan | last post by:
How would I use a regular expression to remove all trailing Carriage Returns and Line Feeds (%0D%0A) from a textarea's value? Thanks in advance. Also, are they any great references for learning...
1
by: Glenn Wilson | last post by:
Can anyone help me with a regx to match the values 1 to 6. No these could come in several formats and we only want matches where there is a single number with no other numbers next to it in the...
1
by: Jake Barnes | last post by:
This was working for me, and now it isn't, and I can't remember what i changed - the idea was to imitate the PHP command nl2br, which takes newlines and turns them into newlines plus BR tags. Does...
2
by: dongdong | last post by:
for example: re.sub('<a( +)+\s?>*</a>','',' asd ga<a target="_blank" href="http://www.sine.com" class="wordstyle"> asdgasdghae rha</a>') I wish to get the return value "asd ga asdgasdghae...
2
by: Holger | last post by:
I needed a tool for extracting patches from CVS based on the log messages. I.e. we mark our fixes and features with a "Bugdb XYZ" And sometimes you need to move a fix/feature to another branch or...
4
by: oldyork90 | last post by:
If we toss this in a global area, is it compiled just once one the js file is included in the new page? var re = //o Thank you.
3
by: Cain | last post by:
A very simple regular expression test: var regx = /^\d+$/g; alert(regx.test("11") + ": " + regx.test("11")); And the output is "true: false". If I change to regx = new RegExp("^\\d+$",...
0
by: scsoce | last post by:
MRAB wrote: Yes, you are right, but this way findall() capture only the 'top' group. What I really need to do is to capture nested and repated patterns, say, <tabletag in html contains many <tr>, ...
1
by: jain236 | last post by:
Hi i am trying to write regx for the time format HH:MM:SS in the below way /\d:\d0:\d/ but i could not get the desired output, can some one throw some light why and where it is going wrong?...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.