[26354] in Perl-Users-Digest
Perl-Users Digest, Issue: 8527 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 15 21:05:16 2005
Date: Sat, 15 Oct 2005 18:05:04 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 15 Oct 2005 Volume: 10 Number: 8527
Today's topics:
Re: match 1/2/3, replace with a/b/c <ebohlman@omsdev.com>
Re: match 1/2/3, replace with a/b/c <rvtol+news@isolution.nl>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 15 Oct 2005 23:47:23 GMT
From: Eric Bohlman <ebohlman@omsdev.com>
Subject: Re: match 1/2/3, replace with a/b/c
Message-Id: <Xns96F0C0E6CF421ebohlmanomsdevcom@130.133.1.4>
RedGrittyBrick <RedGrittyBrick@SpamWeary.foo> wrote in news:dirde0$1fq$1
@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com:
> #!perl
> use strict;
> use warnings;
>
> my %upgrade = (
> '486DX' => 'P4',
> '640KB' => '2GB',
> '50MB HDD' => '400GB HDD',
> '1.44MB FDD' => 'Flash Media Reader',
> '6X CD-ROM' => '6X DL DVD'
> );
>
> while (<DATA>) {
> foreach my $feature (keys %upgrade) {
While it doesn't matter with the particular example data you used, in
general you should use
foreach my $feature (reverse sort keys %upgrade) {
so that if one or more feature names is a substring of another one, the
longest one will be matched.
> s/$feature/$upgrade{$feature}/eg;
> }
> print;
> }
------------------------------
Date: Sun, 16 Oct 2005 02:21:39 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: match 1/2/3, replace with a/b/c
Message-Id: <dise1n.1g4.1@news.isolution.nl>
Eric Bohlman:
> While it doesn't matter with the particular example data you
> used, in general you should use
>
> foreach my $feature (reverse sort keys %upgrade) {
>
> so that if one or more feature names is a substring of another
> one, the longest one will be matched.
For that you need to use the length, because a substring can also be
anywhere inside that other one.
Also beware of loops, like when replacements contain later searches.
Should not be a problem with 's/$feature/$upgrade{$feature}/eg'.
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 8527
***************************************