Can't use string as a subroutine ref while "strict refs"

------=_NextPart_000_0004_01C70428.644E8960
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

use strict;
use warnings;
use CGI;

my $q =3D new CGI;

my $do =3D $q->param('do') || 'main'';

if ($do) {
&$do;
}

sub main {
blah blah
}
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Trying to call the subroutine main from variable $do but I am gettin' =
error:
Can't use string ("main") as a subroutine ref while "strict refs.
But somehow I don't want to remove the 'use Strict;'

Any way out?

Sara.



------=_NextPart_000_0004_01C70428.644E8960--

0
sara
11/9/2006 12:56:33 PM
perl.beginners.cgi 3839 articles. 0 followers. Follow

4 Replies
834 Views

Similar Articles

[PageSpeed] 42

On 11/09/2006 06:56 AM, Sara wrote:
> use strict;
> use warnings;
> use CGI;
> 
> my $q = new CGI;
> 
> my $do = $q->param('do') || 'main'';
> 

my $do = $q->param('do') || main();

> if ($do) {
> &$do;
> }
> 
> sub main {
> blah blah
> }
> =========================================
> Trying to call the subroutine main from variable $do but I am gettin' error:
> Can't use string ("main") as a subroutine ref while "strict refs.
> But somehow I don't want to remove the 'use Strict;'
> 
> Any way out?
> [...]

Yes.
Start->Run->"perldoc perlsyn"
Start->Run->"perldoc perlsub"



0
mumia
11/9/2006 3:07:25 PM
------_=_NextPart_001_01C7044E.F9196BC9
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

=20

  Anyone knows how to write a timeout script using perl, basically I
want to like this,

=20

*         Use perl to connect to an oracle database

*         After 5 minutes cannot connect to the database through
database listener, get a timeout message and email to a distribution
list

=20

=20

Thanks,

Allen


------_=_NextPart_001_01C7044E.F9196BC9--
0
Allen
11/9/2006 10:32:43 PM
Sara wrote:
> use strict;
> use warnings;
> use CGI;
> 
> my $q = new CGI;
> 
> my $do = $q->param('do') || 'main'';
> 
> if ($do) {
> &$do;
> }
> 
> sub main {
> blah blah
> }
> =========================================
> Trying to call the subroutine main from variable $do but I am gettin' error:
> Can't use string ("main") as a subroutine ref while "strict refs.
> But somehow I don't want to remove the 'use Strict;'
> 
> Any way out?

my $q = new CGI;

my $do = $q->param( 'do' ) || \&main;

if ( ref $do eq 'CODE' ) {
    $do->();
}

sub main {
    blah blah
}



John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall
0
krahnj
11/11/2006 9:41:26 AM
Use a hash dispatch.

my %dispatcher = (
	something	=> \&somethingElse,
	default		=> \&main,
);

my $do = exists $dispatcher{ $q->param('do') } 
	?	$dispatcher{ $q->param('do') }
	:	$dispatcher{default};

$do->();

On Thu, Nov 09, 2006 at 05:56:33PM +0500, Sara wrote:
> use strict;
> use warnings;
> use CGI;
> 
> my $q = new CGI;
> 
> my $do = $q->param('do') || 'main'';
> 
> if ($do) {
> &$do;
> }
> 
> sub main {
> blah blah
> }
> =========================================
> Trying to call the subroutine main from variable $do but I am gettin' error:
> Can't use string ("main") as a subroutine ref while "strict refs.
> But somehow I don't want to remove the 'use Strict;'
> 
> Any way out?
> 
> Sara.
> 
> 

-- 
Brad Lhotsky
0
brad
11/13/2006 8:54:25 PM
Reply:

Similar Artilces:

Can't use string ("1") as a HASH ref while "strict refs" in use at ./policy.sanitizer line 255.
Hi there, I am trying to figure out why the following lines are giving me an error: --- snip --- $found{filter}{$filter}{family}{$family} = 1; print keys %{ $found{filter}{$filter}{family} }; --- snip ---- here's the error Can't use string ("1") as a HASH ref while "strict refs" in use at ../policy.sanitizer line 255. I am trying to the display all the keys for $found{filter}{$filter}{family} please Cheers, Noah On 10/9/09 Fri Oct 9, 2009 2:12 PM, "Noah" <noah-list@enabled.com> sc...

Can't use string ("1") as a HASH ref while "strict refs"
--00151747694010009a04ad544f1b Content-Type: text/plain; charset=UTF-8 Hi, I was getting this error message for one of my script. The reason came out out to be, I had not place a semi-colon at the end of try-catch block. try { something } catch some_exception { do something } After I placed the semi-colon, I am no longer getting this error (Can't use string ("1") as a HASH ref while "strict refs") try { something } catch some_exception { do something }; My questions is I have quite a few scripts that are using the SAME try-catch...

Can't use string ("3862926") as a HASH ref while "strict refs"
I guess I'm not understanding what I'm doing (or have been reading in my web searches)... Can someone explain the difference between these two code snippets... SUN83-PRODWEB>more foo #! /usr/local/bin/perl use strict; my %t; my ($a, $c); my ($aa, $cc); $a=3D$aa=3D1; $c=3D$cc=3Dq{Additional Electrical Circuit}; $t{$a}{$c}{AMT}=3D1000; $c=3Dq{Additional}; $t{$a}{$c}{AMT}=3D2; print $t{$aa}{$cc}{AMT}, "\n"; &Ix($t{$aa}{$cc}{AMT}); sub Ix { my ($v) =3D @_; ...

bugzilla: undef error
I'm encountering the problem described here: https://bugzilla.mozilla.org/show_bug.cgi?id=300448 I'm running bugzilla 2.18.3 on fedora. The problem seems to be that a line was added to this file: template/en/default/bug/create/created.html.tmpl So I commented out this line: mailrecipients = item.mailrecipients and restarted everything, but I'm still getting the same error. I'm not sure that I understand the solution very well. Any ideas? Thanks, Bryan ...

DBD::Proxy::db table_info failed: Server returned error: Failed to execute method CallMethod: Can't use string ("1") as an ARRAY ref while "strict refs" in use
------_=_NextPart_001_01C2BB46.4379CEA8 Content-Type: multipart/related; type="multipart/alternative"; boundary="----_=_NextPart_002_01C2BB46.4379CEA8" ------_=_NextPart_002_01C2BB46.4379CEA8 Content-Type: multipart/alternative; boundary="----_=_NextPart_003_01C2BB46.4379CEA8" ------_=_NextPart_003_01C2BB46.4379CEA8 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I'm having a problem using the table_info() via ProxyServer... I'm = getting the following error messages: I am us...

lwp-rget error message ("can't use string ("URI::URL") as ARRAY ref)
I've been using lwp-rget, for instance: cyc$ lwp-rget --depth=2 --limit=100 "http://www.somesite.com/~whoever with no problems. tonight I got this msg: Can't use string ("URI::URL") as an ARRAY ref while "strict refs" in use at /usr/local/path_to_module/URI/WithBase.pm line 41. version info: This is perl, version 5.005_03 built for i386-freebsd and: This is lwp-rget version 1.19 (libwww-perl-5.52) Any advice would be really appreciated. CYC. Hi! I have a simple program which opens each URL in a file and saves ...

Can't use string ("") as an Array ref
I'm getting the following when trying running the following code with use strict; without it, it works fine.=20 =23=21/usr/bin/perl -w=20 use strict;=20 use warnings;=20 use Data::Dumper;=20 my (=40data,=40contents);=20 =40data =3D <STDIN>; push(=40contents,map =7B =5B split/:/,=24_ =5D if/=5E=5Cw+/ =7D (sort = =40data) );=20 for(1..=24=23contents) =7B=20 print =24contents=5B=24_->=5B0=5D . =22=5Cn=22 if = defined(=24contents=5B=24_=5D->=5B0=5D);=20 =7D - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - = - - - - - - - Th...

Can't use string ("bug/create/create-guided.html.tm") as a HASH ref
- I could use some help with my Bugzilla install - I have installed the stable release of Bugzilla (2.16.5) and have customized some of the templates (which is a cool new way to do things). I am following the instructions to modify create.html.tmpl and comment.txt.tmpl to create some fields for bug entry. However, I get the following perl error message and I can't figure out why: Can't use string ("bug/create/create-guided.html.tm") as a HASH ref while "strict refs" in use at /usr/lib/perl5/site_perl/5.8.0/Template/Provider.pm line 663. I am new to...

(setxkbmap) can't use "ALT_GR"/"left ALT" button after using it
hello folks i use LXDE as i'm known and my only solution to switch keyboard is to use setxkbmap now after i define keyboards layouts to switch and chose ALT+Shift to switch it goes "bugged" using the right ALT will switch the layouts and i'm not able to write the "other" letters help please P.S : this is the command i use �setxkbmap -option grp:switch,grp:alt_shift_toggle,grp_led:scroll fr,ar� -- SAFAD ------------------------------------------------------------------------ bump up rotfl! -- SAFAD -------------------------------...

"xmlns" ref can't be found
I had everything working great then I had an ASP.NET problem and re-installed .netFramwork and ASP.NETnow I get the following message when I go to run my portalParser Error Message: Unrecognized attribute 'xmlns'.Source Error: Line 1: <?xml version="1.0" encoding="utf-8"?> Line 2: <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"> Line 3: </configuration> Source File: c:\inetpub\wwwroot\web.config    Line: 2 What Happened and why am I getting this message ??????????????????? Make sure that the IIS virtual directory  is...

why can't i use the attribute "onchange" or "onfocus" in checkbox
when i use the code like this:myCheckBox.Attributes["onfocus"]="this.blur()" it doesn't work,just generate the tag "span" containing the javascriptMSN:supNate2000@hotmail.com You should be using RegisterStartupScript or RegisterClientScript. See this article by Scott Mitchell: Injecting Client-Side Script from an ASP.NET Server Control http://msdn.microsoft.com/asp.net/using/understanding/aspnet/default.aspx?pull=/library/en-us/dnaspp/html/aspnet-injectclientsidesc.aspDarrell Norton, MVPDarrell Norton's BlogPlease mark this post as answered if it...

Can't we use "Usercontrol" in an "asp:view" control in asp.net
 HiIn my application i have used multiview and view controls i have implemented some user controlsnow i don't want to write the whole code in view control instead i want to use the usercontrolcan we place the usercontrol in view controlhow can we do thati have registered the usercontrol but when I'm trying to place in view control its not showing the tagprefixdoes anyone know this how to dothanks in advanceArchu   archu136:  Hi In my application i have used multiview and view controls i have implemented some user controls now i don't want to writ...

Using "Address Selector" in "Find by Example"
Hi When doing a find by example and using the address selector to double click a resopurce address to select it 80% of the time it enters the first entry in the address book rather than the address selected. For user addresses it works fine though. Is there a way to use the address selectro in a find by example? Or do you have to type the address for resources? Thanks Rampaola, It appears that in the past few days you have not received a response to your posting. That concerns us, and has triggered this automated reply. Has your problem been resolved? If not, you ...

Web resources about - Can't use string as a subroutine ref while "strict refs" - perl.beginners.cgi

Resources last updated: 11/30/2015 12:35:41 AM