On Tue, 17 Jul 2001, Tillema, Glenn wrote:
> I have two scalars, each contain a comma-separated 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',);
Using the hash slice example in Learning Perl 2nd Edition, page 70, I
wrote the following script:
#!/usr/bin/perl -w
my $scaOne = "1,2,3,4,5";
my $scaTwo = "label one,labelTwo,label,label4,label five";
# convert scalars to arrays using join
my @One = split( ",", $scaOne );
my @Two = split( ",", $scaTwo );
my %hashOne;
# use arrays as hash slices with interpolation
@hashOne{ @One } = @Two;
while ( ( $a, $b ) = each( %hashOne ) ) {
print "$a is $b\n";
}
The output of this script is:
1 is label one
2 is labelTwo
3 is label
4 is label4
5 is label five
Hope that's what you wanted.
Best wishes,
Rachel Coleman
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]