Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A better way? Remove empty slices from array. 1

Status
Not open for further replies.

travs69

MIS
Joined
Dec 21, 2006
Messages
1,431
Location
US
working code
Code:
for $line (@data) {
 if ($line ne "") {
  push @data2, $line;
 }
}

Is there a better (more effecient) way?

Thanks :)


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those Who Say It Cannot Be Done Are Usually Interrupted by Someone Else Doing It; Give the wrong symptoms, get the wrong solutions;
 
this might be a little more efficient:

Code:
@data2 = grep {$_ ne ""} @data;

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Thanks Kevin..

If you guys haven't noticed I'm on a bit of learning kick. Trying to figure out different and better ways to do the same old things.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those Who Say It Cannot Be Done Are Usually Interrupted by Someone Else Doing It; Give the wrong symptoms, get the wrong solutions;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top