
lie soul
Novice
Sep 25, 2012, 8:07 PM
Post #1 of 4
(2592 views)
|
(2) Questions regarding the [Hash] and [Reading a directory]
|
Can't Post
|
|
I have two questions. 1) I'm trying to let the user type his "directory path" (perl example.pl /Users/name/file) in order to show the files or directory folder, i also wanted to show if the file or directory can or cannot be read, written, and executed This the code i came up with.. but i still wanted to know if i can find the way of indicating if the file or directory and if it can or cannot be read, written, and executed. I also wanted to make sure about what i making is good on other systems ( Linux/Unix/Mac)
#!/usr/bin/perl -w use strict; my $dir = shift || die "Argument missing: Please make sure from your directory name\n"; my $dir = ".."; opendir DIR, $dir; my @values = readdir(DIR); closedir DIR; foreach (@values) { printf "$_ is a file\n" if -f "$dir/$_"; printf "$_ is a dir\n" if -d "$dir/$_"; } 2) Question 2, i want to print out elements of hash and i want to use different ways of listing them.. just as each funiction, keys function, values function and finaly sort keys.. and what i did was the following code and i don't know where is my problem... $A = user input.. $B = user input..
#!/usr/bin/perl -w use strict; print "Enter A: "; $A = <STDIN>; chomp $A; print "Enter B: "; $B = <STDIN>; chomp $B; my %hash = ( 'A' => "$A", 'B' => "$B", 'Z' => 'Z', 'D' => 'D', 'H' => 'H', ); print "A: $hash{ 'A' }\n"; print "B: $hash{ 'B' }\n"; print "Z: $hash{ 'Z' }\n"; print "D: $hash{ 'D' }\n"; print "H: $hash{ 'H' }\n"; These are the 2 questions that i'm facing problem with... Thanks
|