I have a script that I'm working on that handles setup of new servers, via user input. The user enters server information which is then stored in a hash. The hash keys all start with 'node'.
The issue is that the hash entries are stored as node0-9wwn0, etc.
Sample:
What I need is to pull JUST the node key (which is variable based on how many servers are entered...could be node0-node199).Key: node0 Value: servername0 Key: node0wwn0 Value: servername0wwn0 ...
If I regex match on node0-9 inside the loop it pulls the last hash entry (node0wwn0 in this case), and all I need is 'node0' and it's corresponding key. After several days of searching and getting nowhere with substr and regexes I decided to throw myself on the mercy of the Monks.
As you can see from above regex, that matches anything on that line with node0-9, when all I want to pull out of the hash is node0-9...my problem is that the key is variable, as I said, so I can't hard code it. Can someone point me in the right direction? Thank you much!foreach my $key (sort keys %$ref) { if ($key ne "Server") { print $key .":" . " " . $ref->{$key} . "\n"; } ### Search the hash for cluster nodes. ### If they exist, perform operations ### Regex looks for the node.* keys, which indicates a cluster node. ### If there's no cluster, there won't be any node.* keys. if ($key =~ m/node.*$/) { print "We have a cluster! Here are the entries: " .$key. ":" . $ref-> +{$key}. "\n"; } if ($key =~ m/node[0-9]/) { print $key . ":" . $ref->{$key}. "\n"; } }
In reply to Partial string match -- with a twist. by smw6181
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |