I know i can make sure things are unique if i just used a hash, but thats more of a hassle for me and puts a bit more work task for my program. So for example:
push @urls,$url;
how can i make sure that push only allows unique urls? or is this even possible?
push @array,$url if !grep(lc($_) eq lc($url),@array);
this will work OK as long as the arrays are not really big, meaning many thousands of elements in the array. For a few thousand elements or less it should be good enough if you don't want to use a hash instead.
Note my sample code is doing string checking (case insensitive) instead of pattern matching, this may not work for your purposes. If not you can switch to a regexp istead of using a string comparison operator.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.