bryan.p.spears has asked for the wisdom of the Perl Monks concerning the following question:
I've written very little code, and this is my first attempt at something in perl, so please forgive the ignorance. I am trying to pass output from an external program called checkuser, into an array. Here is the error:
$ ./testpl.pl bryan@domain1.net Can't use string ("0") as a symbol ref while "strict refs" in use at . +/testpl.pl line 29. $ cat -n testpl.pl | grep 29 29 open (@checkuser_output, "checkuser $user{'name'}\@$user{'doma +in'} $domain_action{$user{'domain'}}") || die "Failed: $!\n";
And, for context, here is the script
#!/usr/local/bin/perl -Tw use strict; use Data::Dumper; chomp $ARGV[0]; my %user; my @input; my @checkuser_output; <==== took this out my $default_domain = 'default.net'; my $maintainer = 'bryan.p.spears@default.com'; my %domain_action = ( 'default1.net' => 'first', 'default2.net' => 'second', 'default3.net' => 'third', ); @input = split(/@(.*)/,lc($ARGV[0])); $user{'name'} = $input[0] ? $input[0] : '?'; $user{'domain'} = $input[1] ? $input[1] : $default_domain; my $explanation = <<END; explanation goes here END if ((@ARGV > 1) || ($user{'name'} eq '?')) { printf $explanation; exit(1); }; # placeholder: going to validate domain, here # Instead of this ====> open (@checkuser_output, "checkuser $user{'nam +e'}\@$user{'domain'} $domain_action{$user{'domain'}}") || die "Failed +: $!\n"; open (my $checkuser_output, "checkuser $user{'name'}\@$user{'domain'} +$domain_action{$user{'domain'}}") || die "Failed: $!\n"; print Dumper @checkuser_output
Per suggestions by choroba and anonymous (thank you both, very much), I removed the checkuser_output array declaration at top, and referenced it in the open statement as a scalar. One hurdle cleared..
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Can't use string ("0") as a symbol ref while "strict refs" in use
by choroba (Cardinal) on Feb 22, 2013 at 21:03 UTC | |
|
Re: Can't use string ("0") as a symbol ref while "strict refs" in use
by Anonymous Monk on Feb 22, 2013 at 21:08 UTC |