Home > Archive > PERL Beginners > November 2007 > Chomping directories
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Chomping directories
|
|
| Gianluca Tognin 2007-11-19, 7:59 am |
| Hi,
Well I got to test check a dir.
If I select /etc or /home/user it works. But if I leave a blank, just only
ENTER I got the below error. "/home/user exist and is rwx".
What I'm missing in my script?
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
#!/usr/bin/perl
use diagnostics;
use strict;
print "Please select your directory\n";
chomp (my $dirname=<STDIN> );
my $UPATH=`pwd`;
print "\$UPATH = $UPATH\n";
if ($dirname =~ /^\s*$/){
$dirname="$UPATH";
print "\$dirname=$dirname\n";
}
print "\$dirname=$dirname\n";
opendir DH, $dirname or die "Cannot open $dirname: $!"; #line number 31
while (my $file = readdir DH) {
$file="$dirname/$file";
next if $file =~ /^\./;
print "One file is $file\n";
}
closedir DH;
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Then running the script:
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
../script
Please select your directory
<empty> ENTER
$UPATH = /home/user
$dirname=/home/user
Uncaught exception from user code:
Cannot open /home/user
: No such file or directory at ./script line 31, <STDIN> line 1.
at ./script line 31
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Thank you.
--
Gianluca Tognin
Systems Engineer
Ascom Italia S.p.A.
Via Magellano,1 41100 Modena - Italy
Office (pabx): +(39)059 895011
Office: +(39)059 895059
FAX: +(39)059 895010
mobile 335 7191683
WEB: www.ascom.it
| |
| Zentara 2007-11-19, 7:59 am |
| On Mon, 19 Nov 2007 11:58:27 +0100, gtognin@ascom.it (Gianluca Tognin)
wrote:
>Hi,
>Well I got to test check a dir.
>If I select /etc or /home/user it works. But if I leave a blank, just only
>ENTER I got the below error. "/home/user exist and is rwx".
>What I'm missing in my script?
chomp your $UPATH, it has a newline on it.
>- - - - - - - - - - - - - - - - - - - - - - - - - - - -
>#!/usr/bin/perl
>use diagnostics;
>use strict;
>
>print "Please select your directory\n";
>chomp (my $dirname=<STDIN> );
>
>my $UPATH=`pwd`;
chomp $UPATH;
>print "\$UPATH = $UPATH\n";
>
>if ($dirname =~ /^\s*$/){
> $dirname="$UPATH";
> print "\$dirname=$dirname\n";
>}
>print "\$dirname=$dirname\n";
>
>opendir DH, $dirname or die "Cannot open $dirname: $!"; #line number 31
>
>while (my $file = readdir DH) {
> $file="$dirname/$file";
> next if $file =~ /^\./;
> print "One file is $file\n";
>}
>closedir DH;
>- - - - - - - - - - - - - - - - - - - - - - - - - - - -
zentara
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
|
|
|
|
|