CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: [SOLVED] How to use global variable in subroutine: Edit Log



waldauf
Novice

Nov 1, 2012, 3:08 AM


Views: 1902
[SOLVED] How to use global variable in subroutine

Hello perl's folk,

I would like to use global variable in subroutine. It is simply script which enables me turn on/out debug mode.



Code
#!/usr/local/bin/perl 

# watchdog for declaration of variables. At first you have to declare variable via "my $variable"
use strict;
# Print warnings messages
use warnings;

sub print_s {
if ( $DEBUG eq "1" ) {
print "$_";
}
else {
print "$DEBUG";
}
}


my $DEBUG = "0";

print_s "Today is good day to write good script in Perl.";



And output:

Code
 
$ ./debug.pl
Global symbol "$DEBUG" requires explicit package name at ./debug.pl line 11.
Global symbol "$DEBUG" requires explicit package name at ./debug.pl line 15.
Execution of ./debug.pl aborted due to compilation errors.



Or do you know better way how implement debug mode of script? :]

Thx,

Waldauf


(This post was edited by waldauf on Nov 2, 2012, 8:32 AM)


Edit Log:
Post edited by waldauf (Novice) on Nov 2, 2012, 8:32 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives