matching ??

Discussion in 'Perl Misc' started by Tim, Oct 24, 2003.

  1. Tim

    Tim Guest

    data: s1 s2 s3 0.900 0.890 0.588
    data2: s1 s2 s3 2.900F 1.890F 0.888
    data3: s1 s2 s3 1.900F 6.890F 0.388F

    My ReqX:
    I would like to store the data in @name using the expression below:
    @name = m/(\d+\.\d+)/g;
    however, It does not ALWAYS work because for this case

    data2: s1 s2 s3 2.900F 1.890F 0.888
    $name[0] = 2.900 but I want $name[0] = 2.900F
    $name[1] = 1.890 but I want $name[1] = 1.890F
    $name[2] = 0.888

    Please help.
    Tim, Oct 24, 2003
    #1
    1. Advertising

  2. In article <>, Tim wrote:
    > data: s1 s2 s3 0.900 0.890 0.588
    > data2: s1 s2 s3 2.900F 1.890F 0.888
    > data3: s1 s2 s3 1.900F 6.890F 0.388F
    >
    > My ReqX:
    > I would like to store the data in @name using the expression below:
    > @name = m/(\d+\.\d+)/g;

    [cut]

    What about

    @name = m/(\d+\.\d+F?)/g;

    or maybe

    @name = m/(\d+\.\d+\w?)/g;

    --
    Andreas Kähäri
    Andreas Kahari, Oct 24, 2003
    #2
    1. Advertising

  3. Tim

    J. Gleixner Guest

    Bernard El-Hagin wrote:
    > (Tim) wrote in news:21724be2.0310240043.3fdf1120
    > @posting.google.com:
    >
    >
    >>data: s1 s2 s3 0.900 0.890 0.588
    >>data2: s1 s2 s3 2.900F 1.890F 0.888
    >>data3: s1 s2 s3 1.900F 6.890F 0.388F
    >>
    >>My ReqX:
    >>I would like to store the data in @name using the expression below:
    >>@name = m/(\d+\.\d+)/g;
    >>however, It does not ALWAYS work because for this case
    >>
    >>data2: s1 s2 s3 2.900F 1.890F 0.888
    >>$name[0] = 2.900 but I want $name[0] = 2.900F
    >>$name[1] = 1.890 but I want $name[1] = 1.890F
    >>$name[2] = 0.888
    >>
    >>Please help.


    Since it appears you want to capture the value in the columns 4-6, why
    not use split?

    $_ = '1 s2 s3 1.900F 6.890F 0.388F';
    my (@name) = (split)[3,4,5];
    print "@name\n";
    1.900F 6.890F 0.388F
    J. Gleixner, Oct 24, 2003
    #3
  4. Tim

    Tore Aursand Guest

    On Fri, 24 Oct 2003 01:43:10 -0700, Tim wrote:
    > data: s1 s2 s3 0.900 0.890 0.588
    > data2: s1 s2 s3 2.900F 1.890F 0.888
    > data3: s1 s2 s3 1.900F 6.890F 0.388F
    >
    > My ReqX:
    > I would like to store the data in @name using the expression below:
    > @name = m/(\d+\.\d+)/g;
    > however, It does not ALWAYS work because for this case
    >
    > data2: s1 s2 s3 2.900F 1.890F 0.888
    > $name[0] = 2.900 but I want $name[0] = 2.900F
    > $name[1] = 1.890 but I want $name[1] = 1.890F
    > $name[2] = 0.888


    Why bother using regular expression to do something this simple? split()
    would do, wouldn't it?

    my @data = ();
    while ( <DATA> ) {
    chomp;
    my @tmp = split( /\s+/ );
    push( @data, $tmp[4] );
    push( @data, $tmp[5] );
    push( @data, $tmp[6] );
    }

    No problem substituting the three push() calls with only one.


    --
    Tore Aursand <>
    Tore Aursand, Oct 25, 2003
    #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. Seth
    Replies:
    1
    Views:
    1,066
    Ray Andraka
    Aug 1, 2003
  2. DelphiDude
    Replies:
    3
    Views:
    1,161
  3. Eric A. Hall

    weird matching problems

    Eric A. Hall, Jul 24, 2003, in forum: Perl
    Replies:
    0
    Views:
    970
    Eric A. Hall
    Jul 24, 2003
  4. Marc Bissonnette

    Pattern matching : not matching problem

    Marc Bissonnette, Jan 8, 2004, in forum: Perl Misc
    Replies:
    9
    Views:
    220
    Marc Bissonnette
    Jan 13, 2004
  5. Bobby Chamness
    Replies:
    2
    Views:
    215
    Xicheng Jia
    May 3, 2007
Loading...

Share This Page