Link to home
Start Free TrialLog in
Avatar of itnifl
itniflFlag for Norway

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of monas
monas
Flag of Lithuania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of itnifl

ASKER

Thanks!