in reply to Re: Re: Comma separated list into a hash
in thread Comma separated list into a hash

The input to split is (usually) a Regex, followed by a string to split. And the output (the return value) is a list of each individual item split out.

So the idea is that you will put your string to be 'parsed' into a scalar variable, say, for example, $string. You will then assign the output of split to a list.

If I were splitting a string containing numbers seperated by whitespace, I might do this:

my $string = "1 3 5 7 11 13"; my @numbers = split /\s+/, $string;

Now @numbers is an array holding six elements, each element containing one number.

You don't have to split into an array though. You can split such that the return value is used to populate 'foreach' with data to iterate over. My previous example might look like this:

my $string = "1 3 5 7 11 13"; foreach my $number ( split /\s+/, $string ) { # Do some stuff with $number. # Number will contain one number from the list each time # through the loop. }
Hope this helps...


Dave