Save yourself a lot of typing and frustration: start using ARGV instead of prompting the user and fetching values for variables via responses from STDIN.

I don't get why you're using glob here... Could you explain what  @list = glob "$name, $final"; is supposed to do?

Also, the basis for your decision between symlink and hard link seems cryptic, and possibly at odds with your probable intention. (But even given your reply to tilly, it's not clear what your intention is, or what might still be going wrong with the symlink part.)

Based on the regex in your "if" statement, any of the following values for $final would trigger creation of a symlink having this value as its name: "-", "foo-", "-s", "foo-s", "-ss", "foo-ss", "foo-bar", "pre-sorted", and many more. Basically, any value that contains a hyphen, whether or not the hyphen is followed by any number of s's.

Just guessing now... Do you want all the symlinks you create to have "-s" at the end of their names? Then:

use strict; my $Usage = <<ENDUSE; Usage: $0 file_name link_name if link_name ends with "-s", it will be a symbolic link. otherwise, it will be created as a hard link. ENDUSE die $Usage unless ( @ARGV == 2 and -e $ARGV[0] ); if ( $ARGV[1] =~ /-s$/ ) { symlink $ARGV[0], $ARGV[1] or die "symlink failed: $!\n"; } else { link $ARGV[0], $ARGV[1] or die "link failed: $!\n"; } print "$ARGV[1] is now installed as a link to $ARGV[0]\n";
Now, if your intention is to allow any string as a symlink name (including any that does not end with "-s"), you could accept an optional third argument in the command line usage -- something like "-s file_name link_name" -- i.e.:
my $Usage = <<ENDUSE; Usage: $0 [-s] file_name link_name blah blah... ENDUSE my $ltype = ( @ARGV and $ARGV[0] eq '-s' ) ? shift : ''; die $Usage unless ( @ARGV == 2 and -e $ARGV[0] ); if ( $ltype eq '-s' ) { symlink ... } else { link ... }
(this is, of course, just how the unix "ln" command works)

In reply to Re: brain re-engaging perl mode by graff
in thread brain re-engaging perl mode by bluethundr

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.