using Perl to find string..

Discussion in 'Perl Misc' started by seanjao@yahoo.com, Dec 18, 2006.

  1. Guest

    Hi there:

    I would like to use Perl to search a file containing data like the
    following.
    aaa01234 99.99 99.99 99.99
    bb0567 99.99 99.99 99.99
    ccccc89101 99.99 99.99 99.99

    How can I let perl to match the first column if I type "bb567" without
    the zero between "bb" and "567"?

    Thanks
    Sean
     
    , Dec 18, 2006
    #1
    1. Advertising

  2. Dr.Ruud Guest

    Glenn Jackman schreef:

    > if (/^$wanted\b/) {


    Safer:
    if (/^\Q$wanted\E\b/) {

    --
    Affijn, Ruud

    "Gewoon is een tijger."
     
    Dr.Ruud, Dec 19, 2006
    #2
    1. Advertising

  3. Glenn Jackman wrote:
    > At 2006-12-18 03:21PM, "" wrote:
    >
    >> Hi there:
    >>
    >> I would like to use Perl to search a file containing data like the
    >> following.
    >> aaa01234 99.99 99.99 99.99
    >> bb0567 99.99 99.99 99.99
    >> ccccc89101 99.99 99.99 99.99
    >>
    >> How can I let perl to match the first column if I type "bb567" without
    >> the zero between "bb" and "567"?

    >
    >
    > Based on these requirements:
    >
    > my $wanted = 'bb567';
    >
    > while (<DATA>) {
    > if (/^$wanted\b/) {
    > print 'exact match >> ';
    > }
    > elsif (/^([a-z]+)0+(\d+)/ and $wanted eq "$1$2") {


    Based on the requirements "without *the* zero", that would be
    elsif (/^([a-z]+)0?(\d+)/ and $wanted eq "$1$2") {

    Personally, I would have made that
    elsif (/^([a-z]+)0*(\d+)/ and $wanted eq "$1$2")

    Josef
    --
    Josef Möllers (Pinguinpfleger bei FSC)
    If failure had no penalty success would not be a prize
    -- T. Pratchett
     
    Josef Moellers, Dec 19, 2006
    #3
  4. Guest

    Thanks guys!
    It helps.

    Sean
     
    , Dec 19, 2006
    #4
  5. wrote:
    > Thanks guys!


    For what?

    > It helps.


    What helps?

    Please quote whatever you are replying to!

    Thank you,

    Josef

    NB Please quote, but don't top-post.
    --
    Josef Möllers (Pinguinpfleger bei FSC)
    If failure had no penalty success would not be a prize
    -- T. Pratchett
     
    Josef Moellers, Dec 20, 2006
    #5
  6. Guest

    Josef Moellers wrote:
    > wrote:
    > > Thanks guys!

    >
    > For what?
    >
    > > It helps.

    >
    > What helps?
    >
    > Please quote whatever you are replying to!
    >
    > Thank you,
    >
    > Josef
    >

    Hey Josef:

    I think I am polite enough to express my appreciaton to all the
    thoughts I got.
    Of course, including your thought.
    Why do I need to specifically to quote anything?
    Think about it, man.

    > > Thanks guys!
    > >

    > For what?

    For their time and efforts to help someone he/she does not know.
    Understand?

    Sean
     
    , Jan 4, 2007
    #6
  7. Paul Lalli Guest

    wrote:
    > Josef Moellers wrote:
    > > wrote:
    > > > Thanks guys!

    > >
    > > For what?
    > >
    > > > It helps.

    > >
    > > What helps?
    > >
    > > Please quote whatever you are replying to!
    > >
    > > Thank you,
    > >
    > > Josef
    > >

    > Hey Josef:
    >
    > I think I am polite enough


    .... there's some irony...

    > to express my appreciaton to all the thoughts I got.
    > Of course, including your thought.
    > Why do I need to specifically to quote anything?
    > Think about it, man.


    Please do some thinking of your own. Not everyone reads a newsgroup
    with threadding enabled. Even those of us who do are not guaranteed to
    have seen the post to which you are replying. It's entirely possible
    that your "thanks" showed up before the posts to which you're replying,
    or that the posts to which you're replying simply never showed up at
    all. That's how Usenet works. And that's why it's been standard
    convention to quote material to which you're replying for *decades*.

    Please do a bit of reasearch into what you're talking about before
    accusing someone far more familiar with the medium of not thinking.

    Paul Lalli
     
    Paul Lalli, Jan 4, 2007
    #7
  8. Guest


    > And that's why it's been standard
    > convention to quote material to which you're replying for *decades*.


    If so, please let an experienced user, like you to show me how to
    express my appreciation
    to all of the thoughts posted for this topic.

    Thank you.
    Sean Jao
     
    , Jan 4, 2007
    #8
  9. Ted Zlatanov Guest

    On 4 Jan 2007, wrote:

    >> And that's why it's been standard
    >> convention to quote material to which you're replying for *decades*.

    >
    > If so, please let an experienced user, like you to show me how to
    > express my appreciation to all of the thoughts posted for this
    > topic.


    Next time you reply with "thanks" make sure to quote enough so that a
    random person could look at your message by itself and understand
    what's happening. Welcome to comp.lang.perl.misc :)

    Ted
     
    Ted Zlatanov, Jan 5, 2007
    #9
    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. korean_dave
    Replies:
    2
    Views:
    325
    John Machin
    Jun 17, 2008
  2. petry

    std::string::find vs std::find

    petry, Jul 5, 2009, in forum: C Programming
    Replies:
    1
    Views:
    358
    petry
    Jul 5, 2009
  3. Wybo Dekker
    Replies:
    1
    Views:
    388
    Yukihiro Matsumoto
    Nov 15, 2005
  4. vdvorkin
    Replies:
    0
    Views:
    433
    vdvorkin
    Feb 10, 2011
  5. vdvorkin
    Replies:
    3
    Views:
    846
    vdvorkin
    Feb 14, 2011
Loading...

Share This Page