![]() |
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. |
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. |
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 |
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, |
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, |
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 |
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." |
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.