bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: /usr/bin/perl assumed when running src/wheel-gen.pl


From: Bob Proulx
Subject: Re: /usr/bin/perl assumed when running src/wheel-gen.pl
Date: Fri, 28 May 2004 10:10:21 -0600
User-agent: Mutt/1.3.28i

Albert Chin-A-Young wrote:
> Don't assume Perl is located in /usr/bin/perl.
> [...]
> -     $(srcdir)/wheel-gen.pl $(wheel_size) > address@hidden
> +     $(PERL) -w $(srcdir)/wheel-gen.pl $(wheel_size) > address@hidden

A good find.  Thanks for reporting it.

I would prefer if the scripts were changed instead of the calling of
the scripts.  That way knowledge of what the scripts are written in is
encapsulated only within the script.  That is, the scripts could be
changed to be shell, or ruby, or whatever without needing to change
how they are called.  Therefore I think the following would be a
better fix for this.

  -#!/usr/bin/perl -w
  +#!/usr/bin/env perl

I prefer 'use strict;' instead of -w.  But I know many still do prefer
just '-w' without 'use strict;'.  But Getting the -w into perl without
it being an option is slighly tricky.  You can't put it on the #! line
since #! only takes one single optional argument.  You can use the $^W
variable like this: 'BEGIN { $^W = 1; }' but needing it to be in a
begin routine is ugly.  Remember it needs to be enabled in the scan
phase and the execution phase is too late.  'use strict;' works
because it is a compile time construct.

I frequently use the following when I need to insert some shell code
such as setting PATH.  I will include a PATH=... for illustration.
With this method you can run arbitrary shell code and then run
arbitrary options to perl on the #! perl line.  The perl -x option
discards lines until a #!perl is encountered and then processes
options from that line ignoring non-option strings.

  #!/bin/sh
  PATH=/usr/local/bin:$PATH
  eval 'exec perl -x -S $0 ${1+"$@"}'
  #! perl -w mentioned to stop looping and enable warnings
  use strict;

Gosh, '#!/usr/bin/env perl' does seem so much simpler.  :-)

But how to get the configured PERL?  This just gets 'perl' and not the
configured one.  But we don't allow users to configure override
/bin/sh for scripts.  So I am not sure this is a really important
thing.  But perl is not standardized and often has multiple versions
installed.  Handling it is easy enough in the shell section.

  #!/bin/sh
  PERL=${PERL:-perl}
  eval 'exec $PERL -x -S $0 ${1+"$@"}'
  #! perl -w
  use strict;

That invocation will use the configured PERL if set.  Otherwise it
will use the 'perl' found on path.  It is a shell script and the
caller does not need to do any special handling of it.  Perl options
such as -w can be placed on the #!perl line.

Bob




reply via email to

[Prev in Thread] Current Thread [Next in Thread]