FW: [Pdx-pm] Escaping a character in a string from a file

Rasmussen, Michael Michael.Rasmussen at columbiamanagement.com
Wed May 12 15:30:16 CDT 2004


> From: John [mailto:jgoalby at hotmail.com]
> I have a file of regular expressions I want to match.  I read in the file
> and then match each entry as such:

> if ($something =~ /$tomatch/i)

> I want to be able to specify something like ".pl" in the file so that I
can
> match all perl files.  Specifying .pl matches .apl.  Is there a way I can
> escape the "." when it is in a file?  I tried "\.pl", but it didn't work.

It doesn't?  

[mrasmuss at cmclink tback]$ ls
a.apl  a.pl  b.bpl  b.pl  tpl  
[mrasmuss at cmclink tback]$ cat tpl
#!/usr/bin/perl

@file = `ls`;
@pats = qw {
        pl
        .pl
        \.pl
};

foreach $something (@file) {
        chomp $something;
        foreach $pat (@pats) {
                if ($something =~ /$pat/i) {
                        print "did ";
                } else {
                        print "did not ";
                }

                print "find $pat in $something\n";
        }
}

[mrasmuss at cmclink tback]$./tpl
did find pl in a.apl
did find .pl in a.apl
did not find \.pl in a.apl
did find pl in a.pl
did find .pl in a.pl
did find \.pl in a.pl
did find pl in b.bpl
did find .pl in b.bpl
did not find \.pl in b.bpl
did find pl in b.pl
did find .pl in b.pl
did find \.pl in b.pl
did find pl in tpl
did find .pl in tpl
did not find \.pl in tpl
[mrasmuss at cmclink tback]$

--
  Michael Rasmussen, Infrastructure Engineer
  Columbia Management Company, Portland, Oregon
  Michael.Rasmussen at ColumbiaManagement.com 
  Desk:  971-925-6723  
  Desk:  503-973-6723 (deprecated)
  Cell:  503-209-6227
Mailstop:  ORFM75901B (Until June 1)
Mailstop:  OR1-523-01-01 (Preferred)
-------------- next part --------------
"WorldSecure <fleetsecurities.com>" made the following
 annotations on 05/12/2004 04:24:27 PM
------------------------------------------------------------------------------
NOTICE:  This communication may contain confidential or other privileged
information.  If you are not the intended recipient, or believe that you have
received this communication in error, please do not print, copy, retransmit,
disseminate, or otherwise use the information.  Also, please indicate to the
sender that you have received this email in error, and delete the copy you
received.  Any communication that does not relate to official Columbia
Management Group business is that of the sender and is neither given nor
endorsed. 
Thank you. 

==============================================================================


More information about the Pdx-pm-list mailing list