- Perl Basics
- Perl - Home
- Perl - Introduction
- Perl - Environment
- Perl - Syntax Overview
- Perl - Data Types
- Perl - Variables
- Perl - Scalars
- Perl - Arrays
- Perl - Hashes
- Perl - IF...ELSE
- Perl - Loops
- Perl - Operators
- Perl - Date & Time
- Perl - Subroutines
- Perl - References
- Perl - Formats
- Perl - File I/O
- Perl - Directories
- Perl - Error Handling
- Perl - Special Variables
- Perl - Coding Standard
- Perl - Regular Expressions
- Perl - Sending Email
- Perl Advanced
- Perl - Socket Programming
- Perl - Object Oriented
- Perl - Database Access
- Perl - CGI Programming
- Perl - Packages & Modules
- Perl - Process Management
- Perl - Embedded Documentation
- Perl - Functions References
- Perl Useful Resources
- Perl - Questions and Answers
- Perl - Quick Guide
- Perl - Useful Resources
- Perl - Discussion
Perl untie Function
Description
This function breaks the binding between a variable and a package, undoing the association created by the tie function.
Syntax
Following is the simple syntax for this function −
untie VARIABLE
Return Value
This function returns 0 on failure and 1 on success.
Example
Following is the example code showing its basic usage −
#!/usr/bin/perl -w package MyArray; sub TIEARRAY { print "TYING\n"; bless []; } sub DESTROY { print "DESTROYING\n"; } sub STORE { my ($self, $index, $value ) = @_; print "STORING $value at index $index\n"; $self[$index] = $value; } sub FETCH { my ($self, $index ) = @_; print "FETCHING the value at index $index\n"; return $self[$index]; } package main; $object = tie @x, MyArray; #@x is now a MyArray array; print "object is a ", ref($object), "\n"; $x[0] = 'This is test'; #this will call STORE(); print $x[0], "\n"; #this will call FETCH(); print $object->FETCH(0), "\n"; untie @x #now @x is a normal array again.
When above code is executed, it produces the following result −
TYING object is a MyArray STORING This is test at index 0 FETCHING the value at index 0 This is test FETCHING the value at index 0 This is test DESTROYING
perl_function_references.htm
Advertisements