TL;DR - always quote things.
Always use use strict
in Perl code, which here will cause a failure for the bareword orig_file1
(or barewords orig_file1
and gz
which is two potential subroutines whose output should be joined with the .
catenation operator).
% perl -Mstrict -e 'symlink "x", asdf'
Bareword "asdf" not allowed while "strict subs" in use at -e line 1.
Execution of -e aborted due to compilation errors.
% perl -Mstrict -e 'symlink "x", asdf.gz'
Bareword "asdf" not allowed while "strict subs" in use at -e line 1.
Bareword "gz" not allowed while "strict subs" in use at -e line 1.
Execution of -e aborted due to compilation errors.
%
The fix is to properly quote all the terms, not just the first one:
#!/usr/bin/env perl
use strict;
use warnings;
symlink "file1.txt.gz", "orig_file1";
This behavior may be contrasted with the shell (which Perl is somewhat related to), which lets you (sometimes) get away with not quoting things:
#!/bin/sh
ln -s -- file1.txt.gz orig_file1
though these especially if they are variables should be quoted in the shell (this is a usage suggestion, not a hard requirement) as the shell may do unexpected things with various special characters that vary from shell to shell.
The somewhat related language TCL lets you get away with not quoting things as it has a very simple syntax:
file link orig_file1 file1.txt.gz
however one probably should quote things especially if people unfamiliar with TCL are reviewing the code:
file link "orig_file1" "file1.txt.gz"
orig_file1
a Perl scalar that you have forgotten the$
on? – Kusalananda Sep 01 '18 at 19:53