Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Odd behaviour on Mac OS X Lion

Reply
Thread Tools

Odd behaviour on Mac OS X Lion

 
 
Trudge
Guest
Posts: n/a
 
      06-11-2012
I've been having some odd behaviour lately on our work computer running the installed Apple Perl. I have the following few lines of code:

#!/usr/bin/perl
BEGIN
{
open (STDERR,">>$0-err.txt");
print STDERR "\n",scalar localtime,"\n";
}
use strict;
use warnings;

my $ext="pdf";
my $Source = "/Desktop/test1";
my $Destination = "/Desktop/test2";

print "Now running $0 ...\n";
print "\$ext: $ext\n";
print "\$Source: $Source\n";
print "\$Destination: $Destination\n";

However, there is no output to the Terminal window, and no entry is made in the log file. There should at least be a date/time stamp.

If I remove the 'shebang' line, the script outputs as expected, and an entry is made in the log file indicating the timestamp.

What gives?
 
Reply With Quote
 
 
 
 
Dave Saville
Guest
Posts: n/a
 
      06-11-2012
On Mon, 11 Jun 2012 06:54:20 UTC, Trudge <(E-Mail Removed)> wrote:

> I've been having some odd behaviour lately on our work computer running the installed Apple Perl. I have the following few lines of code:
>
> #!/usr/bin/perl


<snip>

> What gives?


I take it that *is* the correct path to your perl executable?
--
Regards
Dave Saville
 
Reply With Quote
 
 
 
 
Trudge
Guest
Posts: n/a
 
      06-11-2012
On Monday, June 11, 2012 3:13:44 AM UTC-4, Dave Saville wrote:
> On Mon, 11 Jun 2012 06:54:20 UTC, Trudge wrote:
>
> > I've been having some odd behaviour lately on our work computer running the installed Apple Perl. I have the following few lines of code:
> >
> > #!/usr/bin/perl

>
> <snip>
>
> > What gives?

>
> I take it that *is* the correct path to your perl executable?
> --
> Regards
> Dave Saville


Heh. Yes. I have several other scripts on this box all running just fine.
--
 
Reply With Quote
 
Alan Curry
Guest
Posts: n/a
 
      06-11-2012
In article <(E-Mail Removed)>,
Trudge <(E-Mail Removed)> wrote:
>On Monday, June 11, 2012 3:13:44 AM UTC-4, Dave Saville wrote:
>> On Mon, 11 Jun 2012 06:54:20 UTC, Trudge wrote:
>>
>> > I've been having some odd behaviour lately on our work computer

>running the installed Apple Perl. I have the following few lines of
>code:
>> >
>> > #!/usr/bin/perl

>>
>> <snip>
>>
>> > What gives?

>>
>> I take it that *is* the correct path to your perl executable?
>> --
>> Regards
>> Dave Saville

>
>Heh. Yes. I have several other scripts on this box all running just fine.


There's probably something extra in the #! line, like a ^M or some Unicode
fluff, that you're not seeing because you're using the wrong editor.

--
Alan Curry
 
Reply With Quote
 
Trudge
Guest
Posts: n/a
 
      06-11-2012
On Jun 11, 5:29*pm, Ben Morrow <(E-Mail Removed)> wrote:
> Quoth Trudge <(E-Mail Removed)>:
>
>
>
>
>
>
>
>
>
> > I've been having some odd behaviour lately on our work computer running
> > the installed Apple Perl. I have the following few lines of code:

>
> > #!/usr/bin/perl
> > BEGIN
> > {
> > * *open (STDERR,">>$0-err.txt");
> > * *print STDERR "\n",scalar localtime,"\n";
> > }

> <snip>
>
> > However, there is no output to the Terminal window, and no entry is made
> > in the log file. There should at least be a date/time stamp.

>
> > If I remove the 'shebang' line, the script outputs as expected, and an
> > entry is made in the log file indicating the timestamp.

>
> Are you running it with
>
> * * perl script
>
> or with
>
> * * ./script
>
> ? If the latter, does it make a difference if you invoke perl directly?
>
> I ask because I wonder if something is inserting a UTF-8 BOM (or some
> other such invisible character) at the beginning of the file, which is
> causing the kernel not to recognise the #!. Of course, I would then
> expect you to get some sort of error message...
>
> Otherwise, start with something completely minimal, like
>
> * * #!/usr/bin/perl
> * * 1;
>
> and add pieces of the original script until it stops working. If you get
> as far as replacing the whole script, compare the two files with 'cmp'
> to see if they are actually identical, and if they aren't hex-dump them
> both to see what the difference is.
>
> Ben


I'm running 'perl -f test.pl', but I did try your suggestion of
'perl ./test.pl' with identical results.

I'll now try your 2nd one and build it a line at a time.

btw, I'm using TextWrangler with 'Invisibles' turned on but don't see
anything strange.
--
Amer Neely
 
Reply With Quote
 
Trudge
Guest
Posts: n/a
 
      06-12-2012
On Jun 11, 7:30*pm, Trudge <(E-Mail Removed)> wrote:
> On Jun 11, 5:29*pm, Ben Morrow <(E-Mail Removed)> wrote:
>
>
>
>
>
>
>
>
>
> > Quoth Trudge <(E-Mail Removed)>:

>
> > > I've been having some odd behaviour lately on our work computer running
> > > the installed Apple Perl. I have the following few lines of code:

>
> > > #!/usr/bin/perl
> > > BEGIN
> > > {
> > > * *open (STDERR,">>$0-err.txt");
> > > * *print STDERR "\n",scalar localtime,"\n";
> > > }

> > <snip>

>
> > > However, there is no output to the Terminal window, and no entry is made
> > > in the log file. There should at least be a date/time stamp.

>
> > > If I remove the 'shebang' line, the script outputs as expected, and an
> > > entry is made in the log file indicating the timestamp.

>
> > Are you running it with

>
> > * * perl script

>
> > or with

>
> > * * ./script

>
> > ? If the latter, does it make a difference if you invoke perl directly?

>
> > I ask because I wonder if something is inserting a UTF-8 BOM (or some
> > other such invisible character) at the beginning of the file, which is
> > causing the kernel not to recognise the #!. Of course, I would then
> > expect you to get some sort of error message...

>
> > Otherwise, start with something completely minimal, like

>
> > * * #!/usr/bin/perl
> > * * 1;

>
> > and add pieces of the original script until it stops working. If you get
> > as far as replacing the whole script, compare the two files with 'cmp'
> > to see if they are actually identical, and if they aren't hex-dump them
> > both to see what the difference is.

>
> > Ben

>
> I'm running 'perl -f test.pl', but I did try your suggestion of
> 'perl ./test.pl' with identical results.
>
> I'll now try your 2nd one and build it a line at a time.
>
> btw, I'm using TextWrangler with 'Invisibles' turned on but don't see
> anything strange.
> --
> Amer Neely


OK, this is very strange. According to TextWrangler this is my code
for perl_test.pl:

#!/usr/bin/perl
BEGIN
{
open (STDERR,">>$0-err.txt");
print STDERR "\n",scalar localtime,"\n";
}

$|=1;
use strict;
use warnings;

my $Source="/Users/prepress/Desktop/northbay_three";
my $Destination="/Users/prepress/Desktop/northbay_two";
my $ext="pdf";
my $f;
my @pdfs=();

print "Now runnng $0.\n";
print "\$Source: $Source\n";
print "\$Destination: $Destination\n";
print "\$ext: $ext\n";


*But* according to cat it is really:
Prepress-Mac-Pro:scripts prepress$ cat perl_test.pl
Prepress-Mac-Pro:scripts prepress$ n";op/northbay_two";

And then cmp tells me:
Prepress-Mac-Pro:scripts prepress$ cmp perl_test.pl perl_test.1.pl
perl_test.pl perl_test.1.pl differ: char 2, line 1

Ben, it looks like you may have hit on the culprit. Where do I go from
here?
--
Amer Neely

 
Reply With Quote
 
Michael Vilain
Guest
Posts: n/a
 
      06-12-2012
In article
<(E-Mail Removed)>,
Trudge <(E-Mail Removed)> wrote:

> On Jun 11, 7:30*pm, Trudge <(E-Mail Removed)> wrote:
> > On Jun 11, 5:29*pm, Ben Morrow <(E-Mail Removed)> wrote:
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > > Quoth Trudge <(E-Mail Removed)>:

> >
> > > > I've been having some odd behaviour lately on our work computer running
> > > > the installed Apple Perl. I have the following few lines of code:

> >
> > > > #!/usr/bin/perl
> > > > BEGIN
> > > > {
> > > > * *open (STDERR,">>$0-err.txt");
> > > > * *print STDERR "\n",scalar localtime,"\n";
> > > > }
> > > <snip>

> >
> > > > However, there is no output to the Terminal window, and no entry is made
> > > > in the log file. There should at least be a date/time stamp.

> >
> > > > If I remove the 'shebang' line, the script outputs as expected, and an
> > > > entry is made in the log file indicating the timestamp.

> >
> > > Are you running it with

> >
> > > * * perl script

> >
> > > or with

> >
> > > * * ./script

> >
> > > ? If the latter, does it make a difference if you invoke perl directly?

> >
> > > I ask because I wonder if something is inserting a UTF-8 BOM (or some
> > > other such invisible character) at the beginning of the file, which is
> > > causing the kernel not to recognise the #!. Of course, I would then
> > > expect you to get some sort of error message...

> >
> > > Otherwise, start with something completely minimal, like

> >
> > > * * #!/usr/bin/perl
> > > * * 1;

> >
> > > and add pieces of the original script until it stops working. If you get
> > > as far as replacing the whole script, compare the two files with 'cmp'
> > > to see if they are actually identical, and if they aren't hex-dump them
> > > both to see what the difference is.

> >
> > > Ben

> >
> > I'm running 'perl -f test.pl', but I did try your suggestion of
> > 'perl ./test.pl' with identical results.
> >
> > I'll now try your 2nd one and build it a line at a time.
> >
> > btw, I'm using TextWrangler with 'Invisibles' turned on but don't see
> > anything strange.
> > --
> > Amer Neely

>
> OK, this is very strange. According to TextWrangler this is my code
> for perl_test.pl:
>
> #!/usr/bin/perl
> BEGIN
> {
> open (STDERR,">>$0-err.txt");
> print STDERR "\n",scalar localtime,"\n";
> }
>
> $|=1;
> use strict;
> use warnings;
>
> my $Source="/Users/prepress/Desktop/northbay_three";
> my $Destination="/Users/prepress/Desktop/northbay_two";
> my $ext="pdf";
> my $f;
> my @pdfs=();
>
> print "Now runnng $0.\n";
> print "\$Source: $Source\n";
> print "\$Destination: $Destination\n";
> print "\$ext: $ext\n";
>
>
> *But* according to cat it is really:
> Prepress-Mac-Pro:scripts prepress$ cat perl_test.pl
> Prepress-Mac-Pro:scripts prepress$ n";op/northbay_two";
>
> And then cmp tells me:
> Prepress-Mac-Pro:scripts prepress$ cmp perl_test.pl perl_test.1.pl
> perl_test.pl perl_test.1.pl differ: char 2, line 1
>
> Ben, it looks like you may have hit on the culprit. Where do I go from
> here?
> --
> Amer Neely


On BBEdit, it will show the line endings. They should be Unix-style
endings. Just a SWAG, but is your file CRLF (Windows) line endings?

Try creating the file in vi. That will only create UNIX style line
endings.

--
DeeDee, don't press that button! DeeDee! NO! Dee...
[I filter all Goggle Groups posts, so any reply may be automatically ignored]


 
Reply With Quote
 
Trudge
Guest
Posts: n/a
 
      06-12-2012
On Tuesday, June 12, 2012 6:07:07 AM UTC-4, Ben Morrow wrote:
> Quoth Trudge
> > On Jun 11, 7:30�pm, Trudge <(E-Mail Removed)> wrote:
> > >
> > > I'm running 'perl -f test.pl', but I did try your suggestion of
> > > 'perl ./test.pl' with identical results.

>
> Do you know what -f does?
>
> > > I'll now try your 2nd one and build it a line at a time.
> > >
> > > btw, I'm using TextWrangler with 'Invisibles' turned on but don't see
> > > anything strange.

> >
> > OK, this is very strange. According to TextWrangler this is my code
> > for perl_test.pl:
> >
> > #!/usr/bin/perl
> > BEGIN

> <snip>
> >
> > *But* according to cat it is really:
> > Prepress-Mac-Pro:scripts prepress$ cat perl_test.pl
> > Prepress-Mac-Pro:scripts prepress$ n";op/northbay_two";

>
> cat is a very bad tool for examining files. At least use less; something
> like od would be better.
>
> It looks to me as though this file has Apple line-endings (\015) rather
> than Unix (\012). This means that as far as perl is concerned your file
> is one very long line, which happens to all be a comment. If you remove
> the #!, it is no longer all a comment, so it works properly.
>
> > And then cmp tells me:
> > Prepress-Mac-Pro:scripts prepress$ cmp perl_test.pl perl_test.1.pl
> > perl_test.pl perl_test.1.pl differ: char 2, line 1

>
> That's interesting: I would have expected something like 'char 16'. Is
> there some other difference? Look at the file with od.
>
> > Ben, it looks like you may have hit on the culprit. Where do I go from
> > here?

>
> Throw away TextWrangler and get a real text editor.
>
> Ben


Heh. Why did I know you would say that

OK, based on yours and Michael's *suggestion* I'll switch to another editor..

btw, TextWrangler was set to Mac line endings. Right on Ben.

Thank you all who responded to this thread. Unless something else weird happens, I would consider this post SOLVED.
--
Amer Neely
 
Reply With Quote
 
Jim Gibson
Guest
Posts: n/a
 
      06-12-2012
In article <(E-Mail Removed)>, Ben Morrow
<(E-Mail Removed)> wrote:

> Quoth Trudge <(E-Mail Removed)>:
> > On Jun 11, 7:30?pm, Trudge <(E-Mail Removed)> wrote:
> > >


> > Ben, it looks like you may have hit on the culprit. Where do I go from
> > here?

>
> Throw away TextWrangler and get a real text editor.


TextWrangler /is/ a real editor, one of the best on the Mac platform.

In this case, the person using TextWrangler can use the 'File > Hex
Dump Front Document' menu option to see what characters are in his
file. If line endings are a problem, he can use the 'Edit > Document
Options' menu selection to change the line endings for the whole file.
If some other set of characters is the problem, he can use the 'Text >
Zap Gremlins' option to modify or delete non-ASCII, control, or null
characters.

--
Jim Gibson
 
Reply With Quote
 
Michael Vilain
Guest
Posts: n/a
 
      06-13-2012
In article <120620121300222790%(E-Mail Removed)>,
Jim Gibson <(E-Mail Removed)> wrote:

> In article <(E-Mail Removed)>, Ben Morrow
> <(E-Mail Removed)> wrote:
>
> > Quoth Trudge <(E-Mail Removed)>:
> > > On Jun 11, 7:30?pm, Trudge <(E-Mail Removed)> wrote:
> > > >

>
> > > Ben, it looks like you may have hit on the culprit. Where do I go from
> > > here?

> >
> > Throw away TextWrangler and get a real text editor.

>
> TextWrangler /is/ a real editor, one of the best on the Mac platform.
>
> In this case, the person using TextWrangler can use the 'File > Hex
> Dump Front Document' menu option to see what characters are in his
> file. If line endings are a problem, he can use the 'Edit > Document
> Options' menu selection to change the line endings for the whole file.
> If some other set of characters is the problem, he can use the 'Text >
> Zap Gremlins' option to modify or delete non-ASCII, control, or null
> characters.


BBEdit, TextWrangler's big brother, allows you to change the file's line
endings between UNIX (\n), Mac (\r), and Windows (\r\n) by selecting the
type at the bottom of the file's window.

I just downloaded TextWrangler 4.01 and it has the same feature. Unless
you like TextWrangler more than MacVim or Emacs, it's time to RTFM and
find out the features of the tool your using.

--
DeeDee, don't press that button! DeeDee! NO! Dee...
[I filter all Goggle Groups posts, so any reply may be automatically ignored]


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Installing Python Apps on Mac Lion JKPeck Python 3 03-13-2012 07:28 PM
Can't get tilde character with IDLE 3.2.2 on French Mac Lion Franck Ditter Python 4 03-05-2012 01:41 AM
MySQLdb on Mac Lion Tim Johnson Python 0 10-13-2011 12:52 AM



Advertisments