in reply to Re: Recursive subroutines with sort
in thread Recursive subroutines with sort

Hah. I didn't know that. I have exclusively used the BLOCK form to this date. It's nice being able to refer to a sub by name, but when is it useful that sub being able to recurse?


holli

You can lead your users to water, but alas, you cannot drown them.

Replies are listed 'Best First'.
Re^3: Recursive subroutines with sort
by LanX (Saint) on Jul 08, 2019 at 12:46 UTC
    > but when is it useful that sub being able to recurse?

    what comes to mind are chained comparisons in sort °

    sort { $a->[0] cmp $b->[0] or $a->[1] cmp $b->[1] # * or $a->[2] cmp $b->[2] # * or ... # * } @AoA # *) only check if former was equal == 0 == false

    if you don't know the number of fields, recursive comparisons come in handy.

    I'm bu-la-zy, so constructing the recursion is left as exercise. ;-)

    HTH!

    update

    In hindsight ... this particular case could also be solved in a loop.

    So think about a more complicated data structures like trees to be sorted.

    In the end it's about convenience ... every loop can be expressed as recursion and vice versa.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

    °) see examples in code from line 39 onwards