in reply to Perl segfaults: Why?
What is the result of adding an integer to a filehandle?
The addition operator will ask for the numeric representation of its arguments, so they will be coerced into numbers if they're not already. So the real question is: "What is the result of numifying a filehandle?"
Many things are considered file handles in Perl
In this case, you have a reference to a glob
$ perl -MScalar::Util=reftype -le'open my $fh, "<", \$buf; print refty +pe($fh)' GLOB
When you numify a reference, you get the memory address at which the referenced object is located.
$ perl -le'open my $fh, "<", \$buf; print $fh; printf "0x%x\n", 0+$fh' GLOB(0x814ec28) 0x814ec28
So you are adding the address of the glob associated with the file handle.
|
|---|