You could avoid the whole thing by modifying
the original value using an assignment via return
value:

        my $thingy = pluralize($thingy);        # overwrites original
        my $result = pluralize('orange');       # does not try to overwrite original
        sub pluralize { return $_[0] . 's' }

Is there some reason this won't do?

Mark



-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of
Greg London
Sent: Friday, March 22, 2002 9:52 AM
To: mongers of perl
Subject: [Boston.pm] lvalue


Hey all.

I have a subroutine that may want to
modify a parameter passed in via @_.

however, it shouldn't modify it if
it is read-only. how do you test
for a writable parameter in perl?

sub pluralize
{
        $_[0] .= 's';
}


my $thingy = 'apple';
pluralize($thingy); # this will work

pluralize('orange'); #boom!

the only thing I can think of offhand is
to do the assign in an eval block.
is this the best way?


Greg



Reply via email to