Code Comments
Programming Forum and web based access to our favorite programming groups.When I execute the script below, I get the error message "No such file or
directory at simple2.pl line 21." Line 21 is the Open OUT statement.
This script parallels a tutorial script that does work and I don't see the
error. It does print to the screen if I comment out the Open OUT line.
Thanks in advance.
#!/bin/perl
use strict;
use WWW::Mechanize;
my $output_dir = "c:/training/bc";
my $starting_url = "http://clerk.house.gov/members/olmbr.html";
my $browser = WWW::Mechanize->new();
$browser->get( $starting_url );
$browser->submit();
{
open OUT, ">output_dir/simple2.html" or die "Can't open file: $!";
print OUT $browser->content;
close OUT;
}
close PAGE;
print $browser->content;
Post Follow-up to this messageOne simple thing you might want to start doing is including the filename in your error message. Quite often this message means that either you're not in the starting directory you think you're in or part of your filename is being interpreted as something other than what you intended. my $file =3D "output_dir/simple2.html"; open OUT,">$file" or die "Can't open '$file' for writing: $!"; -----Original Message----- From: kc68@cornell.edu [mailto:kc68@cornell.edu]=20 Sent: Monday, May 22, 2006 2:50 PM To: beginners@perl.org Subject: No Such File Error on Simple Scrape When I execute the script below, I get the error message "No such file or =20 directory at simple2.pl line 21." Line 21 is the Open OUT statement. =20 This script parallels a tutorial script that does work and I don't see the =20 error. It does print to the screen if I comment out the Open OUT line. Thanks in advance. <snip> open OUT, ">output_dir/simple2.html" or die "Can't open file: $!"; <snip>
Post Follow-up to this messageOn Monday 22 May 2006 14:49, kc68@cornell.edu wrote:
> When I execute the script below, I get the error message "No such file or
> directory at simple2.pl line 21." Line 21 is the Open OUT statement.
> This script parallels a tutorial script that does work and I don't see the
> error. It does print to the screen if I comment out the Open OUT line.
> Thanks in advance.
>
> #!/bin/perl
>
> use strict;
>
> use WWW::Mechanize;
>
> my $output_dir = "c:/training/bc";
>
> my $starting_url = "http://clerk.house.gov/members/olmbr.html";
>
> my $browser = WWW::Mechanize->new();
>
> $browser->get( $starting_url );
>
>
> $browser->submit();
>
>
> {
>
> open OUT, ">output_dir/simple2.html" or die "Can't open file: $!";
Maybe the directory 'output_dir' does not exists. perl wont create
directories unless you tell it to by using the mkdir function.
>
> print OUT $browser->content;
>
> close OUT;
>
> }
>
> close PAGE;
>
> print $browser->content;
Post Follow-up to this messageOn Mon, 22 May 2006 18:00:25 -0400, Jaime Murillo <jmurill0@pacbell.net> wrote: > On Monday 22 May 2006 14:49, kc68@cornell.edu wrote: > > Maybe the directory 'output_dir' does not exists. perl wont create > directories unless you tell it to by using the mkdir function. > > That's it: I needed $output_dir/simple2.html - missing the $ Now have to start working on the regex as I got the page with "No matches found"
Post Follow-up to this messagekc68@cornell.edu wrote:
> When I execute the script below, I get the error message "No such file
> or directory at simple2.pl line 21." Line 21 is the Open OUT
> statement. This script parallels a tutorial script that does work and
> I don't see the error. It does print to the screen if I comment out
> the Open OUT line. Thanks in advance.
>
> #!/bin/perl
>
> use strict;
>
> use WWW::Mechanize;
>
> my $output_dir = "c:/training/bc";
>
> my $starting_url = "http://clerk.house.gov/members/olmbr.html";
>
> my $browser = WWW::Mechanize->new();
>
> $browser->get( $starting_url );
>
>
> $browser->submit();
>
>
> {
>
> open OUT, ">output_dir/simple2.html" or die "Can't open file: $!";
Does the directory 'output_dir' exist in the current directory or did you
intend to use the variable $output_dir instead?
> print OUT $browser->content;
>
> close OUT;
>
> }
>
> close PAGE;
Where did you open the PAGE filehandle?
> print $browser->content;
John
--
use Perl;
program
fulfillment
Post Follow-up to this messagekc68@cornell.edu schreef: > my $output_dir = "c:/training/bc"; > [...] > open OUT, ">output_dir/simple2.html" or die "Can't open file: $!"; ^ Maybe you meant $output_dir? ^ -- Affijn, Ruud "Gewoon is een tijger."
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.