Sponsored Content
Top Forums Shell Programming and Scripting Another validate input Question. Post 302544430 by DGPickett on Wednesday 3rd of August 2011 05:08:58 PM
Old 08-03-2011
Add a case (*) to every case before esac to catch invalid data. Use both parens to keep vi % working for you.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

validate input from user for file name

Hello, This may have been addressed already somewhere, however I am looking for the easiest/shortest way to validate a response from a user for a file name. The file name should not have any of the following characters ~`!@#$%^&*()_-+={|\:;"'<,>.?/ Further the response should not have any... (2 Replies)
Discussion started by: jerardfjay
2 Replies

2. Shell Programming and Scripting

How to validate input values

Hi How would i validate value of a variable whether it is number,date or string Thanks in advance Sas (5 Replies)
Discussion started by: SasDutta
5 Replies

3. Shell Programming and Scripting

Need to validate a date input format

Hi all, I have a shell script(K shell) which takes a date as input. i want the input to be in DD-MM-YYYY format. Can i enforce such a format of input string using just one line of code? OR do i need to parse the input date into different components and test them using Case statements... (2 Replies)
Discussion started by: rajugp1
2 Replies

4. Shell Programming and Scripting

validate input

the user inputs names that have to be inside square brackets I want to check if the user puts the brackets and if not ask him to re-enter the names (9 Replies)
Discussion started by: DDoS
9 Replies

5. UNIX for Dummies Questions & Answers

BASH validate user input

Hey, im trying to validate a user input and need some help. The input needs to be just a single letter. Im using a case to so this eg: read answer case $answer in *) echo "OK" ;; *) echo "This is a number" read answer ;; *) echo... (2 Replies)
Discussion started by: 602chrislys
2 Replies

6. Shell Programming and Scripting

Validate and sort input

Hi, This will most likely be a simple answer. Currently I have a situation where my script will be sent various options: -o1 -o2 -oe3@somthing.com Now, if I want to run a certain command based on the option I am sent, I am doing the following. for o in $(echo $options) do if ... (3 Replies)
Discussion started by: stuaz
3 Replies

7. Shell Programming and Scripting

How to validate input parameters?

Hi, I wonder how I can know if the input parameters to the script are numbers or text Thanks (11 Replies)
Discussion started by: Gengis-Kahn
11 Replies

8. Shell Programming and Scripting

Epic - Validate input size

Is there an easy way to validate an input field size. Let us say a script is asking to enter 10 digits mobile number, how do I write a script to validate it is numeric and is 10 digits in length? I just need an easy way w/o using looks ...etc. Is there such a away ? Here is what I have so far... (6 Replies)
Discussion started by: mrn6430
6 Replies

9. Shell Programming and Scripting

How to validate user's input..?

$Input_filename=$ARGV; if (!-d $Input_filename && ! -e $Input_filename) { print "USAGE: Please enter '$ABCD/def/dsed.txt' as an arguement \n"; exit; } 1. Input Is suppose to be something like "$ABCD/def/dsed.txt". if the input is wrong the script should throw an ERROR message.... (2 Replies)
Discussion started by: Rashid Khan
2 Replies

10. Shell Programming and Scripting

Validate input files and update

We have a job which we need to run on daily bases, before loading data in a table we need to validate whether the input file is received or not.Inputfile formatsrc_sps_d_Call_Center_Reporting_yyyymmdd_01.dat SPS-Service nameYYYY-yearMM-MonthDD-dayLike above we will get n number of files for... (1 Reply)
Discussion started by: katakamvivek
1 Replies
TryCatch(3pm)						User Contributed Perl Documentation					     TryCatch(3pm)

NAME
TryCatch - first class try catch semantics for Perl, without source filters. DESCRIPTION
This module aims to provide a nicer syntax and method to catch errors in Perl, similar to what is found in other languages (such as Java, Python or C++). The standard method of using "eval {}; if ($@) {}" is often prone to subtle bugs, primarily that its far too easy to stomp on the error in error handlers. And also eval/if isn't the nicest idiom. SYNOPSIS
use TryCatch; sub foo { my ($self) = @_; try { die Some::Class->new(code => 404 ) if $self->not_found; return "return value from foo"; } catch (Some::Class $e where { $_->code > 100 } ) { } } SYNTAX
This module aims to give first class exception handling to perl via 'try' and 'catch' keywords. The basic syntax this module provides is "try { # block }" followed by zero or more catch blocks. Each catch block has an optional type constraint on it the resembles Perl6's method signatures. Also worth noting is that the error variable ($@) is localised to the try/catch blocks and will not leak outside the scope, or stomp on a previous value of $@. The simplest case of a catch block is just catch { ... } where upon the error is available in the standard $@ variable and no type checking is performed. The exception can instead be accessed via a named lexical variable by providing a simple signature to the catch block as follows: catch ($err) { ... } Type checking of the exception can be performed by specifing a type constraint or where clauses in the signature as follows: catch (TypeFoo $e) { ... } catch (Dict[code => Int, message => Str] $err) { ... } As shown in the above example, complex Moose types can be used, including MooseX::Types style of type constraints In addition to type checking via Moose type constraints, you can also use where clauses to only match a certain sub-condition on an error. For example, assuming that "HTTPError" is a suitably defined TC: catch (HTTPError $e where { $_->code >= 400 && $_->code <= 499 } ) { return "4XX error"; } catch (HTTPError $e) { return "other http code"; } would return "4XX error" in the case of a 404 error, and "other http code" in the case of a 302. In the case where multiple catch blocks are present, the first one that matches the type constraints (if any) will executed. BENEFITS
return. You can put a return in a try block, and it would do the right thing - namely return a value from the subroutine you are in, instead of just from the eval block. Type Checking. This is nothing you couldn't do manually yourself, it does it for you using Moose type constraints. TODO
o Decide on "finally" semantics w.r.t return values. o Write some more documentation o Split out the dependancy on Moose SEE ALSO
MooseX::Types, Moose::Util::TypeConstraints, Parse::Method::Signatures. AUTHOR
Ash Berlin <ash@cpan.org> THANKS
Thanks to Matt S Trout and Florian Ragwitz for work on Devel::Declare and various B::Hooks modules Vincent Pit for Scope::Upper that makes the return from block possible. Zefram for providing support and XS guidance. Xavier Bergade for the impetus to finally fix this module in 5.12. LICENSE
Licensed under the same terms as Perl itself. perl v5.14.2 2010-10-13 TryCatch(3pm)
All times are GMT -4. The time now is 10:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy