in reply to Passing a variable to a hash

You don't need $v1, $v2, etc. And in my opinion whenever you start naming variables (or hash keys) with numbers you probably should be using an array anyway. But sticking with the hash, this would probably do what you're attempting.

use strict; use warnings; my $system = 'something'; my %vlan; # --- Lines Omitted --- my $vl_number = 1; while( <STDIN> ) { chomp; $vlan{ 'VLAN' . $vl_number++ } = $_; } # --- Lines Omitted --- while( my ( $key, $value ) = each %vlan ) { print "Now checking: $system\_$key $value\n"; }

Dave

Replies are listed 'Best First'.
Re^2: Passing a variable to a hash
by rspishock (Monk) on Jan 04, 2012 at 11:51 UTC

    Dave </P

    Thanks for your help.  $vl1, $vl2... were just examples, I had to change the variable names when I posted them here. However, your reply has me thinking ahead as to how I might change this script to accommodate a scan when all of the VLANs are not present.

    Thanks again for the guidance.