On Fri, Jun 29, 2001 at 10:21:31AM +1000, Sam Lander wrote:
> I wanted to do this just today. Although, I want to tidy up the resulting
> line a bit by deleting everything before a colon, so I tried this:
> perl -ne "/string/ && print s/.*://" file
> I was surprised that I got this:
> 1111111111111111111111111111111111111111111 (one '1' for each match)
> A bit of playing gave me:
> perl -ne "/Recipient/ && s/.*:// && print"
> Which gave me what I wanted, but is rather unsatisfying (esp to the sedder
> in me).
> What do other people do? Shouldn't DWIM come into play here?
What if you wanted to print the number of matches s///g found, without
resorting to a temporary variable? Granted, it's a little odd, but I think
"print s///g" is a little too ambiguous to simply decide that it should print
$_, and making "print s///" behave differently from "print s///g" is even
more confusing than the current behaviour (if one were to consider the
current behaviour confusing).
Also, "/string/ && s/.*:// && print" is not equivalent to your mythical
"/string/ && print s/.*://", if I understand you correctly. In the first
example, /string/ has to match and s/.*:// has to replace an occurrence
before the string gets printed. In the second example, $_ would be printed
regardless of whether or not the s/// found a match.
Michael
--
Administrator www.shoebox.net
Programmer, System Administrator www.gallanttech.com
--