🐪 Perl File I/O

File handling in Perl is clean and flexible. You can open files for reading, writing, or appending using the open function with modes.

🖥️ Example 1: Reading a File

Use < mode to open a file for reading.

[Simulation] data.txt contents would display here.

🖥️ Example 2: Writing to a File

Use > mode to write (overwrites the file).

[Simulation] File 'output.txt' written.

🖥️ Example 3: Appending to a File

Use >> mode to append to the end of a file.

[Simulation] Line appended to 'output.txt'.
💡 Tip: Always close() filehandles after you're done to free system resources.