Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re^5: array or array ref as variable

by HelenCr (Monk)
on Jun 28, 2013 at 09:30 UTC ( #1041201=note: print w/replies, xml ) Need Help??

in reply to Re^4: array or array ref as variable
in thread array or array ref as variable

In my opinion, something like this could work ( dropping the sub, in case you don't need that sub for something else):

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

I haven't tested it, the right hand-side of the assignment may not work, (but it's close), if it doesn't work, maybe one of the higher gurus here can fix it.

Run it and tell us the result


Replies are listed 'Best First'.
Re^6: array or array ref as variable
by Hossein (Acolyte) on Jun 28, 2013 at 10:57 UTC
    ok, I did this:
    my @arr_methods = ([ \@fw, \&NT::FW, 'FW'], [\@vrf, \&NT::VRF, 'VRF' +], [\@vlan, \&NT::VLAN, 'VLAN'], [ \@portchannel, \&NT::PORTCHANNEL, +'PORTCHANNEL'] ); foreach (@arr_methods) { @{$_->[0]} = ($_->[1])->extract( &slurpFile($CFG{$CFG{$_->[2]} +} ), %CFG); }

    If I run  [ \@fw, &NT::FW, 'FW'] I'll get this error message:

    Undefined subroutine &NT::FW called at line 32.

    but when I do this: [ \@fw, \&NT::FW, 'FW'] that error message is gone.

    and when I run it I get this error message:

    Can't call method "extract" on unblessed reference at line 48.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1041201]
[Corion]: LanX: Ah, yeah - Frankfurt is in the quake region, but at the very border. I think I've never noticed a quake in Frankfurt myself
[marto]: good morning all
[Corion]: On another topic, in the process of Rubber Duck SoPWing, I wrote a post about the best API for generating HTTP requests (not sending them) and while writing it and fleshing out my sample implementation, I came up with some improvements to my ...
[Corion]: ... existing prototype. Cartesian Products will be proud of that module once it gets out ;)
[Corion]: Hi marto ;)
LanX has the same problem with English accents ...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2017-01-18 10:19 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (161 votes). Check out past polls.