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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:29:36+00:00 2026-05-13T19:29:36+00:00

On Server Fault, How to list symbolic link chains? (not my question) talks about

  • 0

On Server Fault, How to list symbolic link chains? (not my question) talks about listing all the symbolic links and following them. To make this doable, let’s consider a single directory at first.

I want to write a short utility that does this. It looks easy to put pairs from symbolic links into a hash and then process the hash.

But then I might have something like:

ls -l
total 0
lrwxrwxrwx 1 pjb pjb 1 2010-02-23 08:48 a -> b
lrwxrwxrwx 1 pjb pjb 1 2010-02-23 08:48 b -> c
lrwxrwxrwx 1 pjb pjb 1 2010-02-23 09:03 c -> a
lrwxrwxrwx 1 pjb pjb 1 2010-02-23 09:17 trap -> b
lrwxrwxrwx 1 pjb pjb 1 2010-02-23 09:17 x -> y
lrwxrwxrwx 1 pjb pjb 1 2010-02-23 09:17 y -> b

where it is obvious that a->b->c is a loop, and that trap points into a loop, but to know x points into a loop I need to follow a bit.

One hash representation is:

a => b
b => c
c => a
trap => b
x => y
y => b

But the reverse representation is better for marking loops to bad starting points, once I know what the loops are.

So here’s some questions:

  • Is a hash the best structure to represent symbolic links?
  • what’s the best way to separate the graph of the file system to tell the loopy components from the tree components to the twig with a loop type pieces?
  • Is there a better algorithm than manually searching for all the loops from all the starting points?
  • From a graph-theory perspective — is this sort of thing in the CPAN already? If not, what are some good helper modules?
  • 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-13T19:29:37+00:00Added an answer on May 13, 2026 at 7:29 pm

    There’s a Graph module on CPAN that you might use as in the following:

    #! /usr/bin/perl
    
    use warnings;
    use strict;
    
    use Graph;
    
    my $g = Graph->new;
    my $dir = @ARGV ? shift : ".";
    
    opendir my $dh, $dir or die "$0: opendir $dir: $!";
    while (defined(my $name = readdir $dh)) {
      my $path = $dir . "/" . $name;
    
      if (-l $path) {
        my $dest = readlink $path;
        die "$0: readlink $path: $!" unless defined $dest;
    
        $g->add_edge($name => $dest);
      }
      else {
        $g->add_vertex($name);
      }
    }
    
    my @cycle = $g->find_a_cycle;
    if (@cycle) {
      $" = ' -> '; #" # highlighting error
      print "$0: $dir: at least one cycle: @cycle\n";
    }
    else {
      print "$0: $dir: no cycles\n";
    }
    

    For example, in a directory similar in structure to the one in your question, the output is

    $ ../has-cycle 
    ../has-cycle: .: at least one cycle: c -> a -> b
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Originally posted on Server Fault , where it was suggested this question might better
This isn't the best programming question but lets face it, the server fault guys
I currently have the following html which does not show the ordered list properly
This might be a borderline Server Fault-question, but here goes. I have a IIS
Not sure if this is best suited to Programmers, Server Fault or Stack Overflow.
Is there a list of COM error codes somewhere? Related: HRESULT: 0x80010105 (RPC_E_SERVERFAULT) question
This is really more of a serverfault/IT question, but I am not part of
Is there a list of possible faultCode values for Flex's Fault object (mx.rpc.Fault; Flex
I've asked this on server fault already but to no avail. So I'm hoping
My service sometimes fails. It's not bad, and on windows 7 and windows server

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.