Hey Monks,
I am just attemmpting to learn to filestat from the llama. I am working off of Chapter 11 in said book, and excercise 1 which states:
Make a program that takes a list of files named on the command line and reports for each one whether its readable, writable, executable, or doesn't exist. (Hint: It may be helpful to have a function that will do all of the file tests for one file at a time.) What does it report about a file that has been chmod-ed to 0? (That is if you are on a Unix system use the command chmod 0
some_file to mark that file as being neither readable, writable nor executable.) In most shells, use a star as the argument to mean all of the normal files in the current directory. That is you should type something like ./ex11-1 to ask the program for the attributes of many files at once.
Iam
going to add the rest of the tests once I have it figured out what I'm doing wrong. But this is very preliminary and I don't know why the first test I added is not working.
#!/usr/bin/perl
use warnings;
use strict;
sub filetest {
my @answer;
return "File does not exist"
unless -e $_;
}
while (<>) {
my @answer = &filetest($_);
}
This is the message I get when I try to run the program:
Unsuccessful stat on filename containing newline at ./ex1-11 line 8, <> line 1Also, in the subroutine 'filetest' I have an (as yet) unused array called
@answer. Once I have the file tests worked out I intend to fill that array with strings indicating the states of the file tests.
Once I have all the data collected I plan to return that array.
Thanks for any help you'd care to dispense!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.