Consider this snippet:
use Data::Dumper;
@targetDirsToScan = ("./");
use IO::All;
$io = io(@targetDirsToScan); # Create new directory object
@contents = $io->all(0); # Get all contents of dir
for my $contentry ( @contents ) {
print Dumper($contentry) ."\n";
}
This prints something like:
$VAR1 = bless( \*Symbol::GEN298, 'IO::All::File' );
$VAR1 = bless( \*Symbol::GEN307, 'IO::All::Dir' );
$VAR1 = bless( \*Symbol::GEN20, 'IO::All::File' );
...
I expected I would get the all the fields of the respective objects dumped, instead; at first, I thought this was a reference, so I thought the fields would be printed if I dereference the variable - but I realized I don't really know how to dereference it.
So - how can I print out all the fields and contents of the @contents
, using the same kind of for my ...
loop?
You can do this:
But you should seriously consider whether doing this is a good idea. One of the core tenets of object-oriented programming is encapsulation. You should not care about the guts of a blessed object - you should interact with it only via the methods it provides.