Perl syntax for strings
Hi, I see in Perl code some cases where a string in written with a space between q or qq or qw and string. Like : qq /foo bar/ instead of qq/foo bar/ It works, but I dont find it in docs like https://perldoc.perl.org/perlop#Quote-Like-Operators Most of cases are in : use CGI qw ( -utf8 ); There are only 29 other cases : git grep -E ' q[qw]? [/({]' | grep -v 'use CGI qw ' Should we add a coding guideline ? https://wiki.koha-community.org/wiki/Coding_Guidelines I must admint for me it would be better to avoid it because it breaks syntax coloring in my editor (Eclipse with EPIC). But maybe other have the same issue. Best regards, -- Fridolin SOMERS <fridolin.somers@biblibre.com> Software and system maintainer 🦄 BibLibre, France
Hi! On Tue, Jun 15, 2021 at 10:19:12AM +0200, Fridolin SOMERS wrote:
I see in Perl code some cases where a string in written with a space between q or qq or qw and string. Like : qq /foo bar/ instead of qq/foo bar/
While this works, it is strongly recommended to not use this "feature". It's main "use" is to use ANY string as quote-like operator: perl -E 'say qq A({/";A' ({/"; But of course this is horrible and should not be used (outside of obfuscations..)
Most of cases are in : use CGI qw ( -utf8 );
This isn't even using the "feature" to allow any string..
There are only 29 other cases : git grep -E ' q[qw]? [/({]' | grep -v 'use CGI qw '
Of course this regex would fail to find why the space after q/qq/qw is allowed, because using the space you can use ANY char for the quote-like op. But I'm quite sure that nobody is crazy enough to put that into production code. And coming up with a regex that matches this would be quite hard... Though maybe there is a Perl::Critic rule for it?
Should we add a coding guideline ? https://wiki.koha-community.org/wiki/Coding_Guidelines
++ Greetings, domm -- #!/usr/bin/perl https://domm.plix.at for(ref bless{},just'another'perl'hacker){s-:+-$"-g&&print$_.$/}
OK so proposing to remove this space makes sens, great ;) Also looks like Perl::Tidy does not remove the space. Le 15/06/2021 à 11:00, Thomas Klausner a écrit :
Hi!
On Tue, Jun 15, 2021 at 10:19:12AM +0200, Fridolin SOMERS wrote:
I see in Perl code some cases where a string in written with a space between q or qq or qw and string. Like : qq /foo bar/ instead of qq/foo bar/
While this works, it is strongly recommended to not use this "feature". It's main "use" is to use ANY string as quote-like operator:
perl -E 'say qq A({/";A' ({/";
But of course this is horrible and should not be used (outside of obfuscations..)
Most of cases are in : use CGI qw ( -utf8 );
This isn't even using the "feature" to allow any string..
There are only 29 other cases : git grep -E ' q[qw]? [/({]' | grep -v 'use CGI qw '
Of course this regex would fail to find why the space after q/qq/qw is allowed, because using the space you can use ANY char for the quote-like op. But I'm quite sure that nobody is crazy enough to put that into production code. And coming up with a regex that matches this would be quite hard... Though maybe there is a Perl::Critic rule for it?
Should we add a coding guideline ? https://wiki.koha-community.org/wiki/Coding_Guidelines
++
Greetings, domm
-- Fridolin SOMERS <fridolin.somers@biblibre.com> Software and system maintainer 🦄 BibLibre, France
participants (2)
-
Fridolin SOMERS -
Thomas Klausner