Sponsored Content
Top Forums Shell Programming and Scripting Perl Matching multiple variables Post 302882672 by popeye on Wednesday 8th of January 2014 01:50:58 PM
Old 01-08-2014
This is working I suppose .... kind of crappy though .. I just play around with $a, $b, $c to test behavior. Is there a better way ?


Code:
#!/usr/bin/perl
$a = 3;
$b ;
$c = 3;

  if ((defined $a) && (!defined $b) && (!defined $c)) {};

  if ((defined $a) && (defined $b) && (defined $c)) { 
     print "all defined\n";
      if (!allequal($a, $b, $c)) { 
       print "They're not all equal!\n";
      }
  }

  if ((defined $a) && (defined $b) && (!defined $c)) {
     print "only \$a $a and \$b $b are defined. But not \$c $c\n";
      if (!allequal($a, $b)) {
       print "They're not all equal!\n";
      }
  }

  if ((defined $a) && (!defined $b) && (defined $c)) {
     print "only \$a $a and \$c $c are defined. But not \$b $b\n";
      if (!allequal($a, $c)) {
       print "They're not all equal!\n";
      }
  }


sub allequal {
 my $first = shift;
 for (@_) {
  return 0 unless $first == $_;
 }
 return 1;
}

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perl basic multiple pattern matching

Hi everyone, and thank you for your help with this. I am VERY new with perl so all of your help is appreciated. I have tried google but as I don't know the proper terms to search for and could be daunting for a newbie scripter... I know this is very easy for most of you! Thanks! I have a... (4 Replies)
Discussion started by: sinusoid
4 Replies

2. Shell Programming and Scripting

Perl Regex matching multiple lines

I need a way to extract data from X 4T Solution 21 OCT 2011 37 .00 to account 12345678 User1 user2 X 4T Solution Solution Unlimited 11 Sep 2009 248 .00 to account 87654321 user3 user4 I need it to extract 'X' '37.00' and account number 12345678. I have extracted above stuff... (3 Replies)
Discussion started by: chakrapani
3 Replies

3. Shell Programming and Scripting

Hidden Characters in Regular Expression Matching Perl - Perl Newbie

I am completely new to perl programming. My father is helping me learn said programming language. However, I am stuck on one of the assignments he has given me, and I can't find very much help with it via google, either because I have a tiny attention span, or because I can be very very dense. ... (4 Replies)
Discussion started by: kittyluva2
4 Replies

4. Shell Programming and Scripting

Help with checking that 2 variables contain matching characters

hi i am writing a hangman script and am having trouble checking the correct letters against the word i need the script to compare the word against the letters guessed that are correct so once all the letters within the word have been guessed it will alow me to create a wining senario eg ... (3 Replies)
Discussion started by: lsecer
3 Replies

5. Shell Programming and Scripting

Help need with PERL multiple search pattern matching!

My example file is as given below: conn=1 uid=oracle conn=2 uid=db2 conn=3 uid=oracle conn=4 uid=hash conn=5 uid=skher conn=6 uid=oracle conn=7 uid=mpalkar conn=8 uid=anarke conn=9 uid=oracle conn=1 op=-1 msgId=-1 - fd=104 slot=104 LDAPS connection from 10.10.5.6 to 10.18.6.5 conn=2... (3 Replies)
Discussion started by: sags007_99
3 Replies

6. Shell Programming and Scripting

Perl script: matching multiple lines error

Dear Perl users, Could somebody help me how to fix my code so I can get my desired output. Here is the data: Pattern Gabriel halo1 halo2 end Pattern Andreas halo1 halo2 endI want to grep multiple lines between the pattern /Pattern Gabriel / and /end/. Then I will store the output into... (6 Replies)
Discussion started by: askari
6 Replies

7. Shell Programming and Scripting

Running a script with multiple variables like 25 variables.

Hi All, i have a requirement where i have to run a script with at least 25 arguements and position of arguements can also change. the unapropriate way is like below. can we achieve this in more good and precise way?? #!/bin/ksh ##script is sample.ksh age=$1 gender=$2 class=$3 . . .... (3 Replies)
Discussion started by: Lakshman_Gupta
3 Replies

8. Shell Programming and Scripting

Reading multiple values from multiple lines and columns and setting them to unique variables.

Hello, I would like to ask for help with csh script. An example of an input in .txt file is below, the number of lines varies from file to file and I have 2 or 3 columns with values. I would like to read all the values (probably one by one) and set them to independent unique variables that... (7 Replies)
Discussion started by: FMMOLA
7 Replies

9. Shell Programming and Scripting

Assigning multiple column's value from Oracle query to multiple variables in UNIX

Hi All, I need to read values of 10 columns from oracle query and assign the same to 10 unix variables. The query will return only one record(row). I tried to append all these columns using a delimiter(;) in the select query and assign the same to a single variable(V) in unix. I thought I... (3 Replies)
Discussion started by: hkrishnan91
3 Replies

10. Programming

PERL: In a perl-scripttTrying to execute another perl-script that SETS SOME VARIABLES !

I have reviewed many examples on-line about running another process (either PERL or shell command or a program), but do not find any usefull for my needs way. (Reviewed and not useful the system(), 'back ticks', exec() and open()) I would like to run another PERL-script from first one, not... (1 Reply)
Discussion started by: alex_5161
1 Replies
info(n) 						       Tcl Built-In Commands							   info(n)

__________________________________________________________________________________________________________________________________________________

NAME
info - Return information about the state of the Tcl interpreter SYNOPSIS
info option ?arg arg ...? _________________________________________________________________ DESCRIPTION
This command provides information about various internals of the Tcl interpreter. The legal option's (which may be abbreviated) are: info args procname Returns a list containing the names of the arguments to procedure procname, in order. Procname must be the name of a Tcl command procedure. info body procname Returns the body of procedure procname. Procname must be the name of a Tcl command procedure. info cmdcount Returns a count of the total number of commands that have been invoked in this interpreter. info commands ?pattern? If pattern isn't specified, returns a list of names of all the Tcl commands in the current namespace, including both the built-in commands written in C and the command procedures defined using the proc command. If pattern is specified, only those names matching pattern are returned. Matching is determined using the same rules as for string match. pattern can be a qualified name like Foo::print*. That is, it may specify a particular namespace using a sequence of namespace names separated by ::s, and may have pat- tern matching special characters at the end to specify a set of commands in that namespace. If pattern is a qualified name, the resulting list of command names has each one qualified with the name of the specified namespace. info complete command Returns 1 if command is a complete Tcl command in the sense of having no unclosed quotes, braces, brackets or array element names, If the command doesn't appear to be complete then 0 is returned. This command is typically used in line-oriented input environments to allow users to type in commands that span multiple lines; if the command isn't complete, the script can delay evaluating it until additional lines have been typed to complete the command. info default procname arg varname Procname must be the name of a Tcl command procedure and arg must be the name of an argument to that procedure. If arg doesn't have a default value then the command returns 0. Otherwise it returns 1 and places the default value of arg into variable varname. info exists varName Returns 1 if the variable named varName exists in the current context (either as a global or local variable) and has been defined by being given a value, returns 0 otherwise. | info functions ?pattern? | If pattern isn't specified, returns a list of all the math functions currently defined. If pattern is specified, only those func- | tions whose name matches pattern are returned. Matching is determined using the same rules as for string match. info globals ?pattern? If pattern isn't specified, returns a list of all the names of currently-defined global variables. Global variables are variables in the global namespace. If pattern is specified, only those names matching pattern are returned. Matching is determined using the same rules as for string match. info hostname Returns the name of the computer on which this invocation is being executed. Note that this name is not guaranteed to be the fully | qualified domain name of the host. Where machines have several different names (as is common on systems with both TCP/IP (DNS) and | NetBIOS-based networking installed,) it is the name that is suitable for TCP/IP networking that is returned. info level ?number? If number is not specified, this command returns a number giving the stack level of the invoking procedure, or 0 if the command is invoked at top-level. If number is specified, then the result is a list consisting of the name and arguments for the procedure call at level number on the stack. If number is positive then it selects a particular stack level (1 refers to the top-most active pro- cedure, 2 to the procedure it called, and so on); otherwise it gives a level relative to the current level (0 refers to the current procedure, -1 to its caller, and so on). See the uplevel command for more information on what stack levels mean. info library Returns the name of the library directory in which standard Tcl scripts are stored. This is actually the value of the tcl_library variable and may be changed by setting tcl_library. See the tclvars manual entry for more information. info loaded ?interp? Returns a list describing all of the packages that have been loaded into interp with the load command. Each list element is a sub- list with two elements consisting of the name of the file from which the package was loaded and the name of the package. For stati- cally-loaded packages the file name will be an empty string. If interp is omitted then information is returned for all packages loaded in any interpreter in the process. To get a list of just the packages in the current interpreter, specify an empty string for the interp argument. info locals ?pattern? If pattern isn't specified, returns a list of all the names of currently-defined local variables, including arguments to the current procedure, if any. Variables defined with the global, upvar and variable commands will not be returned. If pattern is specified, only those names matching pattern are returned. Matching is determined using the same rules as for string match. info nameofexecutable Returns the full path name of the binary file from which the application was invoked. If Tcl was unable to identify the file, then an empty string is returned. info patchlevel Returns the value of the global variable tcl_patchLevel; see the tclvars manual entry for more information. info procs ?pattern? If pattern isn't specified, returns a list of all the names of Tcl command procedures in the current namespace. If pattern is spec- ified, only those procedure names in the current namespace matching pattern are returned. Matching is determined using the same rules as for string match. info script ?filename? If a Tcl script file is currently being evaluated (i.e. there is a call to Tcl_EvalFile active or there is an active invocation of the source command), then this command returns the name of the innermost file being processed. If filename is specified, then the return value of this command will be modified for the duration of the active invocation to return that name. This is useful in vir- tual file system applications. Otherwise the command returns an empty string. info sharedlibextension Returns the extension used on this platform for the names of files containing shared libraries (for example, .so under Solaris). If shared libraries aren't supported on this platform then an empty string is returned. info tclversion Returns the value of the global variable tcl_version; see the tclvars manual entry for more information. info vars ?pattern? If pattern isn't specified, returns a list of all the names of currently-visible variables. This includes locals and currently-vis- ible globals. If pattern is specified, only those names matching pattern are returned. Matching is determined using the same rules as for string match. pattern can be a qualified name like Foo::option*. That is, it may specify a particular namespace using a sequence of namespace names separated by ::s, and may have pattern matching special characters at the end to specify a set of vari- ables in that namespace. If pattern is a qualified name, the resulting list of variable names has each matching namespace variable qualified with the name of its namespace. SEE ALSO
global(n), proc(n) KEYWORDS
command, information, interpreter, level, namespace, procedure, variable Tcl 8.4 info(n)
All times are GMT -4. The time now is 07:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy