Typically this error has to do with where you've written that line of code. For example, you can't execute code like this outside of a function body.
Please post your entire script, as it's impossible to be specific without seeing the context of where this line of code is.