Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^4: undefined value in array reference

by Dandello (Scribe)
on Mar 31, 2011 at 21:43 UTC ( #896735=note: print w/ replies, xml ) Need Help??


in reply to Re^3: undefined value in array reference
in thread undefined value in array reference

Well, in this particular set of data, $x maxes out at 500 and $y maxes out at 10,000. So yes, it's an indexing issue related to @{$aob[ $y - 1 ]} but nothing I've read points to a simple one-line solution that actually produces the proper output.

As is my usual, my current solution is a little sideways. In the section above calling popnum3:

foreach my $r (0 .. $total){ $row[$r] = $aob[$r][$y - 1]; } my @rowin = grep { $_ ne q{} } @row; $mean = mean(@rowin);
then
sub popnum3 { my ( $x, $y, $z, $mean ) = @_; $aob[$x][$y] = $mean * ( 1 + $z ); return $aob[$x][$y]; }

Supposedly @row = @{$aob[ $y - 1 ]} should be equivalent to

foreach my $r (0 .. $total){ $row[$r] = $aob[$r][$y - 1]; }
But it didn't work out that way.

BTW, the grep is in there since I know that although the current parameters shouldn't produce any blanks in the output, other parameters will.


Comment on Re^4: undefined value in array reference
Select or Download Code
Re^5: undefined value in array reference
by kennethk (Abbot) on Mar 31, 2011 at 21:56 UTC
    So you are trying essentially to strip out the $y - 1 column, assuming your AoA is $aob[row][column]? In that case, your code might look like:

    my @row = map $_->[$y - 1], @aob;

    If not, I'm really lost as to the spec.

      YES! - well, it's actually mapping out as $aob[column][row] But that's a minor issue that's all though the whole project. Maybe my conventions are a little off from everyone else's. Wouldn't be the first time.

      Be that as it may my @row = map $_->[$y - 1], @aob; gives me proper results in the output without resorting to a foreach loop.

      Thank You

        For a little background on the column/row confusion, see Row-major_order.

        Glad to have helped.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2015-07-04 15:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls