RE: case insensitive index() ?
=James Birkholz= wrote, on Tuesday, July 08, 2003 9:54 AM : Is there a way to do an index function that is case-insensitive? sub stripTagCaseInsensitive { my $startTag = lc($_[0]); my $endTag = lc($_[1]); my $contentCI = lc($content); while (index($contentCI, $startTag)0) { my $first = substr($content, 0, index($contentCI, $startTag)); my $last = substr($content, (index($contentCI, $endTag)+length($endTag))); $content = $first.$last; $contentCI = lc($content); } } stripTagCaseInsensitive(FoNt,); But wouldn't it be easier to use a regex? $content =~ s/\Q$startTag.*?$endTag//i; # untested! Good luck, Joe == Joseph P. Discenza, Sr. Programmer/Analyst mailto:[EMAIL PROTECTED] Carleton Inc. http://www.carletoninc.com 574.243.6040 ext. 300fax: 574.243.6060 Providing Financial Solutions and Compliance for over 30 Years * Please note that our Area Code has changed to 574! * ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: case insensitive index() ?
On Tue, 8 Jul 2003, =James Birkholz= wrote: Is there a way to do an index function that is case-insensitive? For example: sub stripTag { my $startTag = $_[0]; my $endTag = $_[1]; while (index($content, $startTag)0) { my $first = substr($content, 0, index($content, $startTag) ); my $last = substr($content, (index($content, $endTag)+length($endTag) ) ); $content = $first.$last; } } stripTag(font,); stripTag(FONT,); this code has to be called with each case variant, or I'd have to put a lot of IFs inside the SUB James ps, tips on improving the above coding welcome, I'm just starting to come to grips with Perl. I know there are modules that include similar functions, but I'm doing this as a learning exercise. In the StripTag sub, my suggestion would be to lowercase the tags and also lower case a copy of the content and do your index on the copy. [EMAIL PROTECTED] Carl Jolley All opinions are my own and not necessarily those of my employer ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: case insensitive index() ?
Thanks, Joseph, I'll chew on this tonight. I didn't start by trying a regex, as $content still has many \n in it, but in researching your use of the \Q (which isn't in my tutorial book), I ran across the s modifier. Or I could change all the \n to placeholders and then change them back later. Guess tonight I hit the perl doc on regex. I presume that the \Q is needed to process the variables? I didn't think that was needed. I'm confused about the ? after the * . $content =~ s/\Q$startTag.*?$endTag//i; # untested! At 10:35 AM 7/8/03, Joseph Discenza wrote: =James Birkholz= wrote, on Tuesday, July 08, 2003 9:54 AM : Is there a way to do an index function that is case-insensitive? sub stripTagCaseInsensitive { my $startTag = lc($_[0]); my $endTag = lc($_[1]); my $contentCI = lc($content); while (index($contentCI, $startTag)0) { my $first = substr($content, 0, index($contentCI, $startTag)); my $last = substr($content, (index($contentCI, $endTag)+length($endTag))); $content = $first.$last; $contentCI = lc($content); } } stripTagCaseInsensitive(FoNt,); But wouldn't it be easier to use a regex? $content =~ s/\Q$startTag.*?$endTag//i; # untested! Good luck, Joe == Joseph P. Discenza, Sr. Programmer/Analyst mailto:[EMAIL PROTECTED] Carleton Inc. http://www.carletoninc.com 574.243.6040 ext. 300fax: 574.243.6060 Providing Financial Solutions and Compliance for over 30 Years * Please note that our Area Code has changed to 574! * ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs James Birkholz admin, Posen-L mailing list and website http://www.Posen-L.com ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs