<

Perl differences in Windows and Unix

Published on
6,996 Points
3,996 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
Author:oleggold
Enjoy this complimentary article view.

Get unlimited access to our entire library of technical procedures, guides, and tutorials written by certified industry professionals.

Get 7 days free
Click here to view the full article

Using this article for work? Experts Exchange can benefit your whole team.

Learn More
COLLABORATE WITH CERTIFIED PROFESSIONALS
Experts Exchange is a tech solutions provider where users receive personalized tech help from vetted certified professionals. These industry professionals also write and publish relevant articles on our site.
Ask questions about what you read
If you have a question about something within an article, you can receive help directly from the article author. Experts Exchange article authors are available to answer questions and further the discussion.
Learn from the best.