Careful: this code doesn't deal with circular structures:
my $r1 = [ 1 ]; my $r2 = [ 2, $r1 ]; push @$r1, $r2; print_r($r1);
This will recurse endlessly until the heat death of the universe or you run out of swap, whichever comes first. Then again, perhaps the PHP implementation does as well.
Minor issue: you don't want to explicitly state the package (main::print_r) when you call the function within itself. Using the unqualified name will allow it to work regardless of which package defines the routine.
• another intruder with the mooring in the heart of the Perl
In reply to Re: print_r
by grinder
in thread print_r
by GhodMode
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |