Tillema, Glenn <[EMAIL PROTECTED]> said something to this effect on 07/17/2001:
> I know there must be an easy way to do this but the solution evades me
> and I'm hoping someone here either knows the answer or can point me in
> the right direction so I can figure it out myself ... on to the
> question;
> 
> I have two scalars, each contain a comma-seperated list of values;
> 
> $scaOne = "1,2,3,4,5";
> $scaTwo = "label one,labelTwo,label,label4,label five";
> 
> I want to put these into a hash where the end result would be this;
> 
> %hashOne = ( 1 => 'label one',
>              2 => 'labelTwo',
>              3 => 'label',
>              4 => 'label4',
>              5 => 'label five',);

The easy way to do this is to split $scaOne and $scaTwo and use
them in a hash slice:

  $scaOne = "1,2,3,4,5";
  $scaTwo = "label one,labelTwo,label,label4,label five";

  @one = split /,/, $scaOne;
  @two = split /,/, $scaTwo;

  @h{@one} = @two;

Or, more succicntly, replace the last three lines with:

  @h{split ',', $scaOne} = (split /,/, $scaTwo);

This requires that $scaOne and $scaTwo have the same number of
fields in them (but your problem suggests that they will).

(darren)

-- 
The question of whether computers can think is just like the question of
whether submarines can swim.
    -- Edsger W. Dijkstra

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to