on Tue, 30 Jul 2002 10:51:56 GMT, [EMAIL PROTECTED] (Jean
Berthold) wrote:
> In my case :
>
> 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 ...
There is no need to declare a prototype. If you turn on warnings, you
would get a
Odd number of elements in hash assignment at ...
warning on the line above, because Perl tries to make the following
anonymous hash:
my $record = { FS => SNAP_PATH,
TAPE_POS => undef # oops, no value available
};
If you 'use strict;', Perl would also give you fatal errors about
unallowed use of barewords, since you didn't quote FS, SNAP_PATH and
TAPE_POS. (It is always a good idea to turn on warnings and strictures
;-)
If you use the '=>' "synonym" for the comma operator, Perl
automatically quotes what's on the left of it, as long as it's a
"word".
> # first loop :
> open FH_DF, "df -k -F ufs | cut -c 56-100 |" or die "can't run
> command: $|";
> while (<FH_DF>)
> {
> $counter++ ;
You don't need $counter in this - see below
> chomp; # remove newline
> my $record =
> {
> FS => $_ ,
> SNAP_PATH => `fssnap -i $_ | grep /dev/fssnap | cut -c
> 33-45` ,
> 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 without problems. Why do you think it doesn't
function?
> }
>
> # Second loop:
> for ( my $i = 0; $i <= $counter; $i++ )
It would be more Perl-like to write this loop as
for my $element (@array)
without the need for a counter. In the body of the loop you can then
use "$element" instead of "$array[$i]".
> {
> if ( ( system("ufsdump 0f /dev/rmt/0n $array[$i]->SNAP_PATH")
You do know that system returns 0 on success, do you?
You may want to read 'perldoc -f system' to make sure you have the
return value you expect).
$array[$i]->SNAP_PATH should be $array[$i]->{SNAP_PATH}
(or $element->{SNAP_PATH})
> ) ) {
> $array[$i]->TAPE_POS => `mt status | grep "file no=" | cut
> -c 4-14`; ...
That should be $array[$i]->{TAPE_POS}, or $element->{TAPE_POS}. The
'=>' should be a '=', since you are doing an assigment.
> }
> else
> {
> $array[$i]->STATUS = "FAILED" ;
Again, this should be either $array[$i]->{STATUS} or $element->{STATUS}
> ...
> }
>
> }
One last note: if you are not sure about how/if your (complex)
datastructures are filled, you can 'use Data::Dumper;' to look at them:
use Data::Dumper;
my $ref_to_complex_datastructure = { #whatever };
print Dumper($ref_to_complex_datastructure);
--
felix
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]