in reply to Why can't I create a directory with File::Spec

G'day smturner1,

The code you posted should be giving warnings about my $ARCHIVE = ... appearing twice in the same scope. E.g.

$ perl -Mwarnings -e 'my $x = 1; my $x = 2;' "my" variable $x masks earlier declaration in same scope at -e line 1.

So, either that's not your actual code or you're hiding messages from us. Does autodie, for instance, provide feedback you're not showing?

You should check the File::Spec documentation. Your catpath() code does not match the documented syntax, i.e.

$full_path = File::Spec->catpath( $volume, $directory, $file );

See join for placing dots between your values.

Use a print statement to see the actual value of $ARCHIVE before calling make_path().

-- Ken

Replies are listed 'Best First'.
Re^2: Why can't I create a directory with File::Spec
by smturner1 (Sexton) on Feb 11, 2014 at 19:09 UTC

    Ken, thank you for catching the error. I added it in the post, but it is not in the code I wrote. Please see new code:

    use strict; use warnings; use diagnostics; use autodie; use File::Spec; use File::Path qw( make_path remove_tree ); #Set command line arguments my ($website, $old_ip, $new_ip) = @ARGV; #Set vars my $volume = 'C:/'; + my $ARCHIVE = File::Spec->catpath($volume, qw(Desktop), $website, $ +old_ip, $TIMESTAMP); my $TIMESTAMP = strftime("%Y%m%d%H%M", localtime); my @WEBSITES = qw( three five calnet-test ); #Creates the new dir in archive sub initialize { make_path ($ARCHIVE); return; } initialize;