Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: Alphnumeric Matching

by Util (Priest)
on Jan 31, 2012 at 16:06 UTC ( #951015=note: print w/replies, xml ) Need Help??

in reply to Alphnumeric Matching

In all the code that you posted (both commented-out and uncommented), you populate @tapes_to_eject, but never *use* @tapes_to_eject. In your vmchange command, you use @_ directly (although obtusely).

You must either:

  1. Update @_ with a sorted copy of the tape list, or
  2. Use @tapes_to_eject instead of @_ in the vmchange command.

Here is how I would approach the problem:

#!perl use strict; use warnings; # Global vars: my $robot_num = 42; # Faked my $robot_host = 'localhost'; # Faked my $max_slots = 52; # Derived from original post. my $live_eject = 0; # for testing eject_tapes( qw( B4356R B0001R B1001R ) ); sub sort_tapes { my @tapes = @_; return sort { substr($a, 0, 1) cmp substr($b, 0, 1) or substr($a, 1, 4) <=> substr($b, 1, 4) or substr($a, 5, 1) cmp substr($b, 5, 1) } @tapes; } # This simpler version might be sufficient. #sub sort_tapes { return sort @_; } sub eject_tapes { warn "No tapes passed to eject_tapes()" and return if not @_; my @tapes_to_eject = sort_tapes(@_); while (@tapes_to_eject) { # splice() removes $max_slots tapes from # the front of @tapes_to_eject. my @batch_of_tapes = splice @tapes_to_eject, 0, $max_slots; my $tapes_joined_list = join ':', @batch_of_tapes; my @command = ( qw( /usr/openv/volmgr/bin/vmchange -res -multi_eject -w ), -rn => $robot_num, -rt => 'tld', -rh => $robot_host, -ml => $tapes_joined_list, ); if ($live_eject) { `@command`; } else { print "@command\n"; } # If any tapes remain for another batch of ejections, # then alert the operator and wait. if (@tapes_to_eject) { print <<"END_OF_MESSAGE"; The export door in robot $robot_num only holds $max_slots tape(s), and we have now ejected that many tapes. Please go and empty the import/export doors and press <RETURN> when you are finished. END_OF_MESSAGE <STDIN>; # Waits for <RETURN> } } }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://951015]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2017-06-24 14:53 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (559 votes). Check out past polls.