Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I am attempting to create a filehandle that reads the output of a TSM query (tape drive status) from a file and then creates a hash table of the library drive number and its corresponding status.

Here is what the TSM output file typically looks like:

ANR8330I LTO volume 000165L1 is mounted R/O in drive MT1.0.0.3 (mt1.0.0.3), status: IN USE.
ANR8330I LTO volume 000290L1 is mounted R/W in drive MT1.0.0.2 (mt1.0.0.2), status: IN USE.
ANR8329I LTO volume 000114L1 is mounted R/W in drive MT0.0.0.2 (mt0.0.0.2), status: IDLE.

I want to create a hash table named %drvstat

So, for the above example, the hash slices would be:

$drvstat{"MT1.0.0.2"} = 'IN USE'
$drvstat{"MT0.0.0.2"} = 'IDLE'

I am a novice and am having a bit of trouble getting started, anyone willing to help a newbie out? Thanks!

  • Comment on Read lines from file and place into hash table

Replies are listed 'Best First'.
Re: Read lines from file and place into hash table
by jZed (Prior) on Mar 30, 2004 at 00:22 UTC
    #!perl -w use strict; my %hash; for (<DATA>) { if ( /\((.+)\), status: (.+)$/ ) { $hash{$1}=$2; } } use Data::Dumper; print Dumper \%hash; __DATA__ ANR8330I LTO volume 000165L1 is mounted R/O in drive MT1.0.0.3 (mt1.0. +0.3), status: IN USE. ANR8330I LTO volume 000290L1 is mounted R/W in drive MT1.0.0.2 (mt1.0. +0.2), status: IN USE. ANR8329I LTO volume 000114L1 is mounted R/W in drive MT0.0.0.2 (mt0.0. +0.2), status: IDLE.
Re: Read lines from file and place into hash table
by Anonymous Monk on Mar 30, 2004 at 17:03 UTC
    Thanks, but how would I do this using a filehandle, since the data I wish to read is in a seperate file?