[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 147
  • Last Modified:

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?
1 Solution
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:
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.
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);

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.
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.

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?
@img_files = map{$_->[0]} (sort{ $b->[1] <=> $a->[1]} map{[$_,-M]} </home/mypage/html/images/*.gif>)[-20..-1];
Killroy76Author Commented:
K.. will try it out over the weekend and next week.
Killroy76Author Commented:
it worked.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now