Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: XML::Twig Question (sorta)

by ikegami (Patriarch)
on Mar 28, 2009 at 19:12 UTC ( [id://753889]=note: print w/replies, xml ) Need Help??


in reply to XML::Twig Question (sorta)

Anno is quite right. Here's a quick explanation.

When you call a subroutine, the arguments are flattened into a list.

sub foo { print("There are ", 0+@_, " args\n"); print("They are @_\n"); } my @a = qw( a b c ); my $n = 123; foo(@a, $n);
There are 4 args They are a b c 123

For this reason, an array reference is usually passed instead of the contents of the array.

foo(\@a, $n);
There are 2 args They are ARRAY(0x1829aec) 123

In your case, it would be

populateEventManifest(\@projectEvents, $eventManFh); # <-- extra \ sub populateEventManifest { my( $events, $eventManFh ) = @_; # <-- scalar foreach my $event (@$events) { # <-- extra $ $event->print($eventManFh); } }

Anno provided an alternative solution.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://753889]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-04-25 21:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found