Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Hash Question

by Anonymous Monk
on Jan 09, 2013 at 11:03 UTC ( #1012429=note: print w/ replies, xml ) Need Help??


in reply to Hash Question

I want to change it so that the $text11 could also be $text12,$text14,$text15,$text19 is this possible? if so how?

Yes, whatever you mean by that, it is possible, but its not clear what you mean


Comment on Re: Hash Question
Re^2: Hash Question
by perlnoobster (Sexton) on Jan 09, 2013 at 11:08 UTC
    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!

      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
      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"; } }

      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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1012429]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2014-04-19 16:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (483 votes), past polls