Pattern match problem

C

Chris

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
 
W

Walter Roberson

: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
 
T

Tore Aursand

_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";
}
}
 
C

Chris

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,539
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top