develooper Front page | perl.perl6.compiler | Postings from July 2010

[perl #62682] Anomolous match behaviour using $_

From:
Will Coleda via RT
Date:
July 27, 2010 18:04
Subject:
[perl #62682] Anomolous match behaviour using $_
Message ID:
rt-3.6.HEAD-11314-1280279051-1309.62682-15-0@perl.org
On Sat Jan 24 00:01:33 2009, richardh wrote:
> $perl6
>  > $_ = 'abc'; m/(a)/ and say "matched $0"
> Use of uninitialized value
> matched
>  > $_ = 'abc'; $_ ~~ m/(a)/ and say "matched $0"
> matched a
>  > $_ = 'abc'; m/x/ and say "matched"
> matched
>  >
> 
> Not quite sure what is going on here.
> 
> I understood that a bare match should be against $_.
> 
> But no match was made in first code line with a bare match.
> In second code line, match is explicitly against $_ and the match occurs 
> as expected.
> 
> However, in first line, even though no match was made, m// returned true
> Also in third code line a bare match yielded a true result.
> 
> 

Slight improvement:

$ ./perl6 
> $_ = 'abc'; m/(a)/ and say "matched $0"
matched a
> $_ = 'abc'; $_ ~~ m/(a)/ and say "matched $0"
matched a
> $_ = 'abc'; m/x/ and say "matched"
_block174




-- 
Will "Coke" Coleda



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