Thread chomp nicht nur für ein \n sondern unendlich viele (29 answers)
Opened by gregor at 2006-03-23 11:52

pq
 2006-04-03 13:04
#64005 #64005
User since
2003-08-04
12209 Artikel
Admin1
[Homepage]
user image
[quote=esskar,31.03.2006, 14:31]hmm

Code: (dl )
1
2
3
4
5
6
7
8
sub chomp_all {
  my $retval = 0;
  foreach (@_) {
     my $count;
     1 while chomp($_) && $retval += $count;
  }
  return $retval;
}
[/quote]
das klappt nicht. du setzt $count nicht und $retval += $count
liefert außerdem immer true, sobald $retval > 0 ist.
Code: (dl )
1
2
3
4
5
6
7
8
sub chomp_all {
  my $sum = 0;
  foreach (@_) {
     my $c;
     $sum+= $c while $c = chomp;
  }
  return $sum;
}
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. -- Damian Conway in "Perl Best Practices"
lesen: Wiki:Wie frage ich & perlintro Wiki:brian's Leitfaden für jedes Perl-Problem

View full thread chomp nicht nur für ein \n sondern unendlich viele