> Which is not really portable with command line options, due to how
> env(1) works on OS X:
[quoted text clipped - 5 lines]
> $ ./test
> env: perl -wl: No such file or directory
That is both against the documentation (env(1)) and the UNIX spec,
so I think a bug report to Apple is in order. (Actually, env as such
seems to be working okay, so it is more likely a bug in the #! processing.)
> A different trick that I have not tested on other unix systems (as I
> just use '#!/usr/bin/perl') is to do the following:
[quoted text clipped - 5 lines]
> $ ./test
> hello world
Sherm Pendley - 25 Jul 2004 17:13 GMT
> That is both against the documentation (env(1)) and the UNIX spec,
> so I think a bug report to Apple is in order. (Actually, env as such
> seems to be working okay, so it is more likely a bug in the #!
> processing.)
It's not unique to Mac OS X - I get the same results with Perl 5.8.3 on
Debian "Sarge".
In both cases, running 'env perl -v' from a shell prompt works as
expected.
sherm--
Edward Moy - 25 Jul 2004 19:09 GMT
>> Which is not really portable with command line options, due to how
>> env(1) works on OS X:
[quoted text clipped - 10 lines]
> seems to be working okay, so it is more likely a bug in the #!
> processing.)
This is one of those historical worts. See "man execve":
An interpreter file begins with a line of the form:
#! interpreter [arg]
When an interpreter file is execve()'d, the system execve()'s runs
the
specified interpreter. If the optional arg is specified, it
becomes the
first argument to the interpreter, and the name of the originally
execve()'d file becomes the second argument; otherwise, the name
of the
originally execve()'d file becomes the first argument. The
original
arguments are shifted over to become the subsequent arguments. The
zeroth argument, normally the name of the execve()'d file, is left
unchanged.
Thus:
#!/usr/bin/env perl -wl
is interpreted as:
/usr/bin/env "perl -wl" scriptname
thus, the error message.
------------------------------------------------------------------------
--
Edward Moy
Apple Computer, Inc.
emoy@apple.com
(This message is from me as a reader of this list, and not a statement
from Apple.)
Sherm Pendley - 25 Jul 2004 19:36 GMT
> This is one of those historical worts.
I can ferment it to make beer? Cool! ;-)
sherm--
> #!/usr/bin/env perl -wl
Looking in the Camel, I'm not sure what the -l flag is supposed to
be doing for you. You're not using it with -n or -p, so it isn't
auto-chomping the input lines; you didn't give it an argument, so
it isn't changing the output line terminator. So, what's it for?
My Perl scripts, FWIW, all have the same general format:
#!/usr/bin/env perl
#
# foo - do fooish things
#
# ...
use Bar::Baz; # bring in external modules
...
use strict;
use warnings;
{ # "main" routine
our ($aa, ... # globals used by main
...
);
my ($a, ... # private variables
...
);
... # executable code
}
# foosub - do foosubbish things
#
sub foosub {
my ($p1, ...) = @_; # copies of input arguments
our ($aa, ... # globals used by foosub
...
);
my ($b, ... # private variables
...
);
... # executable code
}
... # more subs
The "use warnings" line takes the place of the "-w" flag. The "use
strict" keeps me even more honest (:-). Putting these lines AFTER
the "use Bar::Baz;" lines(s) prevents me from getting nastygrams
about coding practices in the imported module(s).
By putting the "main" code in a pair of brackets, I cause it to be
indented at the same starting level as the code in the subs. This
also restricts the scope of its statements (e.g., "our"), so they
aren't global to the file.
To be totally honest, I often start out by using a single "our"
statement above the "main" block. Then, when the code is stable,
I go back and replace this with specific "our" statements in the
"main" and sub blocks. This gives me some freedom during the
early stages of development, but controls (and documents) the
visibility of the globals, while the code is in production use.
In any case, I try to keep the use of global variables down, as
overuse of globals can cause confusion...
-r

Signature
email: rdm@cfcl.com; phone: +1 650-873-7841
http://www.cfcl.com - Canta Forda Computer Laboratory
http://www.cfcl.com/Meta - The FreeBSD Browser, Meta Project, etc.
http://www.ptf.com/dossier - Prime Time Freeware's DOSSIER series
Ken Williams - 26 Jul 2004 13:47 GMT
>> #!/usr/bin/env perl -wl
>
> Looking in the Camel, I'm not sure what the -l flag is supposed to
> be doing for you. You're not using it with -n or -p, so it isn't
> auto-chomping the input lines; you didn't give it an argument, so
> it isn't changing the output line terminator. So, what's it for?
It adds a newline after each print().
-Ken