Home / Alt manpages / perl5.38-x86_64-linux-gnu(1)

  • perl5.38-x86_64-linux-gnu(1)
  • User command
  • linux

Run and Check Perl 5.38 Scripts Safely from the Shell

A Perl script that behaves on your laptop can misbehave in production because it quietly ran under a different perl. This walkthrough gets you checking the interpreter, testing a one-liner, and compiling a script before you ever run it for real. Allow about 15 minutes. Everything happens in a disposable working directory, and none of it needs sudo.

1. Confirm the interpreter and version

Check which executable your shell will actually run before you debug anything else. Otherwise you can spend an hour chasing a bug that only exists because you tested against the wrong Perl.

$ command -v perl
/usr/bin/perl
$ perl -V:version
version='5.38.2';
  • Package. On this Ubuntu installation the executable comes from libperl5.38t64:amd64, version 5.38.2-3.2ubuntu0.6.
  • Identity. The interpreter reports itself as Perl 5.38.2, built for x86_64-linux-gnu-thread-multi.
  • Why it matters. Package revisions and build details vary between machines, so record this check whenever a script depends on a particular environment.

2. Try a one-liner without creating a file

The -e option supplies program text on the command line. Wrap it in single quotes so the shell leaves your Perl variables and punctuation alone.

$ perl -e 'print "hello from Perl\n"'
hello from Perl

That is a fine smoke test: it reads no input and leaves nothing behind. Once an experiment grows past a line or two, move to a script file instead; shell quoting turns into a distraction and mistakes get harder to spot.

3. Create a small script with warnings and strict checks

Work in a disposable directory. use strict catches accidental variable misuse and other legacy habits.

$ mkdir -p ~/perl-check
$ cd ~/perl-check
$ cat > greet.pl <<'PERL'
use strict;
use warnings;

my $name = shift // 'world';
print "Hello, $name\n";
PERL

Tip

From use v5.35 upward, Perl 5.38 turns on use warnings for you automatically, but writing it out anyway makes the script's intent obvious and keeps the habit portable to older interpreters. The quoted here-document marker also matters: it stops the shell expanding $name while the file is written. If you use a different directory, substitute the path consistently, and never paste an untrusted value into shell syntax.

4. Check syntax before running the script

Use -c for a compile-only pass. Perl parses the file and tells you whether the syntax is valid, without performing a normal run.

$ perl -c greet.pl
greet.pl syntax OK

A syntax error comes with a line number and a nearby token: fix that line and repeat the exact check. A clean compile is not proof the output or file handling is correct; it only rules out one class of mistake.

5. Run the script and pass an argument

The script name goes after Perl's own options. Anything after that lands in @ARGV; this example uses shift to grab the first value.

$ perl greet.pl 'Ada'
Hello, Ada
$ perl greet.pl
Hello, world
  • Quote arguments that contain spaces or shell punctuation.
  • Use -- before a script or argument that begins with a hyphen, so it is not mistaken for another Perl option.
  • Never build a command by concatenating untrusted input into Perl's option area.

6. Understand warnings and the tempting -w shortcut

The manual documents -w but recommends the use warnings pragma instead. The command-line flag switches on warnings for every bit of Perl that runs in that process, including code you do not control, which can make a dependency noisy or surface warnings you have no way to fix.

$ perl -we 'my $x = 2 + 3; print "sum=$x\n"'
sum=5

That command only demonstrates the flag; it is not a project setup to copy. Keep use warnings in code you own, where its scope stays visible. If output suddenly grows warnings, rerun the command without suppressing them and read the line the diagnostic names.

7. Inspect the library search path when a module is missing

Perl searches the directories in its built-in @INC list for libraries and modules. A "module not found" error can mean the module really is absent, or that the command is quietly using a different interpreter or environment than you expect.

$ perl -e 'print join("\n", @INC), "\n"'
/etc/perl
/usr/local/lib/x86_64-linux-gnu/perl/5.38.2
/usr/local/share/perl/5.38.2
/usr/lib/x86_64-linux-gnu/perl5/5.38
/usr/share/perl5
/usr/lib/x86_64-linux-gnu/perl-base
/usr/lib/x86_64-linux-gnu/perl/5.38
/usr/share/perl/5.38

The exact list depends on the host. For a one-off private library the interpreter also accepts -I<dir>, but prefer a clearly managed environment over silently rerouting search paths in a production command. Run perl -V when you need the full configuration rather than just the version.

8. Recover from a failed check without losing the original

Syntax checking changes nothing on disk, but running a script can touch files, call services or process input, depending on what the code does. Before running anything unfamiliar, read it, work on a copy of important input, confirm its output paths, and never run unknown Perl code as root.

Keep the original until a replacement passes its own check:

$ cp --preserve=all greet.pl greet.pl.bak
$ editor greet.pl
$ perl -c greet.pl
$ perl greet.pl 'Ada'
Hello, Ada

Recovery

If the edited version is wrong, restore the known-good copy with cp --preserve=all greet.pl.bak greet.pl, then run the compile check again. Remove the backup only once the replacement is verified and you no longer need to fall back.

Done means

  • Interpreter confirmed. command -v perl and perl -V:version identify the copy you intended to use.
  • One-liner tested. A short -e command runs with predictable shell quoting.
  • Safety pragmas in place. Your script has explicit use strict and use warnings where they belong.
  • Syntax checked first. perl -c reports syntax OK before the script ever runs.
  • Paths understood. You know where arguments and module search paths come from.
  • Recovery ready. Important inputs and scripts can be restored from a backup, and none of this needed elevated privileges.