On Sat, Jul 05, 2003 at 12:29:46PM -0400, Bob Showalter wrote:
> 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;
>    }

Urgh; this is living proof that sometimes a better statement of the
problem is all that's required.  Thank you very much.


--Dks

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to