in reply to insert element into an array
You're splicing onto the wrong array.
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @R = ([qw(x y z)], [qw(a b c)], [qw(e f g)], [qw(h i j)]); print Dumper \@R; for my $rc (@R) { if ($rc->[0] eq "a") { splice @$rc, 0, 0, '#'; print "$rc->[0]\t","$rc->[1]\t","$rc->[2]\t","$rc->[3]\n" } } print Dumper \@R;
splice @$rc instead of splice @R.
"The first rule of Perl club is you do not talk about
Perl club."
-- Chip Salzenberg
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: insert element into an array
by Anonymous Monk on Nov 18, 2004 at 12:49 UTC | |
by davorg (Chancellor) on Nov 18, 2004 at 15:24 UTC | |
by Anonymous Monk on Nov 19, 2004 at 10:20 UTC |