in reply to Re: Re: Re: Re: Comma separated list into a hash
in thread Comma separated list into a hash
I don't understand. my ($this, $that) = split(/,/, $string); how is this an array? I had to create my variables before my split.
Ah, but in perl, arrays are a single variable that can hold a dynamic number of values! So you don't need to know beforehand how many values will result from the split; you can just do:
my @words = split /,/, $string;
Then, to figure out how many words resulted, you can just use @words in a scalar context:
# find out information about the entire array print "found " . scalar( @words ) . " words\n"; # do stuff with each member of the array foreach my $word ( @words ) { print " word: $word\n"; }
|
|---|