[Za-pm] Graphs with Perl
Nick Cleaton
nick at cleaton.net
Thu Jun 5 04:44:15 CDT 2003
On Thu, Jun 05, 2003 at 09:56:45AM +0200, Bartho Saaiman wrote:
> Since I am on a go now, I decided to add some more..
>
> I have attached the code to the latest 'version' of my script and some
> output. Any comments...
[SNIP]
> sub graph
> {
> my ($size, $total) = @_;
> my $bar = '**************************************************';
>
> return substr($bar, 0, int($size * length($bar) / $total));
> }
I would rather use the 'x' operator than substr there:
sub graph
{
my ($size, $total) = @_;
return '*' x (50 * $size/$total);
}
But that's just personal preference. There's nothing wrong with
your way.
> while (<>)
> {
> my ($from, $bytes, $to) = /^.*? SMS .*?(\w+\@[.\w]+).*? sent (.*?) characters to (.*?)$/;
As Spike mentioned earlier, you sometimes get '.' and '-' in email
usernames. '-' is also allowed in hostnames, so how about:
my ($from, $bytes, $to) = /^.*? SMS .*?([.\w-]+\@[.\w-]+).*? sent (.*?) characters to (.*?)$/;
[SNIP]
> else
> {
> warn 'Ignoring: ' . $_ . "\n";
> }
Good, I like warnings :) If you do get a '.' or a '-' or something
else in an email address, at least you'll find out about it.
--
Nick
More information about the Za-pm
mailing list