Re: awk question
Re: awk question
- Subject: Re: awk question
- From: "Mark J. Reed" <email@hidden>
- Date: Thu, 14 Dec 2006 10:15:52 -0500
*sigh*. So tired of this attitude toward Perl. The argument doesn't
belong on this list, so I won't bother rebutting in detail. I do
submit that Perl, like Javascript, is a victim of its own success in
the early web days, in which it was taken up by zillions of would-be
programmers who had no prior experience, and who then generated bad
examples which others learned from. If you look at Perl code produced
by good programmers (plenty of examples on CPAN), you will find
well-structured, well-documented, quite legible code.
In particular, it is a fallacy to equate expressiveness with
obfuscation, and I certainly don't see anything in my snippet above -
a one-off, incidentally, which should not be held up as an example of
good programming practice in the first place - that is any worse than,
say, the awk equivalent. The least legible part is the regular
expression, whose syntax you certainly can't blame on Perl.
Anyway, as I said, the code readily translates. You prefer Python? Here:
#!/usr/bin/python
import re
import sys
pat = re.compile('"([^"]*)"|(\S+)');
for line in sys.stdin:
fields = []
match = pat.search(line)
while match != None:
field = match.group(1)
if field == None:
field = match.group(2)
fields.append(field)
match = pat.search(line, match.end());
for field in fields:
print field
I trust you find that vastly superior to the obfuscated Perl I started with.
--
Mark J. Reed <email@hidden>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/mailman//archives/applescript-users
This email sent to email@hidden