On Aug 13, 2004, at 9:16 PM, John W. Krahn wrote:

[EMAIL PROTECTED] wrote:
Can someone please tell me, why
my $pattern = /stuff/;

That is short for:

my $pattern = $_ =~ m/stuff/;

Which assigns 1 to $pattern if the match succeeded or
'' if it failed.


$x =~ $pattern;

Which means that this is either:

$x =~ /1/;

Or:

$x =~ //;


or
my $pattern = "/stuff/";

Here you include the '/' character in the pattern which is probably not present in the string you are matching.


$x =~ $pattern;

So this becomes:

$x =~ /\/stuff\//;


don't work the same as
$x =~ /stuff/;

You need to either store the pattern in a string or use the qr operator.

my $pattern = 'stuff';

my $pattern = qr/stuff/;

I see - I don't need the /s in conjunction w/ a variable.

my $pattern = "stuff";
$x =~ $pattern;

works.

Thank you very much for your explanation!

Jack


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to