Visit Our UNIX and Linux User Community

Perl failure with "main::$fn" used only once:" in error logs

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl failure with "main::$fn" used only once:" in error logs
# 1  
Old 03-06-2013
Perl failure with "main::$fn" used only once:" in error logs

Hi all,

Can anyone guess why this is happening? I am new to Perl, so please help me to fix this error:
- I have a static html file which calls the cgi-perl script.
HTML Code:
        <title> Hey Dude! </title>

        <form method="POST" action="/cgis/">
        <p><input type="text" name="name" size="49"></p><br>
        <p><input type="submit" name="submit" value="GO!"></p><br>


and my CGI-PERL code is:
#!/usr/bin/perl -w
 # Read the standard input (sent by the form):
read(STDIN, $form, $ENV{'CONTENT_LENGTH'});
# Get the name and value for each form input:
@pairs = split(/&/, $form);
# Then for each name/value pair....
foreach $pair (@pairs) {
    # Separate the name and value:
    ($name, $value) = split(/=/, $pair);
    # Convert + signs to spaces:
    $value =~ tr/+/ /;
    # Convert hex pairs (%HH) to ASCII characters:
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    # Store values in a hash called %FORM:
    $form{$name} = $value;
#This will generate XHTML-compliant page headers
sub start_html()
        print qq~ 
        <?xml version="1.0" encoding="iso-8859-1"?>
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
        <html xmlns="">

                <title> Cookies </title>

if ($form{'submit'} eq "submit")
    #Start hearders
    print "Set-Cookie: name=$form{'name'}\n";
    print "Content-Type: text/html\n\n";
    #end of headers
    print "Nice to meet you $form{'name'}", ". I hope to see you again soon";
    $old_cookie = $ENV{"HTTP_COOKIE"};
    #if cookie was found
    if ($old_cookie)
    ($cookie_name, $name) = split(/=/, $old_cookie);
    #start headers
    print "Content-Type: text/html\n\n";
    #end of headers
    print "Hey! I know you dude! You are $name";
    print "</body></html>\n";
#cookie not fond
    # redirect user to the form with a redirect header
    print "Location:\n\n";

Error in log_error:
[client] Name "main::cookie_name" used only once: possible typo at /dir/cgi-bin/ line 49., referer:

Last edited by bashily; 03-06-2013 at 02:10 AM.. Reason: Highlight line 49
# 2  
Old 03-06-2013
Beginners Intro to Perl - Part 6 - says:

1. Name ``main::filename'' used only once: possible typo at ./ line 3. and Name ``main::fn'' used only once: possible typo at ./ line 4. Perl notices that $filename and $fn both only get used once, and guesses that you've misspelled or misnamed one or the other. This is because this almost always happens because of typos or bugs in your code, like using $filenmae instead of $filename, or using $filename throughout your program except for one place where you use $fn (like in this program).

You can run CGI on the command line, just set the variables it reads.
# 3  
Old 03-07-2013
Quick fix:
replace the unreferenced variable by undef
    ($cookie_name, $name) = split(/=/, $old_cookie);

    # ($cookie_name, $name) = split(/=/, $old_cookie);
   (undef, $name) = split(/=/, $old_cookie);

# 4  
Old 03-07-2013
I forget the exact rules, but CGI and cron can be fussy about output on stdout, stderr and exit status. I see lots of error printouts on web returns, presumably from programmers who might have a hard time finding the httpd log.

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. Shell Programming and Scripting

Failure: if grep "$Var" "$line" inside while read line loop

Hi everybody, I am new at Unix/Bourne shell scripting and with my youngest experiences, I will not become very old with it :o My code: #!/bin/sh set -e set -u export IFS= optl="Optl" LOCSTORCLI="/opt/lsi/storcli/storcli" ($LOCSTORCLI /c0 /vall show | grep RAID | cut -d " "... (5 Replies)
Discussion started by: Subsonic66
5 Replies

4. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

5. Cybersecurity

"authentication failure" then "session opened". Why?

Ssh connections using shared public keys issue “authentication failure” messages, then succeed with “session opened”. I have found a few other threads with similar issue, but no solutions offered. :wall: How can I eliminate the failure messages? Environment: $ uname -a Linux... (0 Replies)
Discussion started by: KennyCason
0 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. SuSE

VMDB Failure" followed by "Unable to open snapshot file"

keep getting an error when I try to revert to a snapshot: "VMDB Failure" followed by "Unable to open snapshot file" Im using vmware server 1.0.4, host OS is windows xp and guest OS is SLES. Is there anything I can do to recover the snapshot or am I in trouble!?!?! (0 Replies)
Discussion started by: s_linux
0 Replies

8. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep ""|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep ""|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

Featured Tech Videos