Re: Return code to exit from a .bat file
Thanks, it worked or at least gave me an error and exited the batch file. The batch files are difficult to work out if there are a lot (I have 12 or more files to check) so I will probably do as you suggest (write a wrapper) once I have worked out how to do it, and then I can return the error code to Windows. Regards Mark Bedish Surrey,UK In a message dated Mon, 1 Oct 2001 12:30:31 British Summer Time, "Brett W. McCoy" <[EMAIL PROTECTED]> writes: > On Mon, 1 Oct 2001 [EMAIL PROTECTED] wrote: > > > I think my main problem is getting an eror out of perl which is > > recognised by a .bat file. I have set a return code in the program > > from a subroutine but it is not getting to the operating system. > > You should use 'exit' to return a value from a Perl program back to the > OS. 0 means a normal exit, 1 means an error condition. In a typical > batch file, you can do something like 'IF ERRORLEVEL = 1 GOTO > ERRORHANDLER'. DOS Batch files don't do very well handling error > conditions. I would recommend writing a wrapper script in Perl instead to > run your secondary Perl programs, or move to an environment that has > better scripting tools. On Windows, CygWin or MKSTools offer most of > the advantages of Unix scripting tools, like bash or ksh. > > -- Brett > http://www.chapelperilous.net/ > > "Though a program be but three lines long, > someday it will have to be maintained." > -- The Tao of Programming -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Return code to exit from a .bat file
I think my main problem is getting an eror out of perl which is recognised by a .bat file. I have set a return code in the program from a subroutine but it is not getting to the operating system. __SNIP__ while () { chomp; $length = length($_); if ($length != $lp) { print OUT "Invalid record length: $length on Line:$.\n$_\n\n"; ++$errors; } } &rc; sub rc{ #print "Error returned from rc: $errors\n"; return $errors; } __SNIP__ In a message dated Mon, 1 Oct 2001 11:06:48 British Summer Time, "Rajeev Rumale" <[EMAIL PROTECTED]> writes: > You can use label and goto to achive this. > > create a lable end of the batch file. > ": FILE_ERROR > > The check for the condition if it is false then use statement. > "GOTO FILE_ERROR". > > This will send the cursor to last label. and will stop > you can instert a echo command also after this. > echo " Stopped for error." > > For more info check this site http://www.computerhope.com/batch.htm > > > Regareds > > Rajeev > - Original Message - > From: <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Monday, October 01, 2001 5:56 PM > Subject: Return code to exit from a .bat file > > > > I am doing a simple record length check on a series of files via a dos > batch file e.g. check_length.bat: > > > > check_length.pl file1 100 > > check_length.pl file2 200 > > check_length.pl file3 300 > > > > > > Is it possible to do something in perl (like a return code) so that the > batch file aborts if say file2 is incorrect ? > > > > TIA > > > > Regards > > > > Mark Bedish > > Surrey,UK > > > > > > -- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Return code to exit from a .bat file
I am doing a simple record length check on a series of files via a dos batch file e.g. check_length.bat: check_length.pl file1 100 check_length.pl file2 200 check_length.pl file3 300 Is it possible to do something in perl (like a return code) so that the batch file aborts if say file2 is incorrect ? TIA Regards Mark Bedish Surrey,UK -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Formatting File date information
All, I am trying to write some portable code for listing files and directories on Unix and Win and possibly Mac. I want to get specifically the modification date of files into a format that can load into mySQL in -mm-dd format. (This will help me greatly with housekeeping.) I have looked at File::Find which is great for getting fast listings but doesnt give me the mod date, just age? Use File::Find; find sub { print OUT $File::Find::name , -d && '/', ' ', "\t", -s, "\t", -A"\n" }, @ARGV; Are there any modules that would easily give me that info (fspec) or will I have to use stat and then localtime with posix to parse the epoch date which seems also very slow as it traverses the directory tree? Thanks for any advice. Regards, Mark Bedish Surrey,UK -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Compare large files memory error
No, I am using Win NT. Regards, Mark Surrey,UK > Does your system have the 'cmp' program on it? IIRC this is a standard or > fairly standard Unix utility which does exactly what you want and you could > just call it from Perl... >Regards > >Mark Bedish >Surrey,UK > > >In a message dated Tue, 7 Aug 2001 13:36:50 British Summer Time, >[EMAIL PROTECTED] (Randal L. Schwartz) writes: > > > > "Jos" == Jos I Boumans <[EMAIL PROTECTED]> writes: > > > > Jos> if you're just interested in *EXACTLY* the same files, use MD5 > (get it from > > Jos> search.cpan.org) > > Jos> even one BIT of difference (literally) will result in a different > checksum > > Jos> thorough and fast > > > > MD5 is useful when you don't want to use the original data to compare > > (or no longer have access to it). But if you've got both big files > > sitting in front of you, it's a waste to compute md5(one) == md5(two). > > Instead, just get File::Compare from the CPAN, which does a very > > efficient comparison: first length, then big-block by big-block > > equality. > > > > print "Just another Perl hacker,"; > > > > -- > > Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 > > <[EMAIL PROTECTED]> http://www.stonehenge.com/merlyn/> > > Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. > > See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl > training! > > > > -- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > >-- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Compare large files memory error
Is there a better way to compare large files than this snippet, which runs out of memory if files > 30mb. It is also slow, about the same speed as comparing in a text editor! Thank you. __SNIP__ @file1 = (); @file2 = (); $are_equal = compare_arrays(\@file1, \@file2); if ($are_equal) { print "Files are IDENTICAL \n"; } else { print "Files are DIFFERENT \n"; } sub compare_arrays { my ($first, $second) = @_; #no warnings; # silence spurious -w undef complaints return 0 unless @$first == @$second; for (my $i = 0; $i < @$first; $i++) { return 0 if $first->[$i] ne $second->[$i]; } return 1; } __SNIP__ Regards, Mark Surrey,UK -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]