From robert.l.harris at gmail.com Fri Feb 14 11:11:47 2014 From: robert.l.harris at gmail.com (Robert L. Harris) Date: Fri, 14 Feb 2014 12:11:47 -0700 Subject: [Boulder.pm] Adding undefined variables? Message-ID: 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: From deandre at deandrecarroll.com Fri Feb 14 11:22:46 2014 From: deandre at deandrecarroll.com (DeAndre) Date: Fri, 14 Feb 2014 12:22:46 -0700 Subject: [Boulder.pm] Adding undefined variables? Message-ID: <49w1qexw9fo75jjk8c5lx55t.1392405766096@email.android.com> 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" Date:02/14/2014 12:11 PM (GMT-07:00) To: boulder-pm 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: From eddow1976 at yahoo.com Fri Feb 14 14:06:05 2014 From: eddow1976 at yahoo.com (Ed Dow) Date: Fri, 14 Feb 2014 14:06:05 -0800 (PST) Subject: [Boulder.pm] Boulder-pm Digest, Vol 41, Issue 1 In-Reply-To: References: Message-ID: <1392415565.5682.YahooMailNeo@web163902.mail.gq1.yahoo.com> 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" 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" To: boulder-pm Subject: [Boulder.pm] Adding undefined variables? Message-ID: ??? 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: ------------------------------ Message: 2 Date: Fri, 14 Feb 2014 12:22:46 -0700 From: DeAndre 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" Date:02/14/2014? 12:11 PM? (GMT-07:00) To: boulder-pm 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: ------------------------------ 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: From gaurav at ggvaidya.com Fri Feb 14 19:20:01 2014 From: gaurav at ggvaidya.com (Gaurav Vaidya) Date: Fri, 14 Feb 2014 20:20:01 -0700 Subject: [Boulder.pm] Boulder-pm Digest, Vol 41, Issue 1 In-Reply-To: References: Message-ID: <9F366B16-B4FE-4F69-9119-E0AA90FA37F7@ggvaidya.com> Hullo! On 14 Feb, 2014, at 1:00 pm, boulder-pm-request at pm.org wrote: > 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. You might be thinking of the ?logical defined-or? operator: http://perldoc.perl.org/perlop.html#Logical-Defined-Or I think you could track your usage counts like this: https://gist.github.com/gaurav/9014086 Hope that helps! cheers, Gaurav