LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-28-2008, 11:19 AM   #1
knockout_artist
Member
 
Registered: Sep 2005
Distribution: fedora core 9
Posts: 324

Rep: Reputation: 33
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?
 
Old 10-28-2008, 12:41 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
That's because you're comparing string values, not
numbers ... think ASCII values.
 
Old 10-28-2008, 01:20 PM   #3
knockout_artist
Member
 
Registered: Sep 2005
Distribution: fedora core 9
Posts: 324

Original Poster
Rep: Reputation: 33
Quote:
Originally Posted by Tinkster View Post
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 ?
 
Old 10-28-2008, 01:34 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

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


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Wacom acting strange Yoda3114 Ubuntu 9 03-29-2007 02:52 AM
partimage acting strange when invoked from script ffaker Linux - Software 1 08-19-2005 09:55 AM
Php4 acting strange Sevoma Linux - Software 13 02-15-2005 05:44 PM
Avidemux2 acting strange alitrix Linux - Software 0 12-15-2004 10:55 AM
grep acting strange in script fredgt Programming 2 12-14-2004 11:15 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration