Gordon
Gordon

Reputation: 1651

perl, saving the command line option

I have this perl script and it takes in arguments using the getoption package.

Is there an easy way to document what was the exact command the user used to execute?

I would like to document into a log file.

Gordon

Upvotes: 1

Views: 393

Answers (2)

clt60
clt60

Reputation: 63902

or you can simply

my $full;
BEGIN { $full = "$0 @ARGV" }
#
print "log: $full\n";

form the perlvar

$LIST_SEPARATOR
$"

When an array or an array slice is interpolated into a double-quoted string or a similar context such as /.../ , its elements are separated by this value. Default is a space. For example, this:

print "The array is: @array\n";

is equivalent to this:

print "The array is: " . join($", @array) . "\n";

Upvotes: 5

Platinum Azure
Platinum Azure

Reputation: 46183

Use $0 and @ARGV together:

my $full_command = join(' ', $0, @ARGV);

Upvotes: 7

Related Questions