|XP is just a number|
First post! I have inherited a script which is working fine, but I now need to include another variable in the output the script is producing. My Perl ability is pretty basic and my main problem is understanding what some of the existing code does in order to be able to modify it to do what I need - I believe the relevant code is below
So, what does the script currently do - it takes an excel spreadsheet which contains IP address allocations and generates a CSV file with two outputs types, (i) All the IP address allocations, with the output using the headers: "ipaddress,prefix,interface,device_name,location,comment"; (ii) A list of subnets, derived from the IP addresses, output using the headers: "subnet,prefix".
What do I want it now to do? Include a subnet name in the subnet list output, so effectively: "subnet,prefix,name".
My thought was to grab the $comment value from the IPs and use one of these to populate the subnet name field. As there are typically multiple IPs in a subnet, I was thinking just grab the first comment that is populated and use that (not all IPs have the comment field populated). My difficulty is I don't really understand well enough the code that takes the individual IP addresses and then derives the IP subnet address for these IPs - I know it's the second code snippet above - perhaps something like below (but I know this is not checking if wev've already grabbed a defined $comment?):
I think it’s straight forward to carry the $comment field into the store_subnet subroutine for each IP:store_subnet( $ipaddress, $prefix, $comment ) if $prefix;
But I'm not sure how to use the comment in the store_subnet subroutine, and effectivley assign the first populated $comment to the derived subnet address
Then, to print it out – I think it's a small tweak to jsut add the "name" header:
Apologies for the ramblings - appreciate any guidance offered to give me the desired outcome for this script and also improve my Perl ability!
In reply to How to include a variable in output for derived subnets by stroke