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

Re: [MacPerl] Wildcard



> 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 something more powerful than simple wildcards.  They're called 
"regular expressions", often shortened to "regex."

I suspect that examples will soon start pouring in on how to use regular 
expressions for your purposes. Perl recognizes most all of the regular 
expressions handled by other common Unix tools (showing its roots, 
however this is a good thing). Here's some basic regular expressions

. matches any character except a newline "/n" #here's your wildcard
[a-z0-9] Matches any character of the set within brackets
[^a-z0-9] Matches any character NOT in the set
\d Matches any digit, same as [0-9]
\D Matches any non-digit, same as [^0-9]
\w Matches any alphanumeric (valid Unix chars [a-zA-z0-9_])
\W matches non-alphanumerics [^a-zA-Z0-9_]
\s whitespace (space, tab, newline...)
\S non-whitespace

\n newline
\r return
\t tab
\f formfeed
\0 null
\nnn ASCII with this octal value
\xnn ASCII with this hexidecimal value

I'd recommend a good book on regular expressions (I think there's one out 
by O'Reilly).  The camel and llama books don't really say very much on 
the subject, or give more that a hint at how important it is.



# Fungal Parataxonomy                   Mycology Information (Mycoinfo)
# Webmaster, Staff Writer      **The World's First Mycology E-Journal**   
# <mailto:webmaster@mycoinfo.com>            <http://www.mycoinfo.com/> 
# "A couple of guys trying to do something great..."



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