Skip Menu |
 

This queue is for tickets about the String CPAN distribution.

Report information
The Basics
Id: 2574
Status: resolved
Priority: 0/
Queue: String

People
Owner: Nobody in particular
Requestors:
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: sub charAt should^B^B^B^B^B^Bmust use substr
Download (untitled) / with headers
text/plain 693b
sub charAt should^B^B^B^B^B^Bmust use substr sub charAt { my ($string, $n) = @_; unless ( defined($n) ) { croak "Usage: chartAt(n)"; } return substr $string, $n, 1; } Why? 1 -- that's what it's for (and it's more efficient ) 2 -- If the index is out of bounds, and warnings are on, you get "substr outside of string ..." 3 -- what's next, map in void context? ;) Also, sub indexOf has the following statement my $rv = CORE::index($$string, $substring, $start||0); if ( $rv < 0 ) { return -1; } return $rv; This is utterly ridiculous. $rv can only be -1 .. length($$string) - 1 perldoc perldoc perldoc -f index perldoc -f substr
Date: Wed, 14 May 2003 04:39:55 -0600 (MDT)
From: Sherzod Ruzmetov <sherzodr [...] handalak.com>
To: Guest via RT <bug-String [...] rt.cpan.org>
Subject: Re: [cpan #2574] sub charAt should^B^B^B^B^B^Bmust use substr
RT-Send-Cc:
Download (untitled) / with headers
text/plain 576b
:sub charAt should^B^B^B^B^B^Bmust use substr : : 1 -- that's what it's for (and it's more efficient ) : 2 -- If the index is out of bounds, and warnings are on, you get : "substr outside of string ..." : 3 -- what's next, map in void context? ;) Great, thanks for the tip. According to the manual, return value of index() is not guaranteed to be -1 on failure. At least that's what I understood. The use of the word "ordinarily" mislead me, I guess. Any comments? -- Sherzod B. Ruzmetov <sherzodr@handalak.com> <URL: http://author.handalak.com >
Download (untitled) / with headers
text/plain 845b
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. Do you mess with $[ ? I don't thinks so. I also don't know anyone that does it. $> perl -e" $[=1;die index qw[ asdf q ]" 0 at -e line 1. $> The good thing is that since perl5 it is file scoped (only you can mess it up -- see perlvar to convince yourself)
Download (untitled) / with headers
text/plain 167b
Show quoted text
> The good thing is that since perl5 it is file scoped > (only you can mess it up -- see perlvar to convince yourself) >
Thanks, I'll make sure to apply your notes.
Download (untitled) / with headers
text/plain 199b
Change Log 1.3 Friday, May 16, 2003 - match() introduced - charAt() now uses substr() - indexOf() now returns whatever built-in index() returns -- Sherzod Ruzmetov http://author.handalak.com


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.