Closed p5pRT closed 20 years ago
Congratulations on the ongoing excellent work.
I found today that the command-line invocation fails not support
UNIX-style
multiple switches\, and does not warn of this:
perl -ep '\
I suggest you need at least a warning when you ignore superfluous cmdline args.
Secondly: a documentation request ('man perlrun') for the octal codes for the -0 switch (or at least\, the common separator codes e.g. tabs\, space\, comma\, colon)
Best regards\, Stephen McInerney
Frontend CAD Engineer Tel: (408) 919-6877 email:stephenm@transmeta.com Fax: (408) 919-6407 Transmeta Corporation\, 2960 Mission College Blvd.\, Santa Clara\, CA 95054
On Feb 13\, stephenm@transmeta.com said:
perl -ep '\
' will not work correctly whereas: perl -p -e '\ ' does.
This is because -e takes a string to execute.
perl -eprint1
prints 1.
perl -pe 'print 1'
works\, as does
perl -p -e 'print 1'
Secondly: a documentation request ('man perlrun') for the octal codes for the -0 switch (or at least\, the common separator codes e.g. tabs\, space\, comma\, colon)
This can be gotten via 'man ascii'\, or simply by:
perl -e 'printf "%s = \\%03o\n"\, $_\, ord for @ARGV'
Hi Jeff\,
Thanks very much for your response. My question was not "what is the right way of doing this" which I found by trial and error\, but "surely perl should warn if invoked the wrong way?" or at least\, surely "man perlrun" should warn of the potential danger in multiple '-abc' switch style?
To the documentation question\, could you include your solution in the manpages? 'man ascii' does nothing for me\, are you sure that is a standard thing? How do I generate that manpage? (Solaris 8?)
All the best\, Stephen
Jeff Pinyan wrote:
On Feb 13\, stephenm@transmeta.com said:
perl -ep '\
' will not work correctly whereas: perl -p -e '\ ' does. This is because -e takes a string to execute.
perl -eprint1
prints 1.
perl -pe 'print 1'
works\, as does
perl -p -e 'print 1'
Secondly: a documentation request ('man perlrun') for the octal codes for the -0 switch (or at least\, the common separator codes e.g. tabs\, space\, comma\, colon)
This can be gotten via 'man ascii'\, or simply by:
perl -e 'printf "%s = \\%03o\n"\, $_\, ord for @ARGV'
-- Jeff "japhy" Pinyan japhy@pobox.com http://www.pobox.com/~japhy/ CPAN - #1 Perl Resource (my id: PINYAN) http://search.cpan.org/ PerlMonks - An Online Perl Community http://www.perlmonks.com/ The Perl Archive - Articles\, Forums\, etc. http://www.perlarchive.com/
Lightning flashed\, thunder crashed and Jeff Pinyan \jeffp@​crusoe\.net whispered : | On Feb 13\, stephenm@transmeta.com said: |
---|---|
> perl -ep '\ |
|
>will not work correctly whereas: | |
> perl -p -e '\ |
|
>does. | |
This is because -e takes a string to execute. |
In most UNIX utilities\, the order of the flags doesn't matter\, as long as
the options to the flags are in the proper order. For example\,
"tar cbf 20 blah.tar \
This can be gotten via 'man ascii'\, or simply by: |
---|
perl -e 'printf "%s = \\%03o\n"\, $_\, ord for @ARGV' |
Also may be worth noting. Patch attached. I'm not enamoured with the second chunk\, which just adds "(ASCII value)" after "an octal number". Feel free to ignore that one.
-spp
Lightning flashed\, thunder crashed and Stephen McInerney \<stephenm@transmeta.co m> whispered: | To the documentation question\, could you include your solution in | the manpages?
Taken care of\, assuming the pumpking likes my wording.
| 'man ascii' does nothing for me\, are you sure that is a standard thing? | How do I generate that manpage? (Solaris 8?)
You must not have all the man pages installed. man ascii works fine for me on a Solaris 8 installation\, and shows me the ascii(5) man page.
-spp
On Thu\, Feb 15\, 2001 at 05:17:41PM -0500\, Stephen P. Potter wrote:
Lightning flashed\, thunder crashed and Jeff Pinyan \jeffp@​crusoe\.net whispered : On Feb 13\, stephenm@transmeta.com said: > perl -ep '\ ' >will not work correctly whereas: > perl -p -e '\ ' >does. This is because -e takes a string to execute. In most UNIX utilities\, the order of the flags doesn't matter\, as long as the options to the flags are in the proper order. For example\, "tar cbf 20 blah.tar \
" will associate 20 with "b"\, and blah.tar with "f". It could be argued either way whether this is a bug in perl because it does care\, the option must immediately follow the flag. It may be worth noting in the perlrun manpage at least. (Patch at end).
I completely disagree. Most UNIX utilities require the option to immediately follow the flag. tar is the exception\, not the rule.
Ronald
On Thu\, 15 Feb 2001\, Jeff Pinyan wrote:
On Feb 13\, stephenm@transmeta.com said:
perl -ep '\
' will not work correctly whereas: perl -p -e '\ ' does. This is because -e takes a string to execute.
perl -eprint1
prints 1.
perl -pe 'print 1'
works\, as does
perl -p -e 'print 1'
Right. How about:
perl -pie 'print 1' foo
Of course I understand that -i expects an argument for what extension to use for the backup (in this case 'e')\, but it's in the same arena of kinda-counterintuitive behavior\, or at least a newbie "gotchya". All of the unix veterans can sniff their noses\, but it's difficult to explain to people why
perl -pi -e 'print 1' foo
works\, while -pie doesn't (given that they're used to being able to scrunch command line flags\, and -i with no argument looks just like that).
My little 2 cent rant and rave\,
-Aaron
Thanks Stephen and all who responded.
My intent was not to start an ideological flame war about the 'right' command-line syntax\, but merely to document something that is genuinely confusing and tripped up me (a 10-year UNIX veteran and an EE postgrad) let alone newbies. PERL was appearing to be failing without warning.
Thanks for your responses.
Lightning flashed\, thunder crashed and Stephen McInerney \<stephenm@transmeta.co m> whispered: | To the documentation question\, could you include your solution in | the manpages? Taken care of\, assuming the pumpking likes my wording.
| 'man ascii' does nothing for me\, are you sure that is a standard thing? | How do I generate that manpage? (Solaris 8?)
You must not have all the man pages installed. man ascii works fine for me on a Solaris 8 installation\, and shows me the ascii(5) man page.
Will check.
Keep up the good work guys... Stephen
On 15 Feb 2001\, at 17:17\, Stephen P. Potter wrote:
=item B\<-0>[I\
] -specifies the input record separator (C\<$/>) as an octal number. If there are -no digits\, the null character is the separator. Other switches may -precede or follow the digits. For example\, if you have a version of -B\
which can print filenames terminated by the null character\, you -can say this: +specifies the input record separator (C\<$/>) as an octal number (ASCII +value). If there are no digits\, the null character is the separator.
The EBCDIC police should run you up against a wall and shoot your for that :-). Perhaps something like "representing the character code in your default coded character set"? I'm not fully into the terminology of that subject. (Also\, can $/ be set to a number between 0200 and 0377\, inclusive? I assume yes -- but there aren't any characters in ASCII with that value. I presume Perl will just use the byte value\, regardless of the character set.
The special value 00 will cause Perl to slurp files in paragraph mode. The value 0777 will cause Perl to slurp files whole because there is no -legal character with that value. +legal character with that value. The legal values may be found in +L\<ascii(5)>\, or any ASCII conversion chart.
Again: ASCII is a four letter word. And values larger than 0177 work when I try them\, even though that value is not in Solaris 2.6's ascii(5). (The one I tried was -0341\, which is 'ß' in a DOS box.)
Cheers\, Philip
On Thu\, 15 Feb 2001\, Ronald J Kimball wrote:
On Thu\, Feb 15\, 2001 at 05:17:41PM -0500\, Stephen P. Potter wrote:
In most UNIX utilities\, the order of the flags doesn't matter\, as long as the options to the flags are in the proper order. For example\, "tar cbf 20 blah.tar \
" will associate 20 with "b"\, and blah.tar with f I completely disagree. Most UNIX utilities require the option to immediately follow the flag. tar is the exception\, not the rule.
Depends on what you mean by "most" and "UNIX". Tar behaves that way; cpio
doesn't. An awful lot of v7-era programs rolled their own "getopt"
equivalent\, so there was quite a bit of variation. Starting with (I
think) SVR2 AT&T certainly strongly encouraged everyone to use getopt(3).
They even gave the source code to getopt(3) away for free (in 1985\, I
think). An SVR2-getopt(3)-compliant program will care about the order of
the flags.
It may be worth
noting in the perlrun manpage at least. (Patch at end).
Always a good idea.
Migrated from rt.perl.org#5825 (status was 'resolved')
Searchable as RT5825$