Perl Help Snippits
 
 
#
# Initialize Month Hash
#

my %month;
%month = (
 "Jan" => "01",
 "Feb" => "02",
 "Mar" => "03",
 "Apr" => "04",
 "May" => "05",
 "Jun" => "06",
 "Jul" => "07",
 "Aug" => "08",
 "Sep" => "09",
 "Oct" => "10",
 "Nov" => "11",
 "Dec" => "12",
);
 

# 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>){
   my @tmp_arry;
   @tmp_arry=split(/,/,$_);
   $hash_fs{$tmp_arry[1]}=$tmp_arry[2];
}
 

# 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 
# opt on HP-UX
sub check_sun_var {
        $vardir=`df -k /var`;
        @var_out=split(/\n/,$vardir);
        $var_out[1] =~ s/%\s+\/var$//;
        $vperfull = substr($var_out[1], -4 , 4 );
}
 

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;

 
 
 
 
 
 
 
 
 
  Personal Help Snipits
 jeb527@yahoo.com
 john.baur@edward-NOspam-jones.com
 Resume Copyright ©2000