| #
# Initialize Month Hash # my %month;
|
# Read conf file variables into a HASH
# cat a conf file, grep for a term then # load into string variable # then split string var into array and then # split into a hash table. # $conf="/home/jeb/conf"; my $hashf; $hashf = `$cat $conf | $grep '^hashst'`; my @hash_array; @hash_array=split (/\n/, $hashf); foreach (<@hash_array>){
|
| # Standard stuff to find local utilities.
$cat="/usr/bin/cat"; $grep="/usr/bin/grep"; $cut="/usr/bin/cut";
|
# Subroutine to return percent full # opt on Solaris sub check_sun_opt { $optdir=`df -k /opt`; @opt_out=split(/\n/,$optdir); $opt_out[1] =~ s/%\s+\/opt$//; $perfull = substr($opt_out[1], -4 , 4 ); } # Subroutine to return percent full
|
Example of multi-dimension array, Hash of Hashes
%hashOfHashes = (
"hashElement-1" => {
"item1" => "Name",
"item2" => "/HomeDirectory/user",
"item3" => "shell",
"item4" => "Desc",
"item5" => "Group",
},
"hashElement-2" => {
"item1" => "Name",
"item2" => "/HomeDirectory/user",
"item3" => "shell",
"item4" => "Desc",
"item5" => "Group",
},
"hashElement-2" => {
"item1" => "Name",
"item2" => "/HomeDirectory/user",
"item3" => "shell",
"item4" => "Desc",
"item5" => "Group",
},
"hashElement3" => {
"item1" => "Name",
"item2" => "/HomeDirectory/user",
"item3" => "shell",
"item4" => "Desc",
"item5" => "Group",
},
);
how to access data:
foreach $key ( keys %hashOfHashes ) {
print " prefix key >$key< \n";
foreach $detailKey ( keys %{$hashOfHashes{$key}} ) {
print " detailKey >$detailKey< \n";
print " detail element >$hashOfHashes{$key}{$detailKey}< \n";
}
}
|
|
#!/usr/bin/perl -w
#
# Script takes a sub list of a master
# list of serial numbers or names, and returns
# a list of elements from the master that
# do not exist in the sublist.
# baurj:wq
#
my $sub_list = "./subList";
my $total_list = "./All";
my $outfile = "./difference";
open ( IN, "$sub_list" )or die " could not open $sub_list \n";
while ( <IN> ){
chomp;
$hash{$_}="1";
}
open ( OUT, ">$outfile" ) or die " could not open $outfile \n";
open ( ALL, "$total_list" ) or die " could not open $total_list \n";
while ( <ALL> ) {
chomp;
unless ( $hash{$_} ) {
print OUT "$_\n";
}
}
close OUT;
|
|
|
![]() |
|
|
| jeb527@yahoo.com
john.baur@edward-NOspam-jones.com |
Resume | Copyright ©2000 |