G'day Tworec,
Welcome to the monastery.
Firstly, I see you've commented out "use strict;" - uncomment this and also add "use warnings;". Removing the output of warnings does not remove the problem they're telling you about!
You've commented out the declaration "my $element;". You assign nothing to $element. You then use $element as if it's a hashref - this is why you're getting the error message you report.
Your print_easy_tree() subroutine assigns its argument to $node; you then make no further reference to $node! Each instance of $element in this function should probably be $node.
I believe that should fix up your immediate problems. Here's some tips that you may find generally useful (i.e. not just for this code); the first two won't necessarily change how your code runs, but they should make it easier to read and understand:
-
Avoid indirect object syntax when instantiating: use Class->new(args) instead of new Class(args)
-
Avoid embedding complex dereferencing within interpolated strings, e.g. instead of print "<$element->{name}>";, use print '<', $element->{name}, '>';
-
The print function does not output newlines: you'll usually want print $output_line, "\n";. Alternatively, use the say function.
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.