in reply to Re: chomp any data structure recursively
in thread chomp any data structure recursively

Which $_ is the outer one?
The refs should see the values of @_. I can't think of a reason why they wouldn't (help me out here :)

In short, this is the pseudocode:
sub mychomp { for (@_){ $_ is iterable && mychomp it || $_ is a scalar ref && try to chomp its scalar || $_ is not any other reference && chomp it } }
I'd be quite surprised my code works with many different structures if it's bugged.

Could you please give an example of what could go wrong? (of course accompanied by an explanation :)

Anyway, thanks for pointing out that it's bugged.

2;0 juerd@ouranos:~$ perl -e'undef christmas' Segmentation fault 2;139 juerd@ouranos:~$

Replies are listed 'Best First'.
Re: Re: Re: chomp any data structure recursively
by merlyn (Sage) on Dec 21, 2001 at 01:45 UTC
    Looking at just this part:
    sub mychomp { ref eq 'ARRAY' ...
    That's ref of $_, which you have not yet set up, so it's the outer $_ from the caller. Luckily, you didn't test your subroutine with something that needed ref-ARRAY treatment as an argument. {grin}.

    -- Randal L. Schwartz, Perl hacker

      I always thought and assumed the for modifier would set $_ ...
      (You did see it, didn't you? It's just before the sub's closing curly.)

      2;0 juerd@ouranos:~$ perl -e'undef christmas' Segmentation fault 2;139 juerd@ouranos:~$

        Argh. You do have a for, waaaaaaaay down there. OK, I'm gonna write this one down as a tough-to-maintain snippet then. Seeing that, you're fine.

        -- Randal L. Schwartz, Perl hacker