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 9049887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T12:31:03+00:00 2026-06-16T12:31:03+00:00

Quick note: I’ve been stuck with this problem for quite a few days and

  • 0

Quick note: I’ve been stuck with this problem for quite a few days and I’m not necessarily hoping to find an answer, but any kind of help that might “enlighten” me. I would also like to mention that I am a beginner in Perl, so my knowledge is not very vast and in this case recursivity is not my forte. here goes:

What I would like my Perl script to do is the following:

  • take a directory as an argument
  • go into the directory that was passed and its subdirectories to find an *.xml file
  • store the full path of the found *.xml file into an array.

Below is the code that i have so far, but i haven’t managed to make it work:

#! /usr/bin/perl -W

my $path;
process_files ($path);

sub process_files
{
    opendir (DIR, $path) or die "Unable to open $path: $!";

    my @files =
        # Third: Prepend the full path
        map { $path . '/' . $_ }
        # Second: take out '.' and '..'
        grep { !/^\.{1,2}$/ }
        # First: get all files
        readdir (DIR);

    closedir (DIR);

    for (@files)
    {
          if (-d $_)
          {            
            push @files, process_files ($_);
          }
          else
          {
             #analyse document
          }
    }
    return @files;
}

Anybody have any clues to point me in the right direction? Or an easier way to do it?

Thank you,
sSmacKk 😀

  • 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-06-16T12:31:04+00:00Added an answer on June 16, 2026 at 12:31 pm

    Sounds like you should be using File::Find. Its find subroutine will traverse a directory recursively.

    use strict;
    use warnings;
    use File::Find;
    
    my @files;
    my $path = shift;
    find(
        sub { (-f && /\.xml$/i) or return; 
               push @files, $File::Find::name; 
        }, $path);
    

    The subroutine will perform whatever code it contains on the files it finds. This one simply pushes the XML file names (with full path) onto the @files array. Read more in the documentation for the File::Find module, which is a core module in perl 5.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

just a quick note, this is not homework. I'm just trying to brush up
Note - I will really appreciate a quick and complete answer to this question.
Quick text-processing question. It's not necessarily related to programming, but this is the best
After doing a quick search I can't find the answer to this seemingly simple
Note: I've read this and its not quite what I'm looking for: I have
Quick note So, as I was writing the problem below I found a way
Note: This is not a question whether I should use list or deque. It's
Note: I'm only posting this question so that others may find it if they
Quick note on the accepted answer : I disagree with a small part of
I will post my code below as a quick note I define both of

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.