C
ChocMonk
Hello,
I've got a program snippet that takes a multiline string for exapmple:
"asdasdasd@@\main\3
boohoo@@\main\6
toodle@@\main\9"
and forms a hash from it, where each key is the part of each line upto
the first "@" and the value is everything following the second "@". So
the hash key/value pairs for the above string look like:
asdasdasd => \main\3
boohoo => \main\6
toodle => \main\9
Here is the snippet I wrote:
----BEGIN CODE--
$descr = "
asdasdasd@@\main\3
boohoo@@\main\6
toodle@@\main\9";
#grab the filename list
(my $crap, my $cset) = split /names/,$descr,2;
#split each line into an array
my @temp1 = split /\n/,$cset;
#chuck the list into a hash
my %names;
foreach (@temp) {
(my $name, my $ver) = split /\@\@/,$_;
$names{$name} = $ver;
}
----END CODE--
Is this a good way to do it? Any comments on making it more
efficient/elegant would be much appreciated.
Cheers,
Choco
I've got a program snippet that takes a multiline string for exapmple:
"asdasdasd@@\main\3
boohoo@@\main\6
toodle@@\main\9"
and forms a hash from it, where each key is the part of each line upto
the first "@" and the value is everything following the second "@". So
the hash key/value pairs for the above string look like:
asdasdasd => \main\3
boohoo => \main\6
toodle => \main\9
Here is the snippet I wrote:
----BEGIN CODE--
$descr = "
asdasdasd@@\main\3
boohoo@@\main\6
toodle@@\main\9";
#grab the filename list
(my $crap, my $cset) = split /names/,$descr,2;
#split each line into an array
my @temp1 = split /\n/,$cset;
#chuck the list into a hash
my %names;
foreach (@temp) {
(my $name, my $ver) = split /\@\@/,$_;
$names{$name} = $ver;
}
----END CODE--
Is this a good way to do it? Any comments on making it more
efficient/elegant would be much appreciated.
Cheers,
Choco