in reply to Variable variable?
This code will issue a run-time error if you are using strict.sub test { print "nothing\n"; } my $var = 'test'; &$var; # will call the sub, if you are not using strict.
But you will be in trouble if you add an unmatched item to the list of variables, or you misspell one of them. Say, using ('what','woh'), the error will kick off at run-time only.#!/usr/bin/perl -w use strict; package Camel; sub new { my $class = shift; my $self = bless {name =>'Jack Camel'}, $class; } sub who { my $self = shift; return $self->{name} } sub what { my $self = shift; return "a camel, can't you see that?"; } package main; my $camel = new Camel; for ('who', 'what') { print $_, "?\t", $camel->$_, "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Variable variable?
by Trimbach (Curate) on Mar 14, 2002 at 12:44 UTC |