develooper Front page | | Postings from August 2002

Re: Reflections

Thread Previous | Thread Next
Michael W Thelen
August 9, 2002 09:26
Re: Reflections
Message ID:
On Fri, Aug 09, 2002 at 04:49:39PM +0100, Jasper McCrea wrote:
> > Another possibility may be to take the
> > first digit of $^T... an approach that may be valid for all places (if the
> > system clock is correct), but not for all times. In particular, it should fail
> > beginning April 17, 2033.
> $n=1

Drat!  I missed that one!  :-)  Actually, I can't think of a way that using $^T
to get '1' could be short anyway.  Except maybe '$^T%10', and then only test it
every 10 seconds.

Actually, this is kind of an interesting question...  what are the various ways
that people have used to get a value of 1 into a variable?  These aren't all
very good, but here's what I can think of:

- $n=1 is short, but may require parenthesizing
- ++$n is also short, and probably doesn't require parenthesizing
- use the return value of something else that needs to be done anyway, e.g.
- $n=@+ or $n=@- after a successful match with no capturing parentheses
- $n=// where $_ is empty and no previously successful regexes, a la BoB's
  factorial solution
- $n=!$| where $| is an example of some false value
- $n=!!$$ where $$ is an example of some true value
- use -w, thus setting $^W to 1, but winning a golf with a program that
  produces no warnings may well be impossible
- $. when using -n0 or -p0

That exhausts my feeble brain.  Any other tricks people have thought of?

-- Mike

Michael W. Thelen
eval unpack u,'M*"1C/2<P,BDN-"`U+C`A(RLG*3U^>2\A+48O82UZ+SME=F%L*"1C+B(G=2HGM+"

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About