Define local variable in subroutine by using my : my « Subroutine « 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 » Subroutine » my 
Define local variable in subroutine by using my
   
sub printifOK
{
    my $localvalue = $value;

    if ($localvalue > 10 ) {
        print "Value is $value.\n";
    else {
        print "Value is too small.\n";
    }
}

$value = 10;
printifOK;

$value = 12;
printifOK;

   
    
    
  
Related examples in the same category
1.Using my
2.Using my if statement
3.Using my to declare the local variable in a subroutine
4.my ($program, $exitCode) = @_; creates two local variables, $program and $exitCode, from @_.
5.my variable
6.my variable is initialized each time
7.my, local and global variable
8.My value scope
9.The scope of my variables
10.Use my to declare local variable
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.