in reply to OptiPerls Pattern Replace (Regexpses for one Line)
If you read your code in line by line, which is the normal way in perl, the special variable $_ matches the current line automatically, so you don't need a regex to match it.
Or, I guess,
^.*$
will also match an entire line if you have to use a regex. Or
blah.*$
will match everything from the first blah out to the end of the line.
Or maybe you could rephrase the question if that isn't quite what you wanted.
use warnings; use strict; while (<DATA>) { print '$_: ' . "$_"; /^.*$/; print '/^.*$/: ' . "$&\n"; # print the match /blah.*$/; print '/blah.*$/: ' . "$&\n"; print "\n"; } #outputs: #$_: blah #/^.*$/: blah #/blah.*$/: blah # #$_: foo blah #/^.*$/: foo blah #/blah.*$/: blah # #$_: foo bar blah blah blah #/^.*$/: foo bar blah blah blah #/blah.*$/: blah blah blah # #$_: #/^.*$/: #/blah.*$/: __DATA__ blah foo blah foo bar blah blah blah
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: OptiPerls Pattern Replace (Regexpses for one Line)
by Ben Win Lue (Friar) on Mar 02, 2005 at 10:06 UTC | |
by tphyahoo (Vicar) on Mar 02, 2005 at 10:12 UTC |