[Boulder.pm] Adding undefined variables?

DeAndre deandre at deandrecarroll.com
Fri Feb 14 11:22:46 PST 2014


Use 'exists' on hashes to check whether there is an entry for a key.

For example:

$Usage{$MAC}=0 if ( ! exists $Usage{$MAC} );

This should alleviate your warnings problem.


Sent from my Galaxy S®III

-------- Original message --------
From: "Robert L. Harris" <robert.l.harris at gmail.com> 
Date:02/14/2014  12:11 PM  (GMT-07:00) 
To: boulder-pm <boulder-pm at pm.org> 
Subject: [Boulder.pm] Adding undefined variables? 


Quicky here.  I'm processing logs do not necessarily know the MAC's of IP's I'm looking to find usage for.  Right now I'm doing this:



$Usage{$MAC}=0 if ( ! $Usage{$MAC} );
$Usage{$MAC}=$Usage{$MAC}+$NewUsage;


I could have swore there was a way to say something along the line of just set $Usage{$MAC} to Zero if it's not defined.  Without turning off warnings is my goal.


Anyone know a better or cleaner way to do this?

Robert


-- 
:wq!
---------------------------------------------------------------------------
Robert L. Harris

DISCLAIMER:
      These are MY OPINIONS             With Dreams To Be A King,
       ALONE.  I speak for                      First One Should Be A Man
       no-one else.                                     - Manowar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/boulder-pm/attachments/20140214/188a839e/attachment.html>


More information about the Boulder-pm mailing list