how to return a value from a sub function if the value is hashed?

I have the following sub function. How can I return 1 or 0 from this sub function? I will call this function as such:

if (is_valid_cluster() ){
then do this

Open in new window

sub is_valid_cluster {
    my %validClusters =
      map {
          $_ ? ($_ => 1) : ()
      } read_file('/somepath/clusterConfig.txt');

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You need to return the reference of the hash
TolgarAuthor Commented:
Can you please show me how I will do it?

I just want to make sure, you are trying to return 0 or 1 OR %hash
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

For returning a pointer to hash you need to do this

my $ref = \%hash_var;

For recovering hash

you need this:

my %new_hash = %$ref;
Another thing.

When you pass ref to a function, you can recover it as

$ref = shift;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TolgarAuthor Commented:
Sorry but I didn't understand it.

Could you please explain it with my variable names?


If I am not understanding you correctly, please let me know.

I think you are trying to return the following value



If so you need to create a reference to it.

my $ref = \%validClusters;

And then return this value
return $ref;
If you are trying to return only 0 or 1 then just say
return 0;


return 1;

I am sorry, not clear as to what you intend to do.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.