7stud, GrandFather, thank you for the quick reply.
I have warning and defined variables, I was just simplifying
things.
YOu are right, there are no first element in a hash (they are stored in an internal order and format, thanks for pointing that out).
sub initrooms
{
my (@aa, %things, $b, @ar, $t, $de, $ex, $th, @a);
open (RF, "rooms.txt")
or die "could not open datafile: $!";
undef $/;
@ar = split (/0/, <RF>);
$/ = "\n";
foreach (@ar)
{
($t, $de, $ex, $th) = split /:/, $_;
if ($th eq //)
{
next;
}
%things = split /-/, $th;
print %things; (all elements present)
push @a, { TITLE => $t, TEXT => $de, EXITS => $ex, THI
+NGS => {%things} };
}
return \@a;
}
sub lookat
{
my @i;
my ($id, $i, $item);
my ($tg, $cr, $aoa) = @_;
if (exists ($aoa->[$cr]->{THINGS}->{$tg}))
{
print color("bold blue"), "\n", $aoa->[$cr]->{THINGS}-
+>{$tg}, color("reset");
return;
}
print "\nHmm .. where?";
}
In the exist line I can find all things except the first one pushed onto the array. So $aoa->[0]->{THINGS}->{bed} does not exist but $aoa->[0]->{THINGS}->{chair} does exist.
Very strange! And this repeats itself in all 3 $aoa[]
| [reply] [d/l] |
| [reply] |
| [reply] |
GrandFather, please do not apologise, I thank you for taking the time to look through my post. TA
| [reply] |
| [reply] [d/l] [select] |
While most of the suggestions are good, I take objection with two:
What's wrong with using barewords as hash keys? The quotes mostly clutter up the syntax, and it's rare that you want a function call inside a hash key access.
Instead of using global / glob filehandles and closing them manually, I recommend to use lexical filehandles, which will close automatically when the enclosing scope is left.
| [reply] |
Dear Svante, thanks for your suggestions, I am happy you take the time like this to help improve my code. TA
| [reply] |