YaRness
12-14-2000, 11:48 AM
there really hasn't been enough perl on here in the last week or day or hour, so i thought i'd post something.
here's a simple bit of code to take a particular parameter (i.e. matching some pattern) from the command line, or if there isn't one, it asks for the input from the user, or quits if the user enters "q" or "Q".
$_=$ARGV[0] or $_="";
while (! /<some pattern>/)
{
print "Enter input: ";
$_=<STDIN>;
exit if (/^[qQ]$/);
}
i ended up using a substition in the while control, so it looked something like this
$_=$ARGV[0] or $_="";
while (! s/^([a-zA-Z]+)([0-9]+).*$/$1 $2/)
{
print "Enter input: ";
$_=<STDIN>;
exit if (/^[qQ]$/);
}
tr/a-z/A-Z/;
my ($prefix, $suffix) = split();
so if i entered "aBc123" either on the command line or as requested by the program, $prefix would contain "ABC" and $suffix would contain "123".
<edit> (actually dont need a pattern just for matching q, but i actually have /^[qQ].*$/ since the values i'm looking for will never start with q http://www.linuxnewbie.org/ubb/biggrin.gif )
------------------
"Assembly of Japanese bicycle require great peace of mind."
Registered Linux User #188285 http://counter.li.org/
------------------
[This message has been edited by YaRness (edited 14 December 2000).]
here's a simple bit of code to take a particular parameter (i.e. matching some pattern) from the command line, or if there isn't one, it asks for the input from the user, or quits if the user enters "q" or "Q".
$_=$ARGV[0] or $_="";
while (! /<some pattern>/)
{
print "Enter input: ";
$_=<STDIN>;
exit if (/^[qQ]$/);
}
i ended up using a substition in the while control, so it looked something like this
$_=$ARGV[0] or $_="";
while (! s/^([a-zA-Z]+)([0-9]+).*$/$1 $2/)
{
print "Enter input: ";
$_=<STDIN>;
exit if (/^[qQ]$/);
}
tr/a-z/A-Z/;
my ($prefix, $suffix) = split();
so if i entered "aBc123" either on the command line or as requested by the program, $prefix would contain "ABC" and $suffix would contain "123".
<edit> (actually dont need a pattern just for matching q, but i actually have /^[qQ].*$/ since the values i'm looking for will never start with q http://www.linuxnewbie.org/ubb/biggrin.gif )
------------------
"Assembly of Japanese bicycle require great peace of mind."
Registered Linux User #188285 http://counter.li.org/
------------------
[This message has been edited by YaRness (edited 14 December 2000).]