Schrift
[thread]12249[/thread]

Defaultpattern bei Matches



<< >> 5 Einträge, 1 Seite
LanX-
 2008-07-25 03:28
#112674 #112674
User since
2008-07-15
1000 Artikel
BenutzerIn

user image
ich bin da über was für mich sehr neues gestolpert ...

Quote
If the PATTERN evaluates to the empty string, the last success-
fully matched regular expression is used instead. In this case,
only the "g" and "c" flags on the empty pattern is honoured - the
other flags are taken from the original pattern. If no match has
previously succeeded, this will (silently) act instead as a gen-
uine empty pattern (which will always match). perlop#Regexp_Quote_Like_Operators


Code (perl): (dl )
1
2
3
4
5
6
$\="\n";
print "b" =~ //;        #1
print "a" =~ /a/;       #1
print "a" =~ /b/;
print "b" =~ //;
print "a" =~ //;        #1

man vergleiche Zeile 2 und 5!

Mir fällt jetzt kein sinnvolles Usecase für dieses Feature ein, kann mir jmd da ein Snippet zeigen?
renee
 2008-07-25 09:52
#112680 #112680
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Zum Thema "emtpy pattern" gab es letzt bei den Perl 5 Porters eine Diskussion:

http://perl.markmail.org/search/?q=empty+pattern+d...
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/
moritz
 2008-07-25 10:47
#112683 #112683
User since
2007-05-11
923 Artikel
HausmeisterIn
[Homepage]
user image
Quote
man vergleiche Zeile 2 und 5!


Was war denn die vor Zeile 2 zuletzt gematchte Regex?
Wenn du das nicht weisst ist es auch nicht sinnvoll gegen // zu matchen.
LanX-
 2008-07-25 13:50
#112693 #112693
User since
2008-07-15
1000 Artikel
BenutzerIn

user image
moritz+2008-07-25 08:47:16--
Was war denn die vor Zeile 2 zuletzt gematchte Regex?
Wenn du das nicht weisst ist es auch nicht sinnvoll gegen // zu matchen.


Scriptanfang, ich dachte das wär klar...

Quote
If no match has previously succeeded, this will (silently) act instead as a gen-
uine empty pattern (which will always match).


Du bist doch in Perl 6 firm, weißt du ob dieser Logikbruch da abgeschafft wird? [*] Eine Spezialvariable $LAST_SUCCESSFUL_PATTERN wäre viel sinnvoller ... [*] EDIT: ja und nein!
http://dev.perl.org/perl6/doc/design/syn/S05.html#...
LanX-
 2008-07-25 13:55
#112695 #112695
User since
2008-07-15
1000 Artikel
BenutzerIn

user image
renee+2008-07-25 07:52:12--
Zum Thema "emtpy pattern" gab es letzt bei den Perl 5 Porters eine Diskussion:

http://perl.markmail.org/search/?q=empty+pattern+d...


Danke Renee bestätigt meinen Eindruck, siehe auch:
http://www.nntp.perl.org/group/perl.perl5.porters/...

zumindest gibts einen(!) use-case in Verbindung mit s///, das ich nachvollziehen kann.

Code (perl): (dl )
1
2
3
if (m/$pat1/ or m/$pat2/ or m/$pat3/) {
   s///;
}
<< >> 5 Einträge, 1 Seite



View all threads created 2008-07-25 03:28.