in reply to Checking if all the key values are same in an Array

no.


holli, /regexed monk/
  • Comment on Re: Checking if all the key values are same in an Array

Replies are listed 'Best First'.
Re^2: Checking if all the key values are same in an Array
by jbrugger (Parson) on Apr 26, 2005 at 13:04 UTC
    Would you concider this looping?
    #!/usr/bin/perl use strict; my @array = ({key1=>1, key2=>2, key3=>3}, {key1=>1, key2=>2, key3=>3}, + {key1=>1, key2=>2, key3=>3} ); my $amount = scalar(@array); if (!$array[0 .. $amount]->{key1}) { print "no\n" }
    Update holli is right. bah. this code just checks if key1 of the second element of the array is false. There is no loop.
    "We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise." - Larry Wall.
      No. Your code checks if the value under "key1" of the second hashref in the array is false.

      Consider:
      #!/usr/bin/perl use strict; my @array = ( {key1=>0, key2=>2, key3=>3}, {key1=>1, key2=>2, key3=>3}, {key1=>0, key2=>2, key3=>3} ); my $amount = scalar(@array); if (!$array[0..$amount]->{key1}) { print "no\n" }
      which should print "no" but does not, and
      #!/usr/bin/perl use strict; my @array = ( {key1=>0, key2=>2, key3=>3}, {key1=>1, key2=>2, key3=>3}, {key1=>0, key2=>2, key3=>3} ); my $amount = scalar(@array); if (!$array[0..$amount]->{key1}) { print "no\n" }
      which should not print "no" but does.


      holli, /regexed monk/