in reply to Directory Listing to an Array

I'd scope the variables and what-not; also, you're doing far more work than necessary.
sub ls { my $path = @_ ? shift : "."; local *DIR; opendir DIR, $path or die "can't ls $path: $!"; return grep { $_ ne "." and $_ ne ".." } readdir DIR; }

_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a (from-home) job
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Replies are listed 'Best First'.
Re: Re: Directory Listing to an Array
by cybear (Monk) on Apr 17, 2002 at 14:56 UTC
    what does the shift : "." do?
      The ?: operator is like a condensed if/else block.
      my $path; # if an argument was passed, use it if (@_) { $path = shift } # otherwise, use "." else { $path = "." }
      That can be written as my $path = @_ ? shift : "."; -- and if I wanted to be even shiftier (pun intended), I could do my ($path) = (@_, "."); but that's probably rude.

      _____________________________________________________
      Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a (from-home) job
      s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;