in reply to Re^2: Please advice
in thread Please advice

Did you read the documentation for File::Find yet? If so, what part of using File::Find can we clarify for you?


Dave

Replies are listed 'Best First'.
Re^4: Please advice
by ashish_sun123 (Initiate) on Aug 11, 2011 at 09:17 UTC

    I tried to do this

    se strict; use warnings; use Data::Dumper; use Switch; use File::stat; use Time::localtime; use POSIX (); print ("Enter the directory name and date as input arguments:"); my $which_directory; my $which_date; ###$tm = localtime; my $mtime; my $file; $which_directory = $ARGV[0]; print (" The first argument is $ARGV[0]\n" ) ; $which_date = $ARGV[1]; print (" The secnd argument is $ARGV[1]\n"); die("Nothing entered as directory path name\n") if ($which_directory e +q ""); die("Nothing enetered as update date\n") if ($which_date eq ""); opendir(DIR,$which_directory) || die "Error in opening dir $which_d +irectory\n"; my @dir = grep { !/^\.+$/ } readdir(DIR); my $i = 0; foreach (@dir) { readdir($ARGV[0] . "/" . $dir[0]); $mtime = (stat ($file))[9]; print " Time--->" . ($mtime).$file . "\n"; print "Last change:\t" . ($mtime).$file . "\n"; $i++; } closedir(DIR);

    $ perl test_ash.pl /var/opt/nexius/cm/westtr3/oss/ericsson 01/01/2011 Enter the directory name and date as input arguments: The first argument is /var/opt/nexius/cm/westtr3/oss/ericsson The secnd argument is 01/01/2011 Bad symbol for filehandle at test_ash.pl line 39.

    Is there any other approach for reading and entering into the subdirectory ? I saw the File::Find but did not get anything of relevance! . Please guide

      The bad symbol error is caused because you are attempting to feed readdir a string and not a directory handle object. You get a directory handle object from a call to opendir.

      File::Find quite literally does what you require - it crawls over a directory tree and tests each file against criteria of your choosing. Your wanted function might look something like:

      sub wanted { return unless -f; my $mtime = (stat)[9]; return unless $mtime > $limit_time; print "$mtime\t$File::Find::name\n"; }

      where you would have stashed the user input date converted to epoch time in $limit_time.

      I mean this with respect, but I believe you are trying to run before you can walk. Do you have programming experience in other languages, or is this your first one? I note you have an unused loop index variable $i, an unused iteration variable $_ and uninitialized $file variable. I would suggest you review http://learn.perl.org/ for some reference resources. In particular, Beginning Perl is widely considered a strong introduction.

perl code beautification
by ashish_sun123 (Initiate) on Aug 30, 2011 at 23:35 UTC

    Hi Monks, I am trying to beautify perl code on linux. I am having linux o/s and I have written .pl files I tried the following command perltidy somefile.pl but it is not working. What should I do?