Perl::...tachars(3pm)

okay bestie, welcome to Perl::...tachars(3pm) β€” a User Contributed Perl Documentation page, and yes the title is literally giving ellipsis realness πŸ’…βœ¨

🌸 NAME 🌸

Perl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars β€” the policy that warns you might have used single quotes when you really wanted double-quotes 🫢

🫢 AFFILIATION 🫢

This policy is part of the core Perl::Critic distribution. She's not an add-on, she's main character energy πŸ‘‘

✨ DESCRIPTION ✨

This policy warns you if you use single-quotes or q// with a string that has unescaped metacharacters that may need interpolation. It's lowkey hard to know for sure if a string really should be interpolated without looking into the symbol table. So this policy just makes an educated guess by looking for metacharacters and sigils which usually indicate that the string should be interpolated. Cute, right? 🧚

πŸ’… Exceptions

there are lil exceptions where she'll chill:

  • Variable names to use vars:
use vars '$x';          # ok
use vars ('$y', '$z');  # ok
use vars qw< $a $b >;   # ok
  • Things that look like e-mail addresses:
print 'john@foo.com';           # ok
$address = 'suzy.bar@baz.net';  # ok

πŸŽ€ CONFIGURATION πŸŽ€

  • rcs_keywords β€” lets you stop this policy from complaining about things that look like RCS variables, for example, in deriving values for $VERSION variables. πŸ’–

For example, if you've got code like

our ($VERSION) = (q<$Revision$> =~ m/(\d+)/mx);

You can specify

[ValuesAndExpressions::RequireInterpolationOfMetachars]
rcs_keywords = Revision

in your .perlcriticrc to provide an exemption. Slay, no more false alarm πŸŽ€

πŸ“ NOTES πŸ“

Perl's own warnings pragma also warns you about this. So yeah, Perl is also looking out πŸ‘€

πŸ‘€ SEE ALSO πŸ‘€

  • Perl::Critic::Policy::ValuesAndExpressions::ProhibitInterpolationOfLiterals

πŸ‘‘ AUTHOR πŸ‘‘

Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>

Copyright (c) 2005-2023 Imaginative Software Systems.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module.


mwah πŸ’‹ β€” this page is perl v5.42.0, dated 2024-10-23, and that's the whole vibe 🫢✨

πŸ“¦ where this page comes from