develooper Front page | perl.beginners | Postings from February 2009

Making regex's

Thread Next
February 10, 2009 03:28
Making regex's
Message ID:

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/ line ..., near "=~ |"

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

Is that right?

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 |?


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About