Pattern matching in perl

Discussion in 'Perl Misc' started by praveen.kantharajapura@gmail.com, Aug 10, 2006.

  1. Guest

    Hi all,

    I have a file now i need to search for two strings "string1" and
    "string2" in the same line.If both of them occur in the same line
    increment a counter else do not.

    How to go about doing this in perl??

    Regards,
    Praveen
     
    , Aug 10, 2006
    #1
    1. Advertising

  2. wrote:
    > Hi all,
    >
    > I have a file now i need to search for two strings "string1" and
    > "string2" in the same line.If both of them occur in the same line
    > increment a counter else do not.
    >
    > How to go about doing this in perl??


    Try it?

    --
    Josef Möllers (Pinguinpfleger bei FSC)
    If failure had no penalty success would not be a prize
    -- T. Pratchett
     
    Josef Moellers, Aug 10, 2006
    #2
    1. Advertising

  3. <> wrote:

    > I have a file



    perldoc -f open


    > now i need to search for two strings "string1" and
    > "string2" in the same line.



    You would write a pattern match to do that.

    perldoc -f m


    > If both of them occur in the same line



    See the && operator, also in perlop.pod.


    > increment a counter else do not.



    $counter++;


    > How to go about doing this in perl??



    See above.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Aug 10, 2006
    #3
  4. wrote:
    > I have a file now i need to search for two strings "string1" and
    > "string2" in the same line.If both of them occur in the same line
    > increment a counter else do not.
    >
    > How to go about doing this in perl??


    Which part is the problem?
    - the check if a string is contained in another string? See 'perldoc -f
    index'
    - to combine two conditions? See 'perldoc perlop', operator 'and'
    - to create a if clause? See 'perldoc perlsyn', and then the if
    statement in section compound statements
    - to increment a counter? See 'perldoc perlop', operator +=
    - to do nothing? Well, ....

    jue
     
    Jürgen Exner, Aug 10, 2006
    #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. seema

    perl pattern matching

    seema, Mar 12, 2005, in forum: Perl
    Replies:
    1
    Views:
    753
    Bob Walton
    Mar 12, 2005
  2. Xah Lee
    Replies:
    9
    Views:
    878
    Chris Smith
    Feb 2, 2005
  3. Xah Lee
    Replies:
    4
    Views:
    637
    Aaron Sherman
    Feb 11, 2005
  4. Marc Bissonnette

    Pattern matching : not matching problem

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

Share This Page