[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

RE: [MacPerl] Easy regex?



At 17.43 +0100 1998-12-18, Robert Crews wrote:
>#!perl
>
>$orig_path ="server.mydomain.de/directory1/directory2/irritating_filename.pl";
>
>$orig_path =~ m#.*/#;
>
>print "$&\n";

That will be working fine, but $& is one of the three "cursed variables".
If you use $&, $` or $« in your program, Perl will make copies of every
single string you use regexes on. That won't matter much if you're just
using one regex once in a program, but if you're matching large strings
many times, your program will certainly run faster if you don't use $&, $`
or $«. The same result can be accomplished in other ways, such as:

$orig_path =~ m|(.*)/|;
$new_path = $1;

___Carl_Johan_Berglund_________________________
   Adverb Information
   carl.johan.berglund@adverb.se
   http://www.adverb.se/



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch