Save regular expression in an array in perl

my @matches = ( $str =~ /pa(tt)ern/ )
For example:

perl -le ‘@m = ( “foo12gfd2bgbg654” =~ /(\d+)/g ); print for @m’

Gives the output:
12
2
654

http://stackoverflow.com/questions/2304577/how-can-i-store-regex-captures-in-an-array-in-perl

, ,

Writing Regular Expressions of perl in easy way

Check It Out~

http://www.weitz.de/regex-coach/

some reference for regular expressions:

http://www.sdsc.edu/~moreland/courses/IntroPerl/docs/manual/pod/perlre.html

, , , ,

Perl regular expression problem – not expect result

Code:
#!/usr/bin/perl
@line=(’56’, ‘1234’, ’24’);
foreach(@line)
{
$_=~/.*(3).*/;
print “##$1\n”;
}
Not expected result:
##
##3
##3
Code:

#!/usr/bin/perl

@line=(’56’, ‘1234’, ’24’);

foreach(@line)

{

print “##”.check($_).”\n”;

}

sub check

{

$_[0]=~/.*(3).*/;

return $1;

}

Expected result:
##
##3
##
, , ,

orginal:

form->{var} = undef;
my $var;
if($form->{var}){
$var = $form->{var};
}else{
$var = 1;
}

example:

my $var = $form->{var} ? $form->{var} : 1;

$var = $form->{var} || 1;

, , , , ,