in reply to Re^3: Possible bug with array pointer
in thread Possible bug with array pointer

Thanks. That I actually knew, but in my opinion it's more clear to read when using braces.

And in the real world case where I was hit by this unknown "oddity" the code looked like this, before the change.

foreach my $var (@{$self->get('SAMPLEIDS')}) { $var =~ s/_//g; push(@temp_SAMPLEIDS, $var); }

Replies are listed 'Best First'.
Re^5: Possible bug with array pointer
by haukex (Archbishop) on Jan 11, 2017 at 14:57 UTC

    Hi jockel,

    If you've got Perl v5.14 or later, note that there's also s///r:

    use 5.014; my $sampleids = ['A','_B','C']; my @temp_SAMPLEIDS; foreach my $var (@$sampleids) { push(@temp_SAMPLEIDS, $var =~ s/_//gr); } # OR my @temp2_SAMPLEIDS = map {s/_//gr} @$sampleids; use Data::Dumper; print Dumper($sampleids, \@temp_SAMPLEIDS, \@temp2_SAMPLEIDS); __END__ $VAR1 = [ 'A', '_B', 'C' ]; $VAR2 = [ 'A', 'B', 'C' ]; $VAR3 = [ 'A', 'B', 'C' ];

    Hope this helps,
    -- Hauke D