[tpm] Array slice using a variable question

David Golden xdaveg at gmail.com
Fri Jul 11 12:57:10 PDT 2008


eval $slice

But be sure you can trust the string before you do that.

David

On Fri, Jul 11, 2008 at 3:45 PM, Mark Fowle <mfowle at navicominc.com> wrote:
> 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
>
>
> _______________________________________________
> toronto-pm mailing list
> toronto-pm at pm.org
> http://mail.pm.org/mailman/listinfo/toronto-pm
>


More information about the toronto-pm mailing list