Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion using a variable in a subroutine name
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Kristina Clair  
View profile  
 More options Nov 6 2001, 12:37 pm
Newsgroups: comp.lang.perl.misc
From: "Kristina Clair" <kcl...@soya.serve.com>
Date: Tue, 06 Nov 2001 12:36:09 -0500
Local: Tues, Nov 6 2001 12:36 pm
Subject: using a variable in a subroutine name
Hello,

I'm trying to use a variable in the name of a subroutine, like so:

    foreach my $x ("email_zip", "email_txt", "cp_zip", "cp_txt") {
        if ($res = _send_$x($domain, $file, $date, $location)) {
            push (@results, $res);
        }

    sub _send_email_zip {
    }

    sub _send_email_txt{
    }

    etc...

However, I'm getting the following error message:
"Can't locate object method "_send_" via package "email_zip" (perhaps you forgot to load
"email_zip"?)"

So, then I thought I could use the whole subroutine name in the foreach
loop: ("_send_email_zip", "_send_email_txt", etc), but I cannot figure
out if there is a way to get this to work.

Does anyone know of a way to use a variable in the name of a subroutine?

Thanks,
Kristina Clair


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.