You may also want to take the error-handling and error-invocation out of the subroutine (since it sounds like you're moving the subroutine into a library of some sort) and let your application code deal with the error.
Personally, I'd change the subroutine to accept a list of valid referrers and a URL to check, then return either 1 for a good url or 0 (or undef) for a bad URL.
Something like this:
You can use this something like this:sub check_url { local $_ = shift; my $valid_referrers = shift; my $valid = join '|', @$valid_referrers; return /$valid/ ? 1 : 0; }
my @referrers = ('http://www.foo.com/', 'http://www.bar.com/'); my @urls_to_check = ('http://www.baz.com/bar/', 'http://www.foo.com/bar/'); for my $url (@urls_to_check) { print $url, ": ", check_url($url, \@referrers), "\n"; }
In reply to Re: how to use require function with @referer URLs
by btrott
in thread How do I make my script behave differently based on the referring URL?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |