my $email_address = qr {
(?(DEFINE)
(?<addr_spec> (?&local_part) \@ (?&domain))
(?<local_part> (?&dot_atom) | (?"ed_string))
(?<domain> (?&dot_atom) | (?&domain_literal))
(?<domain_literal> (?&CFWS)? \[ (?: (?&FWS)? (?&dcontent))* (?&FWS)?
\] (?&CFWS)?)
(?<dcontent> (?&dtext) | (?"ed_pair))
(?<dtext> (?&NO_WS_CTL) | [\x21-\x5a\x5e-\x7e])
(?<atext> (?&ALPHA) | (?&DIGIT) | [!#\$%&'*+-/=?^_`{|}~])
(?<atom> (?&CFWS)? (?&atext)+ (?&CFWS)?)
(?<dot_atom> (?&CFWS)? (?&dot_atom_text) (?&CFWS)?)
(?<dot_atom_text> (?&atext)+ (?: \. (?&atext)+)*)
(?<text> [\x01-\x09\x0b\x0c\x0e-\x7f])
(?<quoted_pair> \\ (?&text))
(?<qtext> (?&NO_WS_CTL) | [\x21\x23-\x5b\x5d-\x7e])
(?<qcontent> (?&qtext) | (?"ed_pair))
(?<quoted_string> (?&CFWS)? (?&DQUOTE) (?:(?&FWS)? (?&qcontent))*
(?&FWS)? (?&DQUOTE) (?&CFWS)?)
(?<word> (?&atom) | (?"ed_string))
(?<phrase> (?&word)+)
# Folding white space
(?<FWS> (?: (?&WSP)* (?&CRLF))? (?&WSP)+)
(?<ctext> (?&NO_WS_CTL) | [\x21-\x27\x2a-\x5b\x5d-\x7e])
(?<ccontent> (?&ctext) | (?"ed_pair) | (?&comment))
(?<comment> \( (?: (?&FWS)? (?&ccontent))* (?&FWS)? \) )
(?<CFWS> (?: (?&FWS)? (?&comment))*
(?: (?:(?&FWS)? (?&comment)) | (?&FWS)))
# No whitespace control
(?<NO_WS_CTL> [\x01-\x08\x0b\x0c\x0e-\x1f\x7f])
(?<ALPHA> [A-Za-z])
(?<DIGIT> [0-9])
(?<CRLF> \x0d \x0a)
(?<DQUOTE> ")
(?<WSP> [\x20\x09])
)
(?&addr_spec)
}x;
Abigail
--
perl -wlpe '}{$_=$.}{' file # Count the number of lines.
it is incredible
On 14 fév, 22:55, Abigail <abig...@abigail.be> wrote:
> use 5.9.5; # In fact, you need the newest blead.
>
...skipped
> --
> perl -wlpe '}{$_=$.}{' file # Count the number of lines.
^^^^^^^^^^^^^
As a Perl beginner, i'm a bit surprised to see this working. Could you
explain why (and how) these "counter-intuitive" } and { works ? And
how come you found out this trick ? Very very curious about this.
TIA
--
Michel Marcon, SysAdmin & Perl learner
> As a Perl beginner, i'm a bit surprised to see this working. Could you
> explain why (and how) these "counter-intuitive" } and { works ? And
> how come you found out this trick ? Very very curious about this.
Take a look at the 'perlrun' perldoc for an explanation of the -p flag.
You'll note that code you supply is already within a set of brackets.
Does that make sense?
--
Darren Dunham ddu...@taos.com
Senior Technical Consultant TAOS http://www.taos.com/
Got some Dr Pepper? San Francisco, CA bay area
< This line left intentionally blank to confuse you. >
See perlrun, or do a google search for it. It has been explained
many times.
:: how come you found out this trick ? Very very curious about this.
A remark Chip Salzenberg once (in the previous century) made in
The Perl Journal.
Abigail
--
perl -wle'print"Кхуф бопфиет Ретм Ибглет"^"\x80"x24'
>> perl -wlpe '}{$_=3D$.}{' file # Count the number of lines.
> ^^^^^^^^^^^^^
>
>As a Perl beginner, i'm a bit surprised to see this working. Could you
>explain why (and how) these "counter-intuitive" } and { works ? And
>how come you found out this trick ? Very very curious about this.
Let perl tell you:
perl -MO=Deparse -wlpe '}{$_=$.}{'
Hope this sheds some light. BTW: I was very surprised too, when I
first saw it. As it happens with most of Abigail's .sig's.
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,
Thanks a lot.
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
>> :: > use 5.9.5; # In fact, you need the newest blead.
[snip]
>> :: > --
>> :: > perl -wlpe '}{$_=$.}{' file # Count the number of lines.
[snip]
>> See perlrun, or do a google search for it. It has been explained
>> many times.
>>
>Can you post here some link to pages where this is explained? I have Perl
>5.6.1 and code not work for me, I haven't perldoc for 5.9.5 and google not
>accept these characters in search phrase.
http://www.google.it/search?q=%22count+the+number+of+lines%22+abigail
However 5.9.5 was required for the code in the body of the post. The
code being discussed here was part of the .sig: I don't have a 5.6.1
available but I'm sure it will work under the latter too. Read perlrun
for your installation of Perl and you will find the answer anyway.
The sig works for Perl 5.000 and all versions since.
Abigail
--
srand 123456;$-=rand$_--=>@[[$-,$_]=@[[$_,$-]for(reverse+1..(@[=split
//=>"IGrACVGQ\x02GJCWVhP\x02PL\x02jNMP"));print+(map{$_^q^"^}@[),"\n"
c:\>perl -wlpe '}{$_=$.}{' autoexec.bat
c:\>Useless use of a constant in void context at -e line 1.
> Abigail wrote:
>> `` > :: > perl -wlpe '}{$_=$.}{' file # Count the number of lines.
>> `` > :: ^^^^^^^^^^^^^
>> `` > ::
>>
>> The sig works for Perl 5.000 and all versions since.
>>
> I use ActivePerl 5.6.1 on Windows XP but your code still not work wor me.
perldoc -q one-liners
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
c:\>perl -wlpe "}{$_=$.}{" autoexec.bat
Unmatched right curly bracket at -e line 1, at end of line
syntax error at -e line 1, near "}"
Execution of -e aborted due to compilation errors.
c:\>
I'm writting in Perl many years and uderstand what is $_ what is $. what is
{ }, but not understand what should to do } { . What is meaning by brackets
in reverse order?
>> perldoc -q one-liners
>>
>Yes you are right. After I change single quoute to double I got different
>error message :-)
>
>c:\>perl -wlpe "}{$_=$.}{" autoexec.bat
>
>Unmatched right curly bracket at -e line 1, at end of line
>syntax error at -e line 1, near "}"
>Execution of -e aborted due to compilation errors.
C:\temp>perl -wlpe "}{$_=$.}{" foo.pl
19
5.8.8 here, but really no reason why 5.6.1 shouldn't do it.
>I'm writting in Perl many years and uderstand what is $_ what is $. what is
Ouch! You're getting a real PITA: did you care following the advice
that has been given to you?!?
In <news:slrnetaqep....@alexandra.abigail.be> Abigail pointed
you to
perldoc perlrun
Did you check the latter, especially where it explains the behaviour
of -p?
He also suggested a google search. In
<news:er4nad$3108$1...@ns.felk.cvut.cz> you replied that you could not
come up with a sensible search, and in
<news:6l4ct292brb4d3jtj...@4ax.com> I replied in turn
suggesting a suitable one, that I'm repeating here:
http://www.google.it/search?q=%22count+the+number+of+lines%22+abigail
Did you check it? What's wrong with it?!?
OTOH in <news:4rabt21v08jnet2lr...@4ax.com> I suggested
a cheap recipe to have Perl tell you what's going on, which I'm also
repeating here:
perl -MO=Deparse -wlpe '}{$_=$.}{'
What did it tell you?
>{ }, but not understand what should to do } { . What is meaning by brackets
>in reverse order?
Appearently you've been "writting" Perl for many years, but you didn't
check the docs much, nor you seem to be used to. Before this goes on
fot too long, here's the explanation: the -p cmd line switch "puts
code" around the script code, whether it's in a file or supplied
through -e. Basically it puts everything in a cycle, so that e.g.
perl -pe ""
behaves like the cat command. The -l switch modifies -p in a somewhat
minor way:
C:\temp>perl -MO=Deparse -lpe ""
BEGIN { $/ = "\n"; $\ = "\n"; }
LINE: while (defined($_ = <ARGV>)) {
chomp $_;
}
continue {
print $_;
}
-e syntax OK
The code you supply in -e will go right after chomp(). If it starts
with an "unmatched" right curly, the latter won't really be unmatched,
but it will match the left one on the LINE: line. Similarly the
"unmatched" left one at the end will match the one below the chomp()
line, creating an empty block. Thus it's a trick to... trick -p into
doing something it's not really meant to.
HTH,
> HTH,
> Michele
Thank you for explanation. I'm using Perl many years but for web scripts
(cgi) not for one line scripts.
Human are learning along all life :-)
>> perl -MO=Deparse -wlpe '}{$_=$.}{'
>>
>> What did it tell you?
>>
>This help me to understand. I never used module Deparse and don't know why
It's B::Deparse.
>Thank you for explanation. I'm using Perl many years but for web scripts
>(cgi) not for one line scripts.
Well, one liners are generally "simpler". Except when using witty obfu
or golf(-like) techniques on purpose, that is.
>Human are learning along all life :-)
I wholeheartedly second that. In the meanwhile I also apologize if my
post seemed overly aggressive in some points. I hope to have given you
some tips about how not to be spoon fed in the future.
Really helpfull. THX
>
> What did it tell you?
>
> >{ }, but not understand what should to do } { . What is meaning by brackets
> >in reverse order?
>
[...]
> The code you supply in -e will go right after chomp(). If it starts
> with an "unmatched" right curly, the latter won't really be unmatched,
> but it will match the left one on the LINE: line. Similarly the
> "unmatched" left one at the end will match the one below the chomp()
> line, creating an empty block. Thus it's a trick to... trick -p into
> doing something it's not really meant to.
I read "perldoc perlrun", but not enough carefully. Next time...
But I couldn't imagine such tricks ! Maybe I'm a naive programmer...
THX Michele
BTW, your signature worth it, too !
--
michel marcon
>THX Michele
>BTW, your signature worth it, too !
Well, I've been only an occasional obfu player. If you need an
explanation, it's available at <http://perlmonks.org/?node_id=410408>.
A> use 5.9.5; # In fact, you need the newest blead.
A> my $email_address = qr {
A> (?(DEFINE)
A> (?<addr_spec> (?&local_part) \@ (?&domain))
...
A> (?&addr_spec)
A> }x;
I have a question (to you or anyone else informed), as I don't follow
the latest Perl 5 changes and features: is this grammar syntax
experimental, or will it definitely remain in Perl 5 at this point? I
don't mind the latest blead, but I don't want to commit my own code to
it if the feature is experimental.
Thanks for the code, it was fascinating.
Ted
Well, until 5.10 anything could change. But with 5.10 getting close,
it seems unlikely there will be significant changes to the features
I used in the regexp.
Abigail
--
$_ = "\x3C\x3C\x45\x4F\x54" and s/<<EOT/<<EOT/e and print;
Just another Perl Hacker
EOT