Recursively printing data structures in Perl

前端 未结 8 1900
粉色の甜心
粉色の甜心 2021-01-13 05:32

I am currently learning Perl. I have Perl hash that contains references to hashes and arrays. The hashes and arrays may in turn contain references to other hashes/arrays.

8条回答
  •  清酒与你
    2021-01-13 05:39

    1. Always use use strict;
    2. To be a good boy, use use warnings as well.
    3. The names you use for subroutines should make it obvious what the subroutine does. "recurseErrors" kind of violates that principle. Yes, it does recurse. But what errors?
    4. On the first line of each subroutine you should declare and initialize any parameters. recurseErrors first declares $str and then declares its parameters.
    5. Don't mix shift and = @_ like you do in str()
    6. You might consider breaking up what is now called recurseErrors into specialized routines for handling arrays and hashes.
    7. There's no need to quote variables like you do on lines 99 and 109.

    Apart from that I think your instructor had a bad day that day.

提交回复
热议问题