Mimi Cafe wrote:
$s = "The black cat climbed the green tree";

$substring = substr( $s, 1, 15); # this will return "The black cat c".

How can I have this return the whole word climbed rather than the c (i.e. I
need to get "The black cat climbed")? I need to get the remaining characters
from the length till the next white space or end of a phrase.

#!/usr/bin/perl

use strict;
use warnings;

my $str = "The black cat climbed the green tree";
print "string: $str\n";

$str =~ m{ \A ( .{15} .*? ) \s }msx;
my $extracted = $1;
print "extracted: $extracted\n";

__END__



--
Just my 0.00000002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.

Eliminate software piracy:  use only FLOSS.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to