Perl Idioms From Beyond

pudge on 2003-06-30T20:15:43

You may or may not know about this little (hopefully largely unused) idiom:

perl -le '$FILE = ".bashrc"; open(FILE); print '

Since we don't use global variables anymore (right?), this is no longer useful. But wouldn't it be cool if that could work with lexicals? I offer no solution. Just the thought.


one-arg open()

vsergu on 2003-06-30T20:35:42

The special case open 0 has been sighted in programs that print themselves.

*0

rafael on 2003-06-30T20:36:37

That's most useful with $0, to write quines :
open 0;print<0>
But if you want to start some interesting discussion, you should post this on P5P.

Re:*0

pudge on 2003-06-30T20:44:28

Yes, but that is the same old global.

And what, interesting discussions don't happen on use Perl? :-) I don't want this to be taken too seriously so don't want to contribute to p5p noise.

Re:*0

rafael on 2003-06-30T20:49:00

I didn't say "interesting", I said "<i>interesting</i>". With an "i" like in "irony".

Re:*0

jamiemccarthy on 2003-07-01T02:51:07

So that's why my films keep ending up with snarky and cynical subtexts: I'm using iMovie.

An Ugly Lexicalish Solution

chromatic on 2003-06-30T21:08:37

Here's one shot at it:

perl -e 'my $file = ".bashrc"; open( *FILE = \$file ); print <FILE>'

It even works with strict and warnings. It doesn't work with the flags -ew, though, which should tell you something. (-we works.)