Click here to get back home

regular expression problem ? and * characters

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
regular expression problem ? and * characters compboy 05-28-2006
Posted by compboy on May 28, 2006, 7:02 am
Please log in for more thread options


Im writing a perl script now and this is part of the sricpt

chomp = ($pattern = ARGV[0]);

for each(@thisarray)
{
if($_ =~ m/$pattern/i)
{
print ("found it here, $_");
}
}

the array @thisarray is given.

this scprit reads from the command line and pass that input the the
pattern
and will check if the pattern match the any string inside the array it
will
print the msg.

I have done this part succesfully if the input is just a normal string
like a ab

my question is how do you imporve it so it can accept the input that
contains* and ?
character(s) like *ab? a*b* *a*

thanks a lot.


Posted by Dr.Ruud on May 29, 2006, 6:41 am
Please log in for more thread options


compboy schreef:

fup set to clpm

> Im writing a perl script now and this is part of the sricpt
>
> chomp = ($pattern = ARGV[0]);

That is not real code. ITYM

chomp ($pattern = ARGV[0]) ;


> for each(@thisarray)

That is not real code. ITYM

foreach (@thisarray)

or

for (@thisarray)

> {
> if($_ =~ m/$pattern/i)
> {
> print ("found it here, $_");
> }
> }

You can change all that to

/\Q$pattern/ and print "found '$_'\n" ;


> my question is how do you imporve it so it can accept the input
> that contains* and ?
> character(s) like *ab? a*b* *a*

Read perlre, look for \Q.

(so if you meant wildcards, don't use "\Q").

--
Affijn, Ruud

"Gewoon is een tijger."



Posted by metaperl@gmail.com on May 29, 2006, 2:30 pm
Please log in for more thread options



compboy wrote:
> Im writing a perl script now and this is part of the sricpt
>
> chomp = ($pattern = ARGV[0]);

you clearly are not using strict
ARGV[0] should be $ARGV[0]


Posted by Eric Bohlman on May 29, 2006, 10:15 pm
Please log in for more thread options


38g2000cwa.googlegroups.com:

> Im writing a perl script now and this is part of the sricpt
>
> chomp = ($pattern = ARGV[0]);
>
> for each(@thisarray)
> {
> if($_ =~ m/$pattern/i)
> {
> print ("found it here, $_");
> }
> }

No it isn't. That's not Perl. It won't compile.

Please show your actual code, not something that "looks like it."

> my question is how do you imporve it so it can accept the input that
> contains* and ?
> character(s) like *ab? a*b* *a*

perldoc -f quotemeta

Similar ThreadsPosted
How to parse with regular expression... May 5, 2005, 6:33 am
Regular Expression Generator June 26, 2006, 1:42 am
Simple Regular Expression Help May 16, 2007, 1:59 pm
trickiness (?) calling regular subroutines from OO methods August 23, 2004, 11:16 am
Removing non-printing characters ... October 7, 2004, 8:47 pm
handling UTF-8 characters in LWP module August 31, 2006, 10:39 pm
replacing nonprintable characters in a file June 3, 2005, 4:21 pm
replacing characters with their ASCII codes August 20, 2005, 8:50 pm
Spreadsheet::Read special characters handling November 20, 2006, 2:33 am
Print Subject without characters Just Numbers using POP3Client. Please Help April 10, 2007, 11:27 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap