Pattern match problem

Discussion in 'Perl Misc' started by Chris, Jan 14, 2004.

  1. Chris

    Chris Guest

    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
     
    Chris, Jan 14, 2004
    #1
    1. Advertising

  2. 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...
     
    Walter Roberson, Jan 14, 2004
    #2
    1. Advertising

  3. Chris

    Tore Aursand Guest

    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
     
    Tore Aursand, Jan 14, 2004
    #3
  4. Chris

    Chris Guest

    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
     
    Chris, Jan 14, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dafke8

    problem with pattern match

    Dafke8, Apr 30, 2004, in forum: Perl Misc
    Replies:
    6
    Views:
    93
    Dafke8
    May 1, 2004
  2. Lex

    pattern match problem

    Lex, Jun 17, 2004, in forum: Perl Misc
    Replies:
    8
    Views:
    132
  3. Niall Macpherson

    Problem with memory usage in pattern match

    Niall Macpherson, Dec 5, 2005, in forum: Perl Misc
    Replies:
    2
    Views:
    187
    Anno Siegel
    Dec 9, 2005
  4. neilsolent

    Problem with pattern match

    neilsolent, Mar 8, 2007, in forum: Perl Misc
    Replies:
    3
    Views:
    90
    Mumia W.
    Mar 8, 2007
  5. samuel

    Multiple Line Pattern Match problem

    samuel, May 31, 2007, in forum: Perl Misc
    Replies:
    7
    Views:
    147
    samuel
    Jun 4, 2007
Loading...

Share This Page