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..


In reply to [resolved] Can't use string ("0") as a symbol ref while "strict refs" in use by bryan.p.spears

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.