On Tue, 30 Jul 2002, Jean Berthold wrote:
> my @array ;
> my $counter = 0 ;
> # how to declare the prototype for the record used below ???
> my $record = { FS, SNAP_PATH, TAPE_POS } ; # don't function ...
You don't have to declare the keys of a hash beforehand.
When you say
my $record = {
a => 'b',
c => 'd' };
a reference to the anonymous hash you have on the LHS is stored in $rec.
perldoc perlreftut, perldoc perlref, perldoc perllol
my $record = { FS, SNAP_PATH, TAPE_POS }; works like this. The list is
split into two elements at a time, the first element becomes the key and
the second one the value. In your case you have 3 elements and you will
get an error like 'Odd number of elements in anonymous hash at line ...'
>
> # first loop :
> open FH_DF, "df -k -F ufs | cut -c 56-100 |" or die "can't run command: $|";
This should be open ..... or die "can't run command: $!" not $|
perldoc -f open
> while (<FH_DF>)
> {
> $counter++ ;
> chomp; # remove newline
> my $record =
> {
> FS => $_ ,
> SNAP_PATH => `fssnap -i $_ | grep /dev/fssnap | cut -c 33-45` ,
What does the output of fssnap look like, if it spans across multiple
lines you will end up with some extra key value pairs in you hash.
> TAPE_POS => undef ,
> STATUS => undef ,
> };
>
> # TAPE_POS and STATUS will be filled later
> # Now, I need to store this record into a array ...
>
> push( @array, $record ) ; # That don't function ...
This should work, your @array is a array of hashes or hash references. Are
you sure this doesn't work.
> }
>
> # Second loop:
> for ( my $i = 0; $i <= $counter; $i++ )
You can do away with $counter totally, just loop through @array like
this
foreach (@array) {
# Now $_ is an alias for every element of @array that is being processed
# Changing $_ will also change the contents of @array
# perldoc perlsyn
}
> {
> if ( ( system("ufsdump 0f /dev/rmt/0n $array[$i]->SNAP_PATH") ) )
system returns a 0 if the command succeeds, this will cause the if to
fail. You will have to check $? for any error, perldoc -f system shows you
how to do the same
> {
> $array[$i]->TAPE_POS => `mt status | grep "file no=" | cut -c 4-14`;
> ...
> }
> else
> {
> $array[$i]->STATUS = "FAILED" ;
> ...
> }
>
> }
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]