Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Pattern match problem

Reply
Thread Tools

Pattern match problem

 
 
Chris
Guest
Posts: n/a
 
      01-14-2004
I need help in trying to match something from a list. The list
consist of many lines. Once I get the match I want to extract a
number from it (no starting zeros) and place that value in $1 by using
parentheses. Can you help?

Here is an example of the list with as many possible variations I
could think of:

_CCCRM_01 nm7fg.gdf.cfg
_CCCRM_02 n8ehg.ghd.cfg
_CCCRM_10 nmgft.fhe.cfg
_CCCRM_11 cd6ls.ty4.cfg
_CCCRM_12 ntew3.ghe.cfg
_CCCRM_21 dgw42.t3j.cfg

Things that are consistant in the pattern: periods, underscores,
CCCRM, cfg
I need to store in $1 the number from CCCRM. i.e. the 21 from
_CCCRM_21

If there is a 0 in left placement it needs to be dropped.

This is what I thought that works, but doesn't:
_CCCRM_0?(/d+)/b/s/b.+\..+\.cfg

Can you help me?

-Chris
 
Reply With Quote
 
 
 
 
Walter Roberson
Guest
Posts: n/a
 
      01-14-2004
In article < >,
Chris <> wrote:
:I need help in trying to match something from a list.

:This is what I thought that works, but doesn't:
:_CCCRM_0?(/d+)/b/s/b.+\..+\.cfg

\d, \b, \s not /d, /b, /s
--
Aleph sub {Aleph sub null} little, Aleph sub {Aleph sub one} little,
Aleph sub {Aleph sub two} little infinities...
 
Reply With Quote
 
 
 
 
Tore Aursand
Guest
Posts: n/a
 
      01-14-2004
On Tue, 13 Jan 2004 21:34:55 -0800, Chris wrote:
> _CCCRM_01 nm7fg.gdf.cfg
> _CCCRM_02 n8ehg.ghd.cfg
> _CCCRM_10 nmgft.fhe.cfg
> _CCCRM_11 cd6ls.ty4.cfg
> _CCCRM_12 ntew3.ghe.cfg
> _CCCRM_21 dgw42.t3j.cfg
>
> Things that are consistant in the pattern: periods, underscores,
> CCCRM, cfg
> I need to store in $1 the number from CCCRM. i.e. the 21 from
> _CCCRM_21
>
> If there is a 0 in left placement it needs to be dropped.
>
> This is what I thought that works, but doesn't:
> _CCCRM_0?(/d+)/b/s/b.+\..+\.cfg


You escape the wrong way; You should use \d, \b and \s instead of /d, /b
and /s. Anyway;

while ( <DATA> ) {
if ( /^_\w+_(\d+)/ ) {
print int($1) . "\n";
}
}


--
Tore Aursand <>
"What we see depends mainly on what we look for." -- Sir John Lubbock
 
Reply With Quote
 
Chris
Guest
Posts: n/a
 
      01-14-2004
Thanks for your help. I couldn't match it exactly as you said because
\w matches underscores. This is finally what I used:
m/_(\d?\d\d)\b/
$temp = int($1)

-Chris
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple Line Pattern Match problem samuel Perl Misc 7 06-04-2007 02:12 AM
Problem with pattern match neilsolent Perl Misc 3 03-08-2007 08:09 PM
Problem with memory usage in pattern match Niall Macpherson Perl Misc 2 12-09-2005 12:59 PM
pattern match problem Lex Perl Misc 8 06-18-2004 05:06 PM
problem with pattern match Dafke8 Perl Misc 6 05-01-2004 10:26 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57