Loading ...
Sorry, an error occurred while loading the content.

RE: [PBML] Question about hash of arrays accessing

Expand Messages
  • Charles K. Clarkson
    ... You can. ... This sets $test[0] to the reference to the array at $hash{$searchPattern}. my @test = @{ $hash{$searchPattern} }; This sets @test to the array
    Message 1 of 4 , Sep 3, 2004
    • 0 Attachment
      From: greg.hering@... <mailto:greg.hering@...> wrote:

      : <snip>
      : So why can't I iterate through @test with foreach?

      You can.

      : 95  if ( defined( $KeyWordHashRef->{$searchPattern} )) {
      : 96    my %hash = %{$KeyWordHashRef};

      : 97    my @test = $hash{$searchPattern};

      This sets $test[0] to the reference to the array at
      $hash{$searchPattern}.

      my @test = @{ $hash{$searchPattern} };

      This sets @test to the array referenced by
      $hash{$searchPattern}.


      : 98    foreach my $notPattern1 ( @test ) {
      : 99      foreach my $notPattern ( @$notPattern1 ) {

      Stop using @test.

      foreach my $notPattern ( @{ $hash{$searchPattern} } ) { # [1]

      : 100       if ( $debugLevel > 3 ) { print "notPattern: ", $notPattern; }
      : 101       if ( $debugLevel > 3 ) { print "\n"; }
      : 102       if ( $debugLevel > 3 ) { print "String to be tested:

      Dude, use statement modifiers:

      print "notPattern: $notPattern\n" if $debugLevel > 3;

      print "String to be tested: $_\n" if $debugLevel > 3;


      HTH,

      Charles K. Clarkson
      --
      Mobile Homes Specialist
      254 968-8328

      [1] I am assuming that $hash{$searchPattern} is a reference to an
      array, not an array of arrays. I'm too lazy to go back and
      look.
    Your message has been successfully submitted and would be delivered to recipients shortly.