3

Bear with me as I'm new to Perl, but I am having an error in compilation on a use statement, but I'm not entirely sure why I'd get one there. I am using perlbrew on Mac Sierra. The perl version is 5.26.1.

I'm not quite sure where to really start. I did a little research and the only thing I found close to what I needed was an invalid shebang line, which I'm not using. I did try with a valid shebang line with no change.

I did comment the offending line to see what would happen and it just failed on the very next one so it's my use statements.

use warnings;
use strict;

# Lib Folders;
use lib "/Users/user/perl5/lib/perl5/darwin-thread-multi-2level"

# Load Modules
use DBI;
use DBD::MariaDB;
use Text::CSV;
use Excel::Writer::XLSX;
use Time::Piece;
use Log::Log4perl qw(get_logger);

Since I can't compile past this point, I can't verify if anything else beyond it doesn't work. I'm at a loss as to why this is causing an error.

I would expect another compilation error or a successful compilation if I wrote everything else properly.

"use" not allowed in expression at report.pl line 8, at end of line
syntax error at report.pl line 8, near "use DBI"
BEGIN not safe after errors--compilation aborted at report.pl line 9.
Command terminated with non-zero status.
Command [perl report.pl] terminated with exit code 255 ($? = 65280) under the following perl environment:
Current perl:
  Name: perl-5.26.1
  Path: /Users/user/perl5/perlbrew/perls/perl-5.26.1/bin/perl
  Config: -de -Dprefix=/Users/user/perl5/perlbrew/perls/perl-5.26.1 -Aeval:scriptdir=/Users/user/perl5/perlbrew/perls/perl-5.26.1/bin
  Compiled at: Jun  4 2019 12:12:08

This is what the terminal is giving me when I run perlbrew exec perl report.pl. I must've missed something but I'm not sure what exactly.

Marisa
  • 151
  • 1
  • 3
  • 2
    In Perl, always check your semi-colons. I think you're missing one. – tadman Jun 07 '19 at 17:38
  • 2
    So it's a missing semicolon. A note on error reporting: Perl's diagnostic output is excellent. But in some cases it just can't nail it down, and then you need to go backwards from where it reports a problem and _read your code really closely_ ... and simply spot the error. I think it's fair to say that the silliest syntax errors are hardest to catch (because they allow perl to keep cranking and that breaks down only later by which time the error appears weird) – zdim Jun 07 '19 at 17:53

2 Answers2

3

You're missing a semicolon at the end of the use lib "..." line.

jwodder
  • 54,758
  • 12
  • 108
  • 124
3

You're missing a semicolon at the end of line 5.

A good general rule when debugging error messages is to check the line(s) immediately preceding the line where the error is reported as occurring.

Dave Mitchell
  • 2,193
  • 1
  • 6
  • 7
  • Thanks for the tip but don't I feel like a dope. But naturally it fails on compiling the DBI module. – Marisa Jun 07 '19 at 17:48
  • @Marisa - As this answer says, look backwards from the reported line. In this case, Perl sees the command `use lib "..." use DBI;`. The `use lib "..."` part is fine, but then it hits `use DBI` and knows at that point that something is wrong, but it's not sure what exactly the problem is, so it reports that the problem is "_near_ `use DBI`". If you put, e.g., a `print` statement after the missed semicolon, the error would be reported as "near `print`" - it has nothing at all to do with the DBI module. – Dave Sherohman Jun 08 '19 at 15:41