in reply to Problem parsing and printing data from file

I haven't figured out the main problem, yet, but I'll offer some suggestions for tidying this up:
# $file = "$lsdir" . '/album' . "$album_nr" . '/album.dat'; # becomes $file = "$lsdir/album$album_nr/album.dat"; # open FILE, "$file" or # Don't quote variables unless you're constructing new strings open FILE $file or # $name = (/.*\"(.*)\"/)[0]; # no need for leading .*; better as ($name) = /"(.*)"/; # s/\n//g; # ($desc = (/.*\"(.+)\"/)[0]) || ($desc = ""); # Better as tr/\n//d; ($desc) = /"(.+)"/;
Okay, I just thought of a possibility: There is a carriage return in the $name field for that album. In that case, the data is all there, but when you print it, the carriage return is causing the data that follows it to overwrite everything before it.

The PerlMonk tr/// Advocate

Replies are listed 'Best First'.
Re: Re: Problem parsing and printing data from file
by Anonymous Monk on May 06, 2004 at 15:00 UTC
    hey, that is the solution :)

    thanks a lot..
    (and for the code style tips) :)

    i had ours of headache on this one, but to go deeper in on this problem(so i don't make this error in the future):
    what exactly is the difference between a \n and \r?
    never really understood that

    tnx
      oh.. and why is tr/\n//d better that s/\n//g ?

      :)
        Because that's what tr/// is for: replacing or removing specific characters, without concern for context. There's also a trivial amount of improved efficiency, but it's mostly about using the "right tool for the right job".

        The PerlMonk tr/// Advocate