To check if a file exists, you might be better off using the built-in file
tests.

if(-e $file){
   Do something...
}else{
   Do something else...
}


-----Original Message-----
From: Eric Plowe [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, April 02, 2002 4:03 PM
To: Glenn Cannon
Cc: [EMAIL PROTECTED]
Subject: Re: 2 questions


Glenn..

to print the current directory name...try

---
#!/usr/bin/perl -w
use strict;
use Cwd;

$curr = cwd();
print "$curr\n";

easy enough
----

this is bit longer example.. you could prolly do it another way..but 
this is how *I* would do it
---
#!/usr/bin/perl -w
use strict;
use Cwd;

my $curr = cwd(); (sets $curr to the current directory the script is 
being ran from)
my @files = &getdirfiles();
my $nof = "the name of the file you're looking to see exists";

if (grep /^$nof$/, @files) {
    print "File $nof exists\n";
    $nof = '';
} elsif (!grep /^$nof$/, @files) {
    print "File $nof does not exsist";
    $nof = '';
}

sub getdirfiles {
opendir(CURRDIR, $curr) or die "Can't open directory\n";
@files = readdir(CURRDIR);
closedir(CURRDIR);
return @files;
}
----

hope those examples help...

~Eric
On Tuesday, April 2, 2002, at 06:20 PM, Glenn Cannon wrote:

> Hi all,
>
> Couple of questions from a newbie...
>
> 1)  How can I print the current directory name?
>
> 2)  How can I check to see if a file I know the name of exists?
>
> Thx,
>
> Glenn
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--------------------------------------------------------------------------------
This email may contain confidential and privileged 
material for the sole use of the intended recipient. 
If you are not the intended recipient, please contact 
the sender and delete all copies.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to