0

What I am doing wrong? Opened file is not empty. But I'm still getting

Global symbol "$tabbb" requires explicit package name at mix.pl line 8.

#!/usr/bin/perl

use strict;
use warnings;

open FILE, "<", "seeds.data" or die $!;
my @tab = <FILE>;
print @$tab;
nervosol
  • 1,295
  • 3
  • 24
  • 46

2 Answers2

2

you want print @tab; instead of print @$tab;.

Dan O
  • 6,022
  • 2
  • 32
  • 50
1

You have correctly used use strict and use warnings, and one of the benefits is that Perl will warn you if you use a variable you haven't declared. The error message

Global symbol "$tabbb" requires explicit package name at mix.pl line 8.

is saying that, because you are using strict, you cannot refer to a variable called $tabbb that hasn't been declared. Your line

print @$tab;

is dereferencing the scalar variable $tab as an array, and since you haven't declared a $tab I imagine that is what the error message means. However you do have an array variable @tab that contains the contents of the file you opened, so write

print @tab;

instead.

Best of all, read the file line-by-line and write

use strict;
use warnings;

open my $fh, '<', 'seeds.data' or die $!;
while (<$fh>) {
  print;
}
Borodin
  • 126,100
  • 9
  • 70
  • 144