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.
> 
> The value may have been specified as a literal, so I can't do
> anything using the *{foo}{SCALAR} syntax (even if I had the name of
> the variable and not its value).
> 
> Any thoughts?

You can use a prototype for the sub.

sub something ($@) {
    my ( $scalar, @array ) = @_;
    # rest of sub
    }

# code that uses something
something $one, $two;


You can also declare the prototype at the start of the program.

#!/usr/bin/perl
use warnings;
use strict;

sub something ($@);

# code that uses something
something $one, $two;

sub something ($@) {
    my ( $scalar, @array ) = @_;
    # rest of sub
    }


perldoc perlsub


John
-- 
use Perl;
program
fulfillment

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

Reply via email to