Hi geniuses,
I'm processing some video data from Google's API.
I have an array, @vidids, that could have up to several thousand elements which are video IDs. I want to get the view count for each video ID.
I want to loop through the array, taking 50 elements on each pass (which is the max allowed) and getting the view counts for those. These counts I want to stuff into array @counts, until the @vidids is empty.
With limited understanding of perl, I imagine starting out something like:
my $idees = join ',', @vidids[0..49]; #the id's must be comma separated
foreach (@vidids) {
my $uri = "https://www.googleapis.com/youtube/v3/videos?part=items(vie
+wCount)&id=$idees&key=$API_KEY"; ##$idees is the 50-max comma separa
+ted string of video IDs
my $result = get($uri);
my $json = decode_json($result);
for my $i( @{$json->{items}} ) {
push @counts, $i->{viewCount};
}
$idees = "the next 50 elements from @vidids..." #and keep looping unti
+l all are processed
}
I have all of it working except the looping through @vidids. I just don't have the grasp of perl operations to put it together well. Also, what if there aren't 50 left at the end? I don't want to create null elements. Thanks!
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.