Joseph L. Casale wrote:
Paul,
Reading the perlre doc I am starting to understand this line:
$line =~ s/(\S+)\s+(\S+)\s+(\S+)/X$1 Y$2 Z$3/;
I have a few questions.
1. What is the tilde for?
From `perldoc perlop`:
Binding Operators
Binary "=~" binds a scalar expression to a pattern match.
Certain operations search or modify the string $_ by default. This
operator makes that kind of operation work on some other string. The
right argument is a search pattern, substitution, or transliteration.
The left argument is what is supposed to be searched, substituted, or
transliterated instead of the default $_. When used in scalar context,
the return value generally indicates the success of the operation.
Behavior in list context depends on the particular operator. See
"Regexp Quote-Like Operators" for details and perlretut for examples
using these operators.
If the right argument is an expression rather than a search
pattern, substitution, or transliteration, it is interpreted as a search
pattern at run time.
Binary "!~" is just like "=~" except the return value is negated
in the logical sense.
2. I see you built a pattern to search for consisting of a non-whitespace
followed by a whitespace followed by a non etc. I see the replacement, but cant
figure out how to modify it for the case where I want to go straight to the
last file, X# Y# Z[some var].
$line =~ s/(\S+)\s+(\S+)\s+(\S+)/X$1 Y$2 [some var]$3/;
Doesn't work? I assume it's the [] chars?
How do I escape these in to that expression?
$some_var = 'Z'; # change to whatever you want
$line =~ s/(\S+)\s+(\S+)\s+(\S+)/X$1 Y$2 $some_var$3/;
--
Just my 0.00000002 million dollars worth,
Shawn
"For the things we have to learn before we can do them, we learn by
doing them."
Aristotle
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/