0

I'm trying to create an excel file using perl scripting.
I followed the tutorial and write the following code :

#!/usr/bin/perl

use strict;
use warnings;
use Excel::Writer::XLSX;
use Excel::Writer::XLSX::Utility;

my $workbook = Excel::Writer::XLSX->new( 'perl.xlsx' );    # Step 1
$worksheet = $workbook->add_worksheet('cc');                   # Step 2
$worksheet->write( 'A1', 'Hi Excel!' );  

But I got the following error :

Global symbol "$worksheet" requires explicit package name at test_excel.pl line 10.
Global symbol "$worksheet" requires explicit package name at test_excel.pl line 11.
simbabque
  • 53,749
  • 8
  • 73
  • 136
  • When you say tutorial, do you mean the synopsis in the CPAN documentation? – simbabque Feb 20 '20 at 12:01
  • Add `my ` to the left of the first occurence of `$worksheet` – Kjetil S. Feb 20 '20 at 12:12
  • This generates a compile-time error if you access a variable that wasn't declared via "our" or "use vars", localized via "my()", or wasn't fully qualified. please check url https://perlmaven.com/global-symbol-requires-explicit-package-name – amit bhosale Jun 24 '20 at 07:24

1 Answers1

5

You need to declare the $worksheet variable, like this

my $worksheet = $workbook->add_worksheet('cc');                   # Step 2
pmqs
  • 3,066
  • 2
  • 13
  • 22