in reply to Removing Newline Characters from File Data (chomp not working)

I need to be corrected if wrong but I see that you are reading the entire file into a string and not reading one line at a time, hence chomp would result in only chomping at the end of the file and not every line end as you intend to...I haven't tested it anyways. This an initial look at it.

(Update): After ack clarification, and I always have been having a trouble with scalar and list contexts, I would say I retract my observation since I thought the $firstline is the same as the @firstline, thanks ack and excuse my ignorance for I am still learning too.


Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.
  • Comment on Re: Removing Newline Characters from File Data (chomp not working)
  • Download Code

Replies are listed 'Best First'.
Re^2: Removing Newline Characters from File Data (chomp not working)
by ack (Deacon) on Aug 27, 2009 at 15:59 UTC

    From the op's code, $firstline appears to be scalar context, not list context (which would use the sigil '@' rather than the op's sigil '$'). In scalar context, the input operator '< >' only returns the next line; in list context (e.g., @firstline), the input operator '< >' will read all the lines in the file...one line per list element in @firstline). Hence, that part of the op's code looks to me to be OK.

    I believe that the other responders' notations and observations (i.e., that the op has failed to account for the what is actually at the end of each input line in terms of the line separators) are the likely source of the op's difficulties.

    ack Albuquerque, NM