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:
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.: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";
(this is, of course, just how the unix "ln" command works)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 ... }
In reply to Re: brain re-engaging perl mode
by graff
in thread brain re-engaging perl mode
by bluethundr
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |