G'day smturner1,

Welcome to the monastery.

While you're learning, you'll find it useful to use the diagnostics pragma, i.e.

... use strict; use warnings; use diagnostics; ...

This will provide more detailed explanations of the normally much shorter warning and error messages you receive. This is a developer tool that produces a lot of output that's typically unsuitable for endusers: it's generally a good idea to either delete or comment out the use diagnostics; line in your production code. Follow the link I provided for a more complete description.

In addition to the already lengthy list of issues, it looks like you may have another problem with:

my $destinationDir = 'C:\Users\Shaun\Documents\$website';

unless the $destinationDir path does in fact end with a directory that's literally called "$website".

As you haven't declared the $website variable, that could be an omission or that could be exactly what you intended. Regardless, I'll point out some issues that might at least be useful for future reference.

Variables do not interpolate within single quotes, so $website will evaluate exactly to the string "$website" and not to whatever value was assigned to $website.

Simply changing the single-quotes to double-quotes does not fix this situation. Every character preceded by a backslash ('\') is considered to be escaped (i.e. it has some special meaning). "C:\Users\Shaun\Documents\$website" will be parsed as follows:

All of this means that "C:\Users\Shaun\Documents\$website" will evaluate to:

C:SERSSHAUNDOCUMENTS$WEBSITE

To fix this, you'd need to escape the escapes, i.e. change each instance of '\' to '\\':

"C:\\Users\\Shaun\\Documents\\$website"

Clearly, this is now becoming rather messy, less readable and error-prone.

A better way to deal with this (from coding, maintenance and portability perspectives) is to use the core module File::Spec. In this specific instance, you could simply write:

File::Spec->catfile('C:\Users\Shaun\Documents', $website)

[Aside: When posting questions about error messages you receive, we can provide much better help if you post the exact error message rather than a rough description of it. Details about this, as well as other guidelines for posting here, can be found in "How do I post a question effectively?".]

-- Ken


In reply to Re: Syntax Error deleting files and folders in a directory by kcott
in thread Syntax Error deleting files and folders in a directory by smturner1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.