Reputation: 1001
I am trying to execute the following gpg command from within Perl:
`gpg --yes -e -r [email protected] "$backupPath\\$backupname"`;
However I get the following error:
Global symbol "@mydomain" requires explicit package name (did you forget to declare "my @mydomain"?)
Obviously I need to escape the '@' symbol but don't know how. How do I execute this command in Perl?
Upvotes: 1
Views: 316
Reputation: 6798
Backticks run process in sub shell (slower, consumes more resources) and have some issues which you should investigate.
Following code demonstrates other approach which does not spawn sub shell.
use strict;
use warnings;
use feature 'say';
my $backupPath = '/some/path/dir';
my $backupname = 'backup_name';
my $command = "gpg --yes -e -r me\@mydomain.com $backupPath/$backupname";
my @to_run = split ' ', $command;
system(@to_run);
Upvotes: -1
Reputation: 1901
When you do:
`gpg --yes -e -r [email protected] "$backupPath\\$backupname"`;
perl sees the @mydomain
part and assumes you want to interpolate the @mydomain
array right into the string.
But since there was no @domain
array declared, it gives you the error.
The fix is simple: To tell perl that you want to treat @mydomain
as a string and not as an array, simply put a backslash (\
) before the @
, like this:
`gpg --yes -e -r me\@mydomain.com "$backupPath\\$backupname"`;
Upvotes: 3