Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I threw together the following code while reviewing perldsc and perlref.
#!/usr/bin/perl -w #use strict; my %family = ( 'parents' => ['Barbie', 'Ken'], 'siblings' => ['John', 'Robert'], 'wife' => ["Heather"], 'pets' => ["Miles", "Vanilla", ["Dallas", "some cat +"], ["snoopy", "woodstock"] ], 'inlaws' => [ ["Luke", "Leigh"], ["Carol", "Jack"] ], 'sisinlaw' => ["Lucy"], 'broinlaw' => ["Linus", "Pig Pen"], 'friends' => ["Jack", "Jill", "Peter", "Mac"], 'coworkers'=> ["sammy", "colin", "dave"] ); for my $label ( sort keys(%family) ) { my @names = $family{$label}; print "$label\n"; for my $name ( 0 .. $#names ) { for my $names ( 0 .. $#{ $family{$label} } ) { print "\t$family{$label}->[$names]\n"; for my $x ( 0 .. $#{ $family{$label}->[$names] } ) { print "\t$family{$label}->[$names][$x]\n "; #this is where Im stuck. Id like to # just print out the names in the # arrays } } } }
and it does what I want. Wellllll, almost. Plus I cant use strict; My output looks like this:
broinlaw
	Linus
	Pig Pen
coworkers
	sammy
	colin
	dave
friends
	Jack
	Jill
	Peter
	Mac
inlaws
	ARRAY(0x8069d88)
	Luke
 	Leigh
 	ARRAY(0x8069db8)
	Carol
 	Jack
 parents
	Barbie
	Ken
pets
	Miles
	Vanilla
	ARRAY(0x8069ce0)
	Dallas
 	some cat
 	ARRAY(0x8069d10)
	snoopy
 	woodstock
 siblings
	John
	Robert
sisinlaw
	Lucy
wife
	Heather
if I  use strict; the following code must be removed
for my $x ( 0 .. $#{ $family{$label}->[$names] } ) { print "\t$family{$label}->[$names][$x]\n "; }
and Ill get this output
broinlaw
	Linus
	Pig Pen
friends
	Jack
	Jill
	Peter
	Mac
inlaws
	ARRAY(0x806a030)
	ARRAY(0x806a060)
parents
	Barbie
	Ken
pets
	Miles
	Vanilla
	ARRAY(0x8069fc4)
siblings
	John
	Robert
sisinlaw
	Lucy
wife
	Heather
Which is obviously not my intention either. Any pointers to some help would be greatly appreciated.


Ted

--
"Men have become the tools of their tools."
  --Henry David Thoreau

In reply to iterating a hash of (complex?) arrays by tcf03

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2024-03-28 10:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found