[tpm] Array slice using a variable question

Ilia Lobsanov samogon at gmail.com
Fri Jul 11 13:07:19 PDT 2008


Or...

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


On 11-Jul-08, at 4:04 PM, Ilia Lobsanov wrote:

> 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";
>
>
> ilia.
>
> On 11-Jul-08, at 3:45 PM, Mark Fowle 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