Hello Jeff,
In fact, As you seen .. I'm newbie in Perl (in english too !)
I'm just trying to translate a korn-shell script to perl-script for learning
....
I try to use hashes like structs in C language, is it possible ?
I search an easy way like: declare a struct an put it's reference in an array
....
In perlfaq4 I think I found what I need...
$record = {
NAME => "Jason",
EMPNO => 132,
TITLE => "deputy peon",
AGE => 23,
SALARY => 37_000,
PALS => [ "Norbert", "Rhys", "Phineas"],
};
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 ...
# first loop :
open FH_DF, "df -k -F ufs | cut -c 56-100 |" or die "can't run command: $|";
while (<FH_DF>)
{
$counter++ ;
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 ...
}
# Second loop:
for ( my $i = 0; $i <= $counter; $i++ )
{
if ( ( system("ufsdump 0f /dev/rmt/0n $array[$i]->SNAP_PATH") ) )
{
$array[$i]->TAPE_POS => `mt status | grep "file no=" | cut -c 4-14`;
...
}
else
{
$array[$i]->STATUS = "FAILED" ;
...
}
}
Of course, I will follow your advice and use substr() function instead these
hugly cut ... :-)
All theses information will be used later to generate reports and alarm by
email.
Is it possible to implement this idea in a perl script ?
Thanks again for your help and have a nice day.
Jean Berthold
Jeff 'japhy' Pinyan a �crit :
> On Jul 29, Jean Berthold said:
>
> >open( FH_DF, system( "df -k -F ufs | cut -c 56-100" ) ) ;
>
> open() doesn't work like that. Or, more to the point, system() doesn't
> work like that. system() executes a command, and anything the commands
> prints gets printed. You want:
>
> open FH_DF, "df -k -F ufs | cut -c 56-100 |" or
> die "can't run command: $!";
>
> >while ( <FH_DF> )
> >{
> > $Slices{$key} = '$_' ;
> >}
>
> Where does $key come from? And why did you put $_ in single quotes?
> Remove the quotes around $_. And figure out what $key is.
>
> >for example, second loop :
> >while ($key) = each %Slice )
> >{
> > $Slice{$value} = `fssnap -i $key | grep /dev/fssnap | cut -c 33-45` ;
> >}
>
> Where did $value come from? And you're missing a '(' on your while loop.
>
> Perhaps you wanted to do:
>
> while (<FH_DF>) {
> chomp; # remove newline
> $Slices{$_} = `fssnap -i $_ | grep /dev/fssnap | cut -c 33-45`;
> }
>
> Although you could really use substr() instead of calling cut.
>
> --
> Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
> RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
> ** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
> <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
> [ I'm looking for programming work. If you like my work, let me know. ]
--
________________________________
Jean Berthold
EOS - energie ouest suisse
Chemin de Mornex 10 , CP 570
CH-1001 Lausanne , Switzerland
Tel. : +41 (0)21 341 24 58
Fax : +41 (0)21 341 20 49
E-Mail : [EMAIL PROTECTED]
________________________________