tags:

views:

43

answers:

1

Hello,

What does this following do? Can anybody explain me?

$data = "What is the STATUS of your mind right now?";

$data =~/.*/; print "$1,$2\n";

$data =~/(.*?)(u+).*/; print "$1, $2\n";

$data =~/(.?)(u+).*/; print "$1, $2\n";

$data =~/(\w+\s)+/; print "$1, $2\n";

What is $1 and $2? How does this get it's value? and what are all these regular expressions?

Thanks in advance :)

+4  A: 

Please read perldoc perlretut, which will answer all your questions.

The general reference for Perl regular expressions is perldoc perlre, but you should read the tutorial first as it serves as a nicer introduction.

Ether
ok But what is $1 and $2 ?
Ankit Rathod
@Nitesh: that question is answered in the [Extracting Matches](http://perldoc.perl.org/perlretut.html#Extracting-matches) section of the document I linked to.
Ether
@Nitesh: They are called backreferences. Have you read the links yet?
BoltClock
@BoltClock's a Unicorn :- No i started just now.
Ankit Rathod