[tpm] Array slice using a variable question

Mark Fowle mfowle at navicominc.com
Fri Jul 11 12:45:07 PDT 2008


I want to slice an array using info passed  in a text string (in my
example $slice).
Maybe it's because its Friday, but my forehead is starting to hurt from
the banging.

Any help would be appreciated.

Thanks in advance.

Mark

---- Snipit ----
#!/usr/bin/perl
use strict;
use warnings;

my $slice = "1..3";
my @in = qw(a b c d e f g h);
my @out = $in[$slice];
my $p = join(" ", at out);
print "$p\n";

---- Output ----
Argument "1..3" isn't numeric in array slice at ./test.pl line 7.
b


---- I wanted ----
b c d




More information about the toronto-pm mailing list