in reply to What does $, = " " do in this code?
What others have said, yes. What they didn't address is the fact that $, - like any other special variable - is a global variable.
So, this code is badly behaved because it changes this variable's content for the caller also, from the first invocation of this subroutine until the end of it's runtime. What it should do would be at least:
sub dumpvar { ... my $saved_sep = $,; $, = " "; # Iterate through the symbol table, which contains glob values ... $, = $saved_sep; # restore original value }
or, more concise
local $, = " "; # localize the the change to this scope
See local.
|
|---|