Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Unable to remove items from an array that are empty ' '

by choroba (Cardinal)
on Apr 25, 2015 at 21:14 UTC ( [id://1124708]=note: print w/replies, xml ) Need Help??


in reply to Unable to remove items from an array that are empty ' '

Where do you increment $a_counter?

This is how you can fix it:

#!/usr/bin/perl use warnings; use strict; use Data::Dumper; my @left_split = ('stuff', '', 'stuff', '', '10', '', '-', ''); my $index = 0; while ($index <= $#left_split) { if ('' eq $left_split[$index]) { splice @left_split, $index, 1; } else { ++$index; } } print Dumper \@left_split;

But I would simply use grep:

@left_split = grep '' ne $_, @left_split;
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-19 22:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found