Jump to content
  • Advertisement

0_o

Sign in to follow this  
  • entries
    18
  • comments
    21
  • views
    12291

perl

Sign in to follow this  
Penten

617 views

Well I decided to learn perl by writing myself an image directory display script thingy.
I haven't bothered to install a file manager yet so I've been using mozilla to look through the directories, but when files are called things like 10215420.jpg it can be difficult to find what you're looking for.

Anyway, here it is in all its horrifying glory. I'm sure you perl gurus out there will find many ways to reduce this to two lines of code but I'm just learning, ok. [grin]


#!/usr/bin/perl

use strict;
use warnings;
use Image::Size;

print "Enter directory :";
my $dir = ;
chomp $dir;
my $filename = "$dir/imgs.html";
my $imgs;
$imgs = `ls $dir`;
my @lines;
@lines = split(/\n/, $imgs);
open(FILE, ">$filename") or die "error opening file\n";
print FILE "\n$dir\n\t\n\n\n";
my $counter = 0;
foreach my $l (@lines)
{
if ($l =~ /\.jpg|\.bmp|\.png/)
{
if ($counter%4 == 0)
{
print FILE "";
$counter++;
}
}
print FILE "\t\n";
close(FILE);




It requires the Image::Size module. And creates a table with four images per line. Yay! (Oh, and I ecpect that the html is rather iffy as well, but it works!, I love that [grin])

edit: the html file has a title now
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!
";
}
else
{
print FILE "
";
}
(my $width, my $height) = imgsize("$dir/$l");
$width = ($width * 128)/$height;
print FILE "$l\">$l\">\n";
print FILE "