Newbie Question

A

Amy Lee

Hi,

I'm a perl newbie, and I face something I can't handle.

I make a small perl script to find the shell script, one of parts is like
this:

.... ...

my $ROOT="/root"

print "Please enter the shell script name: ";
my $ANSWER=<STDIN>;
until (-e "$ROOT/$ANSWER")
{
print "Error: Couldn't find the specific shell script.\n";
print "Please enter the shell script name: ";
my $ANSWER=<STDIN>;
}

.... ...

In my root directory, there's a file called testlink script, when I input
the name testlink, it always shows that "Error: Couldn't find the specific
shell script.". And notice me to type again.

I don't know how to accomplish this function.

Thanks in advance~

Amy Lee
 
G

Gunnar Hjalmarsson

Amy said:
I make a small perl script to find the shell script, one of parts is like
this:

... ...

my $ROOT="/root"

print "Please enter the shell script name: ";
my $ANSWER=<STDIN>;

chomp $ANSWER;
until (-e "$ROOT/$ANSWER")
{
print "Error: Couldn't find the specific shell script.\n";
print "Please enter the shell script name: ";
my $ANSWER=<STDIN>;

You don't want to my() declare here.
 
M

Mumia W.

Hi,

I'm a perl newbie, and I face something I can't handle.

I make a small perl script to find the shell script, one of parts is like
this:

.... ...

my $ROOT="/root"

print "Please enter the shell script name: ";
my $ANSWER=<STDIN>;

chomp $ANSWER;
until (-e "$ROOT/$ANSWER")
{
print "Error: Couldn't find the specific shell script.\n";
print "Please enter the shell script name: ";
my $ANSWER=<STDIN>;
}

.... ...

In my root directory, there's a file called testlink script, when I input
the name testlink, it always shows that "Error: Couldn't find the specific
shell script.". And notice me to type again.

I don't know how to accomplish this function.

Thanks in advance~

Amy Lee

Probably there is a newline in $ANSWER that must be removed by chomp().
 
G

Gunnar Hjalmarsson

Amy said:
Thank you very much, but why I can't add my() declare in the "until"
function?

You can, but you probably don't want, since that would make $ANSWER in
the until block a separate variable from the $ANSWER variable you
declared outside the block.
 
M

Michele Dondi

Subject: Newbie Question

Yes, *which* question? (That is, *please* put the subject of your post
in the Subject.)
I make a small perl script to find the shell script, one of parts is like
this:

Seeing what you pasted below, the fact that what you're looking for
happens to be a *shell script* is irrelevant.

I hope that those dots comprise

use strict;
use warnings:

because otherwise the first, single and best advice I can give you is
to do so.
my $ROOT="/root"

print "Please enter the shell script name: ";
my $ANSWER=<STDIN>;

chomp(my $ANSWER=<STDIN>); # See perldoc -f chomp

Handles are not autochomped by default (yet).
until (-e "$ROOT/$ANSWER")
{
print "Error: Couldn't find the specific shell script.\n";
print "Please enter the shell script name: ";
my $ANSWER=<STDIN>;
}

You may be interested in

perldoc -f redo
perldoc -f last

for an alternative and IMHO simpler syntax.


Michele
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top