in reply to Syntax Error deleting files and folders in a directory

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

Replies are listed 'Best First'.
Re^2: Syntax Error deleting files and folders in a directory
by smturner1 (Sexton) on Dec 29, 2013 at 00:46 UTC

    Thank you Ken. MS is the problem here, regarding the '\'. I knew that it would probably become an issue due to the fact that it is used to escape chars to literals and not syntax. I will research File::Spec as I was informed by my Perl sme that there was a module that could correct MS's ridiculous '\' issue within directory names, but he could not remember the name of the module. My suspicion is that you just provided me the answer/module I was looking for. As for the error; Padwalker via EPIC only gave me "Syntax Error" on the line I cited. I apologize for being vague, but I had no other information. I will also employ the diagnostics module so that I can avoid the same in the future. I appreciate this community so much now that I have found it. What a prize to have such a supportive group, especially for a Newb.

      Nah, MS is not the problem. Pretty much anywhere you can use / instead of \ in MS paths (some applications get grumpy, but it's pretty much always ok in Perl).

      You may find Padre IDE better than Eclipse/EPIC for working with Perl scripts. It's a long while since I last looked at the Eclipse/EPIC abomination and it may have improved out of sight, but Eclipse was a poor fit for use as a Perl IDE. If all you need is a good editor take a look at Komodo Edit or Sublime Text. The Komodo IDE is excellent, but costs around $US300 so unless you plan to be a serious user it's likely not an option.

      In any case running the script should get you the real diagnostics that Eclipse/EPIC is protecting you from.

      True laziness is hard work

        Thanks again Grandfather. I plan on being a serious user....but my learning curve seems to be pretty flat with Perl, which paradoxically has become a stumbling block. I will sally-forth with as much tenacity as I can muster and try to get through this part of the learning phase.