Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: regular expressions and nested loops

by Errto (Vicar)
on Aug 26, 2007 at 02:26 UTC ( #635084=note: print w/replies, xml ) Need Help??

in reply to regular expressions and nested loops

I don't see any fundamental problems here except one: in your outer loop you're iterating over the size of the array @car, when logically it seems that you want to iterate over @make. To reduce your confusion, you can just use foreach-style loops for both:
foreach my $make (@make) { foreach my $car(@car) { if ($make =~ /$car/) { push (@shop, $make); print cftr2dmatch2 "@shop"; } } }
I also removed the calls to next which you don't need because the foreach loop will take care of that for you. Also, if cftr2dmatch2 is a function, make sure it is defined in your code at some earlier point, otherwise it will be treated as a filehandle. To avoid this problem say  print cftr2dmatch2("@shop"); instead. Also be sure to add use warnings; at the top of your code.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://635084]
[stevieb]: I have fixed a boatload of issues across several of my distributions, including a couple that have been nagging for a very long time and were exceptionally difficult to solve. Saving $ before we move, so thought I'd have a code session...
[stevieb]: ...session weekend. Went far better than I could have imagined. Even got a bunch of stuff soldered for another one of my electronics projects on the go, and am working on a fix for a MetaCPAN::Client issue I found
[shmem]: the smaller your boat is, the smaller is the load...
shmem is going to look for problems with C++. Urgh.

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2017-06-25 22:24 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (571 votes). Check out past polls.