Front page | perl.beginners |
Postings from April 2002
Re: 2 questions
Thread Previous
From:
Eric Plowe
Date:
April 2, 2002 16:03
Subject:
Re: 2 questions
Message ID:
339892B6-4696-11D6-81A5-003065A95F3E@hypoflux.net
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: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
>
Thread Previous