EXPR->* - The Dereference Operator

This section provides a tutorial example on how to use symbolic references with the dereference operator like EXPR->[*], EXPR->{*}, or EXPR->(*) for array elements, hash elements and function calls.

As mentioned in the previous section, if a symbolic reference is used with a subscription of [*], {*}, or (*), the dereference operator, -> can be used between the identifier string expression and the subscription. Note that subscription [*] is used for array elements, {*} is used for hash elements, (*) is used for function calls.

The following tutorial program shows you some examples. Note that you can not use -> to access hard slices.

#- SoftRef3.pl
#- Copyright (c) 1999 by Dr. Herong Yang, http://www.herongyang.com/
#
   $name = 'foo';
   @name = ('foo');
   %name = ('i', 'foo');

   $name->[0] = 30; print "$foo[0]\n";   
   $name->[0,1] = (40,41); print "$foo[0]\n";     # not working
   $name->{'k'} = 60; print "$foo{k}\n";  
   $name->{'k','l'} = (70,71); print "$foo{k}\n"; # not working
   $name->(80);                           

   'foo'->[0] = 130; print "$foo[0]\n";   
   ('bla','foo')->{'k'} = 160; print "$foo{k}\n";  
   ('f'.'oo')->(180);                           

   $name[0]->[0] = 230; print "$foo[0]\n";
   $name{'i'}->{'k'} = 260; print "$foo{k}\n";
   &name->(280);

sub foo {print "$_[0]\n";}
sub name {return 'foo';}

Here is the output of the tutorial program:

30
30
60
60
80
130
160
180
230
260
280

Table of Contents

 About This Book

 Perl on Linux Systems

 ActivePerl on Windows Systems

 Data Types: Values and Variables

 Expressions, Operations and Simple Statements

 User Defined Subroutines

 Perl Built-in Debugger

 Name Spaces and Perl Module Files

Symbolic (or Soft) References

 Using Symbolic References

 $$name - Replacing Identifiers by Scalar Variables

 ${EXPR} - Replacing Identifiers by Expressions

EXPR->* - The Dereference Operator

 $$$name - Nested Symbolic References

 Hard References - Addresses of Memory Objects

 Objects (or References) and Classes (or Packages)

 Typeglob and Importing Identifiers from Other Packages

 String Built-in Functions and Performance

 File Handles and Data Input/Output

 Open Files in Binary Mode

 Open Directories and Read File Names

 File System Functions and Operations

 Converting Perl Script to Executable Binary

 Using DBM Database Files

 Using MySQL Database Server

 Socket Communication Over the Internet

 XML::Simple Module - XML Parser and Generator

 XML Communication Model

 SOAP::Lite - SOAP Server-Client Communication Module

 Perl Programs as IIS Server CGI Scripts

 CGI (Common Gateway Interface)

 XML-RPC - Remote Procedure Call with XML and HTTP

 RPC::XML - Perl Implementation of XML-RPC

 Integrating Perl with Apache Web Server

 CGI.pm Module for Building Web Pages

 LWP::UserAgent and Web Site Testing

 References

 PDF Printing Version