you can also say@list = $string =~ /(regex1)(regex2)/;
which is why you have the parentheses. You just have one item in the list in your example.( $match1, $match2 ) = $string =~ /(regex1)(regex2)/;
If you omit the parentheses you just get the number of matches, ie the list is forced to scalar context. In your example you get 0 or 1.
This is useful because you can say
As for question 2, I can't see how it does. There is a typo in your line:if ( $string =~ /(regex1)/ ){ $found = $1; }
If as you say this is to check that it starts with a '-', then I would guess that you mean:if(@ARGV && $ARGV[0] =~ /'^-') {
Then the if block would only be entered if $ARGV[0] starts with "-". In the block, $count only gets a value if $ARGV[0] starts with one or more digits. Which it can't because it starts with a "-"!if(@ARGV && $ARGV[0] =~ m'^-') {
-- iakobski
In reply to Re: why the need to match when assigning?
by iakobski
in thread why the need to match when assigning?
by slok
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |