RE za behu
Honza Pazdziora
adelton na informatics.muni.cz
Sobota Srpen 30 15:43:26 MEST 2003
On Sat, Aug 30, 2003 at 03:32:52PM +0200, Jiri Polcar wrote:
>
> mam promenou $re, ve ktere je ulozen regularni vyraz. Pak mam promenou
> $text, kterou chci proti $re testovat:
>
> $re = '/x/';
V te promenne $re evidentne neni ulozen regularni vyraz, ktery
zamyslite, ale regularni vyraz, ktery ma kolem sebe lomitka.
> $text = 'xyz';
>
> if ( $text =~ $re ) { print "MATCH\n" } else { print "NO\n" }
> if ( $text =~ /$re/ ) { print "MATCH\n" } else { print "NO\n" }
> if ( eval { $text =~ $re } ) { print "MATCH\n" } else { print "NO\n" }
> if ( eval { $text =~ /$re/ } ) { print "MATCH\n" } else { print "NO\n" }
> if ( eval '$text =~ '.$re ) { print "MATCH\n" } else { print "NO\n" }
>
> Teprve posledni radek zabral. Jeste bych se smiril s tim, ze nefunguji
> prvni dva radky. Proc ale nepracuji druhy dva?
Protoze se efektivne snazite delat
$text =~ m!/x/!;
A v tom textu zadna lomitka nejsou.
--
------------------------------------------------------------------------
Honza Pazdziora | adelton na fi.muni.cz | http://www.fi.muni.cz/~adelton/
.project: Perl, mod_perl, DBI, Oracle, auth. WWW servers, XML/XSL, ...
Only self-confident people can be simple.
Další informace o konferenci Perl