?
Solved

Time-Stamp & Filename Hash

Posted on 1998-11-24
2
Medium Priority
?
699 Views
Last Modified: 2008-02-20
Hi,

Want to create an associative array of filename and timestamp from a listing of a directory on a unix box.

Any pointers?

Thanks,

Andreas
0
Comment
Question by:context
2 Comments
 
LVL 5

Accepted Solution

by:
b2pi earned 300 total points
ID: 1206555
perldoc File::Listing starts with ....

NAME
    parse_dir - parse directory listing

SYNOPSIS
     use File::Listing;
     for (parse_dir(`ls -l`)) {
         ($name, $type, $size, $mtime, $mode) = @$_;
         next if $type ne 'f'; # plain file
         #...
     }

     # directory listing can also be read from a file
     open(LISTING, "zcat ls-lR.gz|");
     $dir = parse_dir(\*LISTING, '+0000');

DESCRIPTION
    The parse_dir() routine can be used to parse directory listings.
    Currently it only understand Unix `'ls -l'' and `'ls -lR''



So,

use File::Listing;

for (parse_dir(`ls -l`)) {
    ($name, $type, $size, $mtime, $mode) = @$_;
    next if $type ne 'f'; # plain file
    $Files{$name} = $mtime;
}


0
 
LVL 85

Expert Comment

by:ozo
ID: 1206556
opendir(DIR,'.');
%Files=map{$_,(stat $_)[9]}readdir(DIR);
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question