thanks, that works, but it won't solve my problem.

I'm writing a program where the user enters a list through the keyboard, like:
"0..10,33..43,100..111"

I would like to pass this list directly into a foreach function.  The
problem is, when i pass my scalar in, i get:
###
Argument "0..15,33..43,100..111" isn't numeric in array element
###

i guess a better question is, can I ?cast? that string into a variable
that can be recognized by the foreach?


On 7/24/06, Joshua Colson <[EMAIL PROTECTED]> wrote:
On Mon, 2006-07-24 at 12:40 -0400, Ryan Moszynski wrote:
> Is there a way to make my commented 'foreach" line act the same as the
> line above it?
>
Sure.

> 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;
# In the previous statement, you're initializing a 1024
# who's values are all undefined
> # my $list4 = "0..10,33..43,100..111";

# use an array instead of a scalar
my @list4 = ( 0..10, 33..43, 100..111 );

>
>     #foreach (0..10,33..43,100..111){
>     #foreach ($list4){
     foreach (@list4) {
>
>     $array[$_] = $_;
>
# this next statement is going to print a bunch of nothing
# useful as there are no values in the array
>     print "array--$array[$_]-- --$_--\n";
>
> }
> ###########
>

HTH

--
Joshua Colson <[EMAIL PROTECTED]>



--
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