Thanks. I was asking because i was wondering where the new lines in my case
were coming from. 
--
my @dirs = `du -sk $path/*`;
...
foreach (@dirs) {
        ..... #this is where i had to chomp 
----
the shell command added new lines after each entry, that is what i had to
chomp. wierd though because i did a similar command in another script which
did not need chomping. i gues when in doubt, chomp !


-----Original Message-----
From: Jonathan E. Paton [mailto:[EMAIL PROTECTED]]
Sent: Friday, June 07, 2002 1:42 AM
To: [EMAIL PROTECTED]
Subject: Re: When to chomp


 --- "Kipp, James" <[EMAIL PROTECTED]> 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. 

chomp(@array); # What are you iterating for?  :)
chomp(@array = <STDIN>);

In short, chomp when you need to get rid of newlines
at the end of strings.  There is no harm doing it
multiple times (just wasteful), and sometimes it is
just the last array element that needs chomped.
Easily fixed with:

chomp($array[-1]);

But usually I chomp on the loop, like most people:

while (<>) {
    chomp;

    ...
}

If your algorithm doesn't care about the newline, and
you are outputing it again then leaving the newline
in isn't much of a problem (until you get to the last
line - which may/may not have a final newline).

Jonathan Paton

=====
s''-//--/\\///|-\/\|--\--/-\-/\-//\-|/\\\|/\///|-\--\\\\',
s''/-\\\/|///|-|/|/--\--/--//\|\/\||/|/-/\\\-/\///|-\-\-',
y'|\/-'3210',$_=join qq\\,map{s|2|10|||s|3|11|||s|^|0|;$_}
m|.|g;map{print chr unpack'N',pack'B32','0'x24 .$_}/.{8}/g

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to