Thanks for the reply and the clarification, I understand what you're saying now. :)

I remembered something I had problems with before and tried that and now I'm even more puzzled...(I've had problems with things not working due to whitespace issues so I fairly routinely use a trim function I got from the cookbook), I tried it with this problem and lo and behold it works.

my $months = $dbh->selectall_arrayref("select to_char(last_day(add_mon +ths('14-May-2004', (rownum-1))),'MON-RRRR') dt from all_objects where rownum <= months_between(sysdate,'31-May-2004')+1"); my $month; my $monthhash; my $i = 0; # populate month hash with zero's for now (this may need to be done la +ter) foreach $month (@$months) { $monthhash{@$month[0]} = $i; # print "pop @$month[0] $i\n"; $i++; } for($i=0; $i<$#$months; $i++) { print "hope 1 @{$months->[$i]}\n"; print "hope 2 $monthhash{trim(@{$months->[$i]})}\n"; print "hope 2A $monthhash{@{$months->[$i]}}\n"; } sub trim { my @out = @_; for (@out) { s/^\s+//; #trim left s/\s+$//; #trim right } return @out == 1 ? $out[0] #only one to return : @out; #or many }

Results. I added an incrementing value to the hash when I created it to make sure that I was indeed getting the correct value - As far as I can see the only difference between hope 2 & hope 2A is the trim call, yet one works and the other doesn't. I don't know why this should make any difference but it is now working.

I was wondering whether it had anything to do with the array only having one element. I started with the simple query so I'll be using your notation later on. If thats not it, then I have no idea why the trim should make any difference.

hope 1 MAY-2004 hope 2 0 hope 2A hope 1 JUN-2004 hope 2 1 hope 2A hope 1 JUL-2004 hope 2 2 hope 2A hope 1 AUG-2004 hope 2 3 hope 2A hope 1 SEP-2004 hope 2 4 hope 2A

In reply to Re^2: Using array value (from array ref) as hash key?? by Haddock
in thread Using array value (from array ref) as hash key?? by Haddock

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.