sanju7:

I downloaded your code so I could study it in more detail. Here are some things I noticed:

At this point, I had:

#! /usr/bin/perl -w use strict; use diagnostics; use File::Find; # Variable "ThisMoveTarget" contains destination archive location # path. If this stores a path (i.e if directories are archived) # then the main body of code (i.e walk down the source location # for deleting empty directories) should execute # my $ThisMoveTarget = q|holds location where archive files # should go |; my $ThisMoveTarget = '/home/ssaha/tmp/archive'; # our $DelEmptyFoldrArchive = q|holds yes or no |; our $DelEmptyFoldrArchive = "yes "; # our $ThisSourceDirectory = q|holds the source file location |; our $ThisSourceDirectory = "/home/ssaha/tmp/source/"; #our $ThisSourceDirectory = "\\\\hostname\\share-test"; my $file ; if ($DelEmptyFoldrArchive eq "yes ") { print STDERR "Debug3: entering check1 \n" ; find({ wanted => \&wanted, no_chdir => 1 }, $ThisSourceDirectory); if ($file) { print STDERR "Debug3: entering check2 file is file \n" ; print STDERR "The $ThisSourceDirectory has files present \n" ; } elsif (!$file) { print STDERR "Debug3 entering check3 file is no file\n" ; finddepth (sub { print "rmdir $_\n"; }, $ThisSourceDirectory); } } else { print STDERR "Debug3: entering check5 \n" ; print STDERR "DelEmptyFoldrArchive is $DelEmptyFoldrArchive, skippi +ng directory deletion. \n" ; } sub wanted { return unless -f; $file = $_; print STDERR "$file \n " ; }

At this point, the code is pretty clear, and one of the errors is apparent: Some of the code you probably intended to be in the wanted subroutine was actually following it, so it only checked the last file found at that part. The my $file; declaration was at the outermost scope, and hid that from you. By moving the declaration inside of sub wanted (along with the associated code), it cleans things up a bit more.

I stopped at this point for now, so you can work a little more on it.

Another note: perl works well with forward slashes in paths, even under Windows. You may find it helpful (as I do) to always use forward slashes in paths. It helps portability and you can avoid the headache of quoting backslashes.

...roboticus


In reply to Re^7: Remove Script for a Infrastructure file managenet system running embedded perl by roboticus
in thread Remove Script for a Infrastructure file managenet system running embedded perl by sanju7

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.