Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

code works in Windows (Strawberry Perl), fails in Unix - possible path/environment issue

by ilmenolimone (Initiate)
on Mar 02, 2015 at 16:36 UTC ( [id://1118430]=perlquestion: print w/replies, xml ) Need Help??

ilmenolimone has asked for the wisdom of the Perl Monks concerning the following question:

Any help would be MUCH appreciated - thank you!

I'm forced to work with someone else within the company who is running this in the Unix environment. This disconnect makes resolving issues frustrating.

Due to company restrictions, I do not have access to a Unix environment to test my code, and can only relay error messages from my coworker. This is frustrating for both of us!

My perl version is perl 5, version 20, subversion 1 (v5.20.1) built for MSWin32-x64-multi-thread. I have reached out to my coworker to ask what version of perl he is using.

Here is the full code:

#!/usr/bin/perl -w use strict; use warnings; use Encode; use Cwd; use File::Copy; #my ($path) = @ARGV; #use this to pass path as argument #my ($path) = 'C:/TMP/wow/'; #use this to force path my ($path) = cwd(); #use this to set path = current directory #print $path . "\n"; #makes archive and output directories if they don't exist my $dirout = $path . "/output"; my $dirarc = $path . "/archive"; mkdir $dirout; mkdir $dirarc; $path // die "No path specified"; (-e $path) or die "Path not found: $path"; (-d $path) or die "Not a directory: $path"; my @files = <$path/*.x937>; foreach my $file (@files) { process($file); } sub process { my ($fname) = @_; my ($dir, $file) = $fname =~ m{^(.*)/(.+)$}; my $tiff_flag = 0; my $count = 0; my $outfile = sprintf("%s/output/%s_0.txt", $dir, $file); $outfile =~ s/.x937//; while (-e $outfile) { $outfile =~ s/([0-9]+).txt/$1 + 1/e; $outfile = $outfile . ".txt"; } my $mfname = sprintf("%s/archive/%s_0.x937", $dir, $file); $mfname =~ s/.x937_/_/; while (-e $mfname) { $mfname =~ s/([0-9]+).x937/$1 + 1/e; $mfname = $mfname . ".x937"; } open (my $outfh, '>', $outfile) or die "Unable to create $outfile. + $!"; open (my $infh, '<:raw', $fname) or die "Error opening '$file'. $! +"; my $buffer = undef; while (read ($infh,$buffer,4)) { my $rec_len = unpack("N", $buffer); die "Bad record length: $rec_len" unless ($rec_len > 0); read ($infh, $buffer, $rec_len); if (substr($buffer, 0, 2) eq "\xF5\xF2") { if ($tiff_flag) { $count++; my $tiff_filename = sprintf('%s/output_%s_img%04d.tiff +', $dir, $file, $count); open (my $tiffh, '>', $tiff_filename) or die "Can't cr +eate image file $!"; binmode($tiffh) or die 'Error setting binary mode on i +mage file'; print $tiffh substr($buffer, 117); close $tiffh; } $buffer = substr($buffer, 0, 117); } print $outfh decode ('cp1047', $buffer) . "\n"; } close $infh; close $outfh; move($fname,$mfname) or die "Move failed: $!"; }

Here are the errors received:

Scalar found where operator expected at x937.pl line 32, near ")$}" (Missing operator before $}?) Global symbol "$file" requires explicit package name at x937.pl line 1 +9. Global symbol "$file" requires explicit package name at x937.pl line 1 +9. Global symbol "$fname" requires explicit package name at x937.pl line +19. Global symbol "$dir" requires explicit package name at x937.pl line 19 +. Global symbol "$file" requires explicit package name at x937.pl line 1 +9. Global symbol "$fname" requires explicit package name at x937.pl line +19. syntax error at x937.pl line 32, near "my ($dir, $file) = $fname =~ m{ +^(.*)/(" (Might be a runaway multi-line // string starting on line 19) Global symbol "$dir" requires explicit package name at x937.pl line 38 +. Global symbol "$file" requires explicit package name at x937.pl line 3 +8. Global symbol "$dir" requires explicit package name at x937.pl line 45 +. Global symbol "$file" requires explicit package name at x937.pl line 4 +5. Global symbol "$fname" requires explicit package name at x937.pl line +54. Global symbol "$file" requires explicit package name at x937.pl line 5 +4. Global symbol "$dir" requires explicit package name at x937.pl line 67 +. Global symbol "$file" requires explicit package name at x937.pl line 6 +7. Global symbol "$fname" requires explicit package name at x937.pl line +80. Unmatched right curly bracket at x937.pl line 81, at end of line x937.pl has too many errors.

  • Comment on code works in Windows (Strawberry Perl), fails in Unix - possible path/environment issue
  • Select or Download Code

Replies are listed 'Best First'.
Re: code works in Windows (Strawberry Perl), fails in Unix - possible path/environment issue
by toolic (Bishop) on Mar 02, 2015 at 16:47 UTC
    Also, post the versions of Perl you are using on both OS's:
    perl -v
Re: code works in Windows (Strawberry Perl), fails in Unix - possible path/environment issue
by Anonymous Monk on Mar 02, 2015 at 16:43 UTC

    The code you provided compiles fine on Linux for me. The error messages you show do not match the code you posted; they refer to lines that do not exist in the code. Please see How do I post a question effectively? and post the actual script and/or the actual error messages.

      I'm forced to work with someone else within the company who is running this in the Unix environment. This disconnect makes resolving issues frustrating.

      I updated my post to reflect the code exactly as I gave it to him (the only difference was a handful of blank lines I had originally omitted). The errors posted are from his message back to me.

        The error messages match up a little better with the code now, and without having tested it I've got a suspicion: It may be a Perl version before v5.10 which does not support the // defined-or operator. If that's the case it would have to be replaced by equivalent logic using defined. See also perlver.

        BTW, please mark your updates in the original node a little more clearly, see here for why.

Re: code works in Windows (Strawberry Perl), fails in Unix - possible path/environment issue
by Anonymous Monk on Mar 02, 2015 at 17:37 UTC
    "I'm forced to work with someone else within the company who is running this in the Unix environment. This disconnect makes resolving issues frustrating."

    Quite the opposite. It is your co-worker that is being forced to work with your code. When you have no unit testing in place, nor any smoke tests or commit hooks, this is what happens. How can your co-worker expect to use your code if it has not been tested, in the environment it wiill be deployed to, first?

      That's fair. I should have said:

      'Due to company restrictions, I do not have access to a Unix environment to test my code, and can only relay error messages from my coworker. This is frustrating for both of us!

        ""I'm forced to work with someone else within the company who is running this in the Unix environment ... Due to company restrictions, I do not have access to a Unix environment to test my code ..."

        Let us break this down. You are both within the same company, yet one has access to a Unix environment while the other does not. This is the problem, and unless you push back you will be forever the brunt of it. Good luck!

Re: code works in Windows (Strawberry Perl), fails in Unix - possible path/environment issue
by Anonymous Monk on Mar 02, 2015 at 17:21 UTC
    I'm forced to work with someone else within the company who is running this in the Unix environment. This disconnect makes resolving issues frustrating.

    Writing cross-platform Perl only takes a little more effort if you take a little time to look into the right modules for doing so. For example, for file manipulation, see the core modules under File::* such as File::Spec, as well as Path::Class or Path::Tiny. Also, you can set up a VM fairly easily :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1118430]
Approved by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-04-25 11:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found