in reply to Dynamically changing the value of a passed variable into a sub
You'll need to pass a reference to the scalar variable as a parameter to the subroutine.
TimeStamp(\$data_created); sub TimeStamp { my ($dataRef) = @_; if ($$dateRef =~ /(\d{4})(\d{2})(\d{2})/) { $$dateRef = "$2/$3/$1"; } else { warn("..."); } }
Since Perl has call-by-value semantics, i.e. a copy of the variable is passed to the subroutine rather than the value itself, you have to pass the address of the variable (i.e. \$date_created) to the subroutine.
In the subroutine, you manipulate the value $$dateRef which is stored at address $dataRef.
Hope this helps, -gjb-
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Dynamically changing the value of a passed variable into a sub (see node below, this one got submitted in error)
by jdporter (Paladin) on Nov 04, 2002 at 21:11 UTC |