Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: undefined hash elements

by rmcgowan (Sexton)
on Dec 18, 2013 at 21:25 UTC ( [id://1067714]=note: print w/replies, xml ) Need Help??


in reply to undefined hash elements

What operating system are you using? I have access to Linux and Solaris systems, but cannot duplicate your problem. I get multiple lines on tty output (to the terminal) but when I run the 'df' in backquotes, all the data is on one line, for each device. This is also true if I pipe 'df' output through 'grep', just as you found.

What I don't understand is why the same doesn't happen for you with the backquotes.

As an untested suggestion, you could do your 'split' into an explicit variable declared outside the loop, and check it's size:

my ($tmp, $prev); # ...loop here if (@tmp == 1) { @prev = @tmp; next; }

You could then merge the two arrays to process with the slice. Perhaps not the most elegant solution, but it has the advantage of not failing if the df output ever changes to be single lines in all cases. Since this is done before creating the hash, it should fix at least that part of the problem.

Replies are listed 'Best First'.
Re^2: undefined hash elements
by MrTEE (Novice) on Dec 18, 2013 at 22:21 UTC

    I am using linux. maybe I am too hung up on this undefined hash values thing. maybe it is better to masage the data going in. i have seen this undef error so many times when using hashes that to rememdy i just take off 'strict' - which ultimately causes even more headaches. hey check this out

    df -Ph | perl -ne 'chomp; printf "\n%-40s %8s %8s %8s %8s %-20s", spli +t / +/, $_, 6 ; '
      mayb ei am using the wrong df :

      check this out. this is df -k

      [icapsper@casperbox .wjohnson]$ df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup00-LogVol00 28G 9.4G 17G 37% / /dev/sda1 99M 27M 67M 29% /boot tmpfs 2.9G 0 2.9G 0% /dev/shm /dev/mapper/VolGroupPROD-ExportHome 15G 3.4G 11G 24% /export/home /dev/mapper/VolGroupPROD-Production 15G 1.5G 13G 11% /production /dev/mapper/VolGroupPROD-ProdLog 30G 20G 8.4G 71% /production/log /dev/mapper/VolGroupPROD-ProdArchive 9.9G 1.7G 7.8G 18% /production/archive

      and this is df -P (which is better ) the df -P does not put the mounted files on a separate line

      [casper@casperbox .wjohnson]$ df -P Filesystem 1024-blocks Used Available Capacity Mounted on /dev/mapper/VolGroup00-LogVol00 28313732 9812576 17039704 37% + / /dev/sda1 101086 27516 68351 29% /boot tmpfs 2987896 0 2987896 0% /dev/shm /dev/mapper/VolGroupPROD-ExportHome 15481840 3495504 11199904 + 24% /export/home /dev/mapper/VolGroupPROD-Production 15481840 1523736 13171672 + 11% /production /dev/mapper/VolGroupPROD-ProdLog 30963708 20621072 8769772 71 +% /production/log /dev/mapper/VolGroupPROD-ProdArchive 10313016 1693936 8095204 + 18% /production/archive [icapfo@usprvfotr25s .wjohnson]$

      maybe I am using wrong df

        i pity the fool who uses the wrong df flag in his perl script...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1067714]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-24 07:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found