hi ive wrote a script then looks in directories, reads a file in each directory, and grabs some values in the file. This seems to work. But when i print the output, i get weird results.
#!/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
------------end of program
ok, now the real problem: when i run it in bash i get this output:
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
the first two sentences are ok.. but after that comes this:
:by SuuZ, Oxi, Vaisha, SPoT_D, SCVNGR, Groenshirt & TeKnoID
and that should've been:
75:04-04-29 Teknival Noord-Frankrijk:by SuuZ, Oxi, Vaisha, SPoT_D, SCV +NGR, Groenshirt & TeKnoID
as you can see, this really sucks. one variable seems to replace another in (only) the first value of the array @names.
i have completely no idea why this happens, so i thought mayb you would :)

if you could help me with this, thanxs a lot

In reply to Problem parsing and printing data from file by Anonymous Monk

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.