Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Re: every combination of Y/N in 5 positions
_
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

Report this thread to moderator Post Follow-up to this message
Old Post
Abigail
04-02-08 12:14 AM


Re: every combination of Y/N in 5 positions
Abigail 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

Report this thread to moderator Post Follow-up to this message
Old Post
Willem
04-02-08 12:14 AM


Re: every combination of Y/N in 5 positions
_
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";'

Report this thread to moderator Post Follow-up to this message
Old Post
Abigail
04-02-08 12:14 AM


Re: every combination of Y/N in 5 positions
Abigail 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

Report this thread to moderator Post Follow-up to this message
Old Post
Willem
04-02-08 12:14 AM


Re: every combination of Y/N in 5 positions
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.

Report this thread to moderator Post Follow-up to this message
Old Post
David Harmon
04-02-08 03:30 AM


Re: every combination of Y/N in 5 positions
David 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

Report this thread to moderator Post Follow-up to this message
Old Post
John W. Krahn
04-02-08 03:30 AM


Re: every combination of Y/N in 5 positions
David 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/"

Report this thread to moderator Post Follow-up to this message
Old Post
Tad J McClellan
04-02-08 03:30 AM


Re: every combination of Y/N in 5 positions
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.


Report this thread to moderator Post Follow-up to this message
Old Post
Ben Morrow
04-02-08 09:38 AM


Re: every combination of Y/N in 5 positions
_
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";

Report this thread to moderator Post Follow-up to this message
Old Post
Abigail
04-03-08 11:15 AM


Re: every combination of Y/N in 5 positions
Abigail 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

Report this thread to moderator Post Follow-up to this message
Old Post
Frank Seitz
04-03-08 11:15 AM


Sponsored Links




Last Thread Next Thread Next
Pages (3): « 1 [2] 3 »
Search this forum -> 
Post New Thread

PERL Miscellaneous archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 09:47 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.