Smith, Derek wrote: > I have inherited a program that does snmp walks and gets, but within the > code (keep in mind they turned off strict for references) > > I am failing to understand the push @$node_type "$name"; > > The person who wrote this said with strict on the push statement above > will not work...complains about a scalar is undefined. I said yes it > will not b/c you can only push an array and $ is scalar, arrays in > scalar context return the count of elements. > > > > His reply was well I am doing this b/c I need to create a dynamic array > composed of all device types. > > Is this bad code as I have never seen push @$arrayname? > > Please explain what this is doing. >
Yes, this is bad practice. The scalar $node_type contains strings from @all_node_types. The expression @$node_type is a symbolic reference (see `perldoc perlref`) to an array with the same name as the string. For example, the first string is "CiscoAPVPN", so for it, @$node_type is the same as @CiscoAPVPN. This is also why the statement 'no strict "refs";' must be used; it allows symbolic references. The preferred practice is to use a hash: my %all_nodes = (); ... push @{ $all_nodes{$node_type} }, $name; -- __END__ Just my 0.00000002 million dollars worth, --- Shawn "For the things we have to learn before we can do them, we learn by doing them." Aristotle * Perl tutorials at http://perlmonks.org/?node=Tutorials * A searchable perldoc is at http://perldoc.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>