in reply to Re: passing of values by reffernence and taint mode?
in thread passing of values by reffernence and taint mode?

at this point it seems clear to me that i have no idea what i am doing.... after messing with this for the last hour the best i have gotten is

#!/usr/bin/perl -w use strict; my $thingy = "No Change\n"; print $thingy; &change($thingy); print $thingy; sub change { my $in = shift; $$in = "Changed\n"; }
I get the following error
Can't use string ("No Change") as a SCALAR ref while "strict refs" in +use at asdf.pl line 12
It seems like it is doing some sort of weird passing by value thing to me... but then I have no idea what I am doing (haven't you noticed...sigh) I read through perlref and it mentioned this problem existed but I could discern no answer also the 2 perl books I have on hand made similar statments with no answer I could find.

and I forgot to login, blast I guess today is not my day.......

Replies are listed 'Best First'.
Re: Re: Re: passing of values by reffernence and taint mode?
by djantzen (Priest) on Jun 06, 2003 at 17:19 UTC

    It seems like it is doing some sort of weird passing by value thing to me

    Yes, but it's not weird, it's doing exactly what you're telling it -- passing a string that you're then trying to dereference. Look at hardburn's post and you'll see the critical difference is the backslash preceding the scalar.

    &change($thingy); # passes by value &change(\$thingy); # creates and passes a *reference*


    "The dead do not recognize context" -- Kai, Lexx
Re: Re: Re: passing of values by reffernence and taint mode?
by hardburn (Abbot) on Jun 06, 2003 at 17:22 UTC

    First, you should avoid the ampersand syntax unless you have a specific reason to use it.

    Second, you're passing by value, not by referance. When you get to the $$in = "Changed\n"; part, perl tries to use $in as a symbolic ref. Symbolic refs are (rightfully) illegal with strict 'refs' turned on, hence the error message. To pass by a hard referance, you need to change how you call the sub to change(\$thingy);. Notice the '\' before the '$', which is saying "make a referance to $thingy". No change should be necessary to the subroutine itself.

    ----
    I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
    -- Schemer

    Note: All code is untested, unless otherwise stated