in reply to Simple Perl one-liner in command line

perl -ne "if (/Variable3 (.*)/ > 0.900) { print 1 }" ...

This puts the regular expression into scalar context, which means it will only return a true value on a match or a false value when not matched. $1 is populated with the contents of the first capture group, so you could write something like if (/Variable3 (.*)/ && $1 > 0.900) .... Alternatively, you can put the regular expression into list context, and since it contains capture groups and doesn't use the /g modifier it will return the contents of the capture groups as a list (details in perlop). The following puts the regex into list context and immediately fetches the first item of that list:

perl -ne "if ( (/Variable3 (.*)/)[0] > 0.900 ) { print 1 }" ...

Note that one debugging technique for troubles with one-liners is to put the code in a normal script file first, spell it out a little more verbosely, Use strict and warnings, find the problem (Basic debugging checklist), and then, if you still want to, reduce it back to a one-liner.

Replies are listed 'Best First'.
Re^2: Simple Perl one-liner in command line
by wewantmoore (Initiate) on Mar 26, 2015 at 13:51 UTC

    Wow, thank you guys so much for the quick response. Your simple line of code fixed the problem and it works now.