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

Making regex's

Thread Next
From:
Dermot
Date:
February 10, 2009 03:28
Subject:
Making regex's
Message ID:
9c7446e70902100328h397053dci3cc2db6d3732e9b2@mail.gmail.com
Hi,

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?

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

Thanx,
Dp.

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About