in reply to Syntax question (Perl 5.005)...

This code works for me:

use strict; package foo; sub bar { print "Works\n" } package main; my $var = "bar"; foo->$var;

It's possible that your error is somewhere else. Perl's error messages are often, um, less then perfect at pointing to the real place the error is at.

----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer

: () { :|:& };:

Note: All code is untested, unless otherwise stated

Replies are listed 'Best First'.
Re: Re: Syntax question...
by freddo411 (Chaplain) on Nov 07, 2003 at 22:01 UTC
    Interesting. I copied your code and tried to run on my machine and got an error. Perhaps this is due to the fact I'm running on Perl 5.005.

    gonzo:/export/home/fredk/docs/test: more foo.pl #!/usr/local/bin/perl use strict; package foo; sub bar { print "Works\n"; } package main; my $var = "bar"; foo->$var; gonzo:/export/home/fredk/docs/test: ./foo.pl syntax error at ./foo.pl line 10, near "$var;" Execution of ./foo.pl aborted due to compilation errors.
    UPDATE

    This works if I change foo->$var to foo->$var();

    Can someone confirm this is a 5.005 thing?

    -------------------------------------
    Nothing is too wonderful to be true
    -- Michael Faraday