[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Problem - rewrite and simplify




VLB wrote:
> 
> # Original code:
> 
> 	    until (index($line, ', ',0)< 0) {
> 	         $ids[$count++] = substr($line,0,index($line,', ',0));
> 	         $line = substr($line, index($line, ', ',0) + 2);
> 	    }
> 	    $ids[$count] = substr($line,0);

Ugh! C programmer.


> 	  while ($line = <CLONEIDSLIST>) {
> 	     chop($line);
> 	     push(@ids, split(/, /, $line));
> 	  }
> 
> # Better ideas??

First, your code would be improved by:
  a) using chomp() instead of chop();
  b) used defined() in the while test.

And personally I would opt for terseness:

	while (<CLONEIDSLIST>) {
	   chomp;
	   push @ids, split /, /;
	}

Which of course leads to:

  @ids = map { chomp; split /, / } <CLONEIDSLIST>;

John Porter


==== Want to unsubscribe from Fun With Perl?
==== Well, if you insist... Send mail with body "unsubscribe" to
==== fwp-request@technofile.org