Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

how to split the content of a directory

how to split the content of a directory

how to split the content of a directory

I'm new to perl and I have a simple question .
How do I split he content of a directory

here is the content of the directory:

mai 11 10:25 .
oct 10 1997  ..
mai 05 05:57 index
mai 11 11:36 test.pl

I want each line to be an element of an array
and after that I want to remove the first and the second element.


RE: how to split the content of a directory

Use opendir and readdir.  Here's a little snippet of code to illustrate:

opendir(MYDIR, ".");    #Open a new directory handle.

# Read each file name from the directory handle.  When
# we run out of file names, the while will fail and
# we'll move on.
while ( $Current_File = readdir(MYDIR) ) {

    # Ignore "." and ".." (Optional)
    if ( $Current_File =~ /\.¦\.\./ ) {

    Do your file processing here

Note:  I've just tapped this in from memory, and at my age that can be a bit dodgy ;^)  You might need to sort out any missing braces, or the regexp might be a little suspect.

Hope it puts you on the right track though.  Additionally, you can do a perldoc -f opendir or perldoc -f readdir to see the online docs.

Hope this helps.

RE: how to split the content of a directory


opendir DIR,".";
@filelist=grep { /^./ } readdir DIR;
closedir DIR;

then @filelist contains every element in the dir that DOESN'T start with "." (assuming that's what you want to get rid of)

RE: how to split the content of a directory


@files = glob( "*" );

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close