|
Prev: Boolean Regexp with perlre
Next: Taint and memory usage
From: Ala Qumsieh on 13 Sep 2006 20:12 danparker276(a)yahoo.com wrote: > Oh yeah, and I top-posted on purpose. Everyone on this group is so > stuck up. .NET 2.0 blows everything away anyway. At least on their > formus, people from microsoft will answer questions instead of "Look at > the docs" Well, they are being paid by Microsoft to do that. If somebody (for example, you) pays me, I'll answer too. Otherwise, you don't really get to complain. --Ala
From: Tad McClellan on 13 Sep 2006 22:07 danparker276(a)yahoo.com <danparker276(a)yahoo.com> wrote: > .NET 2.0 blows everything away anyway. At least on their > formus, people from microsoft will answer questions instead of "Look at > the docs" That's because Bill's mindless minions _need_ someone to hold their hand. This programming stuff is pretty scary! -- Tad McClellan SGML consulting tadmc(a)augustmail.com Perl programming Fort Worth, Texas
From: Mumia W. on 13 Sep 2006 23:45 On 09/13/2006 05:31 PM, danparker276(a)yahoo.com wrote: > Tad, > " open($fh, '>', \$variable)" This would work perfect, just not the > right version of perl. [...] Do you mean that you can't install and use IO::Scalar? If you haven't tried it, you probably can.
From: Michele Dondi on 14 Sep 2006 06:56 On 13 Sep 2006 11:48:26 -0700, "Brian McCauley" <nobull67(a)gmail.com> wrote: >[1] Actually it's not completely built-in, behind the curtain open() >actually loads a module IIRC. But please ignore the man behind the >curtain. :-) Indeed I've been sort-of bit in the neck by this while preparing some example code for a PM node, specifically <http://perlmonks.org/?node_id=572127>. Although it was not strictly necessary I wanted to provide support for a Foo.pm module by means of the code-in-(a)INC feature, as both a way to generate the code and have everything in one single script. Again, it was a game and a proof of concept, not a way to add to clarity! Thus in real code I would write something like my $mod=pop; return undef unless $mod eq 'Foo.pm'; # return a fh to Foo.pm's contents But in this case I wanted to be a smart dude and use a somewhat more exhotic way to select upon 'Foo.pm'. Eventually I just used &&'s short circuiting, so that a stripped down version of the script may be the following: #!/usr/bin/perl -l use strict; use warnings; use lib sub { pop eq 'Foo.pm' && do { open my $fh, '<', \<<'.EOM' or die $!; # -------------------- package Foo; sub new { bless [], shift } 1; # -------------------- .EOM $fh; }; }; use Foo; print Foo->new; __END__ However before getting to this I was thinking of another witty way to return the correct filehandle if the second argument passed to the anonymous sub is 'Foo.pm' and undef otherwise: just using hash(ref) lookup, as in { 'Foo.pm' => $fh }->{ pop() }; Thus the actual code I tried first was similar to the one above with the C<use lib> statement replaced by the following one: use lib sub { { 'Foo.pm' => do { open my $fh, '<', \<<'.EOM' or die $!; # -------------------- package Foo; sub new { bless [], shift } 1; # -------------------- .EOM $fh; } }->{+pop}; }; Guess what happens when you actually try to run this? $ ./subinc Recursive call to Perl_load_module in PerlIO_find_layer at subinc line 9. BEGIN failed--compilation aborted at sunininc.pl line 22. BEGIN failed--compilation aborted at sunininc.pl line 22. The reason is obviously that in this case there's no short circuiting, thus perl tries to open() anyway, which needs loading a module, which calls the same sub for lookup, and so on... Of course I wrote that "I've been *sort-of* bit in the neck by this" because it is not a *real* problem and there are tons of workarounds. Simply, it was unexpected. Michele -- {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB=' ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_, 256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
From: Brian McCauley on 14 Sep 2006 13:56
Michele Dondi wrote: > On 13 Sep 2006 15:31:58 -0700, "danparker276(a)yahoo.com" > <danparker276(a)yahoo.com> wrote: > > >Why does everyone have to always say "read the docs". This is > > Because some people tries very hard to keep the docs up to date and > rich and helpful, maybe? Because it is the best way to teach one how > to find quickly help without bothering people with questions that do > not really deserve being asked? That's only part of it. There's also the fact that to an experienced programmer just looking at an inappropriate denormalization is painful. Retyping information that's covered in the standard docs is a denomalization. So even if it weren't for the fact that it's more effort for the person answering and less help to the person asking I'd still be uncomfortable retyping. |