Hi guys, I am not a Perl expert, so I was just hoping someone could maybe preview this and let me know if there is anything I could do better. Below is an example of the output I am trying to parse, I am mostly concerned with the data under Name: for example "PHRCFL-xx-xxx".
This is a listing off all my SAN volumes and I want to put just that field into an array. I wrote up the following and it seems to work, but I was just hoping someone could see if there is anything I could improve upon.
Code:
Compellent Command Utility (CompCU) 5.2.1.2
=================================================================================================
User Name: Admin
Host/IP Address: 10.10.1.10
Single Command: volume show
=================================================================================================
Connecting to Storage Center: 10.10.1.10 with user: Admin
Running Command: volume show
Index Name Status ConfigSize ActiveSize ReplaySize Folder StorageProfile DeviceID SerialNumber ConfigSizeBlock ActiveSizeBlock ReplaySizeBlock MaxWriteSizeBlo ReadCache WriteCache
------ -------------------------------- -------- --------------- --------------- --------------- ---------------------------------------------------------------- -------------------------------- -------------------------------- ----------------- --------------- --------------- --------------- --------------- ---------- ----------
14 PHRCFL-xx-xxx Up 300.00 GB 218.66 GB 0.00 KB Examiners/wbrooks RAID 10 and RAID 5 Tier 1 6000d3100007fe00000000000000000f 000007fe-0000000f 629145600 458567680 0 0 Disabled Enabled
This is a listing off all my SAN volumes and I want to put just that field into an array. I wrote up the following and it seems to work, but I was just hoping someone could see if there is anything I could improve upon.
Code:
my @data = `command above`
# I added this to remove all the top information login, address, etc..
splice(@data,0,12);
# Remove the carriage returns.
chomp(@data);
# delete the last three array members, they contain success messages.
for ($i = 0; $i < 3; $i++){
pop(@data);
}
foreach my $var (@data){
#I wanted to use white spaces, but some of my users put spaces in their volume names, so I went with Up since this should not change.
@index = split(/Up/, $var);
# I did not want all that other information just sitting there
delete $index[1];
# I set another variable to delete the first seven characters and it leaves me with just the volume name, which is what I want.
my $vol = $index[0];
$vol = substr($vol,7);
# Put the name into a new array I made.
push(@volumes, $vol);
}
# Sort the list alphabetically
@volumes = sort {$a cmp $b } @volumes;
# Print the volumes or put them in a listbox
foreach (@volumes){
print $_;
$drpvolume->insert('end',$_);
}