file tests

X

Xenos

Do file tests only works with statements of the form:

do_something if -e filename;

can't I do something like:

if -e filename
{
do several things here
}

It doesn't see to like this. What is the best way to do more than on
statement on a file test if? This seems klunky:

my exists = 0;
exists = 1 if -e filename;
if (exists)
{
do stuff
}

Thanks,

DrX
 
G

Gunnar Hjalmarsson

Xenos said:
Do file tests only works with statements of the form:

do_something if -e filename;

can't I do something like:

if -e filename
{
do several things here
}

Which programming language are you dealing with? Post real code!!
It doesn't see to like this.

How would we know when you haven't showed us real code. :(
 
P

Paul Lalli

Xenos said:
Do file tests only works with statements of the form:

do_something if -e filename;
No.

can't I do something like:

if -e filename
{
do several things here
}

no, because that's not proper syntax. You're missing the parentheses.
It doesn't see to like this.

That's a very poor error description. What results are you seeing? How
do they not match your expectations? What error messages are being
printed?
What is the best way to do more than on
statement on a file test if?

if (-e 'file.txt'){
#do thing 1
#do thing 2
}
This seems klunky:

my exists = 0;
exists = 1 if -e filename;
if (exists)
{
do stuff
}

Yes, it does. There's no reason to do anything like that. Furthermore,
that is also not valid syntax.

Have you read the Posting Guidelines that are posted twice weekly? They
ask you to please post a *short but complete* script which demonstrates
the problem you're having.

Paul Lalli
 
D

David Gale

Quoth Xenos said:
Do file tests only works with statements of the form:

do_something if -e filename;

can't I do something like:

if -e filename
{
do several things here
}

It doesn't see to like this. What is the best way to do more than on
statement on a file test if? This seems klunky:

Try proper parenthesizing. :)

if( -e filename ) {
do several things here
}
 
J

Jürgen Exner

Xenos said:
Do file tests only works with statements of the form:

do_something if -e filename;

can't I do something like:

if -e filename
{
do several things here
}

It doesn't see to like this.

Well, yeah, for rather obvious reasons. Didn't you get a syntax error? You
should have included it in your posting. As an error description "It doesn't
seem to like it" is about as useless as possible.

In Perl the condition in an "if" statement must be enclosed in paranthesis:

if (-e filename) {
# do several things here
}

Further details please see "perldoc perlsyn", section "Compound statements"

jue
 

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

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,432
Latest member
GTRNorbert

Latest Threads

Top