LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   perl Script acting strange. (https://www.linuxquestions.org/questions/linux-newbie-8/perl-script-acting-strange-679575/)

knockout_artist 10-28-2008 11:19 AM

perl Script acting strange.
 
Hi,

This script needs to show directories older than certain time (ARGV[1])

It works fine till the values 1 to 9, directory count decreases.
How ever if I do 10 as an arg. direcory no. increases. It more then with "9" 0r "4".


Here is the code:

Code:



chdir($ARGV[0]) or die "Unable to enter dir $workdir:$!\n";
 
 opendir(DIR, ".") or die "Unable to open $ARGV[0]\n";
    my @names = readdir(DIR);
    closedir(DIR);

    foreach my $name (@names){
        next if ($name eq ".");
        next if ($name eq "..");

  if (-d $name && -M $name ge $ARGV[1])
        {
          print"$name\n";
        }
  }


Any Ideas?

Tinkster 10-28-2008 12:41 PM

That's because you're comparing string values, not
numbers ... think ASCII values.

knockout_artist 10-28-2008 01:20 PM

Quote:

Originally Posted by Tinkster (Post 3324204)
That's because you're comparing string values, not
numbers ... think ASCII values.

So like c language I need to get $ARGV[1] and declare it as int ?

Tinkster 10-28-2008 01:34 PM

Just change the comparison from ge to >= ...
perl isn't a typed language.


All times are GMT -5. The time now is 03:20 AM.