[Israel.pm] new module for CPAN: Getopt::Long::String

Mikhael Goikhman migo at homemail.com
Mon Jan 30 12:35:12 PST 2006


On 30 Jan 2006 19:59:02 +0200, Yuval Kogman wrote:
> 
> Shellwords is kind of like string2list, but probably more accurate
> since string2list isn't necessarily shell oriented.

If the task is to parse the command line, like the shell does, then both
shellwords and string2list are equally useless. Even simple input may
produce unexpected result (at, least I didn't expect it before running):

  print "[$_]\n" foreach shellwords(q{ date });

  print "[$_]\n" foreach shellwords(q{\""});

And I am not speaking already about total unawareness of special shell
chars like "#", "(", "&", "|", ";". These two functions are, for example,
usless if the task is to parse constructions common to many shells, like
$((2 + 3)) or $(date; date) or ${HOME:s/h/ /} that may include whitespace.

This is why such OP module or suggested 2-liners only solve simple cases.
The only sane way to split to words is to either already get list of args
prepared by the shell, a-la @ARGV, or apply the command line parsing,
specific to the problem domain (shell, or some other line-based protocol).

BTW, reinventing wheel is one thing (useful to build XP stats), but fixing
and replacing broken wheels is another. As well as inventing new cars.

Regards,
Mikhael.

-- 
perl -e 'print+chr(64+hex)for+split//,d9b815c07f9b8d1e'



More information about the Perl mailing list