Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

i am having a script in which i read a file and store its content in a array.Like
@testListArray=<TEST_LIST>;where TEST_LIST is a handle.
if file is
test1
test2
array will have test1 test2. i change to these directories one by one. this is expected behaviour
but if file is
test1
test2

here there is empty string after test2. array will have test1 test2 and empty string.now when i try to do change directory for each folder it works fine with both test folders but when it sees empty string it changes directory to home directory in linux, solaris. is there any way i remove this empty string from array so it has only test folder names. i tried with chop(arrayname) but does not seems to work.

Replies are listed 'Best First'.
Re: manipulating arrays
by GrandFather (Saint) on Mar 20, 2006 at 11:10 UTC
    @testListArray = grep {length} @testListArray;

    will run through the array and generate a new copy of the array omitting empty elements.


    DWIM is Perl's answer to Gödel
Re: manipulating arrays
by matze (Friar) on Mar 20, 2006 at 11:15 UTC
    Try grep:
    @dirs = grep !/^$/, @testListArray;
    gives you an array without empty strings.