Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   what is "}{"? (http://www.velocityreviews.com/forums/t902919-what-is.html)

zenny lenny 05-02-2007 05:39 PM

what is "}{"?
 
I DID check the FAQ first.

Two questions:

1. This code adds a column of numbers: perl -lne '$x+=$_}{print $x;'

What is the purpose of "}{"?

2. Is there any way to search groups or the web for symbols like "}
{"? Google seems to ignore symbols like this.


Brian McCauley 05-02-2007 05:48 PM

Re: what is "}{"?
 
On May 2, 6:39 pm, zenny lenny <zennyle...@gmail.com> wrote:
> I DID check the FAQ first.
>
> Two questions:
>
> 1. This code adds a column of numbers: perl -lne '$x+=$_}{print $x;'
>
> What is the purpose of "}{"?


It is the end of one block (executed once per line) and the start of
another block (executed once).

It makes sense if you know what -n actually does.

The above is simply short for:

perl -le ''LINE: while (<>) {$x+=$_}{print $x;}'

> 2. Is there any way to search groups or the web for symbols like "}
> {"?


Not that I know of.

However you could perhaps grep the Perl manual - this trick may be
mentioned in there somewhere.


Klaus 05-02-2007 06:01 PM

Re: what is "}{"?
 
On May 2, 7:39 pm, zenny lenny <zennyle...@gmail.com> wrote:
> 1. This code adds a column of numbers: perl -lne '$x+=$_}{print $x;'
> What is the purpose of "}{"?


You are using "-n" in a very clever way indeed:

perldoc perlrun:
>> ====================
>> -n
>> causes Perl to assume the following loop around
>> your program, which makes it iterate over filename
>> arguments somewhat like sed -n or awk:
>>
>> LINE:
>> while (<>) {
>> ... # your program goes here
>> }
>> ====================


....so with '$x+=$_}{print $x;'
your program will be...

LINE:
while (<>) {
$x+=$_}{print $x;
}

....or reformatted...

LINE:
while (<>) {
$x+=$_
}
{ print $x; }

-- Klaus


Michele Dondi 05-02-2007 07:14 PM

Re: what is "}{"?
 
On 2 May 2007 11:01:09 -0700, Klaus <klaus03@gmail.com> wrote:

>> 1. This code adds a column of numbers: perl -lne '$x+=$_}{print $x;'
>> What is the purpose of "}{"?

>
>You are using "-n" in a very clever way indeed:


s/You are/Someone is/; # :-)


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,

Michele Dondi 05-02-2007 07:21 PM

Re: what is "}{"?
 
On 2 May 2007 10:39:58 -0700, zenny lenny <zennylenny@gmail.com>
wrote:

>Subject: what is "}{"?


news://er8luv$268s$1@ns.felk.cvut.cz


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,

Wade Ward 05-02-2007 07:23 PM

Re: what is "}{"?
 

<attn.steven.kuo@gmail.com> wrote in message
news:1178129152.457542.266120@n76g2000hsh.googlegr oups.com...
> On May 2, 10:39 am, zenny lenny <zennyle...@gmail.com> wrote:
>> I DID check the FAQ first.
>>
>> Two questions:
>>
>> 1. This code adds a column of numbers: perl -lne '$x+=$_}{print $x;'
>>
>> What is the purpose of "}{"?
>>
>> 2. Is there any way to search groups or the web for symbols like "}
>> {"? Google seems to ignore symbols like this.

>
>
>
> Heh, that's intentional obfuscation. Abigail explains it
> here (see the "Counting Lines" section):
>
> http://ucan.foad.org/~abigail/Perl/Talks/Japhs/
>
> The -n switch (see 'perldoc perlrun') wraps your
> code, similar to -p but without the continue and
> print portion.
>
> You can also use a module to make things clearer:
>
> $ perl -MO=Deparse -nle '$x+=$_}{print $x;'
>
> BEGIN { $/ = "\n"; $\ = "\n"; }
> LINE: while (defined($_ = <ARGV>)) {
> chomp $_;
> $x += $_;
> }
> {
> print $x;
> }
> -e syntax OK

Aren't they just curly braces that are guaranteed to be unmatched? A google
search would hit every entry that has two or more sets of curly braces.
--
Wade Ward



Dr.Ruud 05-03-2007 07:29 PM

Re: what is "}{"?
 
zenny lenny schreef:

> 1. This code adds a column of numbers: perl -lne '$x+=$_}{print $x;'
>
> What is the purpose of "}{"?


Try -MO=Deparse like this:

perl -MO=Deparse -ne'$x+=$_}{print $x'

--
Affijn, Ruud

"Gewoon is een tijger."

Michele Dondi 05-03-2007 09:47 PM

Re: what is "}{"?
 
On 03 May 2007 20:50:55 GMT, Abigail <abigail@abigail.be> wrote:

>== What is the purpose of "}{"?
>==
>
>
>Self reflection. Do you see a vase, or two faces looking at each other?


A yo-yo. With no string.


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,


All times are GMT. The time now is 11:47 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57