[tpm] Array slice using a variable question
Mark Fowle
mfowle at navicominc.com
Fri Jul 11 13:00:28 PDT 2008
Eval was my first thought but I'm not getting anywhere with it.
The input it fully tested in the real program, which runs in taint mode,
but thanks for the reminder.
-----Original Message-----
From: David Golden [mailto:xdaveg at gmail.com]
Sent: Friday, July 11, 2008 3:57 PM
To: Mark Fowle
Cc: Toronto Perl Mongers
Subject: Re: [tpm] Array slice using a variable question
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