On Nov 22, 2003, at 2:05 PM, but however wrote:

HI,
I use the command plot in Perl to draw a graph:

I'm not familiar with 'plot', so I'll leave that part of the question for others. But...


I am not vey clear with the variables $1 and $2. I did not define them in my file, what are they?

$1, $2 ... $n (for n that is a positive integer) are the variables where regular expression captures are stored. After a successful match, you can examine these variables for captured information.


Let's take a look at a one-line example:

>>> perl -e '"some example text" =~ /^((\w+).+?(\w+))$/ && print "$1\n$2\n$3\n"'

This above prints:

some example text
some
text

As you can see, my three sets of parenthesis are adding values to $1, $2 and $3. Whatever is captured by the first OPENING parenthesis goes in $1, the next OPENING parenthesis goes to $2 and so on. Even though the second group of parens closes before the first, it's only the opening paren we count to find which variable a value will be stored in. Later, we can use those numbers to retrieve our values, as I did with the print above.

This is very similar to the question you asked earlier today. Both are issues with Perl's regular expressions. I recommend you look up more information on Perl's regular expressions in your favorite reference book, or read the documentation with:

perldoc perlre

Good luck.

James


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to