Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 26th, 2012, 07:46 PM
testerV testerV is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 65 testerV User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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 ;

Reply With Quote
  #2  
Old November 27th, 2012, 01:14 AM
Laurent_R Laurent_R is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2012
Posts: 508 Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 4 Days 19 h 29 m 2 sec
Reputation Power: 385
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.

Reply With Quote
  #3  
Old November 27th, 2012, 10:10 AM
FishMonger FishMonger is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2009
Posts: 1,650 FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 2 h 37 m 31 sec
Reputation Power: 1170
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.

Reply With Quote
  #4  
Old November 27th, 2012, 11:00 AM
testerV testerV is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 65 testerV User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Error-No such file or directory

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap