1

How can the SOCKET recv function modify the value of the scalar $PDU directly? Usually this syntax is a pass by value not a pass by reference, I assumed up to now at least.

my $PDU; 
my $addr = $socket->recv($PDU, MAXBYTES);

I want to use this effect for my own purpose so best would be a handy test subroutine which depicts how this can be achieved.

Like:

my $PDU="orig";
sub test {
  my $par1=shift;
  $par1="test";
}
print "$PDU\n";

As you know this will result into "orig" not "test".

Thank you in advance.

Kind regards, Hermann

0

1 Answer 1

1

Your function should be well documented when having such behavior,

my $PDU="orig";
sub test {
  $_[0] = "test";
}

test($PDU);
print "$PDU\n";

or

sub test {
  my ($par1) = map \$_, @_;

  $$par1 = "test";
}

output

test
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.