Perl::...Substr(3pm)

πŸ’– NAME πŸ’–

okay so this is Perl::...Substr(3pm) from User Contributed Perl Documentation, and it's the manual for Perl::Critic::Policy::BuiltinFunctions::ProhibitLvalueSubstr. The whole vibe: use the 4-argument substr instead of writing substr($foo, 2, 6) = $bar. That's the policy. Slay. πŸ’…

🫢 AFFILIATION 🫢

This Policy is part of the core Perl::Critic distribution. No cap. 🫢

✨ DESCRIPTION ✨

Conway discourages using substr() as an lvalue. Instead, the recommendation is to use the 4-argument version of substr(). Like:

substr($something, 1, 2) = $newvalue;     # not ok
substr($something, 1, 2, $newvalue);      # ok

The four-argument form of substr() was introduced in Perl 5.005 β€” iconic. This policy does not report violations on code which explicitly specifies an earlier version of Perl (e.g. use 5.004;), so it's not gonna come for that code. πŸ¦‹

πŸŽ€ CONFIGURATION πŸŽ€

This Policy is not configurable except for the standard options. Literally just the standard options, bestie. πŸŽ€

πŸ¦‹ SEE ALSO πŸ¦‹

  • "substr" in perlfunc (or run perldoc -f substr).
  • "4th argument to substr" in perl5005delta

🌸 AUTHOR 🌸

Graham TerMarsch <graham@howlingfrog.com> β€” periodt. 🌸

Copyright (c) 2005-2011 Graham TerMarsch. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


xoxo, your local manual page πŸ’… β€” footer tea: perl v5.42.0, dated 2024-10-23. Byeee! πŸ¦‹

πŸ“¦ where this page comes from