Perl oneliner match repeating itself

I'm trying to read a specific section of a line out of a file with Perl. The file in question is of the following syntax.

# Sets $USER1$ 
# Sets $USER2$ 

My oneliner is simple,

perl -ne 'm/^\$USER1\$\s*=\s*(\S*?)\s*$/m; print "$1";' /my/file

For some reason I'm getting the extraction for $1 repeated several times over, apparently once for every line in the file after my match occurs. What am I missing here?


You are executing print for every line of the file because print gets called for every line, whether the regex matches or not. Replace the first ; with an &&.

Need Your Help

Given the X and Y velocity of an object, how can the angle be computed?

math vector

For a particle moving about in the Cartesian coordinate system (neglecting z), how can the angle of travel be computed given the velocity of X and Y? Before anyone says this isn't programming relat...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.