I have the following Perl. It attempts to detect a Git Clone (as opposed to an offline zip) and print the repo information. The idea is, if git rev-parse
fails, then its probably not a Git repo.
if (system "git rev-parse HEAD") { # Line 234
my $revision = `git rev-parse HEAD | cut 1-16`; # Line 235
my $branch = `git rev-parse --abbrev-ref HEAD`; # Line 236
print "Git repo: $branch ($revision)\n"; # Line 237
} # Line 238
It results in the errors below. If I am parsing What's the differences between system and backticks and pipes in Perl and How can I store the result of a system command in a Perl variable correctly, it should work.
According to How to print variables in Perl, print "Git repo: $branch ($revision)\n"
should work. Based on Global symbol requires explicit package, the Q&A says to use @
instead of $
. I tried to print "Git repo: @branch (@revision)\n"
, but it resulted in the same errors (with a different symbol).
I have two questions:
Why does Perl think the variable is a package?
What is wrong with the Perl, and how do I fix it?
Global symbol "@branch" requires explicit package name at ./Configure line 237.
Global symbol "@revision" requires explicit package name at ./Configure line 237.