On 11/01/2011 14:30, Brian Fraser wrote:

On Tue, Jan 11, 2011 at 10:19 AM, John W. Krahn<jwkr...@shaw.ca>  wrote:

foreach (@arr) {
  push @new, $_;
}

Trying to use a scalar as the first argument to push will result in an
error message.


Doesn't make the original any less wrong, but as an aside, that's no longer
true on 5.13.7+ Perls. http://www.effectiveperlprogramming.com/blog/756

This being a beginner's list, I imagine John was simply trying to avoid
any confusion that the mistake may have caused. I can see no other
errors in Shawn's post and don't understand how it can otherwise be made
'less wrong'.

The link you supply talks about recent versions of push, pop, etc.
working on array references as well as arrays, so that the code could
also be written

  my $new_ref = \...@new;

  foreach (@arr) {
    push $new_ref, $_;
  }

That is a long way from being able to provide any scalar value as the
first parameter of push.

Rob

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to