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

  • Home
  • SEARCH
  • 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 6735607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:01:58+00:00 2026-05-26T11:01:58+00:00

I am looking to iterate through these data structures (basically a directory structure) which

  • 0

I am looking to iterate through these data structures (basically a directory structure) which I pass a given path.

The goal is to list the root/base path and then list out all the sub paths if they exist and for every sub path that exists, list the file from that sub path.

I know this probably requires looping through HoH or AoH. Can someone show me the perl techniques for doing this? Thanks.

Base level: /work/eng/feeds

 $VAR1 = {
              'recursive' => 'no',
              'version' => '0.20.202.1.1101050227',
              'time' => '2011-10-26T00:20:18+0000',
              'filter' => '.*',
              'path' => '/work/eng/feeds',
              'directory' => [
                             {
                               'owner' => 'tst_act',
                               'group' => 'eng',
                               'permission' => 'drwxrwxr-x',
                               'path' => '/work/eng/feeds',
                               'accesstime' => '1970-01-01T00:00:00+0000',
                               'modified' => '2011-08-27T03:13:53+0000'
                             },
                             {
                               'owner' => 'tst_act',
                               'group' => 'eng',
                               'permission' => 'drwxr-xr-x',
                               'path' => '/work/eng/feeds/customer_care',
                               'accesstime' => '1970-01-01T00:00:00+0000',
                               'modified' => '2011-10-25T23:54:17+0000'
                             }
                           ],
              'exclude' => ''
            };

Next level: /work/eng/feeds/customer_care

$VAR1 = {
          'recursive' => 'no',
          'version' => '0.20.202.1.1101050227',
          'time' => '2011-10-26T00:21:06+0000',
          'filter' => '.*',
          'path' => '/work/eng/feeds/customer_care',
          'directory' => [
                         {
                           'owner' => 'tst_act',
                           'group' => 'eng',
                           'permission' => 'drwxr-xr-x',
                           'path' => '/work/eng/feeds/customer_care',
                           'accesstime' => '1970-01-01T00:00:00+0000',
                           'modified' => '2011-10-25T23:54:17+0000'
                         },
                         {
                           'owner' => 'tst_act',
                           'group' => 'eng',
                           'permission' => 'drwx------',
                           'path' => '/work/eng/feeds/customer_care/abc',
                           'accesstime' => '1970-01-01T00:00:00+0000',
                           'modified' => '2011-10-25T17:12:56+0000'
                         },
                         {
                           'owner' => 'tst_act',
                           'group' => 'eng',
                           'permission' => 'drwx------',
                           'path' => '/work/eng/feeds/customer_care/def',
                           'accesstime' => '1970-01-01T00:00:00+0000',
                           'modified' => '2011-10-25T21:05:50+0000'
                         },
                         {
                           'owner' => 'tst_act',
                           'group' => 'eng',
                           'permission' => 'drwx------',
                           'path' => '/work/eng/feeds/customer_care/test',
                           'accesstime' => '1970-01-01T00:00:00+0000',
                           'modified' => '2011-10-25T21:28:14+0000'
                         }
                       ],
          'exclude' => ''
        };

One more level: /work/eng/feeds/customer_care/test (here a file exists)

$VAR1 = {
          'recursive' => 'no',
          'version' => '0.20.202.1.1101050227',
          'time' => '2011-10-26T00:30:02+0000',
          'filter' => '.*',
          'file' => {
                    'owner' => 'tst_act',
                    'replication' => '3',
                    'blocksize' => '134217728',
                    'permission' => '-rw-------',
                    'path' => '/work/eng/feeds/customer_care/test/q_data_20111023.dat',
                    'modified' => '2011-10-26T00:29:46+0000',
                    'size' => '379085',
                    'group' => 'eng',
                    'accesstime' => '2011-10-26T00:29:46+0000'
                  },
          'path' => '/work/eng/feeds/customer_care/test',
          'directory' => {
                         'owner' => 'tst_act',
                         'group' => 'eng',
                         'permission' => 'drwx------',
                         'path' => '/work/eng/feeds/customer_care/test',
                         'accesstime' => '1970-01-01T00:00:00+0000',
                         'modified' => '2011-10-26T00:29:46+0000'
                       },
          'exclude' => ''
        };
  • 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-26T11:01:58+00:00Added an answer on May 26, 2026 at 11:01 am

    Here’s a starter:

    sub list_path_files {
        my ($data) = @_;
    
        say $data->{path}; # get value from a hashref
    
        my @directories;
        # check whether it is a single value or an arrayref of values
        if (ref $data->{directory} eq 'ARRAY') {
            @directories = @{ $data->{directory} }; # dereference the arrayref to get an AoH
        } else {
            @directories = $data->{directory}; # just get the single value
        }
    
        for my $dir (@directories) {
            next if $dir->{path} eq $data->{path};
            say $dir->{path};
        }
    
        # I'll leave the rest for you to do
    }
    

    Update:

    To iterate the hashref, you first need to dereference it, then use the each, keys or values functions:

    %hash = %$VAR1; # dereference
    
    while (my ($key, $value) = each %hash) {...}
    
    for my $key (keys %$VAR1) {
        my $value = $VAR1->{$key};
    }
    
    for my $value (values %$VAR1) {...}
    

    You will also need to dereference the hash value if it is a nested structure:

    if (ref $val eq '') {
        # $val is just a scalar - don't need to deref
    }
    elsif (ref $val eq 'HASH') {
        my %hash = %$val;
    }
    elsif (ref $val eq 'ARRAY') {
        my @array = @$val;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for some code (C# or VB.NET preferred) to iterate through all folders
I am working with some US govt data which has a lengthy list of
Looking for C# class which wraps calls to do the following: read and write
I have made an each statement which iterates through each class item found. At
I'm wondering if there's an easy way to iterate through a fd_set? The reason
I've got some code that needs to scan through a hierarchical database schema, looking
I've written a census program to iterate through all the rows in a Column
I am working on an application which is used to scrape data from an
Looking for feedback on : http://code.google.com/p/google-perftools/wiki/GooglePerformanceTools
Looking for an example that: Launches an EXE Waits for the EXE to finish.

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.