Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Variable with curly braces?

by Athanasius (Archbishop)
on Oct 24, 2021 at 06:38 UTC ( [id://11137942]=note: print w/replies, xml ) Need Help??


in reply to Variable with curly braces?

Hello wyt248er, and welcome to the Monastery!

The syntax $UTF8{Euro} = ...; is indeed a variable assignment, but the variable assigned to in this case is a member of a hash. You can see this yourself in two ways:

# Method 1: With an explicit declaration use strict; use Data::Dump; my %v; # Hash declaration $v{u} = "hello"; print $v{u}, "\n"; dd %v; # Show the contents of the hash
# Method 2: Without a declaration # No "use strict" here! use Data::Dump; $v{u} = "hello"; print $v{u}, "\n"; dd %v; # Show the contents of the hash

The first method declares the hash %v using the my keyword, as mandated by the use strict; pragma. This is good practice. The second method just uses the hash without first declaring it. This will work only if the use strict; pragma is not in effect. This is considered bad style in modern Perl.

Bear in mind that the Perl documentation has been around for some time, and may pre-date modern best practice. In any case, the code examples in the documentation are snippets only, not complete scripts.

Update: Added 2 code comments

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2024-04-18 15:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found