I pondered this on the way home. I know you can use -p on the shebang line, but in that case, the question to ask would be what happens when you run a script that contains
#! /usr/bin/perl -p
... and nothing else. Curiously enough, this does do the same thing as cat(1). Which only begs the question why does it work when -p is placed on the shebang line of a script, as opposed to needing -e 1 when used on a command line? The command line behaviour looks like a bug to me.
print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u' | [reply] [d/l] |
Which only begs the question why does it work
when -p is placed on the shebang line of a script, as opposed to needing -e 1 when used on a command line?
For the same reason you *never* need -e if you
run the program from a file - either by using the shebang
line, or by doing perl program.
Perl uses the following strategy to find the program:
- If there are one or more -e arguments,
that's where the program was found.
- If the command was invoked as perl [options] file,
the program text is found in the file.
- Otherwise, the program text is found on STDIN.
You might say, what about the shebang line? The shebang line
is handled by the kernel - the interpreter found on the shebang
line is started, and the content of the file (including the
shebang line) is passed on STDIN. (This also explains why
such interpreters always use # as the start of
the comment).
Abigail
| [reply] [d/l] [select] |
2. If the command was invoked as perl options file, the program text is found in the file.
3. Otherwise, the program text is found on STDIN.
This is one step, iirc. The filename is the first non-option argument given on the command line, where "-" is STDIN, and it defaults to "-".
The shebang line is handled by the kernel
perl does its own interpretation too. This is why files with "#!/usr/bin/perl -w" still get warnings, even if called with "perl foo.pl". This is only if it's the first line.
- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.
| [reply] |
| [reply] |