Subject: Minns ni strukturerings-grejjen?
From: Carl-Johan Sveningsson (woc@wlug.westbo.se)
Date: Wed, 16 Jun 1999 21:20:24 +0200 (CEST)
Hejsan.
Minns ni att jag för länge sen frågade om hur man skapade massa hashar och
skit fram och tillbaka?
Nu har jag lärt mig det, och det är så infernaliskt krångligt att jag inte
kan motstå behovet att vräka ur mig lite kod. :-)
Den här strukturen kommer i princip fylla behovet jag hade, med massa
olika filer fram och tillbaka, och en bunt ändringar för varje.
#!/usr/bin/perl
push (@info, { "File:" => "/usr/bin/",
"Datum" => "89/03/15",
"Changes" => [
{"Info" => "Ändrades av Moi",
"Change" => "Adderade lite shit"},
{"Info" => "Ändrades av WoC",
"Change" => "Adderade mer shit"} ]
}) ;
push (@info, { "File:" => "/usr/X11R6" , "Datum" => "89/05/15" }) ;
for $i (0..$#info) {
print "\t [ ", %{$info[$i]}, " ]\n";
}
for $i ( 0..$#{ $info[0]->{"Changes"} } ) {
print "\n\$Info då va:\t", $info[0]->{"Changes"}[$i]->{"Info"},
"\n";
print "\$Change var det här:\t",
$info[0]->{"Changes"}[$i]->{"Change"}, "\n";
}
Tufft värre va? :-) Bara att köra...
/WoC - lyrisk över perversa structer i Perl.
"If the notion of infinite loops bothers you, we should point out that
you can always terminate such a loop from the inside with an appropriate
loop-control command. Of course, if you're writing the code to control a
cruise missile, you may not actually need to write a loop exit. The loop
will be terminated automatically at the appropriate moment.*
* That is, the fallout from the loop tends to occur automatically."
-- Programming Perl, L. Wall
----------o--o-oOo-o--o----------
Carl-Johan Sveningsson
woc@wlug.westbo.se
ICQ# 2357535
http://come.to/woc/
http://wlug.westbo.se/