[Melbourne-pm] Perl chop behaviour

Alfie John alfiejohn at acm.org
Thu Aug 11 22:04:13 PDT 2005


Hey,

AFAIK, chop will only chop an array at 1D. I don't think chop will go  
more than that. Thus the chopping of the reference. I could be wrong  
though.

Alfie.

On 12/08/2005, at 2:48 PM, Becky Alcorn wrote:

> Hi everyone,
>
> I have a bit of a strange question.  Can anyone shed some light on the
> behaviour of chop() when you pass it an array that contains an array.
>
> Example code is:
>
> #!/usr/bin/perl
> use strict;
> use warnings;
> use Data::Dumper;
>
> my @array = (
>   'fred',
>   'bob',
>   ['aa', 'bb'],
> );
>
> my $chr = chop(@array);
>
> print Dumper(\@array) . "\n";
> print "Char: $chr\n";
>
> And the output from that is:
>
> $VAR1 = [
>           'fre',
>           'bo',
>           'ARRAY(0x812bfc0'
>         ];
>
> Char: )
>
> I can see that it is taking the ')' from the array reference.  Is  
> it a bug
> in my version of Perl (5.8.3), or does that actually make sense at  
> some
> level?  I understand that it is a little bit difficult for Perl to  
> decide
> what to do in this case, but I didn't expect it to do that!
>
> Cheers
> Becky
>
> _______________________________________________
> Melbourne-pm mailing list
> Melbourne-pm at pm.org
> http://mail.pm.org/mailman/listinfo/melbourne-pm
>



More information about the Melbourne-pm mailing list