02-15-2009
Taking user response in perl
I was wondering if it was possible to take in a user's response in a perl program.
For example.
Ask user a yes or no question, and then depending on the response, print out a corresponding answer?
Thanks!
9 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Would there be any reason for why a 'read ans' would not wait for a user's response (i.e user has to hit a key to continue)? I know for sure that it is doing everything else in that part of my 'if' statement but it doesn't wait for me to hit a key before continuing.
The strange thing is that... (4 Replies)
Discussion started by: giannicello
4 Replies
2. Shell Programming and Scripting
How would i go about the following,
I open a text document with loads of text, about 150 lines
e.g. "Best Time: 02:55.88"
How would i get perl just to take the time and put into a variable but also be able to take any time like that from the file??
i've done this so far to open the... (2 Replies)
Discussion started by: perleo
2 Replies
3. Shell Programming and Scripting
Hi,
I am new to perl
I need to connect from linux server to oracle database and i need to query the database and take result into csv file.
i try to do but i am getting this error:
#!/usr/bin/perl
use DBI;
BEGIN {
$ENV{ORACLE_HOME} = '/home/oracle/product/8.1.7';
... (1 Reply)
Discussion started by: prakash.gr
1 Replies
4. Shell Programming and Scripting
I am using the following code in a CShell script to get a yes/no response from the user:
echo ""
echo -n "Do you want to archive your main level directory? <y> or n: "
set main_answer = $<
Is there a way to extract the first letter from the user's response and then perhaps convert that... (4 Replies)
Discussion started by: phudgens
4 Replies
5. Shell Programming and Scripting
Hi All,
I am facing a problem while taking input from user in Shell Script. Basically , I want to read a file line by line. And I want to remove certain lines of that file.But before removing those lines , I need to ask the user whether user wants to remove the lines. If user inputs "Yes" , the... (3 Replies)
Discussion started by: swapnil.nawale
3 Replies
6. Shell Programming and Scripting
Need help in scripting . Below is the situation and need your inputs
Checking all the processes, scripts running time based on user input time . Below Example
ps -aef -o user,pid,etime,stime,args| grep sleep
<user> 28995 01:24 14:14:39 sleep 120
<user> 29385 00:52 14:15:10... (8 Replies)
Discussion started by: ajayram_arya
8 Replies
7. Shell Programming and Scripting
Dear community, I'm going crazy to convert TCP response to HEX using perl. I have a simple connection request where I send data, something like:
use strict;
use IO::Socket;
my $sock;
$sock = new IO::Socket::INET(
PeerAddr => '192.168.10.7',
PeerPort =>... (1 Reply)
Discussion started by: Lord Spectre
1 Replies
8. Shell Programming and Scripting
In the bash below I am trying to run the script entire script including the ....(which is a bunch of code) and then in the run function if the user response is y (line in bold). then start processing from execute function. Basically, goto the # extract folder for variable filename line and start... (4 Replies)
Discussion started by: cmccabe
4 Replies
9. Shell Programming and Scripting
I created a program, so a kid can practice there math on it. It dispenses varies math problems and the kid must input an answer. I also want it to grade the work they have done, but I can't find the best place for it to print out the grade.
I have:
if ( $response =~ m/^/ ) {
$user_wants_to_quit... (1 Reply)
Discussion started by: germany1517
1 Replies
LEARN ABOUT DEBIAN
rpmatch
RPMATCH(3) Linux Programmer's Manual RPMATCH(3)
NAME
rpmatch - determine if the answer to a question is affirmative or negative
SYNOPSIS
#include <stdlib.h>
int rpmatch(const char *response);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
rpmatch(): _SVID_SOURCE
DESCRIPTION
rpmatch() handles a user response to yes or no questions, with support for internationalization.
response should be a null-terminated string containing a user-supplied response, perhaps obtained with fgets(3) or getline(3).
The user's language preference is taken into account per the environment variables LANG, LC_MESSAGES, and LC_ALL, if the program has called
setlocale(3) to effect their changes.
Regardless of the locale, responses matching ^[Yy] are always accepted as affirmative, and those matching ^[Nn] are always accepted as neg-
ative.
RETURN VALUE
After examining response, rpmatch() returns 0 for a recognized negative response ("no"), 1 for a recognized positive response ("yes"), and
-1 when the value of response is unrecognized.
ERRORS
A return value of -1 may indicate either an invalid input, or some other error. It is incorrect to only test if the return value is
nonzero.
rpmatch() can fail for any of the reasons that regcomp(3) or regexec(3) can fail; the cause of the error is not available from errno or
anywhere else, but indicates a failure of the regex engine (but this case is indistinguishable from that of an unrecognized value of
response).
CONFORMING TO
rpmatch() is not required by any standard, but is available on a few other systems.
BUGS
The rpmatch() implementation looks at only the first character of response. As a consequence, "nyes" returns 0, and "ynever; not in a mil-
lion years" returns 1. It would be preferable to accept input strings much more strictly, for example (using the extended regular expres-
sion notation described in regex(7)): ^([yY]|yes|YES)$ and ^([nN]|no|NO)$.
EXAMPLE
The following program displays the results when rpmatch() is applied to the string given in the program's command-line argument.
#define _SVID_SOURCE
#include <locale.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
int
main(int argc, char *argv[])
{
if (argc != 2 || strcmp(argv[1], "--help") == 0) {
fprintf(stderr, "%s response
", argv[0]);
exit(EXIT_FAILURE);
}
setlocale(LC_ALL, "");
printf("rpmatch() returns: %d
", rpmatch(argv[1]));
exit(EXIT_SUCCESS);
}
SEE ALSO
fgets(3), getline(3), nl_langinfo(3), regcomp(3), setlocale(3)
COLOPHON
This page is part of release 3.44 of the Linux man-pages project. A description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
GNU
2007-07-26 RPMATCH(3)