Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
my (@array, %hash);
while (<>) {
my ($key, $val) = split(',', $_);
$hash{$key} = $val;
push @array, $key;
}
foreach (@array) {
print "$_ - $hash{$_}";
}
my (%order, %hash, $counter);
while (<>) {
my ($key, $val) = split ',', $_;
$order{++$counter} = $key;
$hash{$key} = $val;
}
foreach (sort {$a <=> $b} keys %order) {
print "$order{$_} - $hash{$order{$_}}";
}
my (%order, %hash, $counter);
@data = split (/,/, $text);
my %data = ( @data );
while( my($key, $val) = each(%data) ) {
$order{++$counter} = $key;
$hash{$key} = $val;
}
foreach (sort {$a <=> $b} keys %order) {
print OUT"$order{$_} - $hash{$order{$_}}";
}
#!perl
use strict;
use warnings;
my (@order, %hash);
my ($key, $val);
while (<DATA>) {
chomp;
($key, $val) = split /,/;
push @order, $key;
$hash{$key} = $val;
}
for (@order) {
print qq($_ => $hash{$_}\n);
}
__DATA__
apples,red
grapes,purple
lemons,yellow
peaches,pink
kiwis,green
oranges,orange
Output:
apples => red
grapes => purple
lemons => yellow
peaches => pink
kiwis => green
oranges => orange
my $text = "key1,val1,key2,val2,key3,val3,key4,val4";
my (%order, %data, $counter);
my @data = split (/,/, $text);
#my %data = ( @data );
#while( my($key, $val) = each(%data) ) {
while (@data) {
my ($key, $val) = splice @data, 0, 2;
$order{++$counter} = $key;
$data{$key} = $val;
}
$hash{"1"} = "oldhashkey1::value";
$hash{"2"} = "oldhashkey2::value";