CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
subroutines and strict

 



andrew_b
stranger

Aug 27, 2002, 5:26 PM

Post #1 of 2 (816 views)
subroutines and strict Can't Post

recently I wanted to say something like:


Code
use strict; 

my $foo = 'bar';

&$foo();

sub bar{
print "Hello\n";
}


but use strict doesn't like it.

How can I call a subroutine with a variable under the use strict pragma? (Besides "no strict 'refs'" :-)

Andrew


davorg
Thaumaturge / Moderator

Aug 27, 2002, 11:11 PM

Post #2 of 2 (812 views)
Re: [andrew_b] subroutines and strict [In reply to] Can't Post

You're making $foo into a symbolic reference, which is a bad idea and therefore "use strict" complains.

Get round the problem by making $foo into a real reference.

Code
#! /usr/bin/perl -w 

use strict;

my $foo = \&bar;

&$foo();

sub bar{
print "Hello\n";
}


--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives