On Tue, 2008-10-07 at 21:09 +0100, Rob Dixon wrote:
> Incorrect, delete does not remove array elements:
> > 
> > $ perl -le'use Data::Dumper; my @a = "a".."d"; delete $a[1]; print 
> > Dumper [EMAIL PROTECTED]'
> > $VAR1 = [
> >            'a',
> >            undef,
> >            'c',
> >            'd'
> >          ];
> 
> According to exists() it does.

Data::Dumper does not test for exists, it only tests defined.  Therefore
it reports that !exists as undef.

#!/usr/bin/perl

use strict;
use warnings;

use Data::Dumper;
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Indent   = 1;
$Data::Dumper::Maxdepth = 0;

my @a = 'a' .. 'd';
delete $a[1];

print "\nFor each element of [EMAIL PROTECTED]";
for my $s ( @a ){
  print "$s\n";
}

print "\nFor each index of [EMAIL PROTECTED]";
for my $i ( 0 .. $#a ){
  if( exists $a[$i] ){
    if( defined $a[$i] ){
      print "element $i exists and defined: $a[$i]\n";
    }else{
      print "element $i exists but not defined\n";
    }
  }else{
    print "element $i does not exists\n";
  }
}

print "\nData::Dumper ", Dumper [EMAIL PROTECTED];

__END__


-- 
Just my 0.00000002 million dollars worth,
  Shawn

Linux is obsolete.
-- Andrew Tanenbaum


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to