Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Re: Grep Pattern Match

by LostS (Friar)
on Dec 27, 2002 at 15:26 UTC ( [id://222550]=note: print w/replies, xml ) Need Help??


in reply to Re: Grep Pattern Match
in thread Grep Pattern Match

Would this syntax be correct:
@files = grep {/^nc$year.*\.log$/} @files;
or
@files = grep {/^nc.$year.*\.log$/} @files;
Where the $year is the 2 digit number of the year I am in??

-----------------------
Billy S.
Slinar Hardtail - Hand of Dane
Datal Ephialtes - Guildless
RallosZek.Net Admin/WebMaster

perl -e '$cat = "cat"; if ($cat =~ /\143\x61\x74/) { print "Its a cat! +\n"; } else { print "Thats a dog\n"; } print "\n";'

Replies are listed 'Best First'.
Re: Re: Re: Grep Pattern Match
by BrowserUk (Patriarch) on Dec 27, 2002 at 15:33 UTC

    The former looks right to me, though the easiest way is to check is to try it:)

    Why did you think that you might need the extra '.' in the latter?


    Examine what is said, not who speaks.

      Hummm ok a quiz I guess... put it there cause I saw you put it before the * which made me thing hey myabe I need to seperate the sections with a . first section being the nc then a variable but due to it is s $year I am kind of worried cause you use $ for end of statement... but also figure having that . in front of the $ made it think hey maybe treat $year as a variable... am I close??

      -----------------------
      Billy S.
      Slinar Hardtail - Hand of Dane
      Datal Ephialtes - Guildless
      RallosZek.Net Admin/WebMaster

      perl -e '$cat = "cat"; if ($cat =~ /\143\x61\x74/) { print "Its a cat! +\n"; } else { print "Thats a dog\n"; } print "\n";'

        Ok. In a regex '.' means match any char. (*)

        '*' means zero or more of the preceeding char. (**)

        So '.*' just means any number of any characters. (*)

        If you know for that you only want to match digits, then you would be better using \d* or if you know that there must be at least 2 then \d{2,}.

        There's much to much to lay it all out here and it's already written many places perlre would be a good starting point. It will only take you 20 minutes to read it, and you won't take it all in at one go probably, but once you seen it, you'll probably remember were to look next time.

        (*)(except \n except in special cases which we can ignore for now, but the internet laywers and perlitists may be watching:)

        (**) more correctly, "preceding pattern"


        Examine what is said, not who speaks.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2024-04-25 15:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found