Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: how to refer the index of an array to another array of the same length

by Athanasius (Chancellor)
on Aug 03, 2013 at 09:34 UTC ( #1047680=note: print w/replies, xml ) Need Help??


in reply to how to refer the index of an array to another array of the same length

I think you need a C-style for loop, to keep track of the array index. Something like this:

for my $i (0 .. $#cg) { my $g = $cg[$i]; if ($g eq $gl[$i]) { push @ind, $g; print N "$g\n"; print S "$csta[$i]\n"; } }

Is that what you’re looking for? If not, please specify sample input (the contents of the arrays) together with the output you expect.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: how to refer the index of an array to another array of the same length
by rocketperl (Sexton) on Aug 03, 2013 at 09:56 UTC
    Thank you so much. The logic is correct but it prints the first index of csta only. Can you suggest me a way to iterate it? Thanks a lot
    @gl LYPLA1 MSC TERF1 CFC1 COL3A1 CLK1 FZD7 ADAM23 CREB1 FN1 XRCC5 DES PAX3 GBX2 TCFCP2L1
    @csta 4797974 14746047 15795739 34592493 45368491 58480932 59539023 63492478 64579378 71699745 72354094 75356919 78193711 91827751 120524522
    @cg LYPLA1 LYPLA1 LYPLA1 LYPLA1 LYPLA1 LYPLA1 LYPLA1 LYPLA1 LYPLA1 LYPLA1 LYPLA1 LYPLA1 LYPLA1
      You are only looking for the key "LYPLA1", which happens to be the first element of @gl and therefore your result will show for every match of "LYPLA1", the first element of @csta, i.e. "4797974". You might wish to vary the search keys a bit to see something different.

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      My blog: Imperial Deltronics
        Thanks a lot.. :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1047680]
help
Chatterbox?
[Mr. Muskrat]: (considered) Re^3: Please help with Regexp::Common needs to be reparented to Re^2: Please help with Regexp::Common
[Mr. Muskrat]: Is it just me or does that timeout issue seems to be happening more often lately?
[Corion]: Mr. Muskrat: I'm not sure if it really happens more often, but I don't exactly know either
[LanX]: yep
[LanX]: more often for some weeks now
[Corion]: I think I'll have to manually (as god) intervene with that node, as the simple reparenting didn't seem to fix the parent/child relationship of the nodes
[Corion]: I think I have an idea but I'll have to open a ticket with Pair.com on that - hopefully I get to that on the weekend
LanX imagines a burning thorn bush
[Mr. Muskrat]: Thank you!

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (11)
As of 2017-01-19 16:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (170 votes). Check out past polls.