----- Original Message ----- From: ""Ryan Moszynski"" <[EMAIL PROTECTED]>
Newsgroups: perl.beginners
To: <beginners@perl.org>
Sent: Monday, July 24, 2006 12:40 PM
Subject: passing a list as a variable


Is there a way to make my commented 'foreach" line act the same as the
line above it?

Can I pass a list as a variable as I am trying to do, or doesn't perl
support that?

###########
#!/usr/bin/perl -w
$|=1;
#use strict;

system "clear";
my @array = 1024;
my $list4 = "0..10,33..43,100..111";

   foreach (0..10,33..43,100..111){
   #foreach ($list4){

   $array[$_] = $_;

   print "array--$array[$_]-- --$_--\n";

}
###########

Just another way to do it using Set::IntSpan   :-)


#!/usr/bin/perl
use strict;
use warnings;
use Set::IntSpan;

my @array;
my $list4 = "0-10,33-43,100-111";
my $set = Set::IntSpan->new($list4);

foreach ($set->elements()){
$array[$_] = $_;
   print "array--$array[$_]-- --$_--\n";

}


In addition, I'm not sure you would want to create a sparse array like this (with undefined elements between the number runs). But not seeing the overall picture of what you want to accomplish makes it difficult to see a better solution.

Chris


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to