amoura has asked for the wisdom of the Perl Monks concerning the following question:

Hello folks , my file contain the followings :
user/bla/bli/one.cxx cxx bla hi /bin user/somthing/cxx

well I am trying somehow to only grep the directory bla in the first line and one.cxx file from the first line .

when I do match string , I get stuff like cxxd or scxx , I need only the .cxx file and the dirctory containing that file . can someone help .. thanks

2002-06-25 Edit by Corion Added formatting and moved to Seekers of Perl Wisdom

Replies are listed 'Best First'.
Re: grep string
by kvale (Monsignor) on Jun 25, 2002 at 20:34 UTC
    You could first read in the first line like so:
    open FILE, "<file.txt" or die "Could not open file.txt: $!"; my $line = <FILE>; close FILE;
    I am not sure what you are trying to grep here, but your unwanted matches are due to two reasons: you didn't escape the metacharacter `.' and you probably didn't exclude stuff off the end of the string. Try something like, e.g.,
    $line =~ m|^\Q$path/$file\E$|;
    The ^ and $ make the regexp match just the exact string and nothing else on the line, and the \Q...\E quote any metacharacters in your string.

    -Mark
      thanks dude , it worked ;)