can't create symbolic references

M

mike

Can anyone tell me why the following script gives an error message stating
'use of uninitialized value in concatenation or string at line 20'?:

#!/usr/bin/perl -wT
#This is a.cgi, called by woxYNzucw.cgi
use strict;
no strict "refs";
use CGI::Carp qw(fatalsToBrowser);
use CGI qw:)standard -no_xhtml);
use diagnostics;
my $co = new CGI;
print $co->header;
my @atoms = qw ();
print $co->start_html(-title=>'ref');
my $var=5;
my $refv=\$var;
print $co->h2("var = $var; dereferenced hard ref = $$refv");
my $varr=6;
my $varref="varr";
my $vv=$$varref;
print $co->h2("dereferenced varr is $vv");

With output:
var = 5; dereferenced hard ref = 5
dereferenced varr is

Thank you for any help. (I'm not sure why the color change)
 
M

Matt Garrish

mike said:
Can anyone tell me why the following script gives an error message stating
'use of uninitialized value in concatenation or string at line 20'?:

There aren't twenty lines in the code you posted.
#!/usr/bin/perl -wT
#This is a.cgi, called by woxYNzucw.cgi
use strict;
no strict "refs";
use CGI::Carp qw(fatalsToBrowser);
use CGI qw:)standard -no_xhtml);
use diagnostics;
my $co = new CGI;
print $co->header;
my @atoms = qw ();
print $co->start_html(-title=>'ref');
my $var=5;
my $refv=\$var;
print $co->h2("var = $var; dereferenced hard ref = $$refv");
my $varr=6;
my $varref="varr";
my $vv=$$varref;
print $co->h2("dereferenced varr is $vv");

With output:
var = 5; dereferenced hard ref = 5
dereferenced varr is

You can't use symbolic references with lexically scoped variables (see the
"Symbolic references" section in perlref).

Why do you need them, though? As said many times in the past, a hash is
almost always a better option to symrefs.

Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top