http://www.perlmonks.org?node_id=1012430


in reply to Re: Hash Question
in thread Hash Question

Hello Anonymous Monk, Sorry, I've made a mistake! This is the coding that needs adjusting:    if ($bHash{$text[3]} eq $text[11]) { I need it to be adjusted so that it does the following function:  if ($bHash{$text[3]} eq $text[11]|$text12|$text14|$text15|$text19 ) can this be fixed? if so how? Thank you!

Replies are listed 'Best First'.
Re^3: Hash Question
by choroba (Cardinal) on Jan 09, 2013 at 11:19 UTC
    You probably mean
    for my $value (@text[11, 12, 14, 15, 19]) { if ($bHash{ $text[3] } eq $value) { $bHash{ $text[0] } = $value; last; } }
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      Hi Choroba, That's exaclty what I mean! but i can't figure out what's wrong with it? i've included it in my coding but it doesn't work:
      foreach (<$ah>) { my $nullval = ' '; my @text = split(/\t/); my $value (@text[11, 12, 14, 15, 19]) if ($bHash{ $text[3] } eq $value) { $bHash{ $text[0] } = $value; last; print OUT2 join( "\t", @text[1,2,3,4,11,5,6,8,7,11,12]),"\t$nullva +l\t$nullval\t$nullval\t$nullval\t$nullval\t$nullval\t$nullval\t$nullv +al\t$nullval\t$nullval\t1\t1\n"; } }
        The for is also important.
        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

        You're making stuff up again, for loop is for loop, its a for loop

Re^3: Hash Question
by Anonymous Monk on Jan 09, 2013 at 11:11 UTC

    What does that mean?

    You're making up syntax and you're hoping I know what you mean by it -- I can venture a guess, but the point is, you need to ask a better question

      Sorry, I wasn't clear, The hash reference is looking up values that match a column in a text file ($text11) I wanted to know if it was possible to match another column also e.g 14,15,17 etc and if there is a match in any of those columns then the results would be printed as opposed to just having the hash look up the one column ($text11) does that make more sense? Thank you
        Yes,
        if( $f[0] eq $f[1] and $f[0] eq $f[2] and $f[0] eq $f[3] and $f[0] eq $f[4] and $f[0] eq $f[5] ) { ... }
Re^3: Hash Question
by AnomalousMonk (Archbishop) on Jan 09, 2013 at 11:32 UTC

    Here's my guess:

    >perl -wMstrict -le "use List::MoreUtils qw(any); ;; my $s = 'B a B b B c B d'; ;; my @text = split /\s+/, $s; ;; if (any { $text[0] eq $text[ $_ ] } 2, 4, 6, 7) { print 'something was eq'; } " something was eq