For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > February 2007 > Detecting string in string









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Detecting string in string
andrewmchorney@cox.net

2007-02-22, 6:59 pm

Hello

I am not an advanced perl programmer and I do not have my books with me. I want to determine if a string is within a string and to not process the string if the string is found. Could someone please provide a simple sample.

Thanks,
Andrew
Tom Phoenix

2007-02-22, 6:59 pm

On 2/22/07, andrewmchorney@cox.net <andrewmchorney@cox.net> wrote:

> I am not an advanced perl programmer


Have courage -- you'll get there someday!

> and I do not have my books with me.


That's what the perldoc command is for.

> I want to determine if a string is within a string


Do you want the index function?

perldoc -f index

> and to not process the string if the string is found.


Huh? Do you mean you want an if-block? Are you looking for the next operator?

perldoc -f next

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training
Jeff Pang

2007-02-22, 6:59 pm


>
>I am not an advanced perl programmer and I do not have my books with me. I want to determine if a string is within a string and to not process the string if the string is found. Could someone please provide a simple sample.
>


From "perldoc -f index" :

index STR,SUBSTR,POSITION
index STR,SUBSTR
The index function searches for one string within another, but
without the wildcard-like behavior of a full regular-expression
pattern match. It returns the position of the first occurrence
of SUBSTR in STR at or after POSITION. If POSITION is omitted,
starts searching from the beginning of the string. The return
value is based at 0 (or whatever you've set the $[ variable
to--but don't do that). If the substring is not found, returns
one less than the base, ordinarily "-1".

--
Jeff Pang
EMAIL: pangj@earthlink.net AIM: jeffpang
Ken Foskey

2007-02-23, 7:59 am

On Thu, 2007-02-22 at 08:31 -0800, andrewmchorney@cox.net wrote:
> Hello
>
> I am not an advanced perl programmer and I do not have my books with
> me. I want to determine if a string is within a string and to not
> process the string if the string is found. Could someone please
> provide a simple sample.


if( ! $variable =~ /check_string/ ) {
...
}

--
Ken Foskey
FOSS developer

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com