Perl differences in Windows and Unix

Published:
Updated:
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx..
MOST IMPORTANT:
Use Unix file format while saving Your script.
otherwise it will have ^M s or smth likely weird in the EOL,
Then DO NOT use my ad hoc initialization in Unix like my $list = ...;
,never worked,doesn't seem to work now,why bother,
just
compare 2 snips bellow:
#!/usr/bin/perl
                      use Win32::ODBC;
                      use File::Find;
                      #@ARGV = ('.') unless @ARGV;
                      $path = "/stage001/TgtFiles/CMR/";
                      #my    $filesize = 0;
                      $path = "c:\\DATA\\FTP\\" ;
                      $ret = 1;
                      $i = 1;
                      $file = "LOSEOUT_DTL.txt";
                      $trg =  655;
                       
                       if (@ARGV ne ("")) {
                         $file = shift @ARGV;
                         }
                       
                       
                      #   if (&checks) {    system 'gen_geo_files.ksh $file NN'   }
                         &checks;
                       
                             sub checks(){
                       
                       
                       
                       
                       
                                  #    my path = "/ushhetl/stage001/TgtFiles/CMR/"
                       
                                  open (DATAFILE, $path.$file)
                      	or die ("Problem opening file: $!");
                       
                              while (defined ($line = <DATAFILE>)) {
                          chomp $line;
                       
                          $size = length $line;
                          if ($i==1) {$trg=($size-1); }
                         if ( $size<$trg) {
                                   print "$i:$size:$file:$ret" ;
                                 print "$line\n";
                                     $ret  ;
                       
                      }
                       $i  ;
                      #  if ($i>0) {              return   $ret;  }
                                     # output size of line
                      }
                        #  $filesize = -s $file;
                                       print  "\n$file:$i:$trg";
                       #if ($i>0) {
                                     return   $ret;
                      #}
                      }
                      #while (<SPREADSHEET>) {
                       
                        #	$numbers = $_;
                         #	chomp($numbers);
                       
                          #	@numbers = split(/\t/, $numbers);
                       
                       #	$total = 0;
                       
                       #	foreach $number (@numbers){
                        #		$total = $total   $number;
                         #	}
                       
                           #	print $total . "\n";
                       
                      #}
                       
                      #close (SPREADSHEET);

Open in new window


for Unix:
                      #!.perl
                      #use Win32::ODBC;
                      #use File::Find;
                      #@ARGV = ('.') unless @ARGV;
                       
                      $path = "/stage001/TgtFiles/r/";
                      #my    $filesize = 0;
                      # my $path = "c:\\DATA\\FTP\\" ;
                         my $ret = 1;
                          my $i = 1;
                        $file = "_DTL.txt";
                               my $trg =  655;
                       
                       if (@ARGV ne ("")) {
                         $file = shift @ARGV;
                         }
                         # else {       $file = "CLOSEOUT_DTL.txt"; $trg =  655;       }
                          #   find(\&checks, $path);
                       
                      #   if (&checks) {    system 'gen_geo_files.ksh $file NN'   }
                         &checks;
                       
                             sub checks(){
                       
                       
                       
                       
                       
                       
                                  #    my path = "/ushhetl/stage001/TgtFiles/CMR/"
                       
                                  open (DATAFILE, $path.$file)
                      	or die ("Problem opening file: $!");
                       
                              while (defined ($line = <DATAFILE>)) {
                          chomp $line;
                       
                          $size = length $line;
                          if ($i==1) {$trg=($size-1); }
                         if ( $size<$trg) {
                                   print "$i:$size:$file:$ret" ;
                                 print "$line\n";
                                     $ret  ;
                       
                      }
                       $i  ;
                      #  if ($i>0) {              return   $ret;  }
                                     # output size of line
                      }
                        #  $filesize = -s $file;
                                       print  "\n$file:$i:$trg";
                       #if ($i>0) {
                                     return   $ret;
                      #}
                      }
                      #while (<SPREADSHEET>) {
                       
                        #	$numbers = $_;
                         #	chomp($numbers);
                       
                          #	@numbers = split(/\t/, $numbers);
                       
                       #	$total = 0;
                       
                       #	foreach $number (@numbers){
                        #		$total = $total   $number;
                         #	}
                       
                           #	print $total . "\n";
                       
                      #}
                       
                      #close (SPREADSHEET);

Open in new window

0
4,425 Views

Comments (1)

CERTIFIED EXPERT

Commented:
That's some of the worst Perl code I've ever seen.

Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.