-1

I have a nested data structure that I would like to iterate through but my code doesn't seem to be working. No error is displayed. The only way I can access the values is through Data::Dumper

my $statuses = $nt->followers_ids({ screen_name => 'arty00l' });

for $statuses ( keys %HoA ) {
    print "$statuses: @{ $HoA{$statuses} }\n";
}

When I use Data::Dumper it returns:

$VAR1 = {
      'next_cursor_str' => '0'
      'previous_cursor_str' =>
      'next_cursor' => 0,
      'ids' => [
                 98986124,
                 2325887071,
                 2973383805,
                 445207709,
                 316396146,
                 445684239,
                 1265153311,
                 1571662172,
                 2837484211,
                 2881634626,
                 3199312306,
                 2474691877,
                 118090760,
                 2311971607,
                 2298622765,
                 993360248,
                 539085432,
                 52893302,
                 2268568237,
                 20957562,
                 839072018,
                 112728024,
                 140079968,
                 33923443,
                 1450282772,
                 891377682,
                 274127782,
                 284372072,
                 772748041,
                 440211079,
                 30327403,
                 2524695894,
                 354150373,
                 2292575056,
                 68891742,
                 2750381484,
                 316181803,
                 518111226,
                 239159047,
                 284729726,
                 334984455,
                 147508104,
                 159389938,
                 2740303325,
                 212023751,
                 395112717,
                 26411861,
                 172639836,
                 2288625106,
                 24906328,
                 358116535,
                 1493819347,
                 2502142927,
                 30223189,
                 259649352,
                 1375294206,
                 71677965,
                 159632801,
                 24352067,
                 2412589867,
                 1258256690,
                 130765107,
                 1391278070,
                 503718605,
                 1710629294,
                 859406618,
                 362707700,
                 233370937,
                 1707976981,
                 1612009542,
                 407474584,
                 2343960014,
                 237479477,
                 53574764,
                 947969479,
                 276289027,
                 579430568,
                 2474917902,
                 1541546262,
                 2241494730,
                 339179937,
                 77080603,
                 824308147,
                 2434583982,
                 2433258235,
                 1541460948,
                 492471146,
                 2356642530,
                 2327984822,
                 19464956,
                 11245502,
                 14469397,
                 167661601,
                 154072320,
                 167781199,
                 552094012,
                 130158658,
                 1613786857,
                 336603208,
                 32135630,
                 415425580,
                 350058703,
                 65996058,
                 12874852,
                 280884837,
                 106834295,
                 17393362,
                 236185268,
                 62970600,
                 311476854,
                 2289008047,
                 18566247,
                 121598314,
                 1002657601,
                 460224943,
                 376635771,
                 1365484814,
                 2256281789,
                 26632199,
                 2255441468,
                 465013083,
                 1571678467,
                 357547927,
                 259989366,
                 1500479640,
                 19276719,
                 138261007,
                 1030773654,
                 70493313,
                 1406767260,
                 1052462281,
                 72996112,
                 806695453,
                 13027572,
                 555957901,
                 15481158,
                 576112079,
                 920396502,
                 127750483,
                 38542781,
                 42609957,
                 786004562,
                 18289572,
                 412065028,
                 618501933,
                 157882740,
                 952753260,
                 66465341,
                 620076440,
                 23841368,
                 79809731,
                 82091271,
                 311539323,
                 948095714,
                 17191125,
                 804631266,
                 942721417,
                 20525016,
                 403509765,
                 380994873,
                 962970726,
                 182120373,
                 24739893,
                 924945650,
                 36129150,
                 35599004,
                 18068152,
                 189730793,
                 382350502,
                 14910806,
                 84141876,
                 15931491,
                 390450302,
                 850374512,
                 889168250,
                 444940567,
                 58422750,
                 206862729,
                 592305280,
                 225529356,
                 339779020,
                 15957929,
                 587465971,
                 18627463,
                 17485416,
                 715927987,
                 18104730,
                 866372191,
                 564024328,
                 54039049,
                 30588766,
                 124058421,
                 201760549,
                 221005474,
                 82243231,
                 60500502,
                 564774340,
                 564769748,
                 579311942,
                 608952513,
                 509637742,
                 606863740,
                 594839703,
                 151615289,
                 216747794,
                 176608284,
                 635013126,
                 249857095,
                 321985491,
                 18805118,
                 112757114,
                 111065326,
                 111234967
               ],
      'previous_cursor' => 0
    };

What should the code look like after this line?

my $statuses = $nt->followers_ids({ screen_name => 'arty00l'})
Borodin
  • 126,100
  • 9
  • 70
  • 144
  • My guess is you're using Net::Twitter, but it would be helpful if you made that clear in your question. – oalders Jun 25 '15 at 16:43

2 Answers2

1

First of all, always use use strict; use warnings;. It'll catch your errors earlier and more visibly.

On to the question. You didn't specify what you wanted to iterate over. You named the variable "statuses", but there's nothing resembling a status in the variable's output. Presumably, you want to output the ids. For that, use

print "@{ $VAR1->{ids} }\n";

If $VAR1 is a reference to %HoA, the the code is actually

print "@{ $HoA{ids} }\n";
ikegami
  • 367,544
  • 15
  • 269
  • 518
0

You say

When I use Data::Dumper it returns

but you don't say how you are using Data::Dumper or what it is that you're dumping

The code you show isn't doing anything with the return value of followers_ids. This line assigns a value to $statuses

my $statuses = $nt->followers_ids({ screen_name => 'arty00l' });

which is immediately discarded and overwritten by this loop, which uses the same variable

for $statuses ( keys %HoA ) {
    print "$statuses: @{ $HoA{$statuses} }\n";
}

and as you don't say what %HoA is we can't help you further until you supply more information

According to the module documentation, the followers_ids method

Returns a reference to an array of numeric IDs for every user following the specified user

That means all you have to do to display its contents is to write

my $statuses = $nt->followers_ids({ screen_name => 'arty00l' });
print "$_\n" for @$statuses;

but that will just give you a list of IDs

If you elaborate on what you are trying to do then I am sure we can help you better

Borodin
  • 126,100
  • 9
  • 70
  • 144