Argument "SEEK_SET" isn't numeric in seek at ..

Example code below, it will give the error:
Argument "SEEK_SET" isn't numeric in seek at ..

However, the code works. It just generates error messages in my Apache error log.
sub getURL {
	my $url = shift;
	my $movedURL = "";
	my $response_body = tempfile();
	my $curl = WWW::Curl::Easy->new;

	$curl->setopt(CURLOPT_HEADER, 1);
	$curl->setopt(CURLOPT_URL, $url);
	$curl->setopt(CURLOPT_WRITEDATA, \$response_body);

	if($url =~ /http/) {
		my $return_code = $curl->perform;
		if ($return_code == 0) {
			my $response_code = $curl->getinfo(CURLINFO_HTTP_CODE);
			seek($response_body, 0, 'SEEK_SET');     # reset filehandle to beginning of file
			while (<$response_body>) {
				if($_ =~ /blabla/) {
					$movedURL = substr $_, 10;
					if($movedURL =~ /sorry/) {
						$movedURL = "Sorry, an error occured!";
		} else {
			print ("An error occured: ".$return_code." ".$curl->strerror($return_code)." ".$curl->errbuf."\n");
	if(!$movedURL) { return undef;}
	return $movedURL;

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

use Fcntl qw(:seek);

Open in new window

to the begining of your script and remove quotes from SEEK_SET constant, i.e. rewrite that line as
seek($response_body, 0, SEEK_SET);     # reset filehandle to beginning of file

Open in new window

First change will get you constants for the third seek()'s argument defined.
And the present code is working because string 'SEEK_SET' converted to number in perl has value of 0. By accident, SEEK_SET is also defined as 0. But if you have somewhere 'SEEK_END' of 'SEEK_CUR', then that would not work.

Requirements to use Fcntl module are documented in perldoc -f seek:

For WHENCE you may use the constants
"SEEK_SET", "SEEK_CUR", and "SEEK_END" (start of the file,
current position, end of the file) from the Fcntl module.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
itniflAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.