Perl Christmas Quiz
Abigail
abigail at abigail.be
Fri Dec 12 22:39:51 GMT 2008
On Fri, Dec 12, 2008 at 10:13:51PM +0000, Nicholas Clark wrote:
> On Fri, Dec 12, 2008 at 11:01:08PM +0100, Philip Newton wrote:
> > On Fri, Dec 12, 2008 at 15:41, Nicholas Clark <nick at ccl4.org> wrote:
> > > What are the 7 classes of unquoted string that are not barewords. I think it's
> > > 7. It usually requires a Damian to remember them all. Most I can get.
> >
> > What are they then?
> >
> > I can only think of two off the top of my head - things before 'fat
> > comma' and the single-word contents of a hash subscript. Hm, do
> > filehandles count in things such as "print LOGFILE 'bla'"?
>
> Ah yes. Hash subscripts. That was the one I had forgotten.
>
> 1: Predeclared functions
> 2: File handles
> 3: Formats
> 4: Hash subscripts in {}
> 5: To the left of =>
>
> 6: hashes without %
>
> $ perl -wle '%a = ( pie => "mince" ); print keys a'
> Unquoted string "a" may clash with future reserved word at -e line 1.
> Hash %a missing the % in argument 1 of keys() at -e line 1.
> pie
>
> 7: arrays without @
>
> $ perl -wle 'push pie, 3.14; print foreach @pie'
> Unquoted string "pie" may clash with future reserved word at -e line 1.
> Array @pie missing the @ in argument 1 of push() at -e line 1.
> 3.14
Well, I knew you could use all these, and that they don't use quotes.
But I don't know when things are considered 'bare words', and when
it's an 'unquoted string'.
I gather then that method names, class names and subroutine names
are not unquoted strings, but bare words? (But apparently, if the
function is predeclared, it's no longer a bare word, but an unquoted
string).
> Although, arguably it's 8, if you consider directory handles to be distinct
> from file handles. And at this rate I've still missed something.
Some other things that don't need quotes are labels and attributes.
But I've no idea whether those are bare words, or classes of unquoted
strings.
Abigail
More information about the london.pm
mailing list