-
Notifications
You must be signed in to change notification settings - Fork 559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a new perlrun option "-j" which allows JSON parsing in line #22718
base: blead
Are you sure you want to change the base?
Conversation
With this option we basically extend the already existing "-n" and "-p" flags to handle JSON using the inbuilt "JSON::PP" module. Basically we decode the STDIN from "$_" with decode_json into $_ again so you can run something like: sudo journalctl -f -o json | ./perl -njle 'if ( $_->{"_GID"} == 0 ) {print $_->{"MESSAGE"}}' To quickly filter out all root processes, this would make adhoc log analysis of most modern applications a more convenient.
While useful, I'm not sure this belongs in perl itself. Can't this be a separate tool? |
@Leont a whole separate tool that does all of perl plus one per-line calls to Sounds like a pretty big tool to maintain, why you'd need a whole mailing list full of people for 20 to 30 years to build something like that ... |
Not only does this does step into areas of recent discussion, wherein folks mention wanting -n/-p to not:
But it also coincides nicely with giving perl built-in HTTPS (#20739), so it might even make sense to go further and have
... maybe I think it's safe to assume this "The World Wide Web" thing is here to stay. |
That's not what I meant. What if you have a perl script that does exactly what you just described. It wouldn't even be a big script really. |
@Leont In the past I've found that turning a one-liner into a script involves writing a decent chunk of software - those switches do a lot of stuff for you. A Also, it seems worth asking why perl-proper is the wrong place for a feature like this when autosplit ( |
If we add this do we also add similar support for YAML, XML, etc? The line oriented processing has been there (probably) since perl 1, I know I used it in perl3. |
I don't think you can do yaml with per-line, but |
Kind of ugly:
and:
|
https://github.com/Perl/perl5/blame/blead/utils/json_pp.PL this exists, IDK what it does. Perl's bundled -x perm |
Most utils are really scripts from core modules, in this case JSON::PP |
If nobody's needed
... it doesn't do any of the things this PR does. It also raises the question about porting the functionality to the scripts in assorted, non-core It's even mentioned earlier in this thread that round tripping other formats in this situation would be equally handy... That definitely doesn't fit the "Maybe jam it into
This one is the only usable suggestion, and it's a source filter. The religious teachings tell me I should hate and fear source filters, that it's correct and prudent to shun them. On the other hand I am enchanted by their heady and seductive power. I have mixed feelings about this. |
After a bit of thinking, I do think it is worth to use up I'm not sure what's necessary for a consensus here, but I will definitely compile this change into my own Perl for the time being. |
For this type of change you're probably better off asking on the list and perhaps going through the PPC process. |
With this option we basically extend the already existing "-n" and "-p" flags to handle JSON using the inbuilt "JSON::PP" module. Basically we decode the STDIN from "$" with decode_json into $ again so you can run something like:
sudo journalctl -f -o json | ./perl -njle 'if ( $_->{"_GID"} == 0 ) {print $_->{"MESSAGE"}}'
To quickly filter out all root processes, this would make adhoc log analysis of most modern applications a more convenient.
I am by no means a Perl expert so this probably needs some adjustment to fit in, I also at this point have no idea where I would stash some tests for this, but it might be worth discussing merit before spending the time testing, the change works well enough for me now that the idea is reviewable.