Dermot wrote:
Hi,

Hello,

I just hit something that I hadn't noticed before and I am not sure
it's it's a syntax issue or I have not been doing my reading.

I am trying to create a regex to match a directory name in path string

  my $dir = dirname(shift);
  (my $code) = ($dir =~ m|track.(\w{3}).|);
  return $code;

I thought I'd use | as a delimiter rather than the more conventional /
. The regex without the 'm' gives an error:
syntax error at script/import.pl line ..., near "=~ |"

So this appears to be incorrect:
$dir =~ |track.(\w{3}).|

Is that right?

Yes. With the exception of // and ?? the match operator has to start with an 'm'.

Also when you are using other delimiters, like |, do I no longer have
to stop escaping my slash charaters / but now need to escape my new
delimiting character EG |?

Yes, you should try to use a delimiter that is not a part of the pattern, and especially not regular expression metacharacters like |.




John
--
Those people who think they know everything are a great
annoyance to those of us who do.        -- Isaac Asimov

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to