develooper Front page | perl.beginners | Postings from April 2002

Re: associative array not looking like I thought it would

Thread Previous | Thread Next
From:
P. S. Starkey
Date:
April 26, 2002 05:36
Subject:
Re: associative array not looking like I thought it would
Message ID:
20020426122343.51122.qmail@onion.perl.org
Thanks for the info!  Here is a code snippet we are using to process the
array:

sub ViewError( % )
{
   if( $MAIN::FUNCTION != $MAIN::F_NOTHING )
   {
      if ( $MAIN::SOURCE == $MAIN::S_ERROR || $MAIN::SOURCE ==
$MAIN::S_BOTH)
      {
       $Err207Flag = "N";  ###### P. Starkey 10/12/2000 ######
   $Error=$_[0];
       print "\n\t********** Error **********\n";

         foreach $ErrKey (keys(%$Error))
         {
            $ErrNam=substr( $ErrKey, 0 ,14);
            $ErrVal=$$Error{$Errkey};
            $ErrNamLen=length( $ErrNam)+1;
            $Tab="\t";

This was all written by a vendor and I am trying to learn PERL to modify
what they did.  When you say I must print it explicitly, what exactly do you
mean?

Thanks again.
========================
Timothy Johnson wrote in message ...
>
>That's not the way associative arrays work.  They are stored differently.
>If you want them to be printed in a certain order, then you must do it
>explicitly.  I think it is really better to think of it as a hash instead
of
>an associative array for that reason.  Not all of the rules apply.  I
>commonly use a snippet of code like this when I'm printing hashes:
>
>foreach(sort keys %hash){
>   print $hash{$_};
>}
>



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About