I do not understand why scalar is returning me 2/8? Also isn't scalar %hashname the recommended way to get a count of the key or values in any hash?
I tried scalar $sc{$key} and it gave me an error saying my value not numeric. It was trying to count the string /var/adm/crash. My goal is to get a count of the values in each hash. SCALAR VALUE :2/8 SAVECRASH :1 SAVECRASH_DIR :/var/adm/crash => count here should be 2 CRASHCONF_REPLACE :0 CRASHCONF_ENABLED :1 CRASHCONF_READ_FSTAB :1 CRASH_INCLUDED_PAGES :"" => count here should be 4 Thank you Derek #!/usr/bin/perl ##-- INIT environment --## require 5.6.1; use strict; use warnings; use diagnostics; #use MIME::Lite; $ENV{"PATH"} = qq(/usr/sbin:/usr/bin:/usr/local/log); delete @ENV{qw (IFS CDPATH ENV KSH_ENV) }; my (%vg,%lvln) = (); my (%sc,%cc) = (); #my ($sc,$cc) = 0; my $savecrash = qq(/etc/rc.config.d/savecrash); my $crashconf = qq(/etc/rc.config.d/crashconf); my $log = qq(/usr/local/log/hpux_verify.pl.log); ##-- BEGIN ROUTINES --## my $overide = $SIG{__DIE__}; ## get error handler currently assigned 2 die $SIG{__DIE__} = sub { my $error = shift; ## error now holds the mesg passed to die $overide->($error) if (ref $overide); print LOG ($error); }; sub dateme { my ($month,$day,$year) = (localtime)[4,3,5]; sprintf ("%02d/%02d/%02d\n", $month+1,$day,($year % 100)); } ##-- BEGIN MAIN --## ##-- savecrash config check --## open (LOG, ">>$log") || die "unable to open $log $!"; open (SC, "+<$savecrash") || die "unable to open $savecrash $!"; my ($key,$value) = 0; foreach (<SC>) { next if (/\A#/g); if ( /(?i)savecrash=\d+/ || /(?i)savecrash_dir=\W+\w+/ ) { chomp; ($key,$value) = split/=/; $sc{$key} = $value; } } print "SCALAR VALUE\t:", scalar %sc,"\n"; if (exists $sc{$key} ) { while (($key,$value) = each %sc) { print "$key\t:$value\n"; } } else { print "Warning: savecrash hash is empty therefore parameters in savecrash file are commented out\n"; } close (SC) || warn "unable to close $savecrash $!"; ##-- crashconf config check --## open (CC, "+<$crashconf") || die "unable to open $crashconf $!"; my ($key1,$value1) = 0; foreach (<CC>) { next if (/\A#/g); if ( /(?i)crashconf_\w*/ || /(?i)crash_\w+\W+/) { chomp; ($key1,$value1) = split/=/; $cc{$key1} = $value1; s<crash_excluded_\w+\W+>//gi; } } #if (scalar $cc{$key1} >= 1 ) { print "SCALAR:\t",scalar $cc{$key1},"\n"; while (($key1,$value1) = each %cc) { print "$key1\t:$value1\n"; } #} #else { # print "Warning: crashconf hash is empty # therefore parameters in crashconf file are commented out\n"; #} close (CC) || warn "unable to close $crashconf $!"; close (LOG) || warn "unable to close $log $!"; Cardinal Health -- Working together. For life. (sm) _________________________________________________ This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information. If you have received it in error, please notify the sender immediately and delete the original. Any other use of the email by you is prohibited. Dansk - Deutsch - Espanol - Francais - Italiano - Japanese - Nederlands - Norsk - Portuguese - Svenska: www.cardinalhealth.com/legal/email