Akhthar Parvez K wrote:
Hi Shawn,
$str =~ m{ \A ( .{15} .*? ) \s }msx;
I don't think this would work if the value given in the match string (15 as per
above eg.) is greater than the character count of the particular string. Right?
No, it will fail if $str is less than 15 characters. Try:
#!/usr/bin/perl
use strict;
use warnings;
for my $str ( "The black cat climbed the green tree", 'A test' ){
my $extracted = extract( $str );
print "string: $str\n";
print "string: $extracted\n";
}
sub extract {
my $str = shift @_;
$str =~ m{ \A ( .{0,15} .*? ) \s }msx;
my $extracted = $1;
return $extracted;
}
__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/