"be consistent" | |
PerlMonks |
Re: To infinity and beyond: Embedding loopsby antirice (Priest) |
on Jul 16, 2003 at 10:14 UTC ( [id://274755]=note: print w/replies, xml ) | Need Help?? |
If anyone sends me a RTFM advisory they can stuff my output in there I/O and die. Well aren't you a ray of sunshine? :P Where to begin? Well, it shouldn't loop forever. Although, I expect on a large @line and a large @angel it should seem as if it's taking forever. For instance, suppose both are 10_000 elements long. That means you would have 100_000_000 comparisons. When everything is finally finished, @b will be absolutely enormous. For illustrative purposes, let's suppose @line = @angel and that every element in @line is unique. After the loop, @b will contain scalar(@line)**2 - scalar(@line) elements. Needless to say, that's a lot. Also, you're aware that you're pushing indexes into the array, right? You're skipping index 0 on both arrays with your loops. Your comparison checks to see whether or not $k contains the regex contained in $j. This can be a nightmare from a maintainence standpoint since your program will die anytime $j contains a string with an unmatched parenthesis or left bracket. I doubt this is what you really want. You should at least use \Q and \E if you want to see whether or not $k contains the string in $j. If you just wanted to see if they're equal, you should just use lc($k) eq lc($j). Of course, if you want to see whether or not they're actually equal to one another, there's a better way to do it. Here's some code that should be a bit faster and make @b and @a contain what you actually want (except you get to fill in some blanks):
Since I don't want to stuff your input into my I/O and die, I will not tell you to RTFM. Also, if you have time, don't read perlre, perldata or How can I find the union/difference/intersection of two arrays?. Updated: Added comments to the code so it is more understandable to a fellow monk who asked for clarification of how exactly it works. antirice
In Section
Seekers of Perl Wisdom
|
|