- 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 goto Function
Description
This function has three forms, the first form causes the current execution point to jump to the point referred to as LABEL. A goto in this form cannot be used to jump into a loop or external function.you can only jump to a point within the same scope.
The second form expects EXPR to evaluate to a recognizable LABEL. In general, you should be able to use a normal conditional statement or function to control the execution of a program, so its use is deprecated.
The third form substitutes a call to the named subroutine for the currently running subroutine. The new subroutine inherits the argument stack and other features of the original subroutine; it becomes impossible for the new subroutine even to know that it was called by another name.
Syntax
Following is the simple syntax for this function −
goto LABEL goto EXPR goto &NAME
Return Value
This function does not return any value.
Example
Following is the example code showing its basic usage −
#!/usr/bin/perl $count = 0; START: $count = $count + 1; if( $count > 4 ) { print "Exiting program\n"; } else { print "Count = $count, Jumping to START:\n"; goto START; }
When above code is executed, it produces the following result −
Count = 1, Jumping to START: Count = 2, Jumping to START: Count = 3, Jumping to START: Count = 4, Jumping to START: Exiting program