Advertisement

07.07.2005 at 06:52PM PDT, ID: 21484331
[x]
Attachment Details

How to tell if variable is Array, Hash, or Scalar?

Asked by KnotEye in Perl Programming Language

Tags: perl, variable, array, how, tell

Hi,

I want to write a function to manipulate the variable that's passed into it, but if it's an array or hash i want to do the change to each member.  is there an easy way to tell what type a variable is in Perl without making it a reference ?

example function:

sub manipulate($) {
  my $var = shift;
  if ($var is an array) {
    foreach my $v (@var) {
      ...
    }
  }
  elsif ($var is a hash) {
    ...
  }
  return $var;
}Start Free Trial
 
 
Loading Advertisement...
 
[+][-]07.07.2005 at 07:01PM PDT, ID: 14393339

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.07.2005 at 08:44PM PDT, ID: 14393930

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Perl Programming Language
Tags: perl, variable, array, how, tell
Sign Up Now!
Solution Provided By: jmcg
Participating Experts: 2
Solution Grade: B
 
 
[+][-]07.07.2005 at 09:27PM PDT, ID: 14394093

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.07.2005 at 09:56PM PDT, ID: 14394175

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07.07.2005 at 10:10PM PDT, ID: 14394213

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.07.2005 at 10:13PM PDT, ID: 14394221

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32