Solved

Threads - Shared - Reference

Posted on 2004-04-23
3
1,211 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

929 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now