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


In reply to creating an xml file from perl by decerebrate

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.