Perl question

Fairlight fairlite at fairlite.com
Thu Jun 17 14:20:31 PDT 2004


On Thu, Jun 17, 2004 at 01:50:12PM -0700, Steven Waters may or may not have
proven themselves an utter git by pronouncing:
> So I am assuming that, #/usr/bin perl -T is ignored.
> but, #!/usr/bin/perl -T is not?

See Bill's explanation of magics.

Additionally, the '#!/path [flags]' syntax is actually honoured even if
you called the script directly with the perl interpreter 
(eg., `perl somescript.pl`).  Perl, like most shells, will indeed honour the 
magic even though the target program was invoked directly and explicitly
under the perl interpreter.

You -can-, however, manage to override the magic in -one- known case.  I
figured this out for an installation script.  If you give it
#!/usr/bin/perl for example, and no such path exists, you can call 
`perl somescript.pl` and it -will- actually execute it under perl if the
specified path in the magic line does not exist -AND- the basename of the
indicated path is 'perl'.

Examples:

#!/home1/fairlite/perl -w
...
`perl somescript.pl`

This will work, -even- if perl is -not- present in /home1/fairlite.  The
basename is 'perl' and it's smart enough to know that it should hold onto
it in the explicitly called interpreter.

#!/home1/fairlite/bogus -w
...
`perl somescript.pl`

This will NOT work, as the basename does not resolve to 'perl', -and- the
specified interpreter of the magic line is not in extant.  In this case
it would only work if -something- was actually at '/home1/fairlite/parl' to
actually feed the script to.

#!/bin/sh
...
`perl somescript.pl`

This will work, and will hand the script to the Bourne shell.

That first override case specific to basename perl is a nice exemption,
handy for installation scripts, as I said, when you don't necessarily know
where the target machine's perl will be.  You can supply instructions that
indicate one should invoke the interpreter explicitly for the first phase
of installation, then substitute the correct magic lines during all program
file copy operations so that they're properly configured post-installation.

Just one of those "little tricks".  :)  I've never even seen it documented.
I found it by accident and validated all the tests I illustrated.

Enjoy!

mark->
-- 
Bring the web-enabling power of OneGate to -your- filePro applications today!

Try the live filePro-based, OneGate-enabled demo at the following URL:
               http://www2.onnik.com/~fairlite/flfssindex.html


More information about the Filepro-list mailing list