Using ref function to check the parameter type : ref « Data Type « Perl

Home
Perl
1.Array
2.CGI
3.Class
4.Data Type
5.Database
6.File
7.GUI
8.Hash
9.Language Basics
10.Network
11.Regular Expression
12.Report
13.Statement
14.String
15.Subroutine
16.System Functions
17.Win32
18.XML
Perl » Data Type » ref 
Using ref function to check the parameter type
    

@a = (123);
@b = (456);

sub addem
{
    my ($ref1, $ref2= @_;

    if (ref($ref1eq "ARRAY" && ref($ref2eq "ARRAY") {

        while (@$ref1) {

            unshift @result, pop(@$ref1+ pop(@$ref2);

        }

        return @result;

    elsif (ref($ref1eq "SCALAR" && ref($ref2eq "SCALAR") {

        return $$ref1 + $$ref2;

    }
}

@array = addem (\@a, \@b);

print join (', ', @array);

   
    
    
    
  
Related examples in the same category
1.Return Values from the ref Function
2.Using ref function on a subroutine reference
3.Using ref function to get the type of the reference
4.Using ref inside a function
5.The return values of the ref function: ref( \\@array )
6.The return values of the ref function: function
7.The return values of the ref function: ref( \*hash )
8.The return values of the ref function: 10
9.The return values of the ref function: array
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.