New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
my() and my show different result in scalar context #1168
Comments
From inyeol@siimage.comCreated by inyeol@siimage.com(my($foo) = $bar) =~ tr/ //d; # wrong answer and (my $foo = $bar) =~ tr/ //d; # correct answer show different results. Since $bar is a scalar variable, Perl Info
|
From [Unknown Contact. See original ticket]On Feb 10, Inyeol Lee said:
(these test are in Perl 5.005_02) This is independent of my: $b = "a b c"; $a = "a b c"; Notice this error message though: $a = "a b c"; $a = "a b c"; Sigh... the left-hand side is being VERY picky. -- |
From @TimToadyjaphy@pobox.com writes: That's a list assignment in scalar context, so it produces the count : ($a = $b) =~ tr/ //d; print $a; # abc Also expected. : $a = "a b c"; The list composer [$a] makes a copy of $a, which the tr/// successfully : Notice this error message though: That could possibly be made to work, but the demand for fancy lvalues : $a = "a b c"; Again, your list composer makes a copy of $a. : Sigh... the left-hand side is being VERY picky. Only with the list slice. The rest are working as designed. Larry |
Migrated from rt.perl.org#2136 (status was 'resolved')
Searchable as RT2136$
The text was updated successfully, but these errors were encountered: