Code Comments
Programming Forum and web based access to our favorite programming groups._
John W. Krahn (someone@example.com) wrote on VCCCXXVII September MCMXCIII
in <URL:news:EVpIj.9961$9X3.4846@edtnps82>:
-: Mirco Wahab wrote:
-: > Gunnar Hjalmarsson wrote:
-: >> I'm not a golfer, but it's easy to write obfuscated code using Perl...
-: >> perl -le"do{$_=sprintf'%05b',$_;y/01/NY/;print}for(0..0b11111)"
-: >
-: > Much too wordy ;-)
-:
-: I concur.
-:
-: > perl -e' print "$_\n" while glob"{Y,N}"x5'
-:
-: perl -le'print for glob"{Y,N}"x5'
Saving 3 chars:
perl -E'say for glob"{Y,N}"x5'
Abigail
--
$"=$,;*{;qq{@{[(A..Z)[qq[0020191411140003]=~m[..]g]]}}}=*_;
sub _ {push @_ => /::(.*)/s and goto &{ shift}}
sub shift {print shift; @_ and goto &{+shift}}
Hack ("Just", "Perl ", " ano", "er\n", "ther "); # 20080401
Post Follow-up to this messageAbigail wrote:
) _
) John W. Krahn (someone@example.com) wrote on VCCCXXVII September MCMXCIII
) in <URL:news:EVpIj.9961$9X3.4846@edtnps82>:
) -: Mirco Wahab wrote:
) -: > Gunnar Hjalmarsson wrote:
) -: >> I'm not a golfer, but it's easy to write obfuscated code using Perl.
.
) -: >> perl -le"do{$_=sprintf'%05b',$_;y/01/NY/;print}for(0..0b11111)"
) -: >
) -: > Much too wordy ;-)
) -:
) -: I concur.
) -:
) -: > perl -e' print "$_\n" while glob"{Y,N}"x5'
) -:
) -: perl -le'print for glob"{Y,N}"x5'
)
) Saving 3 chars:
)
) perl -E'say for glob"{Y,N}"x5'
perl -e'print glob"{Y,N}"x5'
But this is nicer:
perl -e'$,="\n";print glob"{Y,N}"x5'
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
Post Follow-up to this message_
Willem (willem@stack.nl) wrote on VCCCXXVII September MCMXCIII in
<URL:news:slrnfv4f0b.2lkv.willem@snail.stack.nl>:
?? Abigail wrote:
?? ) _
?? ) John W. Krahn (someone@example.com) wrote on VCCCXXVII September MCMXC
III
?? ) in <URL:news:EVpIj.9961$9X3.4846@edtnps82>:
?? ) -: Mirco Wahab wrote:
?? ) -: > Gunnar Hjalmarsson wrote:
?? ) -: >> I'm not a golfer, but it's easy to write obfuscated code using P
erl...
?? ) -: >> perl -le"do{$_=sprintf'%05b',$_;y/01/NY/;print}for(0..0b1111
1)"
?? ) -: >
?? ) -: > Much too wordy ;-)
?? ) -:
?? ) -: I concur.
?? ) -:
?? ) -: > perl -e' print "$_\n" while glob"{Y,N}"x5'
?? ) -:
?? ) -: perl -le'print for glob"{Y,N}"x5'
?? )
?? ) Saving 3 chars:
?? )
?? ) perl -E'say for glob"{Y,N}"x5'
??
?? perl -e'print glob"{Y,N}"x5'
But that doesn't print newlines after each entry.
?? But this is nicer:
??
?? perl -e'$,="\n";print glob"{Y,N}"x5'
But this subthread involves a golfed solution, not a nice necessarely a
nice one...
Abigail
--
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'
Post Follow-up to this messageAbigail wrote: ) But that doesn't print newlines after each entry. Oh right, I missed the -l flag. Sorry. SaSW, Willem -- Disclaimer: I am in no way responsible for any of the statements made in the above text. For all I know I might be drugged or something.. No I'm not paranoid. You all think I'm paranoid, don't you ! #EOT
Post Follow-up to this messageOn Mon, 31 Mar 2008 23:23:25 +0200 in comp.lang.perl.misc, Gunnar
Hjalmarsson <noreply@gunnar.cc> wrote,
>I do, I hope. :)
>
> foreach my $num ( 0 .. 0b11111 ) {
> local *_ = \ sprintf '%05b', $num;
What is *_ ? It looks like one of those magic perl variables, but
I don't find any documentation on it.
Post Follow-up to this messageDavid Harmon wrote: > On Mon, 31 Mar 2008 23:23:25 +0200 in comp.lang.perl.misc, Gunnar > Hjalmarsson <noreply@gunnar.cc> wrote, > > What is *_ ? It looks like one of those magic perl variables, but > I don't find any documentation on it. It is a typeglob. It means that you want all of the _ variables to have a local value. See the "Typeglobs and Filehandles" section of perldata.pod. perldoc perldata John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall
Post Follow-up to this messageDavid Harmon <source@netcom.com> wrote: > On Mon, 31 Mar 2008 23:23:25 +0200 in comp.lang.perl.misc, Gunnar > Hjalmarsson <noreply@gunnar.cc> wrote, > > What is *_ ? It is a typeglob of the variables named underscore. > It looks like one of those magic perl variables, ^^^ ^^^ It is many of those magic perl variables. It is $_ and @_ and _ and ... > but > I don't find any documentation on it. See the "Typeglobs and Filehandles" section in perldata.pod. -- Tad McClellan email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
Post Follow-up to this message
Quoth "Newsgroup only please, address is no longer replyable."
<bad@example.invalid>:
> On Mon, 31 Mar 2008 23:23:25 +0200 in comp.lang.perl.misc, Gunnar
> Hjalmarsson <noreply@gunnar.cc> wrote,
>
> What is *_ ? It looks like one of those magic perl variables, but
> I don't find any documentation on it.
What noone has said yet is why Gunnar used it. Due to a rather nasty bug
in perl, under certain rather obscure circumstances[0] $_ doesn't
localise properly, so if you need to do so it is safer to localise the
whole of *_. Unfortunately, besides being ugly, this means you lose your
sub arguments (and the magic stat filehandle, of course, but that's
likely less important); personally I would always rather use a for loop
over one element
for (sprintf '%05b', $num) {
or, with 5.10, either 'given' (like for, but gives scalar context to its
argument) or 'my $_'. None of these suffer from the bug.
Ben
[0] If $_ is an alias to an element of a tied hash or array, the value
of that element will be localised along with $_. A simple example is
use Tie::Hash;
tie my %h, 'Tie::StdHash';
$h{a} = 1;
for ($h{a}) {
local $_ = 2;
print $h{a}; # 2, but should be 1
}
print $h{a}; # back to 1 again
This is only really important if you call external code in the scope of
the 'local': if that code reads the hash, it will be surprised to find
the values have changed.
Post Follow-up to this message_
David Harmon (source@netcom.com) wrote on VCCCXXVIII September MCMXCIII
in <URL:news:fb6dnc-9EJLmcm_anZ2dnUVZ_rSrnZ2d@earthlink.com>:
[] On Mon, 31 Mar 2008 23:23:25 +0200 in comp.lang.perl.misc, Gunnar
[] Hjalmarsson <noreply@gunnar.cc> wrote,
[] >I do, I hope. :)
[] >
[] > foreach my $num ( 0 .. 0b11111 ) {
[] > local *_ = \ sprintf '%05b', $num;
[]
[] What is *_ ? It looks like one of those magic perl variables, but
[] I don't find any documentation on it.
It's a silly attempt to obfuscate the code.
It's much better written as:
foreach (0 .. 0b11111) {
my $_ = sprintf '%05b' => $_;
tr _01_NY_;
say "$::_:$_";
}
No silly typeglobs needed.
Abigail
--
map{${+chr}=chr}map{$_=>$_^ord$"}$=+$]..3*$=/2;
print "$J$u$s$t $a$n$o$t$h$e$r $P$e$r$l $H$a$c$k$e$r\n";
Post Follow-up to this messageAbigail wrote:
>
> It's a silly attempt to obfuscate the code.
>
> It's much better written as:
>
> foreach (0 .. 0b11111) {
> my $_ = sprintf '%05b' => $_;
> tr _01_NY_;
> say "$::_:$_";
> }
Nice.
> No silly typeglobs needed.
You forgot
use 5.10.0;
Frank
--
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.