in reply to join should polymorph on hashes

I suppose ... but, saying something like

sub hash_join { my ($hash_ref, $sep1, $sep2) = @_; my $string = ""; $string .= "${_}${sep}$hash_ref->{$_}${sep2}" for sort keys %$hash_ref; $string; } my $string = hash_join \%ENV, " = ", "\n"; print $string;

works just as well, as well as having the benefit of being very obvious as to what you're doing. Your join would have to have too many new arguments, I think. But, that's just my opinion on the matter.

Replies are listed 'Best First'.
Re: Re: join should polymorph on hashes
by japhy (Canon) on May 02, 2001 at 01:49 UTC
    I'd do:
    sub hash_join (\%$$) { my ($h, $between, $end) = @_; my $str; while (my($k,$v) = each %$h) { $str .= "$k$between$v$end"; } return $str; } print hash_join %ENV, "=", "\n";


    japhy -- Perl and Regex Hacker