Monks, I'm in need of a second pair of eyes. I have the following bit of code to try to sort on the cat_name field.

foreach my $category (sort { ($list->{$_}->{cat_name} cmp $list->{$_}- +>{cat_name}) } keys %$list) { say $list->{$category}{cat_name}; }

I'm getting the following errors over and over:

Use of uninitialized value $_ in hash element at ./facebook.pl line 34 +. Use of uninitialized value $_ in hash element at ./facebook.pl line 34 +. Use of uninitialized value in string comparison (cmp) at ./facebook.pl + line 34. Use of uninitialized value in string comparison (cmp) at ./facebook.pl + line 34.

These repeated errors are followed by a listing of the categories, but they are in random order and are not sorted alphabetically. I have no idea why I am getting unitialized value errors. Each element in the hash has a cat_name key with a value.

Here's a sample of the data I'm trying to sort:

$list = { '174972792548177' => { 'places' => [ { '264651060353078' => { 'n +ame' => 'WHIP City Towing', 'l +ink' => 'https://www.facebook.com/WHIP-City-Towing-264651060353078/' } }, { '177166582312074' => { 'l +ink' => 'https://www.facebook.com/Center-City-Service-177166582312074 +/', 'n +ame' => 'Center City Service' } }, { '965119126910980' => { 'l +ink' => 'https://www.facebook.com/Michaels-Towing-965119126910980/', 'n +ame' => 'Michael\'s Towing' } } ], 'cat_name' => 'Towing Service' }, '199850580046875' => { 'cat_name' => 'Garage Door Services', 'places' => [ { '233152426881482' => { 'l +ink' => 'https://www.facebook.com/413doors/', 'n +ame' => '413 Doors & Home Services' } }, { '432129326916445' => { 'l +ink' => 'https://www.facebook.com/Jfcsbose/', 'n +ame' => 'Jfcsbose' } }, { '471289059572856' => { 'l +ink' => 'https://www.facebook.com/Conte-Door-Service-Inc-471289059572 +856/', 'n +ame' => 'Conte Door Service, Inc.' } } ] }, '127806747288007' => { 'places' => [ { '152911074751051' => { 'l +ink' => 'https://www.facebook.com/pages/Pioneer-Valley-Rider-Training +/152911074751051', 'n +ame' => 'Pioneer Valley Rider Training' } } ], 'cat_name' => 'Traffic School' }, };

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks


In reply to Getting unexpected errors when trying to sort hash of hashes by nysus

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.