Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6813807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:36:47+00:00 2026-05-26T20:36:47+00:00

I am very new to Perl (scripting languages in general) and I was wondering

  • 0

I am very new to Perl (scripting languages in general) and I was wondering how to use Perl to get a lisitng of all the leaf directories in Perl. For example, lets say my root directory is C:

C: -> I have folder "A" and "B" and files a.txt and b.txt

Folder "A" -> I have folder "D" and file c.html
Folder "B" -> I have folder "E" and "F" and file d.html 
Folder "D", "E" and "F" -> bunch of text files

How do I get a bunch of directory paths as output for this scenario of:

C:\A\D\
C:\B\E\
C:\B\F\

As you can see, I just want a list of all the leaf directories possible. I dont want C:\A\ and C:\B\ to show up. After doign some reserarch myself, I have noticed that I may somehow be able to use the File::Find module in Perl, but that also I am not 100% sure about how to go ahead with.

Thanks for any help you may be able to provide 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:36:48+00:00Added an answer on May 26, 2026 at 8:36 pm

    From an answer to the question How to Get the Last Subdirectories by liverpole on Perlmonks:

    prints all leaf directories under the current directory (see "./"):

    use strict;
    use warnings;
    
    my $h_dirs = terminal_subdirs("./");
    my @dirs   = sort keys %$h_dirs;
    print "Terminal Directories:\n", join("\n", @dirs);
    
    sub terminal_subdirs {
        my ($top, $h_results) = @_;
        $h_results ||= { };
        opendir(my $dh, $top) or die "Arrggghhhh -- can't open '$top' ($!)\n";
        my @files = readdir($dh);
        closedir $dh;
        my $nsubdirs = 0;
        foreach my $fn (@files) {
            next if ($fn eq '.' or $fn eq '..');
            my $full = "$top/$fn";
            if (!-l $full and -d $full) {
                ++$nsubdirs;
                terminal_subdirs($full, $h_results);
            }
        }
    
        $nsubdirs or $h_results->{$top} = 1;
        return $h_results;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am very new to linux and perl and I am trying to use
I'm very new to perl so I searched for some time but still get
I am very new to Perl, so please bear with my simple question: Here
I very new to Python, and fairly new to regex. (I have no Perl
Pretty new to Perl so there may be a very obvious solution here. I'm
Very new to JQuery and MVC and webdevelopment over all. I'm now trying to
I'm very new to Perl programming. I've just finished reading the Llama book. Up
I am very new to perl so please help me out in following I
I am new to Perl and I have a problem that's very simple but
first of all, I have to admit that I am new to Perl, so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.