On 3/10/06, Gallagher, Tim (NE) <[EMAIL PROTECTED]> wrote:

> My $test = "asdfjaslfkjasdf lksaflksajfalksjf fsalkjsaflkjsafd fajd
> alsjfk";

> I want a way to count the number of characters to the first space.  Is
> there an easy function to do this???

The easy function to find the length of a string is the length() function:

   my $count = length "asdfjaslfkjasdf";

Of course, before you can pass that string as a parameter to length(),
you need to compute it. Maybe you could use a pattern match on $test?

The almost-as-easy function to find a substring is the index() function:

   my $place = index($test, ' ');

Beware the case in which $test has no space, yielding negative $place.

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to