Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use 'say' with Perl 5.8.8?

I'm assigned to a project (PHP/MySQL) that needs some review and possibly fixes.

As a part of it it is planned to check correctness of all variables that we get via GET and POST. We have a bunch of PHP (.php) and Smarty (.tpl) files that have several thousands of lines of code all together, so it would be painful to search for all $_GET[...] and $_POST[...] references manually. So I tried doing this:

find . -name "*.php" -or -name "*.tpl" |
xargs perl -ne 'use feature say; say $1 while m/(\$_(GET|POST)\[[\s]*[\S]+[\s]*\])/g;' |
sort -u

Basically it creates a list of all $_GET[...] and $_POST[...] references in the project, and then deletes the repeated values from it. But it didn't work, because I have Perl 5.8.8 on my development machine, which does not support 5.10+ feature 'say', and our system administrator said that upgrade is undesired. I'm not sure why, but he's the boss.

So, is there a way to replace 'say' with some other code, or maybe even replace Perl with another tool?

like image 237
G. Kashtanov Avatar asked Nov 27 '22 03:11

G. Kashtanov


2 Answers

Don't forget that it's very easy to emulate say:

sub say { print @_, "\n" }

Just add it to the beginning of the Perl code and use as you normally would.

like image 100
Zaid Avatar answered Dec 06 '22 10:12

Zaid


Perl 5.10 added 'say', which is a substitute for 'print', that automatically adds a newline to the output. Hence you can write

say "hello";

...instead of having to write:

print "hello\n";

Simply drop the 'use feature say;' and replace 'say $1' with:

print "$1\n";
like image 34
JRFerguson Avatar answered Dec 06 '22 10:12

JRFerguson