David Storrs wrote: > I've got a function that takes several arguments, the first of which > should be a scalar (specifically, a string). I'd like to have a > precondition to verify that the argument is, in fact, a scalar. Is > there a way to do that (preferably without using modules--I'm trying > to write an entirely self-contained script). > > I could make it take a REFERENCE to a scalar, and then do "ref $_[0] > eq 'SCALAR'", but that's not really what I'm looking for.
I'm not sure the suggestions re:prototypes are what you're looking for. That will coerce a scalar context onto a call like: foo(@INC); When your sub is called, @_ contains a list of scalars. So the first argument *IS* a scalar. If you don't want it to be reference, then you need to use the ref() function: sub foo { my $arg = shift; die "First argument must be a simple scalar, not a reference" if ref $arg; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]