Sponsored Content
Full Discussion: Variable Scope in Perl
Top Forums Programming Variable Scope in Perl Post 302957896 by balajesuri on Friday 16th of October 2015 10:26:04 AM
Old 10-16-2015
1. There is no switch case feature in perl by default. So you may have to use if-elsif-else blocks. Or you could install the Switch.pm module and use switch case.

2. To pass option to Vmax lib:

in main.pl:

Code:
use Vmax;
[...]

my $option = <option_from_command_line>;

Vmax::set_option($option);
Vmax::work_pg(<args>);
[...]

in Vmax.pm:

Code:
my $option = "";
sub set_option {
    $option = shift;
}

if ($option == 1) {
    %pg = ( ... );
}
elsif ($option == 2) {
    %pg = ( ... );
}
[...]

sub work_pg {
    [...]
}

Please correct me if you find a better method. Thanks.
This User Gave Thanks to balajesuri For This Post:
 

10 More Discussions You Might Find Interesting

1. Programming

C++ variable scope and mutexes

I've been wondering if I can make mutexes much easier to use in C++ with creative use of a locking class and variable scope, but I'm not sure if things happen in the order I want. Here's pseudocode for something that could use the class: int someclass::getvalue() { int retval; ... (0 Replies)
Discussion started by: Corona688
0 Replies

2. Shell Programming and Scripting

problem with shell variable's scope

Hi, I am stuck while developing a shell sub-routine which checks the log file for "success" or "failure". The subroutine reads the log file and checks for key word "success", if found it set the variable (found=1). It returns success or failure based on this variable. My problem is, I can... (2 Replies)
Discussion started by: cjjoy
2 Replies

3. Shell Programming and Scripting

scope of the variable - Naga

Hi All, I am new to unix shell scripting, in the below script "num" is an input file which contains a series of numbers example : 2 3 5 8 I want to add the above all numbers and want the result finally outside the while loop. it prints the value zero instead of the actual expected... (13 Replies)
Discussion started by: nagnatar
13 Replies

4. Shell Programming and Scripting

variable scope

Hi, I want to know about the variable scope in shell script. How can we use the script argument inside the function? fn () { echo $1 ## I want this argument should be the main script argument and not the funtion argument. } also are there any local,global types in shell script? if... (3 Replies)
Discussion started by: shellwell
3 Replies

5. Shell Programming and Scripting

[SOLVED] Scope of KSH Variable in Perl?

cat test.ksh #!/usr/bin/ksh VAR="Dear Friends \n How are you? \n Have a nice day \n" export VAR echo "Inside test.ksh"; ./test.pl cat test.pl #!/usr/bin/perl print "Inside test.pl \n"; print "$VAR"; Output: ./test.ksh Inside test.ksh Inside test.plWhat I want to achieve is, I... (1 Reply)
Discussion started by: dahlia84
1 Replies

6. UNIX for Dummies Questions & Answers

Bash loops and variable scope

Hi All, I've been researching this problem and I am pretty sure that the issue is related to the while loop and the piping. There are plenty of other threads about this issue that recommend removing the pipe and using redirection. However, I haven't been able to get it working using the ssh and... (1 Reply)
Discussion started by: 1skydive
1 Replies

7. Shell Programming and Scripting

Help with retaining variable scope

Hi, I use Korn Shell. Searched Forum and modified the way the file is input to the while loop, but still the variable does not seem to be retaining the final count. while read name do Tmp=`echo $name | awk '{print $9 }'` Count=`cat $Tmp | wc -l`... (6 Replies)
Discussion started by: justchill
6 Replies

8. Shell Programming and Scripting

Variable scope in bash

Hello! Before you "bash" me with - Not another post of this kind Please read on and you will understand my problem... I am using the below to extract a sum of the diskIO on a Solaris server. #!/bin/sh PATH=/usr/bin:/usr/sbin:/sbin; export PATH TEMP1="/tmp/raw-sar-output.txt$$"... (3 Replies)
Discussion started by: haaru
3 Replies

9. Shell Programming and Scripting

Maintain Scope of the variable in UNIX

Hi All Is there is any way to maintain the scope of the variable in unix Example x=1 j=1 while do .. .... .... while do .. .. x=x+1 done #inner most while loop ends here done #outer loop ends here (8 Replies)
Discussion started by: parthmittal2007
8 Replies

10. Shell Programming and Scripting

PERL annoying scope problem

Hello, I met a problem with following code: #!/usr/bin/perl -w # test.pl use strict; use diagnostics; use DBI; my $dbh = DBI->connect( "DBI:mysql:BibleBook","yifangt","password") or die("Cannot connect: $DBI::errstr"); my $sql = qq(SELECT * FROM library WHERE isbn =... (2 Replies)
Discussion started by: yifangt
2 Replies
Frame(3)						User Contributed Perl Documentation						  Frame(3)

NAME
Tk::Frame - Create and manipulate Frame widgets SYNOPSIS
$frame = $parent->Frame(?options?); STANDARD OPTIONS
-borderwidth -highlightbackground -highlightthickness -takefocus -class -highlightcolor -relief -cursor See Tk::options for details of the standard options. WIDGET-SPECIFIC OPTIONS Name: background Class: Background Switch: -background This option is the same as the standard background option except that its value may also be specified as an undefined value. In this case, the widget will display no background or border, and no colors will be consumed from its colormap for its background and border. Name: colormap Class: Colormap Switch: -colormap Specifies a colormap to use for the window. The value may be either new, in which case a new colormap is created for the window and its children, or the name of another window (which must be on the same screen and have the same visual as $widget), in which case the new window will use the colormap from the specified window. If the colormap option is not specified, the new window uses the same colormap as its parent. This option may not be changed with the configure method. Name: container Class: Container Switch: -container The value must be a boolean. If true, it means that this window will be used as a container in which some other application will be embedded (for example, a Tk toplevel can be embedded using the -use option). The window will support the appropriate window manager protocols for things like geometry requests. The window should not have any children of its own in this application. This option may not be changed with the configure method. Name: height Class: Height Switch: -height Specifies the desired height for the window in any of the forms acceptable to Tk_GetPixels. If this option is less than or equal to zero then the window will not request any size at all. Name: visual Class: Visual Switch: -visual Specifies visual information for the new window in any of the forms accepted by Tk_GetVisual. If this option is not specified, the new window will use the same visual as its parent. The visual option may not be modified with the configure method. Name: width Class: Width Switch: -width Specifies the desired width for the window in any of the forms acceptable to Tk_GetPixels. If this option is less than or equal to zero then the window will not request any size at all. DESCRIPTION
The Frame method creates a new window (given by the $widget argument) and makes it into a frame widget. Additional options, described above, may be specified on the command line or in the option database to configure aspects of the frame such as its background color and relief. The frame command returns the path name of the new window. A frame is a simple widget. Its primary purpose is to act as a spacer or container for complex window layouts. The only features of a frame are its background color and an optional 3-D border to make the frame appear raised or sunken. WIDGET METHODS
The Frame method creates a widget object. This object supports the configure and cget methods described in Tk::options which can be used to enquire and modify the options described above. The widget also inherits all the methods provided by the generic Tk::Widget class. BINDINGS
When a new frame is created, it has no default event bindings: frames are not intended to be interactive. KEYWORDS
frame, widget perl v5.16.3 2014-06-10 Frame(3)
All times are GMT -4. The time now is 11:31 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy