Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!elroy!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.sources.d Subject: Re: Why can't I print the SIG array in perl? Keywords: perl, signals Message-ID: <3573@jpl-devvax.JPL.NASA.GOV> Date: 22 Nov 88 04:39:48 GMT References: <161@nlgvax.UUCP> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA. Lines: 56 In article <161@nlgvax.UUCP> hans@pcg.philips.nl (Hans Zuidam) writes: : I think I've found a 'bug' in the perl SIG array. The following : script doesn't print anything. Substituting SIG by ENV nicely : shows my environment. : : eval "exec /usr4/hans/bin.${ARCH}/perl.${ARCH} -Sw $0 $*" : if $run_shell; : : @Keys = keys(SIG); : @Values = values(SIG); : : while ($#Keys >= 0) : { : print pop(Keys), " = ", pop(Values), "\n"; : } : : Is this indeed a bug? Is there a fix? Hmm. I don't think it's quite a bug. The SIG array works like regular associative arrays in that there's nothing there unless you put it into it yourself. Any signal that doesn't have a value just does the default. I could set it up to have values for all the signals, if 1) I knew what all the signals were (they vary considerably) and 2) I was willing to endure the overhead of loading them all into the SIG array. Since I don't think either of those are going to be true soon, I've installed the following sentence in the perl manual: The SIG array only contains values for the signals actually set within the perl script. (If you inserted $SIG{'TERM'} = 'IGNORE'; into your script above, you would note that it does print out TERM = IGNORE.) The ENV array has to be different since there's no such thing as a default value for environment variables. If you want all the SIGs very very much, you can say something like this: if (open(SIG,"/usr/include/sys/signal.h")) { while () { eval "\$SIG{'$1'} = 'DEFAULT';" if /^#define\s+SIG(\w+)/; } close SIG; } : B.T.W: The eval at the top is because the #! construct does not use : your PATH. We have multiple architectures (Sun3, Sun4, Sun386i : and VAX), by setting ARCH to `arch`, you get the right perl :-). Cute. I've always wished #! could use the PATH. Larry Wall lwall@jpl-devvax.jpl.nasa.gov