Perl differences in Windows and Unix

AID: 355
  • Status: Published

1900 points

  • Byoleggold
  • TypeGeneral
  • Posted on2008-12-17 at 13:31:00
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);
                                    
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:

Select allOpen 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);
                                    
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:

Select allOpen in new window

Asked On
2008-12-17 at 13:31:00ID355
Tags

Perl

,

Programming

,

OS

,

compile

Topic

Perl Programming Language

Views
1365

Comments

Expert Comment

by: FishMonger on 2010-04-13 at 08:38:29ID: 13091

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

Add your Comment

Please Sign up or Log in to comment on this article.

Join Experts Exchange Today

Gain Access to all our Tech Resources

Get personalized answers

Ask unlimited questions

Access Proven Solutions

Search 3.2 million solutions

Read In-Depth How-To Guides

1000+ articles, demos, & tips

Watch Step by Step Tutorials

Learn direct from top tech pros

And Much More!

Your complete tech resource

See Plans and Pricing

30-day free trial. Register in 60 seconds.

Loading Advertisement...

Top Perl Experts

  1. ozo

    100,340

    Master

    0 points yesterday

    Profile
    Rank: Savant
  2. farzanj

    60,737

    Master

    0 points yesterday

    Profile
    Rank: Genius
  3. FishMonger

    45,500

    0 points yesterday

    Profile
    Rank: Genius
  4. wilcoxon

    39,566

    0 points yesterday

    Profile
    Rank: Sage
  5. kyanwan

    16,300

    0 points yesterday

    Profile
  6. bounsy

    15,700

    0 points yesterday

    Profile
    Rank: Wizard
  7. parparov

    14,460

    0 points yesterday

    Profile
    Rank: Guru
  8. ahoffmann

    14,252

    0 points yesterday

    Profile
    Rank: Genius
  9. simon3270

    11,550

    0 points yesterday

    Profile
    Rank: Wizard
  10. BinaryWarrior

    10,833

    0 points yesterday

    Profile
  11. kaufmed

    9,856

    0 points yesterday

    Profile
    Rank: Genius
  12. DaveBaldwin

    8,582

    0 points yesterday

    Profile
    Rank: Genius
  13. xterm

    8,500

    0 points yesterday

    Profile
    Rank: Sage
  14. woolmilkporc

    6,372

    0 points yesterday

    Profile
    Rank: Genius
  15. Ray_Paseur

    5,900

    0 points yesterday

    Profile
    Rank: Savant
  16. sjklein42

    5,468

    0 points yesterday

    Profile
    Rank: Sage
  17. arnold

    5,100

    0 points yesterday

    Profile
    Rank: Genius
  18. pfrancois

    4,888

    0 points yesterday

    Profile
    Rank: Guru
  19. Tintin

    4,268

    0 points yesterday

    Profile
    Rank: Genius
  20. johanntagle

    4,000

    0 points yesterday

    Profile
    Rank: Sage
  21. Papertrip

    4,000

    0 points yesterday

    Profile
    Rank: Sage
  22. slightwv

    3,800

    0 points yesterday

    Profile
    Rank: Genius
  23. nemws1

    3,800

    0 points yesterday

    Profile
    Rank: Sage
  24. bazika

    3,668

    0 points yesterday

    Profile
  25. dragon-it

    3,650

    0 points yesterday

    Profile
    Rank: Genius

Hall Of Fame