Sponsored Content
Full Discussion: Perl nested if statement
Top Forums Shell Programming and Scripting Perl nested if statement Post 302512682 by bartus11 on Monday 11th of April 2011 09:19:42 AM
Old 04-11-2011
Code:
#!/usr/bin/perl
#
#    Phone Book Application
#

%phonebook = (
    "Wayne", '34687368',
    "Home", '378643287',
    "Work", '017374637',
    "School", '36328323',
    "Gym", '37623938'
);

print "Phonebook Menu.\n";
print "Option 1: Display a phone number.\n";
print "Please select an option [1-1]:";
$option = <STDIN>;
chop $option;
if(option eq "1"){
    print "Please enter a name.\n";
    $usr = <STDIN>;
    chop $usr;
    if($usr =~ /Wayne|Home|Work|School|Gym/){
        print "The phone number for $usr is $phonebook{$usr}.\n";
    }
    else{
        print "No such entry.\n";
    }
}else{
    print "Invalid option.\n";
}

This User Gave Thanks to bartus11 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perl if statement

Hello guys, I was wondering why my code doesn't read a variable when using if statement as follows: $userlist='users.txt'; $user='b999'; open (ACTULOG, ">>$userlist"); print ACTULOG "$user\n"; close (ACTULOG) this will work and prints... (3 Replies)
Discussion started by: Bashar
3 Replies

2. Shell Programming and Scripting

while read loop w/ a nested if statement - doesn't treat each entry individually

Hi - Trying to take a list of ldap suffixes in a file, run an ldapsearch command on them, then run a grep command to see if it's a match, if not, then flag that and send an email alert. The list file (ldaplist) would look like - *********** o=company a o=company b *********** **... (7 Replies)
Discussion started by: littlefrog
7 Replies

3. Shell Programming and Scripting

Nested foreach in perl

I have two arrays @nextArray contains some files like \main\1\Xul.xml@@\main\galileo_integration_sjc\0 \main\1\PortToStorageDialog.xml@@\main\galileo_integration_sjc\0 . . . \main\1\PreferencesDialog.xml@@\main\galileo_integration_sjc\0 @otherArray contains some files like ... (2 Replies)
Discussion started by: nmattam
2 Replies

4. UNIX for Dummies Questions & Answers

Nested If statement within Do / Done

Hi all! I'm really hoping you can help me out here; now i have searched and searched and have at least worked out that you can't have a nested if statement with a 'done' in it (as i have) as you're killing the parent before the child. So here's what i have, and here's hoping someone can help... (2 Replies)
Discussion started by: dalgibbard
2 Replies

5. Shell Programming and Scripting

Perl - nested substitutions

How can I nest substitutions ? My solution just seems cheap ... sample data Cisco Catalyst Operating System Software, Version 235.5(18) Cisco Catalyst Operating System Software, Version 17.6(7) Cisco Catalyst Operating System Software, Version 19.6(7) Cisco Catalyst Operating System... (1 Reply)
Discussion started by: popeye
1 Replies

6. Shell Programming and Scripting

Perl nested array problem

I have a array reference which has some number of array references inside it.The nested array references also contains the array references. my $Filename = "sample.xml"; my $Parser = new XML::Parser( Style => 'tree' ); my $Tree = $Parser->parsefile( $Filename ); Here the $Tree is the... (6 Replies)
Discussion started by: karthigayan
6 Replies

7. Shell Programming and Scripting

If-statement nested in case

I'm trying to write case statements with 'if statements' embedded inside of them. I'm using the korn shell but it's not functioning. If I want to see if a string exists in a file and then perform an action, what would be the best way to do this? For file "asg51fin" to delete a line if a... (1 Reply)
Discussion started by: dazeman27
1 Replies

8. UNIX for Dummies Questions & Answers

Help with Perl If statement

Hi All, I am writing a perl script where I take 2 variables from the user as STDIN to scan the lines of a file to produce as output. How can I do an IF loop to test this for example in the mock file 12 10 35 20 37 5 45 12if I take user input as 40 and 10, how can I get the output lines in... (3 Replies)
Discussion started by: pawannoel
3 Replies

9. Shell Programming and Scripting

Perl- Nested 'for' order change

Hello, I'm quite new to perl so my question is rather basic and I know there is probably a simple way around it but I can't seem to find it. I have a medium-length code and there is a part that works with a nested for loop: foreach my $j(@primpiddelta){ for (my $k=1;... (0 Replies)
Discussion started by: acsg
0 Replies

10. UNIX for Advanced & Expert Users

Convert CSV file to nested XML file using UNIX/PERL?

we have a CSV which i need to convert to XML using Perl or Unix shell scripting. I was able to build this XML in oracle database. However, SQL/XML query is running for long time. Hence, I'm considering to write a Perl or shell script to generate this XML file. Basically need to build this XML... (3 Replies)
Discussion started by: laknar
3 Replies
gst-typefind-0.8(1)						   User Commands					       gst-typefind-0.8(1)

NAME
gst-typefind-0.8, gst-typefind - print MIME type of file SYNOPSIS
gst-typefind-0.8 [gst-std-options] file [file...] gst-typefind [gst-std-options] [--gst-list-mm] [--gst-mm=string] [--print] file [file...] DESCRIPTION
gst-typefind-0.8 uses the GStreamer type-finding system to determine the GStreamer type of the given file(s). gst-typefind is a wrapper script that runs the latest installed version of gst-typefind-X.X. For example, if both gst-typefind-0.7 and gst- typefind-0.8 are installed on your system, gst-typefind runs gst-typefind-0.8. OPTIONS
The following options are supported by gst-typefind-0.8 and gst-typefind: gst-std-options Standard options available for use with most GStreamer applications. See gst-std-options(5) for more information. The following options are supported by gst-typefind only: --gst-list-mm List found major/minor versions. This option displays the versions that are available. --gst-mm=string Force major/minor version. This option enables you to specify a specific version to run, if you do not want to run the default version. --print Print wrapped command line. This option displays the command that will be run, and then runs the command. OPERANDS
The following operands are supported: file Name of file for which you want to find the MIME type. EXAMPLES
Example 1: Identifying the MIME Type of file.ogg example% gst-typefind-0.8 file.ogg file.ogg - application/ogg Example 2: Running the Wrapper Script and Displaying the Command Name example% gst-typefind --print /usr/bin/gst-typefind-0.8 FILES
The following files are used by this application: /usr/bin/gst-typefind-0.Executable to print MIME type of file /usr/bin/gst-typefind Wrapper script that runs the latest installed version of gst-typefind-X.X ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWgnome-media | +-----------------------------+-----------------------------+ |Interface stability |External | +-----------------------------+-----------------------------+ SEE ALSO
gst-complete(1), gst-compprep(1), gst-feedback(1), gst-inspect(1), gst-launch(1), gst-launch-ext(1), gst-md5sum(1), gst-register(1), gst- thumbnail(1), gst-xmlinspect(1), gst-xmllaunch(1), gstreamer-properties(1), libgstreamer-0.8(3), libgstgetbits(3), gst-std-options(5) NOTES
Original man page written by the GStreamer team at http://gstreamer.net/. Updated by Brian Cameron, Sun Microsystems Inc., 2004. SunOS 5.10 14 Oct 2004 gst-typefind-0.8(1)
All times are GMT -4. The time now is 03:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy