Re: Six uses for curlies?
by davido (Cardinal) on Jan 13, 2006 at 05:15 UTC
|
- Code blocks (bare, labled, if(){}, while(){}, do{}, foreach(){}, for(){}, sub{}, map{}, etc.)
- Anonymous hash constructors
- Hash subscripting (and hash slice subscripting)
- Dereferencing
- Quantification (Regexen)
- Extended regexp patterns, ie (??{...})
I'll bet I missed something completely obvious.
...not to mention the fact that you can legitimately use {} in quote-like constructs such as:
- s{}[]
- tr{}{}
- q{}, qq{}, qr{}, qx{}, etc.
- m{}
| [reply] [d/l] [select] |
|
| [reply] |
|
Actually, more than seven if you count the uses within regexen: (?{...}), and (??{...}) are two different types of extended patterns, plus quantification, though you could argue that the curlies function as code blocks within the extended regex patterns, though that's a difficult distinction. Disambiguation!, I knew I missed a good one.
| [reply] [d/l] [select] |
|
Re: Six uses for curlies?
by TimToady (Parson) on Jan 13, 2006 at 17:56 UTC
|
Well, the six in question is a rather fuzzy number, but you can count things like \x{2639} and \N{WHITE FROWNING FACE} as a different category, plus curlies are used in formats to hide newlines in argument lists, though arguably that's also a code block. But in that case the primary intent is not to supply a code block, since the code in question is merely expected to return a list. Also, if I recall correctly, at one point you could replace the = and . surrounding a format with curlies, but that seems to be broken currently.
The internals of toke.c still pretend that they are curlies though. | [reply] |
Re: Six uses for curlies?
by ikegami (Patriarch) on Jan 13, 2006 at 07:17 UTC
|
Another special case of subscripting is glob subscripting. For example, *glob{SCALAR}.
Another special case of disambiguation is in the name of certain special variables, such as ${^TAINT} and ${^ENCODING}.
Thankfully, there's no ${ or $}.
| [reply] [d/l] [select] |
|
Oh yes there is so a $} variable. It's even supported in PPI :)
adam@red:~/cpan2/trunk/Process$ perl -de 1
Loading DB routines from perl5db.pl version 1.25
Editor support available.
Enter h or `h h' for help, or `man perldebug' for more help.
main::(-e:1): 1
DB<1> $} = "Hello World!\n";
DB<2> print $}
Hello World!
DB<3>
| [reply] [d/l] |
|
There is a ${, it's just that you have to (use disambiguation!) access it as ${{}. Much like $}, Perl doesn't use it internally for anything, but it is a punctuation global variable so use strict 'vars'; doesn't trigger on it.
| [reply] [d/l] [select] |
|
| [reply] |
|
|
Re: Six uses for curlies?
by jZed (Prior) on Jan 13, 2006 at 05:32 UTC
|
I'll take the easy one: literal curly braces :-). | [reply] |