study() question 
Author Message
 study() question

Hello,

I've been reading the perldoc for the study() function, and it's not telling
me something I want to know.  Hopefully somebody here knows.  Here's my
question, in perl code.

study($data);
my_function($data);

sub my_function {

  # Is $string studied?

Quote:
} # End my_function

Strings are pass by value in these functions, so I wouldn't necessarily
expect that it would be studied, because it's not technically the same string
internally in Perl.  (Or is it?)  But what about this:

study($data);
my_function(\$data);

sub my_function {

  my $string = ${$ref};

  # $string is studied here, isn't it?

Quote:
} # End my_function

--
David Allen
http://www.*-*-*.com/


Thu, 15 Apr 2004 01:10:36 GMT  
 study() question
[A complimentary Cc of this posting was sent to
David Allen

Quote:
> sub my_function {

>   # Is $string studied?
> } # End my_function

==================================================================

Quote:
> my_function(\$data);

> sub my_function {

>   my $string = ${$ref};

>   # $string is studied here, isn't it?
> } # End my_function

There is no difference between the semantic of these two functions.
Both $string's are *copies* of the studied data.  At any time, there
is only one piece of studied data per process.

Hope this helps,
Ilya



Thu, 15 Apr 2004 09:19:56 GMT  
 study() question

Quote:

> study($data);
> my_function($data);

> sub my_function {

>   # Is $string studied?
> } # End my_function

The problem is in the assignment, which is where the copy occurs.
You do have access to the original studied string, via $_[0] in

You can get the seme effect using refs; just don't copy (via
assignment) what the ref points to; use it directly.

--
John Porter

Somebody set up us the bomb!!!



Fri, 16 Apr 2004 00:00:07 GMT  
 study() question

Quote:

> Strings are pass by value in these functions, so I wouldn't necessarily
> expect that it would be studied, because it's not technically the same string
> internally in Perl.  (Or is it?)

Certainly not.  '=' performs a copy operation.  $_[0] might be still
studied (I'm not sure) but when you use =, you get a copy of the
argument in $string, and the copy isn't studied.

Quote:
> But what about this:

>   my $string = ${$ref};

You did the same thing.  $$ref is the original string, which is
studied.  $string is a copy of this.  Changing $string won't change
the origial argument back in the caller, either.

Quote:
>   # $string is studied here, isn't it?

No.  You would need to use $$ref directly.  That's the original string.

You may want to use the Devel::Peek module to inspect the strings to
see which is studied.



Thu, 15 Apr 2004 22:47:17 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Power function

2. Insertion Sort

3. study() question

4. Newbie question, will study !

5. pre-STUDY-ing question for regex

6. Connecting Delphi32 to Informix 5.01

7. Direct Paralle port access

8. Currency field rounding up from 10.25 to 11.00 why?

9. !POSITIONS AVAILABLE

10. Dumping Pascal for C++, need advice.

11. Turbo pascal won't work with Pentium 2 processor???

12. Putimage

 

 
Powered by phpBB® Forum Software