<

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x

Perl differences in Windows and Unix

Published on
6,887 Points
3,887 Views
Last Modified:
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
Comment
Author:oleggold
1 Comment
LVL 28

Expert Comment

by:FishMonger
That's some of the worst Perl code I've ever seen.
0

Featured Post

Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Join & Write a Comment

Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month