Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: array or array ref as variable

by GrandFather (Sage)
on Jun 28, 2013 at 11:57 UTC ( #1041234=note: print w/replies, xml ) Need Help??


in reply to array or array ref as variable

Having looked over your conversation with HelenCr, I think a slight step back is in order to focus on the key issue. The following code mocks up a solution to the issue of passing in a "module reference" to a "collection" sub to get some work done:

#!/usr/bin/env perl use warnings; use strict; package FW; sub extract { return "It's a FW"; } package VRF; sub extract { return "It's a VRF"; } package main; my @fw = collect('fw'); my @vrf = collect('vrf'); print "$_\n" for @fw, @vrf; sub collect { my ($type) = @_; my $module = uc $type; return $module->extract(); }

Prints:

It's a FW It's a VRF

The key is that if you want to call a function in a module you can use the syntax $modulename->function() to make the call.

True laziness is hard work

Replies are listed 'Best First'.
Re^2: array or array ref as variable
by HelenCr (Monk) on Jun 28, 2013 at 19:48 UTC
    Thank you, GrandFather.

    So, in other words, are you saying that this should work?:

    my @arr_methods = ([ \@fw, 'NT::FW', 'FW'], [\@vrf, 'NT::VRF', 'VRF'], + [\@vlan +, 'NT::VLAN', 'VLAN'], [ \@portchannel, 'NT::PORTCHANNEL', 'PORTCHANN +EL'] ); foreach (@arr_methods) { @{$_->[0]} = $_->[1]->extract( &slurpFile($CFG{$CFG{$_->[2]}} +), %CFG) +; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1041234]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (1)
As of 2018-07-22 01:30 GMTServer Error (Error ID 4465468c64284)

An error has occurred. The site administrators have been notified of the problem and will likely soon fix it. We thank you, for you're patients.

Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (451 votes). Check out past polls.

    Notices?