[Boulder.pm] Boulder-pm Digest, Vol 41, Issue 1

Ed Dow eddow1976 at yahoo.com
Fri Feb 14 14:06:05 PST 2014



It's the ternary logic you're after, I think.   ;-)  

Tried to comment but I'm a programmer not a tech writer.  


#!/usr/bin/perl

my $MAC="10.0.0.1";
my $NewUsage=150;
my %Usage=();

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


#   Assgin                   condition                      0 if T else F assign new usage

$Usage{$MAC}= (!exists($Usage{$MAC}) ? 0:$Usage{$MAC}+$NewUsage);

print "This should be 0\n";
foreach $key(keys %Usage){ print "$key -> $Usage{$key}\n"; }


$Usage{$MAC}= (!exists($Usage{$MAC}) ? 0:$Usage{$MAC}+$NewUsage);

print "This should be 150\n";
foreach $key(keys %Usage){ print "$key -> $Usage{$key}\n"; }





On Friday, February 14, 2014 1:00 PM, "boulder-pm-request at pm.org" <boulder-pm-request at pm.org> wrote:
 
Send Boulder-pm mailing list submissions to
    boulder-pm at pm.org

To subscribe or unsubscribe via the World Wide Web, visit
    http://mail.pm.org/mailman/listinfo/boulder-pm
or, via email, send a message with subject or body 'help' to
    boulder-pm-request at pm.org

You can reach the person managing the list at
    boulder-pm-owner at pm.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Boulder-pm digest..."


Today's Topics:

   1. Adding undefined variables? (Robert L. Harris)
   2. Re: Adding undefined variables? (DeAndre)


----------------------------------------------------------------------

Message: 1
Date: Fri, 14 Feb 2014 12:11:47 -0700
From: "Robert L. Harris" <robert.l.harris at gmail.com>
To: boulder-pm <boulder-pm at pm.org>
Subject: [Boulder.pm] Adding undefined variables?
Message-ID:
    <CAOXayVvTzCpzaD6gjJvWOfcV_KxshdxSVGZSBj07NKSPJehArg at mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

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/9057d25f/attachment-0001.html>

------------------------------

Message: 2
Date: Fri, 14 Feb 2014 12:22:46 -0700
From: DeAndre <deandre at deandrecarroll.com>
To: boulder-pm at pm.org
Subject: Re: [Boulder.pm] Adding undefined variables?
Message-ID: <49w1qexw9fo75jjk8c5lx55t.1392405766096 at email.android.com>
Content-Type: text/plain; charset="utf-8"

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-0001.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Boulder-pm mailing list
Boulder-pm at pm.org
http://mail.pm.org/mailman/listinfo/boulder-pm

------------------------------

End of Boulder-pm Digest, Vol 41, Issue 1
*****************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/boulder-pm/attachments/20140214/5eeee0b8/attachment.html>


More information about the Boulder-pm mailing list