Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

parse_dir doesn't seem to work

by nysus (Vicar)
on Jan 03, 2008 at 17:32 UTC ( #660259=perlquestion: print w/replies, xml ) Need Help??

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

I have a simple function to test the parse_dir function:
1 #!/usr/bin/perl 2 use File::Listing qw(parse_dir); 3 $listing = `ls -l`; 4 @directories = parse_dir($listing); 5 print @directories;
Using perl version 5.8.8. No errors, but nothing is returned even though there are definitely entries in the directory. Any ideas?

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon";
$nysus = $PM . $MCF;
Click here if you love Perl Monks

Replies are listed 'Best First'.
Re: parse_dir doesn't seem to work
by Cubes (Pilgrim) on Jan 03, 2008 at 17:38 UTC
    What's in $listing before you pass it to parse_dir?

    What's in @directories afterwards?

    (Data::Dumper may be useful here)

      using data dumper, $listing is the directory listing. dumping @directories produces nothing.

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon";
      $nysus = $PM . $MCF;
      Click here if you love Perl Monks

        I get the correct list returned (using 5.8.5) from parse_dir. Perhaps there's something it doesn't like about your brand of ls -l? Looks like there's a parameter to parse_dir to make it speak up on unparseable lines... does that help?
Re: parse_dir doesn't seem to work
by GrandFather (Saint) on Jan 03, 2008 at 17:49 UTC

    maybe there are no subdirectories to the current working directory when the script is run?


    Perl is environmentally friendly - it saves trees
      There are definitely subdirectories. When I print $listing, there is 151 directories/symlinks.

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon";
      $nysus = $PM . $MCF;
      Click here if you love Perl Monks

        It may be worth providing a small sample of the $listing contents for those of us that are *nixly challenged.


        Perl is environmentally friendly - it saves trees

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://660259]
Approved by McDarren
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2021-03-07 00:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favorite kind of desktop background is:











    Results (119 votes). Check out past polls.

    Notices?