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

can scalars be passed by reffernence

Sure can.

resulting regular expression in the library untaint them?

You need to dereferance the value and untaint it:

sub untaint_ref { my $in = shift; $$in =~ /(.*)/; return $1; } my $val = 12345; $val = untaint_ref(\$val);

Obviously, you want a better untainting method than /(.*)/.

----
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

Replies are listed 'Best First'.
Re: Re: passing of values by reffernence and taint mode?
by Anonymous Monk on Jun 06, 2003 at 17:11 UTC
    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.......

      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

      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