Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Ways of quoting

by LanX (Saint)
on May 15, 2020 at 00:30 UTC ( [id://11116794]=note: print w/replies, xml ) Need Help??


in reply to Ways of quoting

Hi

IMHO the only purpose of assigning a package's name to a scalar is to handle it later in a referential or symbolic way.

For instance $x->can("function") will return a code ref if "function" exists in the package.

So the benefit of writing $x = anything_could_go_here:: over $x = 'anything_could_go_here' is only catching the error when misspelling the package's name.

(you already demonstrated this after activating warnings )

I'd strongly discourage using this as golfing hack to avoid single quotes around normal strings.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^2: Ways of quoting
by Aaronrp (Scribe) on May 15, 2020 at 02:28 UTC

    Yeah, clearly just using it as a sneaky way of quoting doesn't work.

    Having said this, one thing I've done in the past is something like this:

    use Const::Fast; use A::Really::Long::Class::Name::To::Type; const my $CLASS => 'A::Really::Long::Class::Name::To::Type'; $CLASS->do_something; $CLASS->do_something_else; $CLASS->yet_another_thing; # # and a bunch more of these #

    In that circumstance, seems to me that

    const my $CLASS => A::Really::Long::Class::Name::To::Type::;

    might actually be preferable, in that it gives you that check against the package name.

    All I can say is I've been using perl since the '90s and I still have so much I don't know.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11116794]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2025-06-17 13:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.