Perl Special Literals

PERLServer Side ProgrammingProgramming Scripts

Let me tell you about three special literals __FILE__, __LINE__, and __PACKAGE__ represent the current filename, line number, and package name at that point in your program.

They may be used only as separate tokens and will not be interpolated into strings. Check the below example −

Example

 Live Demo

#!/usr/bin/perl
print "File name ". __FILE__ . "\n";
print "Line Number " . __LINE__ ."\n";
print "Package " . __PACKAGE__ ."\n";
# they can not be interpolated
print "__FILE__ __LINE__ __PACKAGE__\n";

Output

This will produce the following result −

File name hello.pl
Line Number 4
Package main
__FILE__ __LINE__ __PACKAGE__
raja
Published on 28-Nov-2019 14:00:04
Advertisements