Click here to get back home

every combination of Y/N in 5 positions

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
every combination of Y/N in 5 positions joemacbusiness 03-31-2008
Posted by Gunnar Hjalmarsson on April 2, 2008, 7:21 pm
Please log in for more thread options
Abigail wrote:
> _
> Gunnar Hjalmarsson (noreply@gunnar.cc) wrote on VCCCXXVIII September
> ^^ Abigail wrote:
> ^^ > David Harmon (source@netcom.com) wrote on VCCCXXVIII September MCMXCIII
> ^^ > [] On Mon, 31 Mar 2008 23:23:25 +0200 in comp.lang.perl.misc, Gunnar
> ^^ > [] >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.
> ^^
> ^^ I didn't do it for the sake of it; please see the sub-thread starting
> ^^ with
> ^^
http://groups.google.com/group/comp.lang.perl.misc/browse_frm/thread/1c6904d6a4774258/e56a5cb3831212df
> ^^ and the advice provided there by Ben and Brian.
>
> I read it. I still think it's obfuscated. Why use a package scoped glob
> if you can use a lexical variable (even $_)?

Pursuing backwards compatibility justifies the obfuscation. The lexical
$_ was news in v5.9.1.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Posted by Abigail on April 3, 2008, 6:11 am
Please log in for more thread options
_
Gunnar Hjalmarsson (noreply@gunnar.cc) wrote on VCCCXXVIII September
;; Abigail wrote:
;; > _
;; > Gunnar Hjalmarsson (noreply@gunnar.cc) wrote on VCCCXXVIII September
;; > ^^ Abigail wrote:
;; > ^^ > David Harmon (source@netcom.com) wrote on VCCCXXVIII September MCMXCIII
;; > ^^ > [] On Mon, 31 Mar 2008 23:23:25 +0200 in comp.lang.perl.misc, Gunnar
;; > ^^ > [] >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.
;; > ^^
;; > ^^ I didn't do it for the sake of it; please see the sub-thread starting
;; > ^^ with
;; > ^^
http://groups.google.com/group/comp.lang.perl.misc/browse_frm/thread/1c6904d6a4774258/e56a5cb3831212df
;; > ^^ and the advice provided there by Ben and Brian.
;; >
;; > I read it. I still think it's obfuscated. Why use a package scoped glob
;; > if you can use a lexical variable (even $_)?
;;
;; Pursuing backwards compatibility justifies the obfuscation. The lexical
;; $_ was news in v5.9.1.



But "my $foo = sprintf ...;" worked since 5.000.


Or do you think '$foo =~ tr /01/YN/' is the obfuscated version of 'tr /01/YN/'?


Abigail
--
perl -wle'print"Κυστ αξοτθες Πεςμ Θαγλες"^"\x80"x24'

Posted by Ben Morrow on April 2, 2008, 8:04 pm
Please log in for more thread options

Quoth abigail@abigail.be:
> _
> Gunnar Hjalmarsson (noreply@gunnar.cc) wrote on VCCCXXVIII September
> ^^ Abigail wrote:
> ^^ > David Harmon (source@netcom.com) wrote on VCCCXXVIII September MCMXCIII
> ^^ > [] On Mon, 31 Mar 2008 23:23:25 +0200 in comp.lang.perl.misc, Gunnar
> ^^ > [] >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.
> ^^
> ^^ I didn't do it for the sake of it; please see the sub-thread starting
> ^^ with
> ^^
>
http://groups.google.com/group/comp.lang.perl.misc/browse_frm/thread/1c6904d6a4774258/e56a5cb3831212df
> ^^ and the advice provided there by Ben and Brian.
>
>
> I read it. I still think it's obfuscated. Why use a package scoped glob
> if you can use a lexical variable (even $_)?

FWIW I entirely agree. For occasions where the convenience of $_ is
useful and 5.10 is not an option, a one-item for loop is a much cleaner
way of safely doing a local assignment than messing around with *_.

Ben

Posted by Gunnar Hjalmarsson on April 2, 2008, 4:20 pm
Please log in for more thread options
David Harmon wrote:
> On Mon, 31 Mar 2008 23:23:25 +0200 in comp.lang.perl.misc, Gunnar
>> 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.

Others have told you that it's a typeglob and pointed you to relevant docs.

As regards applicable docs on _the reason_ why I didn't just say

local $_ = sprintf ...

please see the "Localization of globs" section in "perldoc perlsub".

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Posted by David Harmon on April 3, 2008, 2:10 am
Please log in for more thread options
On Wed, 02 Apr 2008 22:20:44 +0200 in comp.lang.perl.misc, Gunnar
>As regards applicable docs on _the reason_ why I didn't just say
>
> local $_ = sprintf ...
>
>please see the "Localization of globs" section in "perldoc perlsub".

What I'm wondering is why you didn't use the much simpler (from my
point of view):

foreach my $num ( 0 .. 0b11111 ) {
my $yn = sprintf '%05b', $num;
$yn =~ tr/01/NY/;
print "$yn\n";
}

Doesn't everybody say to prefer lexical over local, unless you
really need local?

Similar ThreadsPosted
Looking for combination.pm June 29, 2005, 10:56 pm
Perl + Objects = Winning combination April 9, 2007, 7:55 pm
Perl Developer Positions in California March 11, 2005, 12:53 pm
htaccess rewriterule in combination with POST form January 28, 2005, 12:38 am
How can I add tokens at arbitrary positions on a line in a file? August 13, 2005, 6:36 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap