Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Data::Dumper does a pretty good job.

#! perl -slw use strict; package scalarObj; my $scalar; sub new{ return bless \$scalar, shift; } package arrayObj; my @private = qw(1 a the 3.14159); sub new { return bless \@private, shift; } package hashObj; sub new { return bless {some=>1, things=>2, in=>3, a=>4, hash=>5 }, shift; } package main; use Data::Dumper; my @objects = ( new scalarObj, new arrayObj, new hashObj ); foreach my $obj (@objects) { print Dumper $obj; } __END__ C:\test>217134 $VAR1 = bless( do{\(my $o = undef)}, 'scalarObj' ); $VAR1 = bless( [ '1', 'a', 'the', '3.14159' ], 'arrayObj' ); $VAR1 = bless( { 'things' => 2, 'a' => 4, 'some' => 1, 'hash' => 5, 'in' => 3 }, 'hashObj' ); C:\test>

Writing your own code to do something similar isn't much harder.

#! perl -slw use strict; package scalarObj; my $scalar= 'test'; sub new{ return bless \$scalar, shift; } package arrayObj; my @private = qw(1 a the 3.14159); sub new { return bless \@private, shift; } package hashObj; sub new { return bless {some=>1, things=>2, in=>3, a=>4, hash=>5 }, shift; } package main; use Data::Dumper; my @objects = ( new scalarObj, new arrayObj, new hashObj ); foreach my $obj (@objects) { if ($obj =~ /scalar/) { print $$obj; } elsif($obj =~ /array/) { print "@{$obj}" } elsif($obj =~ /hash/) { print "$_ => $obj->{$_}" for keys %$obj; + } } __END__ C:\test>217134 test 1 a the 3.14159 things => 2 a => 4 some => 1 hash => 5 in => 3 C:\test>

Okay you lot, get your wings on the left, halos on the right. It's one size fits all, and "No!", you can't have a different color.
Pick up your cloud down the end and "Yes" if you get allocated a grey one they are a bit damp under foot, but someone has to get them.
Get used to the wings fast cos its an 8 hour day...unless the Govenor calls for a cyclone or hurricane, in which case 16 hour shifts are mandatory.
Just be grateful that you arrived just as the tornado season finished. Them buggers are real work.


In reply to Re: Iterating over *any* thing in Perl by BrowserUk
in thread Iterating over *any* thing in Perl by Schemer

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



  • 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, 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, 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (6)
    As of 2021-05-06 18:40 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Perl 7 will be out ...





      Results (78 votes). Check out past polls.

      Notices?