M
Michael Goerz
Hi,
how can I delete from an array by reference (i.e. I already have a
pointer to the array element) instead of by index. Consider the
following code:
#!/usr/bin/perl -w
use strict;
use Data:umper;
my $testarray = [
["bla", "bla"],
["xyz", "xyz"],
"blabla",
123 ];
print("before:\n", Dumper($testarray), "\n");
my $pointer_to_element = $testarray->[1];
undef($pointer_to_element); # no effect ...
undef(@{$pointer_to_element}); # has *some* effect,
# but only works since I know
# the element is an array
print("after undef by reference:\n", Dumper($testarray), "\n");
undef(@{$testarray}[1]); # ... but I want the same as this
print("after undef by index:\n", Dumper($testarray), "\n");
Even better would be to actually delete, not just to undef the element.
Thanks,
Michael Goerz
how can I delete from an array by reference (i.e. I already have a
pointer to the array element) instead of by index. Consider the
following code:
#!/usr/bin/perl -w
use strict;
use Data:umper;
my $testarray = [
["bla", "bla"],
["xyz", "xyz"],
"blabla",
123 ];
print("before:\n", Dumper($testarray), "\n");
my $pointer_to_element = $testarray->[1];
undef($pointer_to_element); # no effect ...
undef(@{$pointer_to_element}); # has *some* effect,
# but only works since I know
# the element is an array
print("after undef by reference:\n", Dumper($testarray), "\n");
undef(@{$testarray}[1]); # ... but I want the same as this
print("after undef by index:\n", Dumper($testarray), "\n");
Even better would be to actually delete, not just to undef the element.
Thanks,
Michael Goerz