My apologies, of course, here's the script.. it's my first test just to see how well the module worked... Any XML related stuff is being called by Net::Amazon::S3 behind the scenes.

Maybe I'm missing something obvious (hope not)?

#!/usr/bin/perl use strict; use warnings; use Net::Amazon::S3; my $aws_access_key_id = 'XXXXXXXXXXXXXXXXXXXX'; my $aws_secret_access_key = 'xxxxxxxxxxxxxxxxxxxx'; my $chosen_bucket = $ARGV[0] || 'default_bucketname'; my $bytes_used = 0; my $s3 = Net::Amazon::S3->new( { aws_access_key_id => $aws_access_key_id, aws_secret_access_key => $aws_secret_access_key } ); my $bucket_now = $s3->bucket($chosen_bucket); my $response = $bucket_now->list_all or die $s3->err . ": " . $s3 +->errstr; &byte_counter; my $num_keys = commify($#{ $response->{keys} }); print $num_keys . " keys in bucket $chosen_bucket." . $/; $bytes_used = commify($bytes_used); print $bytes_used . " total bytes used in bucket $chosen_bucket." . $/ +; #--- sub byte_counter { foreach my $key ( @{ $response->{keys} } ) { $bytes_used += $key->{size}; } } sub commify { my $text = reverse $_[0]; $text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g; return scalar reverse $text; }


Note that Amazon's answers come back in XML which is why the XML stuff is needed...

-Harold

In reply to Re^2: Module uses loads of CPU.. or is it me by hsinclai
in thread Module uses loads of CPU.. or is it me by hsinclai

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.