Email address obfuscation in effect -- please
click here to turn it off.
[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
On Sun, 1 Apr 2001, Mikhail Kovalenko wrote:
[snip]
> It's actually pretty simple until we throw in a couple of levels of
> shell quoting as well. In perl, double quotes translate escaped
> sequences such as \n and \t, single quotes don't so their contents get
> printed literally. One type of quotes doesn't need to be escaped when
> quoted by the other type (like " ' "), otherwise it does (like " \"
> "). Shells have similar rules, so that's where you have to watch out.
> Print will output whatever you give it, separated by commas; it
> doesn't have to be a quoted string. There's probably more to it all,
> so see the manual.
Ah, "quoting hell". This is (or used to ben) actually even worse in
languages like tcl. Given the number of years that people have had to
beat their heads against their keyboards over such things, it would be
sadistic if perl didn't have alternative ways to quote things that
wouldn't confuse the shell. So check out:
q{hello} == 'hello'
qq{hello} == "hello"
qx{ls} == `ls`
etc.
> Better yet, examine someone's code, like below :)
>
> > Oh yeah: the most succinct way to print out mm/dd/yy for the current time
> > that I know of is:
> >
> > perl -lMPOSIX -e 'print strftime("%D",localtime);'
> > 04/01/01
[snip]
> Now, how could I ever beat that? All I knew is how to get rid of awk...
> ;)
Well, if you don't mind calling out, then you might prefer:
perl -e 'print qx{date +%D}'
04/02/01
...because it might make it clearer to somebody looking at the code that
you're just doing a date timestamp. Or not; I think localtime+offset is
probably a prefered idiom if you're mucking around, and it's not that cool
to call out for everything you need.
jking
--
To manage your subscription, go to http://mlug.missouri.edu/members/edit.php
Archives are available at http://mlug.missouri.edu/list-archives/