Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does my Perl script complain about "Global symbol "$random_name" requires explicit package name"?
    text
    copied!<p>I'm learning Perl and at the same time I'm creating a program to my family events, but when I'm trying to use a array with a randomization process I'm getting some errors, as you could see:</p> <pre><code>[ubuntu@eeepc:~/Desktop/mail] ./get.pl -h pop.vix.terra.com.br -u nathanpc -p (:D) Global symbol "$random_name" requires explicit package name at ./get.pl line 17. Execution of ./get.pl aborted due to compilation errors. [ubuntu@eeepc:~/Desktop/mail] </code></pre> <p>And my code is like this:</p> <pre><code>#!/usr/bin/perl # import packages use Net::POP3; use Getopt::Long; use Mail::Message; use List::Util qw(shuffle); use strict; use warnings; # Variable declaration my $host; my $user; my $pass; my $email_file; my $msg; my @array = shuffle(&lt;$random_name&gt;); # read command line options # display usage message in case of error GetOptions ('h|host=s' =&gt; \$host, 'u|user=s' =&gt; \$user, 'p|pass=s' =&gt; \$pass) or die("Input error. Try calling me with: -h &lt;host&gt; -u &lt;username&gt; -p &lt;password&gt;"); # file operations open($email_file, "&gt;&gt;", "Mail.txt"); open my $random_name, "&lt;", "out.txt"; # initiate connection # default timeout = 120 sec my $conn = Net::POP3-&gt;new($host) or die("ERROR: Unable to connect.\n"); # login my $numMsg = $conn-&gt;login($user, $pass) or die("ERROR: Unable to login.\n"); # get message numbers # iterate over list and print first 20 lines of each if ($numMsg &gt; 0) { my $msgList = $conn-&gt;list(); foreach $msg (keys(%$msgList)) { my $rawdata = $conn-&gt;get($msg); my $msg_obj = Mail::Message-&gt;read($rawdata); my $body = $msg_obj-&gt;body; print $email_file $body; print $email_file "\n====================================================\n"; print shift @array; } } else { print "Mailbox is empty.\n"; } # close connection $conn-&gt;quit(); close($email_file); close($random_name); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload