in reply to Re^2: Perl Script in Windows Works, but not in Unix
in thread Perl Script in Windows Works, but not in Unix

Still, without strict and warnings, few people will pour through your code trying to figure out if a variable is getting clobbered where it shouldn't be or something along those lines. It's very difficult to troubleshoot code that way, and it's very inefficient.

Replies are listed 'Best First'.
Re^4: Perl Script in Windows Works, but not in Unix
by dobster936 (Novice) on Jun 26, 2015 at 19:03 UTC
    Right, I'm just saying it is possible you got those errors because you did not use strict and warnings on the full code. I just added those 2 lines and nothing changed in the output. So I think the errors you got are just due to have only a part of the code.

      If you added use strict;and did not get errors, then I think kcott was on the right track when he indicated the invocation was somehow incorrect.

      #!/usr/bin/env perl use strict; # name # Script to extract "item 7" from a 10-K report. # This will write the "good" part of the file to stdout, and will writ +e # a "schema string" on a single line to stderr. $dirtoget="/10K-txt/";

      This should have immediately produced an error if the Perl interpretter was reading it, because you don't have
           my $dirtoget here.

      Also, changing your first line from
          #!/usr/bin/perl
      to
          #!/usr/bin/env perl

      Changed the behavior.

      Something's up with the invocation.

      I know you said you tried the dos2unixutility, which addresses newlines, but could it be a Unicode file and your Linux system isn't happy with that?

      I'm reaching here, but there is an answer. We just need to find it.

        I think we're on the right track with the invocation too. For example, when I use the path /usr/bin/perl, I now get the error #: bad interpreter: No such file or directory. When using path /usr/bin/env perl I get error env: perl\r: No such file or directory. Looking in the bin folder I see I have a file called "env" and a file called "perl".

        jeffa, you're an absolute wiz at the Linux stuff. You're showing up in the "Other Users" nodelet; any ideas?

      You must be invoking the wrong script or something after adding strict and warnings if you're getting no errors or warnings. I assure you it's not because I didn't have the full script.

      I've written you a very small sample script that at least shows you how you can make your code cross-platform compatible... it runs for me on either Unix or Windows systems without any changes. Modify the $dir paths to your environment and try it to see what happens.

      #!/usr/bin/env perl use warnings; use strict; use File::Find; my $dir; if ($^O eq 'MSWin32'){ $dir = "c:\\users\\steve\\devel\\repos"; } else { $dir = "/home/steve/devel/repos"; } find({ wanted => \&do_file, no_chdir => 1 }, $dir); sub do_file { my $file = $File::Find::name; if (! -f $file){ return; } print "$file\n"; }

      -stevieb