Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Hash Question

by perlnoobster (Sexton)
on Jan 09, 2013 at 10:59 UTC ( #1012428=perlquestion: print w/ replies, xml ) Need Help??
perlnoobster has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks, I'm fairly new to perl and was wondering if someone could help me, I have the following hash
foreach (<$bh>) { my @text=split(/\t/); $bHash{$text[0]} = $text[11]; }
I want to change it so that the $text[11] could also be $text[12],$text[14],$text[15],$text[19] is this possible? if so how? Thank you!

Comment on Hash Question
Select or Download Code
Re: Hash Question
by Anonymous Monk on Jan 09, 2013 at 11:03 UTC

    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

      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

        You probably mean
        for my $value (@text[11, 12, 14, 15, 19]) { if ($bHash{ $text[3] } eq $value) { $bHash{ $text[0] } = $value; last; } }
        لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

        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
Re: Hash Question
by jethro (Monsignor) on Jan 09, 2013 at 11:17 UTC

    That's what variables were invented for

    my $inp; print "What column do you want ? "; do { $inp= <>; chomp($inp); } until ($inp=~/^\d+$/ and $inp>=11 and $inp<=19); foreach (<$bh>) { my @text=split(/\t/); $bHash{$text[0]} = $text[$inp]; }

    In this case the user is asked to type in a column number between 11 and 19

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2015-07-05 18:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (67 votes), past polls