Seems to be a popular question for newcomers to ask how to access some component of a complicated structures.
The answer is to user the built-in debugger.
tlegrady@rw-q318:~$ perl -d t.pl
Loading DB routines from perl5db.pl version 1.3
Editor support available.
Enter h or `h h' for help, or `man perldebug' for more help.
main::(t.pl:5): my $data = [
DB<1> n
main::(t.pl:16): my $test = $data->{ name };
DB<1> x $data
0 ARRAY(0x70b910)
0 HASH(0x70b970)
'name' => 'Mary'
DB<2> x $data->[0]
0 HASH(0x70b970)
'name' => 'Mary'
DB<3> x $data->[0]{name}
0 'Mary'
When the debugger starts, it shows that it's about to execute line 5. I do a "next" ( 'n') to complete that, and then it's going to execute line 16. I query the debugger to show the value of $data, and then of its components. Since you're looking right at it, it's easy to tell you want array element '0', hash tag 'name'.
As Occam said: Entia non sunt multiplicanda praeter necessitatem.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|