I'm completely mystified by this.
In the 3 example code blocks below I'm pushing the same things onto an array.
When I push the result of a failed match, nothing is pushed onto the array (unless I first save the result in a variable).
Why is this?!
Thanks!
use strict; use warnings; my @foo; push @foo, 1; print scalar @foo, "\n"; # output +: 1 push @foo, 'abc' =~ /abc/; print scalar @foo, "\n"; # output +: 2 push @foo, 'abc' =~ /abcd/; print scalar @foo, "\n"; # output +: 2 - nothing added to @foo?! push @foo, ''; print scalar @foo, "\n"; # output +: 3 push @foo, 0; print scalar @foo, "\n"; # output +: 4 push @foo, undef; print scalar @foo, "\n"; # output +: 5 @foo = (); print "\n"; push @foo, (1); print scalar @foo, "\n"; # output +: 1 push @foo, ('abc' =~ /abc/); print scalar @foo, "\n"; # output +: 2 push @foo, ('abc' =~ /abcd/); print scalar @foo, "\n"; # output +: 2 - nothing added to @foo?! push @foo, (''); print scalar @foo, "\n"; # output +: 3 push @foo, (0); print scalar @foo, "\n"; # output +: 4 push @foo, (undef); print scalar @foo, "\n"; # output +: 5 @foo = (); my $bar; print "\n"; $bar = 1; push @foo, $bar; print scalar @foo, "\n"; + # output: 1 $bar = 'abc' =~ /abc/; push @foo, $bar; print scalar @foo, "\n"; + # output: 2 $bar = 'abc' =~ /abcd/; push @foo, $bar; print scalar @foo, "\n"; + # output: 3 - this time its been added to @foo $bar = ''; push @foo, $bar; print scalar @foo, "\n"; + # output: 4 $bar = 0; push @foo, $bar; print scalar @foo, "\n"; + # output: 5 $bar = undef; push @foo, $bar; print scalar @foo, "\n"; + # output: 6
In reply to Result of failed regexp match not pushed onto array by zork42
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |