decerebrate has asked for the wisdom of the Perl Monks concerning the following question:
hey guys thanks for reading.
listen, i am a designer-idiot with a simple problem: i am trying to write a perl script that will generate an xml file based on the contents of a directory. the xml file will then be used in flash for a portfolio site.
basically, i will have a folder full of jpeg's, i want the perl script to generate the xml for flash so that the only thing i have to do to change out the images in flash is to replace the files in the directory.
the only info i really need in the xml file is an id attribute for the files (ie image1, image2 etc) and the url of each image.
so the xml could look like this:
<site> <item id="1" imageURL="/images/image1.jpg" /> <item id="2" imageURL="/images/image1.jpg" /> </site>
i found a perl script that works great, but i cant for the life of me figure out how to get the URL attribute (hey, i'm a designer-idiot, right?)
anyways, here is the perl code i am currently mangling:
#!/usr/bin/perl # -- Perl Dynamic XML directory Content Generator_by SUP@ -- # -- # This script is designed to make a dynamic XML file to be used with +flash # out of a directory that holds jpg files. I use this so my client m +ay simply # upload files into a ftp directory and the flash page automatically +gets # updated. This is the first time i give code to anyone on the net. # hope you enjoy it. You must have a little knowledge of perl to make + this # work for you. I commented as much as I could. # -- # By : SUP@ mtlelite@hotmail.com # -- print "content-type: text/html\n\n"; # show Load data ... print "<html><body>"; print "<h1>Loading data...\n"; print "</h1></body><html>"; # open xml file to write open(FIL,">../pub/database.xml"); # lock the file flock(FIL,2); # XML intro print FIL "<?xml version= 1 ?>\n"; # xml category print FIL "<categoryName>\n"; # create index var local $t; $t=0; # open image directory to create xml from opendir(HOMEDIR, "../images/") || die ("Unable to open directory"); # loop thru array of directory while ($filename = readdir(HOMEDIR)) { #parce the . .. things from directory array and for jpgs only if($filename ne "." && $filename ne ".." && substr($filename,l +ength($filename)-4,4) eq ".jpg") { #increment index $t++; my $nfile; # create and print the jpg xml item into xml file $nfile=substr($filename,0,length($filename)-4); print FIL "<pic$t name=\"$nfile\"></pic$t>\n"; } # loop } closedir(HOMEDIR); # finish off xml file with end category and close the file print FIL "</pics>\n"; flock(FIL,8); close(FIL); # -- # By : SUP@ mtlelite@hotmail.com
please help an idiot out. in the meantime i will be reading my ass off over at learn.perl.org and trying to end my lamness.
peace!
decerebrate
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: creating an xml file from perl
by ikegami (Patriarch) on Apr 13, 2005 at 23:11 UTC | |
by decerebrate (Initiate) on Apr 13, 2005 at 23:55 UTC | |
by ikegami (Patriarch) on Apr 14, 2005 at 02:06 UTC | |
by tlm (Prior) on Apr 14, 2005 at 01:08 UTC | |
by polettix (Vicar) on Apr 14, 2005 at 14:01 UTC | |
by ikegami (Patriarch) on Apr 14, 2005 at 14:11 UTC | |
|
Re: creating an xml file from perl
by tlm (Prior) on Apr 14, 2005 at 01:04 UTC | |
by decerebrate (Initiate) on Apr 14, 2005 at 05:09 UTC | |
|
Re: creating an xml file from perl
by Cody Pendant (Prior) on Apr 13, 2005 at 23:48 UTC | |
by decerebrate (Initiate) on Apr 14, 2005 at 00:00 UTC | |
by jdporter (Paladin) on Apr 14, 2005 at 00:24 UTC | |
|
Re: creating an xml file from perl
by cbrandtbuffalo (Deacon) on Apr 14, 2005 at 00:19 UTC |