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

Hi,
I have a Perl executable where I pass regexes like below:

 myPerlScript.pl -input_file myInputFile.txt -pats "^atlas\S+/ || /\/world\s+/ || /\nowhere\s+"
the argument given to pat is used to see if an array key is matching any of these three patterns as below. The array key are some strings we collect from the input_file.
.... .... forach my $hashkey (keys %myHash) { if($hashkey !~ /$pat/) { print "no Match $hashkey\n"; } }

what I am seeing is that the array keys that match  atlas, world, or nowhere are also printed out.
I am not able to figure out what my mistake is. Can you help?
many thanks.
Fung Chi Lu

Replies are listed 'Best First'.
Re: regex not working right (m//atching operator)
by Anonymous Monk on Mar 10, 2015 at 03:31 UTC
    You've confused the m//atching operator for a regular expression, a regular expression goes inside the m//atching operator
    ## matching operator $var =~ m{}; $var =~ m//; $var =~ //; ## matching against default variable, against $_ m{}; m//; //;

    So when your program gets the string  "^atlas\S+/ || /\/world\s+/ || /\nowhere\s+" its not a very good regular expression, it has all these extra | and /

Re: regex not working right
by pme (Monsignor) on Mar 10, 2015 at 02:56 UTC
    Hi Fung,

    this one may do the job:

    -pats "(^atlas\S+)|(\/world\s+)|(\/nowhere\s+)"
    I suspect '/' is missing in front of 'nowhere'.