Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re^2: Hash Question

by perlnoobster (Sexton)
on Jan 09, 2013 at 11:08 UTC ( #1012430=note: print w/replies, xml ) Need Help??

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 (Bishop) 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
        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 (Chancellor) 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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1012430]
[choroba]: Email::Address DoS

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2018-06-20 11:54 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (116 votes). Check out past polls.