Hello,
I've got a program which takes in lines of text via keyboard input, but i am not sure how to place in code to end input by placing a full stop on a newline? Can anyone help?
Hello,
I've got a program which takes in lines of text via keyboard input, but i am not sure how to place in code to end input by placing a full stop on a newline? Can anyone help?
[QUOTE=Skeleton Man]Post the code here and I'll see if I can help
hi,
basically i've got to get keyboard input either in single line mode or multiline. for example, for single line the arguments must be written next to the executable file for it to print out (stored in @ARGV)
ie.
shell> ./script cat in hat
cat in hat
shell>
but then if you just put the executable file without command line arguments it should let you type in multilines and typing a fullstop should exit program.
ie:
shell> ./script
this is
a test
.
shell>
im not sure how to yet put the above into a code??? so far i've just been working with the modes seperately, my code for the multiple lines is;
my $line;
my @ARGV=$line;
while (defined($line=<>)) {
#my $term='.';
#if ($line eq $term){
#exit;
#}else{
print " $line";
#}
}
the commented if else statement doesnt work and doesnt exit with fullstop either....???????????
Whoo hoo!! that works great!! your a legend!! any ideas how input can be intepreted ie, either single line mode (by giving command line argument) or multiline mode (no command line argument) as per above example??? i can't find in any book or internet resources?? but if not its okay my biggest prob was the termination with fullstop, thanks a lot
Here's the basic structure for either single or multi-line input:
The best learning resource for perl is the O'Reilly series of books, I believe there's one with a camel or lama on the front, the title escapes me though..
Code:
#!/usr/bin/perl
# Arrays used in this context give us the number of elements.
# In this case we're using @ARGV which holds command line arguments.
if (@ARGV > 0){
#
# We have a least one command line argument.
#
print "\nArguments: ";
foreach $arg (@ARGV){ print "$arg "; }
print "\n";
}else{
#
# No arguments were given, accept input.
#
$txt = '';
while ($txt ne '.'){
chomp($txt = <STDIN>);
if ($txt ne '.'){ $buf .= "$txt "; }
}
print "\nYou Typed: $buf\n";
}
Last edited by Skeleton Man; 05-03-04 at 05:14 AM.