Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • DSA
  • Practice Problems
  • C
  • C++
  • Java
  • Python
  • JavaScript
  • Data Science
  • Machine Learning
  • Courses
  • Linux
  • DevOps
  • SQL
  • Web Development
  • System Design
  • Aptitude
  • GfG Premium
Open In App
Next Article:
Perl | File Test Operators
Next article icon

Perl | File Test Operators

Last Updated : 21 Feb, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
File Test Operators in Perl are the logical operators which return True or False values. There are many operators in Perl that you can use to test various different aspects of a file. For example, to check for the existence of a file -e operator is used. Or, it can be checked if a file can be written to before performing the append operation. This will help to reduce the number of errors that a program might encounter. Following example uses the '-e', existence operator to check if a file exists or not: Perl
#!/usr/bin/perl  # Using predefined modules use warnings; use strict;   # Providing path of file to a variable my $filename = 'C:\Users\GeeksForGeeks\GFG.txt';  # Checking for the file existence if(-e $filename) {          # If File exists     print("File $filename exists\n"); }  else {          # If File doesn't exists     print("File $filename does not exists\n"); } 
Output: Filename or filehandle is passed as an argument to this file test operator -e.   Following is a list of most important File Test Operators:
Operator Description
-rchecks if the file is readable
-wchecks if the file is writable
-xchecks if the file is executable
-ochecks if the file is owned by effective uid
-Rchecks if file is readable by real uid
-Wchecks if file is writable by real uid
-Xchecks if file is executable by real uid/gid
-Ochecks if the file is owned by real uid
-echecks if the file exists
-zchecks if the file is empty
-schecks if the file has nonzero size (returns size in bytes)
-fchecks if the file is a plain text file
-dchecks if the file is a directory
-lchecks if the file is a symbolic link
-pchecks if the file is a named pipe (FIFO): or Filehandle is a pipe
-Schecks if the file is a socket
-bchecks if the file is a block special file
-cchecks if the file is a character special file
-tchecks if the file handle is opened to a tty
-uchecks if the file has setuid bit set
-gchecks if the file has setgid bit set
-kchecks if the file has sticky bit set
-Tchecks if the file is an ASCII text file (heuristic guess)
-Bchecks if the file is a “binary” file (opposite of -T)
You can use the AND logical operator in conjunction with file test operators as follows: Perl
#!/usr/bin/perl  # Using predefined modules use warnings; use strict;   # Providing path of file to a variable my $filename = 'C:\Users\GeeksForGeeks\GFG.txt';  # Applying multiple Test Operators  # on the File if(-e $filename && -f _ && -r _ ) {    print("File $filename exists and readable\n");  }  else {     print("File $filename doesn't exists") } 
Output: Above example, checks for the existence of the file and if the file is plain or not and if it is readable.

Next Article
Perl | File Test Operators

A

Akanksha_Rai
Improve
Article Tags :
  • Perl
  • Perl-files

Similar Reads

    Perl | Operators | Set - 1
    Operators are the main building block of any programming language. Operators allow the programmer to perform different kinds of operations on operands. In Perl, operators symbols will be different for different kind of operands(like scalars and string). Operators Can be categorized based upon their
    12 min read
    Perl | Operators | Set - 2
    Operators are the main building block of any programming language. Operators allow the programmer to perform different kinds of operations on operands. In Perl, operators symbols will be different for different kind of operands(like scalars and string). Some of the operators already discussed in Per
    7 min read
    Perl | le operator
    'le' operator in Perl is one of the string comparison operators used to check for the equality of the two strings. It is used to check if the string to its left is stringwise less than or equal to the string to its right. Syntax: String1 le String2 Returns: 1 if left argument is less than or equal t
    2 min read
    Perl | String Operators
    Operators are the foundation of any programming language. Thus, the functionality of Perl programming language is incomplete without the use of operators. A user can define operators as symbols that help to perform specific mathematical and logical computations on operands. String are scalar variabl
    4 min read
    Perl | lt operator
    'lt' operator in Perl is one of the string comparison operators used to check for the equality of the two strings. It is used to check if the string to its left is stringwise less than the string to its right. Syntax: String1 lt String2 Returns: 1 if left argument is less than the right argument Exa
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences