in reply to Re: array or array ref as variable
in thread array or array ref as variable
This is my call
my (@fw, @vrf, @vlan, @portchannel); @fw = &collectData('fw', $CFG{$CFG{FW}}); @vrf = &collectData('vrf', $CFG{$CFG{VRF}}); @vlan = &collectData('vlan', $CFG{$CFG{VLAN}}); @portchannel = &collectData('portchannel', $CFG{$CFG{PORTCHANNEL}});
and this is the sub
sub collectData { my $str = shift; my $type = shift; my @array; my $content = &slurpFile($type); if ($CFG{READFILE} eq $CFG{ERROR}){ print $CFG{ERROR_OPEN} = s/--file--/$type/ ,"\n"; return; } $str =~ /^fw/ ? { @array = NT::FW->extract($content, %CFG) +} : $str =~ /^vrf/ ? { @array = NT::VRF->extract($content, %CFG) + } : $str =~ /^vlan/ ? { @array = NT::VLAN->extract($content, %CFG +) } : $str =~ /^portchannel/ ? { @array = NT::PORTCHANNEL->extract($conten +t, %CFG) } : return; return @array; }
How can I do this with less lines of code?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: array or array ref as variable
by HelenCr (Monk) on Jun 28, 2013 at 07:32 UTC | |
by Hossein (Acolyte) on Jun 28, 2013 at 08:12 UTC | |
by HelenCr (Monk) on Jun 28, 2013 at 09:30 UTC | |
by Hossein (Acolyte) on Jun 28, 2013 at 10:57 UTC |