in reply to regex issue

The quotes inside the regex seem to be a problem, since there are no such quotes in the command.

$ perl -wE '"sort by CPU" =~ m/sort\s+by\s+(CPU|USER|PID)/ and say $1' CPU

Works just fine.

Replies are listed 'Best First'.
Re^2: regex issue
by perlNewby (Initiate) on Feb 17, 2012 at 08:53 UTC

    wow, thanks a lot! I didn't think that would matter. I only put the "" in there in the first place because the word sort turned red like it was going to try to use the sort function and I thought it would give me an error so I put them in there to try to force it to see sort as a string. Thanks again!</P

      Don't trust the syntax highlighting in your text editor as an authority on how perl itself will treat a script.

      Perl has been proven to be impossible to parse. (If you define "parse" to mean "determine the structure of without executing it". Clearly it is possible to determine the structure of Perl code if you actually execute it.) Text editors do their best, but sometimes fall short.

      The editors that tend to do the best highlighting for Perl in my experience are Padre and SciTE. With SciTE, the only Perl syntax that seems to consistently confuse it is:

      sub uppercase ($) { return uc $_[0]; }

      (Yes, I'm well-aware that this is a useless function. It's just an example.) SciTE will highlight the $) in the prototype as if it were the $) built-in EGID variable.

        Perl has been proven to be impossible to parse.
        Yeah, that's why PPI is such a waste of time. Perlcritic and perltidy is just stabbing in the dark. And the perl-to-javascript compiler(*) that was shown at FOSDEM was just a scam. ;-)
        Text editors do their best, but sometimes fall short.
        Text editors have much different problem. They have to be 1) interactive (which means, instant response), and 2) work on code in progress -- most of the time, not even perl can parse the text, because it isn't finished yet.

        (*) Yes, I know it isn't complete yet. Give Flavio some time.