extraction of info from fixed position

Discussion in 'Perl Misc' started by Rose, Feb 16, 2008.

  1. Rose

    Rose Guest

    Instead of specifying in detail (e.g. d+d+...) in a regular expression, is
    it possible to specify some fixed numbers for perl to extract information,
    in this example, S, 95 from line 1; 'space',42 from line2 and 'T',156 from
    line3 in the following 3 lines?

    46 51 V S S- 0 0 95 -2,-0.9 -7,-0.2 -6,-0.2
    2,-0.1 -0.899 75.7-167.1-103.3 112.1 10.3 5.4 11.8
    47 52 E > - 0 0 42 -9,-2.9 3,-1.9 -2,-0.6
    2,-0.2 -0.404 37.9 -78.0 -91.0 165.9 6.6 5.6 11.1
    48 53 K T 3 S+ 0 0 156 1,-0.3 -1,-0.1
    2,-0.2 -10,-0.0 -0.457 122.1 14.4 -66.2 127.7 4.9 5.9 7.7
    Rose, Feb 16, 2008
    #1
    1. Advertising

  2. Rose

    Ben Morrow Guest

    Quoth "Rose" <>:
    > Instead of specifying in detail (e.g. d+d+...) in a regular expression, is
    > it possible to specify some fixed numbers for perl to extract information,
    > in this example, S, 95 from line 1; 'space',42 from line2 and 'T',156 from
    > line3 in the following 3 lines?
    >
    > 46 51 V S S- 0 0 95 -2,-0.9 -7,-0.2 -6,-0.2
    > 2,-0.1 -0.899 75.7-167.1-103.3 112.1 10.3 5.4 11.8


    If I've understood you correctly, that's what substr is for.

    Ben
    Ben Morrow, Feb 16, 2008
    #2
    1. Advertising

  3. Rose

    Rose Guest

    >>
    >> 46 51 V S S- 0 0 95 -2,-0.9 -7,-0.2 -6,-0.2
    >> 2,-0.1 -0.899 75.7-167.1-103.3 112.1 10.3 5.4 11.8

    >
    > If I've understood you correctly, that's what substr is for.
    >
    > Ben
    >


    Yes, Ben. You're right. Thanks. Now I have to think about how to solve the
    problem of recognizing space in the first element (so it remains a space)
    and removing spaces in the 2nd element (so the latter one will be a number
    but not a string).
    Rose, Feb 16, 2008
    #3
  4. Rose

    Ben Morrow Guest

    Quoth "Rose" <>:
    > >>
    > >> 46 51 V S S- 0 0 95 -2,-0.9 -7,-0.2 -6,-0.2
    > >> 2,-0.1 -0.899 75.7-167.1-103.3 112.1 10.3 5.4 11.8

    > >
    > > If I've understood you correctly, that's what substr is for.

    >
    > Yes, Ben. You're right. Thanks. Now I have to think about how to solve the
    > problem of recognizing space in the first element (so it remains a space)
    > and removing spaces in the 2nd element (so the latter one will be a number
    > but not a string).


    Don't worry about it. Perl will strip leading and trailing spaces when
    auto-converting a string to a number:

    ~% perl -wle'print " -100.45 " + 1'
    -99.45

    Ben
    Ben Morrow, Feb 16, 2008
    #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. Leif K-Brooks

    Position:fixed and IE/Win

    Leif K-Brooks, Jul 9, 2003, in forum: HTML
    Replies:
    2
    Views:
    443
    Leif K-Brooks
    Jul 9, 2003
  2. david graham

    position: fixed in IE - how?

    david graham, Sep 12, 2003, in forum: HTML
    Replies:
    2
    Views:
    549
    david graham
    Sep 12, 2003
  3. Replies:
    5
    Views:
    24,728
  4. MaggieMagill

    HTML info extraction utility

    MaggieMagill, Mar 3, 2005, in forum: HTML
    Replies:
    5
    Views:
    364
    Andy Dingley
    Mar 4, 2005
  5. johnp
    Replies:
    4
    Views:
    3,666
    Toby Inkster
    May 23, 2005
Loading...

Share This Page