<

Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x

Perl differences in Windows and Unix

Published on
6,591 Points
3,591 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 28

Expert Comment

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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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