Regexp to truncate

Discussion in 'Perl' started by Yannick Turgeon, Oct 11, 2003.

  1. Hello all,

    I just started to use perl and I'm having a Regexp question:

    Say we've got a file with this in it:
    ---- Beginning of file after this line --------
    My list
    A: cat
    B: dog
    C: horse
    A: cow
    C: bird
    [...]
    ---- End of file before this line --------

    What I'd like to do is to truncate everything before the animal
    associated with the FIRST occurence of a label. Here with the label "A:"
    I'd like to truncate everything before "cat" (and not before "cow")

    # This truncate the string before "cow"
    $myFileString =~ s/ ^ .* A:\ //sx;

    Anybody can help?

    One more thing. I use the "s" option but I don't undestand it quite well.
    On the net, I've found the following:
    "This option treats the string as a single line."
    in which situation this could be a problem or something we don't want?

    TIA

    Yannick
    Yannick Turgeon, Oct 11, 2003
    #1
    1. Advertising

  2. Answered on another list.
    Yannick Turgeon, Oct 13, 2003
    #2
    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. Eddie
    Replies:
    1
    Views:
    9,660
    Arthur Yousif
    Dec 23, 2003
  2. Replies:
    4
    Views:
    506
    Jack Klein
    Jun 5, 2004
  3. Natevw

    truncate end of file

    Natevw, Nov 3, 2004, in forum: C++
    Replies:
    1
    Views:
    3,162
    Victor Bazarov
    Nov 3, 2004
  4. Amit Kulkarni

    HOW-TO Truncate first line in a file to zero length?

    Amit Kulkarni, Jun 22, 2004, in forum: C Programming
    Replies:
    4
    Views:
    3,645
    dbtid
    Jun 23, 2004
  5. Joao Silva
    Replies:
    16
    Views:
    339
    7stud --
    Aug 21, 2009
Loading...

Share This Page