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[]
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.