Great stuff everyone!
Some of it is still greek to me ;)
here's what I got to work for me:
#!/usr/bin/perl
my $a="aBe";
my $b="bOb";
my $c="cAb";
aUpper($a);
bUpper($b);
cUpper($c);
print $a . " " . $b . " " . $c . "\n";
#results
#These sub below are good:
sub aUpper { return $_[0] = uc($_[0]); }
sub bUpper { return $_[0] = "\U$_[0]"; }
#These did NOT work for me:
sub cUpper { return $$_[0] = "\U$$_[0]"; }
#sub cUpper { return $_->[0] = "\U$_->[0]"; }
------------------
> Daniel Staal wrote:
>>
>> --On Tuesday, October 14, 2003 15:59 -0700 "[EMAIL PROTECTED]"
>> <[EMAIL PROTECTED]> wrote:
>> >
>> > Also in a slightly different scenario, how can i change the value
>> > of the parameter itself with a sub.
>> >
>> > $a="ca";
>> > toUpper($a); #change the $a value itself
>> > print $a; #I want it to print "CA"
>>
>> Ok, I'll assume this is a made-up example... (Since it would just be
>> easy to write 'print toUpper($a);', using the return value.)
>>
>> The way to do this would be to pass references to the parameters.
>> You would have to pass the references, and work with them.
>
> There is no need to use references because the values of @_ are aliased
> to the variables passed to the sub so modifying the values in @_ will
> also modify the values of the variables.
>
>> So, the function call would become:
>>
>> toUpper(\$a);
>>
>> The sub would be:
>>
>> sub toUpper { return "\U$$_[0]"; } # (Hey, we have linenoise!)
>
> That still doesn't modify the value in $a. You would have to write it
> like:
>
> sub toUpper { return $$_[0] = "\U$$_[0]"; }
>
> Or:
>
> sub toUpper { return $_->[0] = "\U$_->[0]"; }
>
>
>
> John
> --
> use Perl;
> program
> fulfillment
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
-----------------------------------------
eMail solutions by
http://www.swanmail.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]