Display of array of images in a loop. The array changes every five minutes.

For non commercial company I am sort of trying to make a loop of images.

You often see them on the web where they show satellite images. A small loop comprised of the last 20 images is shown to you. I want to do the same. I do know how to wite a loop in perl, but everytime I have to declare an array of the last 20 images. What I want is that this array is not static. It should look into a directory and then look at what the lastest 20 images were (select on date and time of creation) and put those filenames in the array just described (in reversed order!). So, oldest one first., and the newest one last. There must be somewhere some script like this. But I do not know how to find it nor to write it. Can u help me?
Killroy76Asked:
Who is Participating?
 
amc25Commented:
one way to fetch files from within a directory would be:

-------------
$dir = "/home/mypage/html/images";

opendir(BIN, $dir) or die "Can't open $dir: $!";
while (defined ($file = readdir BIN)) {
      push @img_files , $file if ($file =~ /\.gif$/gi || $file =~ /\.jpg$/gi);
}
closedir(BIN);
-------------

I'd recommend to make the file-sorting based on the filename. If it's you who is uploading the images to the specified directory, this should be no problem.
0
 
Kim RyanIT ConsultantCommented:
These types of images are typically animated gifs, several frames assembled into a single file. One way to make thme with Perl is:
http://search.cpan.org/~dmuey/GD-Image-AnimatedGif-0.04/AnimatedGif.pm
0
 
Killroy76Author Commented:
I see.. but is this really the easiest way? I do not quite understand how this program works, namely. Or how to install it on my server.
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
Killroy76Author Commented:
K.. I can do that. But don't i now end up with an array of all filenames, instead of for example the last 20?
0
 
ozoCommented:
@img_files = map{$_->[0]} (sort{ $b->[1] <=> $a->[1]} map{[$_,-M]} </home/mypage/html/images/*.gif>)[-20..-1];
0
 
Killroy76Author Commented:
K.. will try it out over the weekend and next week.
0
 
Killroy76Author Commented:
it worked.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.