Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to see if a file exists

Status
Not open for further replies.

nochoice

Programmer
Jun 17, 2003
72
CA
Hey guys here's my issue:

I am interested in determining if a file exists. Here's the scenario:

1) user wants to add their engineering website to my linklist.

2) User fills in a simple form - name, eng porgram, URL of websited, etc.... and hits submit.

3) I want to verify that the URL they enter actually exists.

How do I do this?

Here is a sample of the code I am using for testing:

open(INF,&quot;< or dienice(&quot;file does not exist: $!&quot;);
flock(INF,2);
seek(INF,0,0);
@ary = <INF>;
close(INF);

foreach $line (@ary) {
chomp($line);
print &quot;$line&quot;;
}

I though I would start by testing a know page (it's part of my site). Then move into variables. I hope I'm not too far off here. Any suggestions would be awesome.

Thanks in advance for your help,
Michael
 
Lwp would be the way to go

search.cpan.org, though I think its now shipped with the Perl distribution

HTH
--Paul
 
yes you need to do as PaulTEG says...

LWP [red]the Library for World Wide Web in Perl[/red] can help with this:-

use LWP;

$browser = LWP::UserAgent->new();

$response = $browser->get(&quot;
if ($response->is_success) {
print &quot;*** SUCCESS ***\n&quot;;
} else {
print &quot;error\n&quot;;
}


If you change the URL to something you know does not exist then the script will return an error

regards
Duncan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top