Hello... Perl lovers (one of which I am seeking to be)....I have the following script but it is returning errors..Here is the script:

use strict; use warnings; use File::Copy 'move'; # Determine destination folder for file based on filename. # All destinations are below a fallback destination provided as input. sub make_dest_finder { my $fallback_dest = shift; return sub { my $fnam = shift; # Determine basename to start looking for a destination folder +. my $basename = substr $fnam, 0, rindex $fnam, '.'; # Shorten name while no homonymous folder exists. chop $basename while $basename && ! -d "$fallback_dest/$basena +me"; return "$fallback_dest/$basename" if $basename; return $fallback_dest; }; } my $srcdir = "/tmp/folder"; my $dest_finder = make_dest_finder '/tmp/folder2'; opendir my $dh, $srcdir or die "Can't open $srcdir: $!"; my @files = grep ! /^\.+$/, readdir $dh; close $dh; my $moved = 0; foreach my $file (@files) { my $old = "$srcdir/$file"; my $dest = $dest_finder->( $file ); print STDERR "moving $file to $dest\n"; if ( ! move $old, $dest ) { warn "Move $old -> $dest failed: $!"; last; } $moved++; } print STDERR "\n\n- moved $moved files\n";

The error states that "Can't open /tmp/folder: Not a directory at movingfilesscript.pl line 23" Can anyone please help a newbie... And let me apologize if this is not the right forum or if in some way, I have disrespect the rules of the forum... This is literally my first post ...


In reply to From a Newbie/help diagnosing an error opening a directory by nu2thegame

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.