in reply to loading a hash of hashes from UNIX command output

Or did you want the volume after highest existing volume?
tapeutil -f /dev/smc0 inventory | perl -le' my $vol = ( sort grep /^ *Volume Tag[ .]+(.*)/, <> )[-1]; print ++$vol; '

Your requirements are very unclear to me.

Replies are listed 'Best First'.
Re^2: loading a hash of hashes from UNIX command output
by novy (Initiate) on Dec 06, 2009 at 23:28 UTC
    I'll send you what I've done so far tomorrow when I get to work. Basically what I need is a script that will tell the robot to unload the running tape back to it's home slot, and load the next in the list into the drive and so on, and make sure it doesn't load the same tape more than once during the entire backup. Also after the backup is done I need to remove all the tapes that that particular backup used off the list so the backup that's next in line doesn't overwrite any of them. Since I can only tell the robot to load a tape from a slot, I'd like to be able to do something like: tapeutil -f /dev/smc0 load $slot_nr(A00401) Come to think of it maybe an ordinary hash would do, but I still don't know how to load that inventory, which has multiple lines per record into a hash, and filter out everything except Slot and Tag.

      Sounds like you want to lookup the volume for a given slot address and that you want to do that for multiple volumes during the run of the program.

      If you have the inventory in a variable:

      my %slot_lkup = reverse map /^Slot address (\d+).*\n +Volume Tag[ .]+([^\n]+)/s, split /(?<=\n)(?! )/, $inventory; ... $slot_lkup{$vol} ...

      If you have the inventory in a file handle:

      my %slot_lkup; { my $slot; while (<$fh>) { if (/^Slot address (\d+)/) { $slot = $1; } elsif (/^ *Volume Tag[ .]+([^\n]+)/) { $slot_lkup{$1} = $slot; } } } ... $slot_lkup{$vol} ...