------------end of program#!/usr/bin/perl #configuration thingies $lsdir = '/var/www/foto'; #this is the dir to look in $dir = '2004'; #hard to explain this one, but it doesnt mat +ter much $year = '04'; #what is the value of yy in yy-mm-dd in on o +f the values grabbed ############################################## foreach (`ls $lsdir`) { #do a ls if (/album(\d{2,})/) { $album_nr = $1; $file = "$lsdir" . '/album' . "$album_nr" . '/album.da +t'; open FILE, "$file" or warn "coud not open $file: $! \n" and next; #s +o this looks in each /var/www/foto/album{2,}/album.dat $/ = ';'; #each string in album.dat is seperated by a +; <FILE>;<FILE>; $_ = <FILE>; s/\n//g; $name = (/.*\"(.*)\"/)[0]; #get the name from album.da +t <FILE>; $_ = <FILE>; s/\n//g; ($desc = (/.*\"(.+)\"/)[0]) || ($desc = "");# get the +description from album.dat while (<FILE>) { if (/parentAlbumName/) { $_ = <FILE>; $file_dir = (/.*\"(.+)\"/)[0]; last; } } #get the virtual directory from album.dat #all the values needed are stored. now some conditions the values shou +ld meet, or else get lost. if ($file_dir eq $dir) { if ($name =~ /\d\d\-\d\d\-\d\d/) { $date = "$&"; $date =~ s/\-//g; unless ($date =~ /^$year/) { warn "the date of album $album +_nr ($name) doesn't seem to be in yy-mm-dd format. skipping..\n"; next; } } else { warn "the title of album $album_nr ($n +ame) doesn't seem to contain a date, or a date in yy-mm-dd format. sk +ipping..\n"; next; } #so if the values met those conditions, store them in @names. unshift @names, "$album_nr:$name:$desc\n"; } } } print "@names"; #print
the first two sentences are ok.. but after that comes this:the title of album 107 (Eerste kwartaal van 2004) doesn't seem to cont +ain a date, or a date in yy-mm-dd format. skipping.. the title of album 131 (Untitled) doesn't seem to contain a date, or a + date in yy-mm-dd format. skipping.. :by SuuZ, Oxi, Vaisha, SPoT_D, SCVNGR, Groenshirt & TeKnoID 130:04-05-05 Zwolle:by Oxi & SPoT_D 124:04-04-28 Amsterdam:by Oxi 118:04-04-17 Hilversum:by Apraxia 117:04-04-17 Zeist:by SuuZ 116:04-04-17 Rotterdam:by SuuZ 113:04-04-17 Hilversum:by Oxi 112:04-04-17 Zeist:by Vaisha & Oxi 111:04-04-17 Bazart Anti Lounge:by Vaisha 110:04-04-10 Maarssen:by SPoT_D & Oxi 106:04-04-03 Tilburg:>Groene Shirt</a> 105:04-04-02 Hypnoskull Nighttown:by Apraxia 104:04-04-03 Tilburg:by Vaisha 103:04-04-17 Bazart Anti-Lounge:by Apraxia
and that should've been::by SuuZ, Oxi, Vaisha, SPoT_D, SCVNGR, Groenshirt & TeKnoID
as you can see, this really sucks. one variable seems to replace another in (only) the first value of the array @names.75:04-04-29 Teknival Noord-Frankrijk:by SuuZ, Oxi, Vaisha, SPoT_D, SCV +NGR, Groenshirt & TeKnoID
In reply to Problem parsing and printing data from file by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |