Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Re: GREP Question

by suaveant (Parson)
on Apr 23, 2001 at 17:46 UTC ( [id://74711]=note: print w/replies, xml ) Need Help??


in reply to Re: GREP Question
in thread GREP Question

It will almost work, but you need a comma...
grep /\[1\]/, filename;
Update voted down? Why? ok, it should probably be @filename, but I just copied it, you do need the comma.
                - Ant

Replies are listed 'Best First'.
Re: Re: Re: GREP Question
by ChemBoy (Priest) on Apr 23, 2001 at 19:54 UTC

    Probably the downvote because, as indicated (albeit somewhat indirectly), the response concerns unix grep(1), not perl grep, so the comma is not needed. Were it to be in perl, and had the file been read into an array using @file = <>, then grep /\[l\]/, @file would be correct, but from the command line, it ain't.

    However, the original response is also wrong: since we're on the command line, the slashes are read as part of the regular expression, not as a pattern delimiter, so what you actually want is either

    #!/usr/bin/perl open FH, "filename" or die "couldn't open file.\n"; @filename = <>; print grep /\[l\]/,@filename;
    or (note single quotes)
    % grep '\[l\]' filename
    You will note which of them is simpler.

    If God had meant us to fly, he would *never* have give us the railroads.
        --Michael Flanders

Log In?
Username:
Password:

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

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

    No recent polls found