$| (undocumented) magic?

M

Michele Dondi

No, but that doesn't mean that JAPHs and golf promote "bad" habits
(whatever the definition of "bad" might be). I have never spent too much
time on JAPHs, but have done so on perlgolf (over at perlgolf.org during
its earlier days). And, I must admit, I learnt lots of useful techniques
and discovered a lot of interesting properties of Perl's built-in vars
in the process of squeezing just one more character out of my code. As a

Indeed! Personally I'm only a mediocre golfer, but I have an IMHO
enlightening example: in a contest at terje the goal was a program
that given any input string would output the *smallest* palindrome
obtained extending that string either on the left or on the right.

(I must say that I have tried my own hand at that contest, when
closed, and taking much time: had I actually took part to it I would
have classified at 4th place IIRC. The point is, anyway, that I chose
an approach similar to that of most other ones.)

The actual winner instead had taken a completely different path, and
as a result he did win not for a hole or two, but for something like
30 or more! Basically he was |'ing the given string with a reverse()d
copy of it "shifted left or right" an increasing amount of chars until
it matched the original string.

I remember I was amazed when I saw *that* solution: the algorithm was
conceptually the most simple of all. Then he did other "awful" things
in order to squeeze the very last byte off his script, like using
symrefs (and in a possibly obscure way!) et similia. Of course one
shouldn't/wouldn't do such things in "production code", but if for any
reason he had to realize that particular task, then an excellent
technique could be the one described above.


Michele
 
M

Michele Dondi

^^^^^^
^^^^^^


#!/usr/bin/perl -w
print "What's your name?";
my $name = <STDIN>;
print "Hi $name I just wanted to show you a valid Perl program in 4
lines. Isnt this valid?\n";

It seems you don't waste your time with JAPHs, because you only spend
your efforts in "productive code", but just at the same time this must
have caused you some comprehension problems e.g. with understanding
what the OP was talking about, i.e. *Python* programs, not *Perl*.

Oh, and BTW, since you only spend your time on "productive code", then
you surely know that (i) -w is somewhat obsolete since C<use warnings>
provides the same functionality in a better and more controlled way,
(ii) it is a bad habit to include literal newlines in strings unless
when writing a japh or when golfing, which is not your case, since you
don't do those things. Also (iii) it may be a deliberate choice, but
wouldn't it be better to chomp($name)?

I'd just write:


#!/usr/bin/perl -l

use strict;
use warnings;

print "What's your name?";
chomp(my $name = <>);
print <<"EOT";
Hi $name I just wanted to show you a valid Perl program in 4
lines. Isn't this valid?
EOT

__END__


Oh, but I was forgetting... you wanted to exhibit a valid program in 4
lines! I'm an idiot!! But then not only there are many *valid*
programs even in one line (and useful too!), but there is even *one*
(and there couldn't be more!) *valid* program in zero lines:

# perl -e ''

And you know what? It' even warnings- and strict-safe:

# perl -wMstrict -e ''


HTH,
Michele
 
M

Michele Dondi

If that's your idea of a fun time I feel bad for your
wife/husband/girlfriend/children/friends/co-workers...

Well, I know it's hard to believe, but surprising as it may be, you'll
find that I do *not* spend all my time writing JAPHs, let alone most
of it or even a considerable part of it. And I don't think I've said
so, but if I have...


Michele
 
E

Eric Schwartz

Michele Dondi said:
It seems you don't waste your time with JAPHs, because you only spend
your efforts in "productive code", but just at the same time this must
have caused you some comprehension problems e.g. with understanding
what the OP was talking about, i.e. *Python* programs, not *Perl*.

I believe the OP was simply pointing out that you can only write
*some* programs in four lines; you can't write *any* program in 4
lines, because some won't fit.

Of course, Perl and Ruby (and I think Python, though I'm not sure) let
you put multiple statements on a line, so I suppose technically you
could just join(';', split(/\n/, <FILE>)) and call that a 'line'. :)

-=Eric
 
K

krakle

Michele Dondi said:
It seems you don't waste your time with JAPHs, because you only spend
your efforts in "productive code"

My point: Programs can be written in 4 lines of code. The rest of your
post was ignored.
 
M

Michele Dondi

I believe the OP was simply pointing out that you can only write
*some* programs in four lines; you can't write *any* program in 4
lines, because some won't fit.

I *do* know what the OP was talking about. And I don't think I've
written anything your last cmt could possibly apply to. But maybe I
didn't express myself clearly, since I'm not a native English speaker.

I think you don't have clear the context of what's going on. To
summarize things up:


They're just jealous because they can't write any valid Python program ^^^^^^
in just four lines (/me ducks and runs for cover).


To which


Well we can't write _any_ valid program in four lines, but we can ^^
manage a JAPy or 30. Some of them are even unreadable. ^^^^
http://www.python.org/cgi-bin/moinmoin/JustAnotherPythoneer
^^^^^^


From which it is clear that *we* refers implicitly to "us Python
programmers". Doesn't it?

And then in reply


#!/usr/bin/perl -w
print "What's your name?";
my $name = <STDIN>;
print "Hi $name I just wanted to show you a valid Perl program in 4
lines. Isnt this valid?\n";


And I'm contending that his wannabe-joke is misplaced for we *all*
know here that we can write valid *Perl* programs in 0..4 and more
lines, including Ala Qumsieh and T. Ogawa. It was a joke about
*Python*, because...
Of course, Perl and Ruby (and I think Python, though I'm not sure) let
you put multiple statements on a line, so I suppose technically you

....(even if I don't know Python in detail myself, it is well known
that) Python, differently from Perl and many other languages is not a
"free form language", i.e. whitespace is mostly significant in it and
a correct indentation is enforced as part of the syntax of the
language.

Said this, I may have seamlessly skipped over this "mistake". Instead
I've deliberately made an ad hominem attack on "krakle" because it
made me upset to read what I judge to be an idiot's cmt from him, and
in the form of a badly written perl program, whereas from what he
wrote previously I got the idea that he must think he's such a smart
guy. It was not fair of me, I must admit it!

I just couldn't resist the temptation for I can't stand arrogant
superficial people...


Michele
 
M

Michele Dondi

My point: Programs can be written in 4 lines of code. The rest of your
post was ignored.

I bet it was! Thank you so much for having informed us all that
"programs can be written in 4 lines of code". I can't imagine where we
could be without your contribution!

Said this... *plonk!*


Michele
 
K

krakle

Michele Dondi said:
Thank you so much for having informed us all that
"programs can be written in 4 lines of code". I can't imagine where we
could be without your contribution!

Michele, Not sure why you are taking offense to any of my replies.. It
was in response to T. Ogawas "we can't write _any_ valid program in
four lines". Ofcourse you can... So hostile in here...
 
J

Jeff 'japhy' Pinyan

Michele, Not sure why you are taking offense to any of my replies.. It
was in response to T. Ogawas "we can't write _any_ valid program in
four lines". Ofcourse you can... So hostile in here...

I think Ogawas meant "any" as "every", that is: "we can't write _every_
valid program".

--
Jeff "japhy" Pinyan % How can we ever be the sold short or
RPI Acacia Brother #734 % the cheated, we who for every service
Senior Dean, Fall 2004 % have long ago been overpaid?
RPI Corporation Secretary %
http://japhy.perlmonk.org/ % -- Meister Eckhart
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,149
Latest member
Vinay Kumar Nevatia0
Top