Deleting an element from an array in perl

Posted by Flamewires on Stack Overflow See other posts from Stack Overflow or by Flamewires
Published on 2010-05-19T19:31:25Z Indexed on 2010/05/19 20:10 UTC
Read the original article Hit count: 239

Filed under:
|
|
|
|

Hey I'm wondering how i can get this code to work, basically i want to keep the lines of $filename as long as they contain the $user in the path. Sry, perl noob.

        open STDERR, ">/dev/null";
        $filename=`find -H /home | grep $file`;
        @filenames = split(/\n/, $filename);
        for $i (@filenames) {
            if ($i =~ m/$user/) {
                #keep results
            } else {
                delete  $i; # does not work.    
            }
        }
        $filename = join ("\n", @filenames);
        close STDERR;

I know you can delete like delete $array[index] but I don't have an index with this kind of loop that I know of.

© Stack Overflow or respective owner

Related posts about perl

Related posts about freebsd