If your idea of valid is just "not an empty string", you can loop on the request for each variable sequentially with something like:
instead of asking the user to enter all 20 variables and then verifying all of the values and restarting from the beginning if one of them had an error.
Setup Info:
This User Id and Password mention below are being used with the ISQL command to connect to a sybase database so they are likely to not be the same as those that were signed on from the session.
Situation:
Using a korn shell, the shell prompts for a User Id and Password. During the... (1 Reply)
I am developing a script that will run with '/bin/ksh' shell.
The script is intended to receive a password by keyboard input, but for security reasons I would like to hide what the user is typing.
The keyboard input is being caught by 'read' command.
exmaple :
echo "Please type your new... (1 Reply)
Hi,
I need a way to detect the up and down arrow key inputs for my program. I do not want to wait for the return key to be entered(so that rules out getch() and family). Also I need to process several of these inputs in parallel, by servicing each request with a thread.
Is that possible?
... (4 Replies)
Does anyone know how do you determine the user idle time of STDIN in order to log the user out for being idle too long. I would like to write a c program to do this but I it is not clear upon how to determine idle time from keyboard input. I have found that the "who.c" source file uses the last... (4 Replies)
How would I change up a script that currently has something like:
bash script
echo what's 1 2 3 4?
then using read 1 2 3 4
I type 1 2 3 4.
so in the script i can do stuff like
echo $1 $2 $3 $4
and such...
i was just doing echo "1 2 3 4"|bash script
But was wondering how could I... (5 Replies)
> sed ''
Hello
hi
Hello output
How
hi output
^D
How
>
sed should take each line as input, process and output the result. In the above scenario the input is passed from keyboard and the output of 'Hello' as you can see is displayed on the screen after 'hi' is passed as input but not as... (1 Reply)
Hey guys, first post! I want to write a script that will wait 1 second and then input the keys CTRL+ALT+J to the application i just opened.
The program is dosbox, and thay key combination starts video recording :) I have no idea how to program this, can anyone help please?
thanks in advance! (2 Replies)
I need to Write a shell script that allows some system-administration tasks to be preformed automatically from a menu-driven interface. with automated following tasks:
Copy directory tree
Delete files or directories
Output Information (this part is done )
*Copy directory tree
The “Copy... (2 Replies)
Dear Friends,
I am looking for a shell script to merge input files into one file .. here is my idea:
1st paramter would be outfile file (all input files content)
read all input files and merge them to input param 1
ex: if I pass 6 file names to the script then 1st file name as output file... (4 Replies)
Hello,
i`m trying to create an network monitoring script and i dont know how to make affect that script by pressing an key from keyboard and that script runs not in while or for or any other loop, but with bash command watch
for example: i have created an file (for example check) with content... (0 Replies)
Discussion started by: bacarrdy
0 Replies
LEARN ABOUT PHP
create_function
CREATE_FUNCTION(3) 1 CREATE_FUNCTION(3)create_function - Create an anonymous (lambda-style) functionSYNOPSIS
string create_function (string $args, string $code)
DESCRIPTION
Creates an anonymous function from the parameters passed, and returns a unique name for it.
Caution
This function internally performs an eval(3) and as such has the same security issues as eval(3). Additionally it has bad perfor-
mance and memory usage characteristics.
If you are using PHP 5.3.0 or newer a native anonymous function should be used instead.
PARAMETERS
Usually these parameters will be passed as single quote delimited strings. The reason for using single quoted strings, is to protect the
variable names from parsing, otherwise, if you use double quotes there will be a need to escape the variable names, e.g. $avar.
o $args
- The function arguments.
o $code
- The function code.
RETURN VALUES
Returns a unique function name as a string, or FALSE on error.
EXAMPLES
Example #1
Creating an anonymous function with create_function(3)
You can use this function, to (for example) create a function from information gathered at run time:
<?php
$newfunc = create_function('$a,$b', 'return "ln($a) + ln($b) = " . log($a * $b);');
echo "New anonymous function: $newfunc
";
echo $newfunc(2, M_E) . "
";
// outputs
// New anonymous function: lambda_1
// ln(2) + ln(2.718281828459) = 1.6931471805599
?>
Or, perhaps to have general handler function that can apply a set of operations to a list of parameters:
Example #2
Making a general processing function with create_function(3)
<?php
function process($var1, $var2, $farr)
{
foreach ($farr as $f) {
echo $f($var1, $var2) . "
";
}
}
// create a bunch of math functions
$f1 = 'if ($a >=0) {return "b*a^2 = ".$b*sqrt($a);} else {return false;}';
$f2 = "return "min(b^2+a, a^2,b) = ".min($a*$a+$b,$b*$b+$a);";
$f3 = 'if ($a > 0 && $b != 0) {return "ln(a)/b = ".log($a)/$b; } else { return false; }';
$farr = array(
create_function('$x,$y', 'return "some trig: ".(sin($x) + $x*cos($y));'),
create_function('$x,$y', 'return "a hypotenuse: ".sqrt($x*$x + $y*$y);'),
create_function('$a,$b', $f1),
create_function('$a,$b', $f2),
create_function('$a,$b', $f3)
);
echo "
Using the first array of anonymous functions
";
echo "parameters: 2.3445, M_PI
";
process(2.3445, M_PI, $farr);
// now make a bunch of string processing functions
$garr = array(
create_function('$b,$a', 'if (strncmp($a, $b, 3) == 0) return "** "$a" '.
'and "$b"
** Look the same to me! (looking at the first 3 chars)";'),
create_function('$a,$b', '; return "CRCs: " . crc32($a) . ", ".crc32($b);'),
create_function('$a,$b', '; return "similar(a,b) = " . similar_text($a, $b, &$p) . "($p%)";')
);
echo "
Using the second array of anonymous functions
";
process("Twas brilling and the slithy toves", "Twas the night", $garr);
?>
The above example will output:
Using the first array of anonymous functions
parameters: 2.3445, M_PI
some trig: -1.6291725057799
a hypotenuse: 3.9199852871011
b*a^2 = 4.8103313314525
min(b^2+a, a^2,b) = 8.6382729035898
ln(a)/b = 0.27122299212594
Using the second array of anonymous functions
** "Twas the night" and "Twas brilling and the slithy toves"
** Look the same to me! (looking at the first 3 chars)
CRCs: -725381282, 342550513
similar(a,b) = 11(45.833333333333%)
But perhaps the most common use for of lambda-style (anonymous) functions is to create callback functions, for example when using
array_walk(3) or usort(3)
Example #3
Using anonymous functions as callback functions
<?php
$av = array("the ", "a ", "that ", "this ");
array_walk($av, create_function('&$v,$k', '$v = $v . "mango";'));
print_r($av);
?>
The above example will output:
Array
(
[0] => the mango
[1] => a mango
[2] => that mango
[3] => this mango
)
an array of strings ordered from shorter to longer
<?php
$sv = array("small", "larger", "a big string", "it is a string thing");
print_r($sv);
?>
The above example will output:
Array
(
[0] => small
[1] => larger
[2] => a big string
[3] => it is a string thing
)
sort it from longer to shorter
<?php
usort($sv, create_function('$a,$b','return strlen($b) - strlen($a);'));
print_r($sv);
?>
The above example will output:
Array
(
[0] => it is a string thing
[1] => a big string
[2] => larger
[3] => small
)
SEE ALSO
Anonymous functions.
PHP Documentation Group CREATE_FUNCTION(3)