Perl syntax error, but I can't find it for the life of me - perl

This error is angering me. I can't see anything near those lines with a parenthesis error or missing brackets. Someone give me a hand? This is my first post, forgive me if the formatting is off; I think I got it right.
EDIT: line 87, the ');' error, is this line: select(SEXTANT_DAEMON_LOG);
syntax error at -edited- line 87, near ");"
syntax error at -edited- line 92, near "if"
syntax error at -edited- line 99, near "if"
Unmatched right curly bracket at -edited- line 102, at end of line
syntax error at -edited- line 102, near "}"
syntax error at -edited- line 109, near "}"
syntax error at -edited- line 120, near ");"
BEGIN not safe after errors--compilation aborted at -edited- line 122.
This is the code near the error (full code here):
$MAIN_DBH = getConnection('Main');
$fs_logfile = getCSConfigValue($MAIN_DBH, 'Log', 'Sextant Update Daemon') or die "pid$$[" . localtime(time()) . "] Main dbh error: " . DBI::errstr;
open(SEXTANT_DAEMON_LOG, '>>', $fs_logfile) or die "pid$$[" . localtime(time()) . "] unable to open log file '$fs_logfile'\n";
$tmp = select(SEXTANT_DAEMON_LOG);
$| = 1;
select(SEXTANT_DAEMON_LOG);

Perl isn't giving a very good error message, but what it's actually complaining about is that "pid$$[" looks like an invalid attempt to access the array #$. Try replacing it with "pid$$\[".
The way I found that was by inserting __END__ near the reported location of the first error. I moved it up and down until I found the first line that caused an error, which was
$fs_logfile = getCSConfigValue($MAIN_DBH, 'Log', 'Sextant Update Daemon') or die "pid$$[" . localtime(time()) . "] Main dbh error: " . DBI::errstr;
Then I tried adding the backslash, and it fixed the error.
Note: perl -c is very useful in situations like this.

Related

PERL syntax error near "= ) "

I have found this example but I get this error:
syntax error at ./test.pl line 11, near "= ) " Execution of ./test.pl
aborted due to compilation errors.
Line 11: while($line = ) {
The author of the script didn't prepare the script to be included in an HTML. The actual code was
while ($line = <INFILE>) {
See readline for details.

Deciphering this syntax error

I cant seem to understand the reason for these syntax errors. The following is part of my code. I have strict and warnings implemented.
my $res = $s->scrape(URI->new($urlToScrape));
#warn Dump $res;
print "Show :".$res->{showtitle}[0];
my #sct;
if ( defined {season}[0] ) {
print $res->{season}[0];
#sct=split(' ', $res->{season}[0]);
} else {
my #spaa=split( {showtitle}[0], {fulltitle}[0] );
print "Couldnt find season num at proper position\n";
print $spaa[0]."\n";
print $spaa[1]."\n";
exit;
}
The error I get is:
$ ./htmlscrape.pl
"my" variable #spaa masks earlier declaration in same scope at ./htmlscrape.pl line 43.
"my" variable #spaa masks earlier declaration in same scope at ./htmlscrape.pl line 44.
syntax error at ./htmlscrape.pl line 37, near "}["
syntax error at ./htmlscrape.pl line 40, near "}"
syntax error at ./htmlscrape.pl line 46, near "}"
Execution of ./htmlscrape.pl aborted due to compilation errors.
There's syntax error in your code. Change:
if ( defined {season}[0] )
to
if ( defined $res->{season}[0] )
and
my #spaa=split( {showtitle}[0], {fulltitle}[0] );
to
my #spaa=split( $res->{showtitle}[0], $res->{fulltitle}[0] );
Also you are getting the warning
"my" variable #spaa masks earlier declaration in same scope at ./htmlscrape.pl line 43.
That means you have declared two arrays with the same name #spaa in same scope. You'll probably find Coping with Scoping by Dominus worth reading. Pay particular attention to the section called "Lexical Variables".

New to perl; getting some errors I'm not sure about

I can't seem to figure out why I'm getting this error when trying to run my .pl script.
Here is the script:
# mini script for creating diff files in a single directory
# directory of patch files
$patchDir = "c:\oc\Patch Files";
if ($#ARGV != 1 && $#ARGV != 2)
{
print "Usage: diff <file name> [-s]\n";
print "Example: \n";
print " |Diff relative to Index (staged)| : diff MOM00123456_1.patch \n";
print " |Diff Staged| : diff MOM00123456_1.patch -s \n";
exit;
}
$fileName = $ARGV[0];
if ($#ARGV == 2)
$stagedArg = $ARGV[1];
if ($stagedArg)
if ($stagedArg == "-s" || $stagedArg == "-S")
system("git diff --staged --full-index > $fileName $patchDir");
else
{
print "Unknown argument: $stagedArg\n";
exit;
}
else
system("git diff --full-index > $fileName $patchDir");
Test:
diff.pl test.patch -s
Output:
Scalar found where operator expected at C:\utils\diff.pl line 18, near
")
$stagedArg"
(Missing operator before $stagedArg?) syntax error at C:\utils\diff.pl line 18, near ")
$stagedArg " syntax error at C:\utils\diff.pl line 21, near ")
if" Execution of C:\utils\diff.pl aborted due to compilation errors.
Execution of C:\utils\diff.pl aborted due to compilation errors.
Can someone shed some light?
Perl if syntax is:
if (condition) {
statements;
}
You can't omit the curly braces.
You might find use diagnostics; useful. Given a simple test script:
use strict;
use warnings;
use diagnostics;
if (1)
print 1;
We get:
syntax error at - line 5, near ")
print"
Execution of - aborted due to compilation errors (#1)
(F) Probably means you had a syntax error. Common reasons include:
A keyword is misspelled.
A semicolon is missing.
A comma is missing.
An opening or closing parenthesis is missing.
An opening or closing brace is missing.
A closing quote is missing.
Often there will be another error message associated with the syntax
error giving more information. (Sometimes it helps to turn on -w.)
The error message itself often tells you where it was in the line when
it decided to give up. Sometimes the actual error is several tokens
before this, because Perl is good at understanding random input.
Occasionally the line number may be misleading, and once in a blue moon
the only way to figure out what's triggering the error is to call
perl -c repeatedly, chopping away half the program each time to see
if the error went away. Sort of the cybernetic version of 20 questions.
Uncaught exception from user code:
syntax error at - line 5, near ")
print"
Execution of - aborted due to compilation errors.

Perl syntax errors on hash generating script

I am getting the following errors when running the code:
syntax error line 5, near "use Digest::MD5
sub makeKey
"
syntax error at line 8, near "}"
syntax error at line 15, near ")
}"
Execution aborted due to compilation errors.
My script:
use lib '/home/me/Desktop/pm/MD5.pm';
use Digest::MD5
sub makeKey
{
my ($strPassword, $strRndk);
$strKey = uc(md5Hash($strPassword)) + $strRndk + "Y(02.>'H}t\":E1" + md5Hash($strKey);
return $strKey;
}
sub md5Hash
{
my ($strPassword);
$strMd5 = md5_hex($strPassword);
return substr($strMd5, 16, 16) + substr($strMd5, 0, 16);
}
makeKey('test', '1A2B3C');
Use Digest::MDd5 needs to end with a semicolon.
Concerning your third (and final?) problem:
"Undefined subroutine &main::md5_hex called on line 14"
Digest::MD5 doesn't export md5_hex (or anything else) by default, you have to explicitly tell it that it should export md5_hex:
use Digest::MD5 qw(md5_hex);
or use the full Digest::MD5::md5_hex name.

Perl syntax error: Bareword found where operator expected

As the title suggests how could I accomplish this?
I have been following a tutorial, but I get a syntax error:
Bareword found where operator expected at arrays_and_variables.pl line
26, near "$2names"
(Missing operator before names?) syntax error at
arrays_and_variables.pl line 26, near "$2names " Execution of
arrays_and_variables.pl aborted due to compilation errors.
The code I have so far is:
#names = ('james','dylan','max');
# join elements of array into a schalar variable.
$2names = join ('', #names);
print $s2names;
2names is an invalid variable name. Names can't start with a number—they have to begin with a letter or an underscore.