in reply to Re^2: Using exists to check element in array
in thread Using exists to check element in array
In Perl keys are auto-quoted!
I.e. this "txt $h{key} txt" works fine.
You are also free to use hash-slices for multiple values, like "txt $h{@keys} txt"
From Learning Perl
Perl offers many shortcuts that can help the programmer, such as omitting the quote marks on some hash keys.
You can’t omit the quote marks on every key since a hash key may be any arbitrary string. But keys are often simple. If the hash key only consists of letters, digits, and underscores without starting with a digit, you may be able to omit the quote marks. This kind of simple string without quote marks is called a bareword since it stands alone without quotes.
One place you are permitted to use this shortcut is the most common place a hash key appears, which is in the curly braces of a hash element reference. For example, instead of $score{"fred"}, you could write $score{fred}. Since many hash keys are like this, not using quotes is a convenience. But beware: if there’s anything inside the curly braces besides a bareword, Perl will interpret it as an expression.
Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Using exists to check element in array
by david (Novice) on Jan 28, 2024 at 10:51 UTC |