Node:Examples of Invalid Single-quoted Strings, Previous:Newlines in Single-quoted Strings, Up:Single-quoted Strings



Examples of Invalid Single-quoted Strings

In finishing our discussion of singled-quoted strings, consider these examples of strings that are not legal because they violate the exceptions we talked about above:

     'You cannot do this: \'; # INVALID: the ending \ cannot be alone
     'It is 5 o'clock!'       # INVALID: the ' in o'clock should be escaped
     'Three \'s: \\\\\';      # INVALID: the final \ escapes the ', thus
                              #          the literal is  not terminated
     'This is my string;      # INVALID: missing close quote
     

Sometimes, when you have invalid string literals such as in the example above, the error message that Perl gives is not particularly intuitive. However, when you see error messages such as:

     (Might be a runaway multi-line '' string starting on line X)
     Bareword found where operator expected
     Bareword "foo" not allowed while "strict subs" in use
     

It is often an indication that you have runaway or invalid strings. Keep an eye out for these problems. Chances are, you will forget and violate one of the rules for single-quoted strings eventually, and then need to determine why you are unable to run your Perl program.