Solved

Threads - Shared - Reference

Posted on 2004-04-23
3
1,218 Views
Last Modified: 2009-07-29
Hi Friends, I have the following code:

use threads;
use threads::shared;
my $a='abc';
my $b : shared = \$a;

For this, I'm getting the error: Invalid value for shared scalar at del.pl line 4.

Basically, I would like to have a variable(here $b) which is shared and holds a reference. Is this possible? If so please help me.

Thanx
0
Comment
Question by:vi_srikanth
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
Mercantilum earned 300 total points
ID: 10900848
You can't put a reference to an unshared value in a shared scalar:

use threads;
use threads::shared;
my $bar;
my $foo : shared;
$foo = \$bar;

gives:

Invalid value for shared scalar at x line 5.

See http://www.nntp.perl.org/group/perl.ithreads/758
0
 
LVL 1

Assisted Solution

by:joesp
joesp earned 200 total points
ID: 10902738
why not:

#!/usr/bin/perl
use threads;
use threads::shared;
my $a= "abc";
my $b = &share(\$a);
print $a . "\n";
print $$b . "\n";

0
 
LVL 10

Expert Comment

by:Mercantilum
ID: 10905180
So, you could simply

use threads;
use threads::shared;
my $bar : shared;
my $foo : shared;
$foo = \$bar;
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question