Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update on former ls -al question

Status
Not open for further replies.

stuellry

Programmer
Apr 14, 2004
4
US
Thanks for all the responses but those weren't exactly what i was looking for. Let me try to rephrase. I need this script to work independently of the existing ls, in other words not call it. Also it needs to be able to be passed an argument. I have some idea that I want to open and read the dir and then output in the appropriate form but don't really know enough about PERL to get it working correctly.

What I need to do exactly is create a Perl script "myls x" that does the equivalent of the Linux command "ls -al". Display the time and date in the format "14:38 Mar 14".
Also this needs to be done without calling ls.

Thanks again for the prompt replies.
 
perldoc -f opendir
perldoc -f readdir
perldoc File::Stat
 
Code:
opendir (LOGDIR, ".");
@logfiles = grep(/[^.]/, readdir (LOGDIR)); # ignore any file starting with a period
close LOGDIR;

foreach $filename (@logfiles) {

  print "$filename";
  $modified = (stat("$filename"))[9];
  $modified = localtime($modified);
  ($month, $hour, $min) = $modified =~ m|([A-Z][a-z]{2})[^\d+]([A-Z][a-z]{2})[^\d]+(\d{1,2})[^\d]+(\d{2}:\d{2}):\d{2}|;
  print " " x (20 - length ($filename));
  print "$4 $2 $3\n";

}


Kind Regards
Duncan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top