Perl FAQ 4.15: Do I always/never have to quote my strings or use semicolons?

Perl FAQ 4.15

Do I always/never have to quote my strings or use semicolons?

You don't have to quote strings that can't mean anything else in the language, like identifiers with any upper-case letters in them. Therefore, it's fine to do this:

    $SIG{INT} = Timeout_Routine;
or
    @Days = (Sun, Mon, Tue, Wed, Thu, Fri, Sat, Sun);

but you can't get away with this:

    $foo{while} = until;

in place of

    $foo{'while'} = 'until';

The requirements on semicolons have been increasingly relaxed. You no longer need one at the end of a block, but stylistically, you're better to use them if you don't put the curly brace on the same line:

    for (1..10) { print }

is ok, as is

    @nlist = sort { $a <=> $b } @olist;

but you probably shouldn't do this:

    for ($i = 0; $i < @a; $i++) {
	print "i is $i\n"  # <-- oops!
    } 

because you might want to add lines later, and anyway, it looks funny. :-)

Actually, I lied. As of 5.001, there are two autoquoting contexts:

This                    is like this
------------            ---------------
$foo{line}              $foo{"line"}
bar => stuff            "bar" => stuff


Other resources at this site: