in reply to insert element into an array
EDIT: And here's your code, modified so it works. I'd personally use unshift rather than splice, though...use strict; use warnings; my @R; # Constructing your matrix... while (<DATA>) { chomp; push @R, [split(/ /)]; } for (@R) { if ($_->[0] eq 'a') { unshift @$_, '#'; print join("\t", @$_)."\n"; } } __DATA__ x y z a b c e f g h i j
You were missing a > and a ; on line 4, btw.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"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: insert element into an array
by Anonymous Monk on Nov 16, 2004 at 14:41 UTC | |
by ikegami (Patriarch) on Nov 16, 2004 at 17:33 UTC |