Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Removing empty string elements from an Array

by Masem (Monsignor)
on Nov 13, 2001 at 06:01 UTC ( [id://124975]=note: print w/replies, xml ) Need Help??


in reply to Removing empty string elements from an Array

@array = grep { $_ ne '' } @array;

-----------------------------------------------------
Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
"I can see my house from here!"
It's not what you know, but knowing how to find it if you don't know that's important

Replies are listed 'Best First'.
(ar0n) Re (2): Removing empty string elements from an Array
by ar0n (Priest) on Nov 13, 2001 at 07:44 UTC
    Taking that one step further, if by "empty" you also mean lines that consist solely of whitespace:
    @array = grep /\S/, @array;

    [ ar0n ]

Re^2: Removing empty string elements from an Array
by Abbot Michael (Initiate) on Mar 08, 2019 at 15:35 UTC

    Masem wrote:

     @array = grep { $_ ne '' } @array;

    Wow, you can't improve on perfection, very cute. Long-handed its an easy problem, but clumsy because this is succinct and cute...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://124975]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-04-23 16:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found