The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Perl Programming
|
Error-No such file or directory
Discuss Error-No such file or directory in the Perl Programming forum on Dev Shed. Error-No such file or directory Perl Programming forum discussing coding in Perl, utilizing Perl modules, and other Perl-related topics. Perl, the Practical Extraction and Reporting Language, is the choice for many for parsing textual information.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 26th, 2012, 07:46 PM
|
|
Contributing User
|
|
Join Date: Jun 2012
Posts: 65
Time spent in forums: 14 h 35 m 42 sec
Reputation Power: 1
|
|
|
Error-No such file or directory
Hi,
I just found my script doesn’t want to work on a machine with Perl 5.8 installed.
I used Perl 5.12 to write the code and it works on my PC.
Getting error: “Cannot open file … No such file or directory…”
Basically I’m looking for new files in a DIR.
I’ll process each new file and then I’ll move the files to a network DIR under the same names.
Do not know how to get around it. Any help will be appreciated.
Thanks, tester
Code:
Code:
#!/use/bin/perl -w
use strict;
use warnings ;
my $compname = $ENV{COMPUTERNAME} ;
use File::Path;
unless(-d "Z:/TErrors/$compname")
{ mkpath("Z:/TErrors/$compname", 0, 0755); }
my $dir = 'D:/Temp';
opendir(DIR, $dir) or die "Can't open directory $dir $!\n";
while (my $file = readdir(DIR)) {
next unless (-f "$dir/$file");
next unless (-M "$dir/$file" < 1);
next unless ($file =~ m/\.log$/);
print $file, "\n" ;
my $logname = $file ;
$nf = "Z:/TErrors/$compname/$logname" ;
open my $nf_fh,'>',$nf or die "Can't open $nf $!\n" ;
open my $file_fh,'<',$file or die "Can't open $file $!\n " ;
while (my $line =<$file_fh>) {
chomp ($line);
if ($line =~ /SomeMatch/)
{
# do somehting else #
print $nf_fh, $line "\n" ;
}
}
close $file_fh ;
close $nf_fh ;
exit ;
|

November 27th, 2012, 01:14 AM
|
|
|
|
Where do you get the error (i.e. on opening the input or the output file)?
As a side note, if your code was properly indented, you would have discovered that you are not closing your filehandles at the right place (you should do it once for every open statement, instead of once at the end), but that should still work because Perl is very nice with people doing this kind of mistakes. But you might discover some other mistake that I did not see. Indenting properly is never a waste of time.
|

November 27th, 2012, 10:10 AM
|
|
|
Your script won't compile.
The starting point would be to read and then fix the problems that those error messages point out.
c:\testing> perl -c testerV.pl Quote:
String found where operator expected at testerV.pl line 34, near "$line "\n""
(Missing operator before "\n"?)
Global symbol "$nf" requires explicit package name at testerV.pl line 23.
Global symbol "$nf" requires explicit package name at testerV.pl line 25.
Global symbol "$nf" requires explicit package name at testerV.pl line 25.
syntax error at testerV.pl line 34, near "$line "\n""
Missing right curly or square bracket at testerV.pl line 39, at end of line
syntax error at testerV.pl line 39, at EOF
testerV.pl had compilation errors. |
|

November 27th, 2012, 11:00 AM
|
|
Contributing User
|
|
Join Date: Jun 2012
Posts: 65
Time spent in forums: 14 h 35 m 42 sec
Reputation Power: 1
|
|
Thank you Lauren, Fish!
I fixed it by adding lines (used code Fish suggested in my previous post):
Code:
my @logfile = grep( -M $_ < 1, <$dir/*.log>);
foreach my $file ( @logfile ) {
chomp $file;
print $file, "\n" ;
my @logname = split ("\/",$file) ;
print $logname[-1], "\n" ;
open my $file_fh,'<', $file or die "CAN'T open $file $!\n" ;
my $nf = "Z:/TErrors/$compname/$logname[-1]" ;
open my $nf_fh,'>',$nf or die "Can't open $nf $!\n" ;
And here:
Code:
close $file_fh ;
close $nf_fh ;
}
exit ;
Thank you again!
testerV
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|