Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Problem in Foreach loop

by Ish (Acolyte)
on Apr 02, 2009 at 05:16 UTC ( #754860=note: print w/replies, xml ) Need Help??


in reply to Problem in Foreach loop

Sorry, I got a bit tied up with something! Try something like this - your data is in an array but otherwise....
use strict; use warnings; my ($i, @array, $bin, $line); my @input = ( "5893 5985 + LOC645399 645399", "7223 7231 - LOC100131533 100131533", "7630 9882 - LOC100131533 100131533", "10142 11428 + LOC100132836 100132836", "12197 13705 - LOC100132070 100132070", "14248 15806 - LOC100132865 100132865", "16830 17405 - LOC100132865 100132865", "18735 19817 + LOC645399 645399", "20802 23113 - LOC100132865 100132865" ); for ($i = 5893; $i <=23113; $i++) { $bin = $i += 7704; push @array, $bin ; } foreach $line (@input) { $line =~ m/\s*(\d+)\s*(\d+)/; foreach my $bin (@array) { if (($bin >= $1) && ($bin <= $2)) { print "$1 $2\n"; last; } } }

Replies are listed 'Best First'.
Re^2: Problem in Foreach loop
by cowboyrocks (Novice) on Apr 02, 2009 at 06:31 UTC
    Thanks for suggesting a good approach :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://754860]
help
Chatterbox?
[Discipulus]: Tanktalus my comment was about how to fork & join in tk?
[marioroy]: Oh, I've might of missed Discipulus's earlier response. I had gone to bed.
[Tanktalus]: ah, I don't even have the perlmonks site open in my browser :)
Tanktalus is chatting through his cbstats application :)
[marioroy]: Perl is so much fun.
[Discipulus]: Tanktalus i recently started a Meditation about marioroy's MCE suit of modules, but is even better to see a practical question answered than responses to my meditation
[Discipulus]: good night mario!
[Tanktalus]: yeah, I saw you post about MCE - the concept looks really really cool. I wonder how well it plays with Coro :)
[Lady_Aleena]: Hi guys. I asked this earlier but got no answer. Why is this dying at -exec: my @music_times = qx(find ~/Music/Albums/ -type f -iname '*.mp3' -exec mp3info -p "%S\n" {} \;);
[Lady_Aleena]: The error find: missing argument to `-exec'

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2017-04-23 19:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (432 votes). Check out past polls.