Why Perl Subroutine Passed In Variable is 1?

The following subroutine prints 1 instead of the content of the Equipment variable. Can someone tell me why?

#!c:/perl/bin/perl.exe
#
use strict 'vars';

my $Equipments = "data/equips.txt";
unless (open(EQUIP_FH, "$Equipments")) { 
  print "errors: $Equipments\n";    # This line prints the variable content
  &ErrMsg ("$Equipments");
}

sub ErrMsg {
  my $file = @_;
  print "Cannot open $file.\n";      # BUT here print 1 instead.
} 

Can someone here tell why the ErrMsg routine is not printing the content of the $file variable?

Thank you!!

Need quotes - see in red below:

#!c:/perl/bin/perl.exe
#
use strict 'vars';
 
my $Equipments = "data/equips.txt";
unless (open(EQUIP_FH, "$Equipments")) { 
  print "errors: $Equipments\n"; # This line prints the variable content
  &ErrMsg ("$Equipments");
}
 
sub ErrMsg {
  my $file ="@_";
  print "Cannot open $file.\n"; # BUT here print 1 instead.
}
1 Like