At 22:11 2002.06.06, Kipp, James wrote: >Could someone enlighten me on when it is necessary to chomp an array. It >seems when i write scripts that have a foreach or a while to iterate through >an array sometimes the chomp is necessary and sometimes it is not. > >Thanks
chomp remove line ending character if there are any at the end of a string, or at the end of all the stings in of an array. You normaly have to use is when you read lines from a file because text file always have a line ending character (except maybe for the last line). If you do not chomp these, you have a "\n" at the end and need to deal with it. One of the few cases where chomping the elements of an array would be needed would be when the array as been filled with the lines read from a text file as in: @array = <OPEN_FILE>; or @array = <>; In that case, all the elements of @array will have a "\n" at the end that probably need to be removed. On a side note, it seams that Perl 6 will include "auto-chomping" file handle which will simplify things a lot. Something to look forward to I guess :-). Best ---------------------------------------------------------- Éric Beaudoin <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]