В Пнд, 07/09/2009 в 14:47 -0400, Uri Guttman пишет:
> >>>>> "MA" == Mishustin Alexey <shum...@shumkar.ru> writes:
> 
>   MA> Why do these regexps handle only the first number?
> 
> 
>   MA> my $raised_num = 'Tab_10' =~ /^Tab_(.*)$/;
>   MA> print $raised_num."\n";
> 
>   MA> $raised_num = 'Tab_11' =~ /^Tab_([0-9]+)$/;
>   MA> print $raised_num."\n";
> 
>   MA> $raised_num = 'Tab_12' =~ /^Tab_([0-9][0-9])$/;
>   MA> print $raised_num."\n";
> 
>   MA> $ ./test.pl 
>   MA> 1
>   MA> 1
>   MA> 1
> 
> try changing the number to something that doesn't start with 1 and see
> the results. then come back here for why this is happening.
> 
>   MA> But, according to all rules, both numbers must be handled:
> 
>   MA> 10
>   MA> 11
>   MA> 12
> 
> you aren't obeying the rules! look carefully at the docs about the
> return value of // and how to grab things. my clue above should help.

Unreal...:

$ cat ./test.pl 
#!/usr/bin/perl

use strict;
use warnings;

my $raised_num = 'Tab_22' =~ /^Tab_(.*)$/;
print $raised_num."\n";

$raised_num = 'Tab_23' =~ /^Tab_([0-9]+)$/;
print $raised_num."\n";

$raised_num = 'Tab_24' =~ /^Tab_([0-9][0-9])$/;
print $raised_num."\n";
$ ./test.pl 
1
1
1

I give up!

What's the mystery?

-- 
Regards,
Alex


--
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