RobinV has asked for the wisdom of the Perl Monks concerning the following question:
Ok this is driving me nuts. I Thought I could figure it out myself however I think Its time to ask the monks.
So here it is.
I got this piece of code:
foreach ($self->{'sections'}) { ..use $_ here to do stuff.. }
But I can't seem to access the value in $_ I tried to figure out what type of value it was by doing this:
print ref($_);
And I got nothing back. SO I googled around and I found the following snipper:
my $val = $_; use Carp qw(confess); if ( ! defined $val ) { return 'null'; } elsif ( ! ref($val) ) { if ( $val =~ /^-?\d+$/ ) { return 'int'; } elsif ( $val =~ /^-?\d+(\.\d+)?$/ ) { return 'float'; } else { return 'string'; } } else { my $type = ref($val); if ( $type eq 'HASH' || $type eq 'ARRAY' ) { return 'array'; } elsif ( $type eq 'CODE' || $type eq 'REF' || $type eq 'GLOB' | +| $type eq 'LVALUE' ) { return $type; } else { # Object... return 'obj'; } }
This code also returned nothing. When I just print $_ I get a value 300 something (I think this is the amount of dimentions the array has). This snipper will show you how the Variable is defined as is.
my $sections = (qx!rabin -Svv $filename!); my @detected_sections = (); while ($sections =~ m/idx\=(\d*) address=(0x(\d|[a-f])*) offset=(0x(\d +|[a-f])*) size=(\d*) align=(0x(\d|[a-f])*) perm=((r|w|x|-){4}) name=( +.*)/gi) { my %section_int = ( index => $1, address => $2, offset => $4, size +=> $6, align => $7, rights => $9, name => $11 ); push (@detected_sections, %section_int); } $report->{'sections'} = @detected_sections;
So am I stupid to guess that the foreach will do foreach array and I would get a hash but I can't use the $_ still in anyway.
So My Question is, What am I doing wrong? And how can I use the $_ in question?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Variable Unusable?
by GrandFather (Saint) on Dec 29, 2009 at 10:15 UTC | |
|
Re: Variable Unusable?
by Anonymous Monk on Dec 29, 2009 at 08:46 UTC | |
by RobinV (Sexton) on Dec 29, 2009 at 09:28 UTC | |
by Mr. Muskrat (Canon) on Dec 29, 2009 at 19:43 UTC |