2 hopefully useful snippets regarding __subject__

Update: as [id://wog] spotted, my original post was absolutely dumb, with myself reinventing the wheel, this being abs2rel routine from File::Spec module.

symlink converter: transforms absolute symlinks from a directory tree into relative ones. mainly useful for normalizing symlinks in a chrooted environment
usage: $0 <base_directory>

#!/usr/bin/perl -w use strict; use File::Spec (); use File::Find (); my $d = shift || '.'; File::Find::finddepth({wanted => sub { return unless -l; my $rl = readlink $_; print $_,'... '; unlink $_ or print 'error: unlink // ',$!,$/, return; symlink File::Spec->abs2rel($rl,$d), $_ or print 'error: symlink // ',$!,$/, return; print 'OK',$/; }, no_chdir => 1}, $d);

simple relative symlink maker: given a source path and a destination directory, it will create a symlink to the source path in the destination directory with the same basename of the source.
usage: $0 src_path <dest_dir>

#!/usr/bin/perl -w use strict; use File::Spec; my $src = shift or die 'ERROR: source not specified!', $/; my $dest = shift || '.'; chdir $dest or die qq{ouch, cannot chdir to '$dest': $!$/}; $src = File::Spec->abs2rel( $src, $dest ) ; $src =~ m|/([^/]+)$|; symlink $src, $1 or die qq{cannot create symlink: $!$/};


In reply to relative symbolic links helpers by AltBlue

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.