in reply to removing a hash from an array of hashes

The easiest way to do what you want in Perl is to use grep{}. Think grep whenever the problem is to filter something - i.e. select a subset of data from a larger set or replace a data set with a subset of itself.

Perl grep is way more powerful than command line grep! Instead of a for loop and some if logic, we have just a single statement as shown below.

@success_array is an array of hash references. Each hash reference enters the grep. If whatever code that is within the grep evaluates to "true", then the hash reference is passed to the output (goes to the left). The code within the grep{} can be any valid Perl statements/conditions that you want. Here it is just a single statement that represents an "if". Note that it is completely legal to assign an array back to itself.

Besides the obvious benefit of being shorter, another benefit is that this avoids all this messing around with subscripts! "off by one" array errors are among the most common problems in programming and many Perl iterators, idioms and techniques are designed to eliminate the need for subscripts. As you write more code the seemingly ubiquitous index "i" in other languages will appear less and less often in your Perl code.

Sometimes there are performance reasons to do something more complicated, but usually the best way is to go with the idiomatic solution.

#!/usr/bin/perl -w use strict; use Data::Dumper; my @success_array = ( { hour=>22, maxDDTF=>2, ydayopen=> -53 }, { hour=>14, maxDDTF=>6, ydayopen=> -71 }, { hour=>03, maxDDTF=>1, ydayopen=> -51}, ); # removes hash references where hash's key of 'ydayopen' is <= -60 + @success_array = grep { $_->{ydayopen} > -60 } @success_array; print Dumper \@success_array; __END__ $VAR1 = [ { 'hour' => 22, 'maxDDTF' => 2, 'ydayopen' => -53 }, { 'hour' => 3, 'maxDDTF' => 1, 'ydayopen' => -51 } ];