Please put the subject of your post in the Subject: of your post.
Think of it this way: suppose you were searching for answers to your
questions in some newsgroup archive like groups.google.com. Would you
be able to figure out that this post was relevant, just by looking at
the Subject: line?
What is the meaning of
my ($common,$local) = @_; in sub?
Read 'perlintro' (with 'perldoc perlintro'). You can probably stop
doing everything else you're doing with Perl until you finish that,
it's that basic.
Also I have a regular expression looking like the following ( see
below).
I does it on a file containing key=value.
Can anyone explain what is done?
You'll want to read 'perlretut' (for "Perl Regex Tutorial") with
'perldoc perlretut'. This one's pretty simple, so I'll help you
decode it, but you'll really want to read perlretut
foreach (@common_lines)
{
if (($common_key,$common_value) = /^\s*([^=#]+?)\s*=\s*(.*)$/)
Let's write it out the long way:
if (my ($common_key,$common_value) = /^\s*
This says there is optional whitespace at the beginning of the line. \s
matches any white space character, and * means there are zero or more of them.
If you wanted to guarantee there was at least one whitespace character here,
then you'd use + instead of *
([^=#]+?)
Followed by a number of characters that are not = or #. The parens put
these matched characters into $1 (because it's the first set of parens)
\s*
Followed by optional whitespace
=
a literal = character
\s*
more optional whitespace
(.*)
and capture everything after the whitespace into $2 (since it's the
second set of parens
$/x))
and $ matches the end of the string. I added /x because /x says to
ignore whitespace in the regex, and you could just rip out my comments
and have an exact equivalent to the regex you quoted.
Now, the bits on the left hand side, as written, are:
($common_key, $common_value) = /...regex.../;
You should always put 'use warnings;' and 'use strict;' at the top of
all your Perl programs. This requires you to declare your variables,
so you'd write instead,
my ($common_key, $common_value) = /...regex.../;
The fact that the variables $common_key and $common_value are in
parentheses means that they are in list context. Perl does different
things sometimes depending on if an operator like // is in scalar
context or list context.
Now, I don't want to give away all the fun, and besides you could
probably stand to learn the practice of looking up the docs on your
own, so why don't you search perlretut for what happens when // is
evaluated in list context, and let us know what you find out? You
should be able to find the documentation easily, but if you can't
understand it, post back, and we'll help you work through it.
-=Eric