Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: grep command

by ferreira (Chaplain)
on Jan 18, 2007 at 14:01 UTC ( [id://595256]=note: print w/replies, xml ) Need Help??


in reply to Re: grep command
in thread grep command

That's the simple modification I told about:

And to answer kyle at Re^2: grep command, my interpretation was that he was concerned about how many times the word happened with no concern for which particular lines. But then he tells about grepping — so if the issue is finding the lines and then telling how many times it appeared in total, this one may work:

Replies are listed 'Best First'.
Re^3: grep command
by ww (Archbishop) on Jan 18, 2007 at 16:47 UTC
    Almost!

    However, the last line in which "hello" is found is printed twice.

    CLI: perl -n -e "print, $count++ while /\bhello\b/g; END { print $count }" hello.out
            (quotes revised for windows)

    file hello.txt:
    hello. hellow, world. bye
    world says hello.
    bye
    hello, hellow, hello
    not now.
    done.

    output
    hello. hellow, world. bye
    world says hello.
    hello, hellow, hello
    hello, hellow, hello
    4

Re^3: grep command
by Tux (Canon) on Jan 18, 2007 at 14:12 UTC
    I don't see it as a *simple* spoiler, as people quite often try it in scalar context like

    $cnt += m{pattern}g;

    which doesn't work as they expect.

    Enjoy, Have FUN! H.Merijn
      I don't see it as a *simple* spoiler, as people quite often try it in scalar context like
      $cnt += m{pattern}g;

      But then the usual workaround is

      $cnt += () = m{pattern}g;

      which is somewhat simpler and more natural than your reference-and-dereference trick.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://595256]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2024-04-20 11:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found