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

Re: [MacPerl] Wildcard



At 09:01 -0700 9/23/98, tboley wrote:
>Is there a way to use wildcards in perl? It would be nice if the folowing
>would work:
>
>if ($text eq "t*") {print "$text\n"} # Where * is a wildcard
>
>So the print comand is executed when $text is "tee" or "time" or ...

Perl has wildcards (called globs), but they are used for file name
matching.  For more general matching, Perl uses regular expressions
(a more general and extremely powerful variation on wildcards), as:

  if ($text =~ /t.*/) { print "$text\n" }

Now for a brief explanation:

  =~        this is a "binding operator", which "binds" $text to
            the following regular expression

  /t.*/     this is a regular expression, matching a "t", followed
            by zero or more instances (*) of any character (.).

Regular expressions can get quite complicated, but simple ones will
do most of what you might wish to do...

It sounds like you should do more reading about Perl fundamentals.
May I suggest our book "MacPerl: Power and Ease"?  It is available
online at http://www.ptf.com/macperl/ptf_book/HTML and may also be
purchased in printed form.

-r

Rich Morin, Canta Forda Computer Laboratory | Prime Time Freeware - quality
  UNIX consulting, training, and writing    | freeware at affordable prices
  P.O. Box 1488, Pacifica, CA, 94044, USA   | www.ptf.com      info@ptf.com
  rdm@cfcl.com            +1 650-873-7841   | +1 408-433-9662   -0727 (Fax)



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