in reply to Grep Pattern Match

Try this. It could be made more specific if the rest of the characters are always digits, but I've stuck to your written description of requirements.

@matched = grep /^nc\d\d.*\.log$/, @files

Examine what is said, not who speaks.

Replies are listed 'Best First'.
Re: Re: Grep Pattern Match
by LostS (Friar) on Dec 27, 2002 at 15:26 UTC
    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";'

      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";'
Re: Re: Grep Pattern Match
by LostS (Friar) on Dec 27, 2002 at 15:46 UTC
    Thank you... Your nudge got me in the right direction. here is the code I am using: @files = grep {/^nc$digyear$digmon.*\.log$/} @files; Works like a charm :)

    -----------------------
    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";'

        Slightly dangerous if the application calls for using the regex in a loop where one of the variables (eg. $month) changes, as unless the qr// is also inside the loop (in which case the optimisation benefits are lost), as the changing value of the variable won't be recognised.


        Examine what is said, not who speaks.