FSU COP 4342 - File testing (21 pages)

Previewing pages 1, 2, 20, 21 of 21 page document View the full content.
View Full Document

File testing



Previewing pages 1, 2, 20, 21 of actual document.

View the full content.
View Full Document
View Full Document

File testing

108 views

Lecture Notes


Pages:
21
School:
Florida State University
Course:
Cop 4342 - Unix Tools (3)

Unformatted text preview:

Fall 2006 Perl 07 File testing Like BASH file tests exist in Perl source perlfunc r w x o File File File File is is is is readable by effective uid gid writable by effective uid gid executable by effective uid gid owned by effective uid R W X O File File File File is is is is readable by real uid gid writable by real uid gid executable by real uid gid owned by real uid man COP 4342 Fall 2006 Perl 07 e z s File exists File has zero size is empty File has nonzero size returns size in bytes f d l p File File File File S b c t File is a socket File is a block special file File is a character special file Filehandle is opened to a tty u g k File has setuid bit set File has setgid bit set File has sticky bit set is is is is a a a a plain file directory symbolic link named pipe FIFO or Filehandle is a pipe COP 4342 Fall 2006 T B File is an ASCII text file heuristic guess File is a binary file opposite of T M A C Script start time minus file modification time in days Same for access time Same for inode change time Unix may differ for other platforms Perl 07 COP 4342 Fall 2006 Perl 07 Using file status You can use file status like this for instance as pre test while chomp next unless f ignore specials COP 4342 Fall 2006 Perl 07 Using file status Or you can use them as a post test if open FH fn if e fn die File fn doesn t exist if r fn die File fn isn t readable if d fn COP 4342 Fall 2006 Perl 07 die fn is a directory not a regular file die fn could not be opened COP 4342 Fall 2006 Perl 07 Subroutines in Perl You can declare subroutines in Perl with sub and call them with the syntax my list qw etc hosts etc resolv conf etc init d map filecheck list sub filecheck if f print is a regular file n else COP 4342 Fall 2006 Perl 07 print is not a regular file n COP 4342 Fall 2006 Perl 07 Subroutine arguments To send arguments to a subroutine just use a list after the subroutine invocation just as you do with built in functions in Perl Arguments are received in the array usr bin perl



View Full Document

Access the best Study Guides, Lecture Notes and Practice Exams

Loading Unlocking...
Login

Join to view File testing and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view File testing and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?