In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how to use the Perl file handle, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!
Perl file handle
The Perl script connects to the outside world through an indirect Perl file handle. External data is imported from the indirect Perl file handle and data is exported by writing to the indirect Perl file handle. Depending on how the indirect Perl file handle is created, it may be connected to:
Disk file.
Hardware devices, such as printers, etc.
A local process, such as a command line window in a window system.
A remote process, such as a network server.
The "bit bucket" device, the / dev/null in the Unix/Linux system, simply attracts data and ignores it.
An indirect Perl file handle can be any valid Perl identifier consisting of uppercase and lowercase letters, numbers, and underscore characters. Unlike other variables, indirect Perl file handles have no iconic prefixes (like "$", "@", "%"). Therefore, in order to distinguish indirect Perl file handles, Perl programmers often represent them in all uppercase letters.
When the Perl script starts execution, three indirect Perl file handles are opened by default: STDIN,STDOUT and STDERR. The STDOUT indirect Perl file handle (that is, "standardoutput") standard output is the default output indirect Perl file handle. The data sent to this indirect Perl file handle is displayed on the user-specified output device, usually the command-line window where the script starts running. STDIN, or "standardinput", standard input, is the default input indirect Perl file handle. The data read from this indirect Perl file handle is taken from the input device of the user's choice, usually the keyboard. STDERR (or "standarderror") standard error output for error messages, diagnostics, debugging, and other similar occasional output. By default, STDERR and STDOUT use the same output device, but the user can change it.
Normal and abnormal output have different independent indirect Perl file handles so that users can transfer them independently; for example, send normal output to a file and error output to the screen.
#! / usr/bin/perl-w chomp ($input=); print "IfIheardyoucorrectly,yousaid:$input\ n"
STDERR is the default target for the warn () function and the die () function. The user can change the connection of three standard indirect Perl file handles before starting to execute the script. On Unix/Linux and Windows systems, use the redirect metacharacter "" to make this change. For example, executing these two redirect commands on a script named change.pl will change the script's standard input to read data from the file data.txt, and change the standard output so that the processed data is output to the file changed.txt:
# perlchange.plchanged.txt
Standard error does not change, so diagnostic information (for example, information returned from the built-in warn () function and die () function) is displayed on the screen.
Indirect Perl file handle
Indirect Perl file handles make it easier to manage namespaces. Because the indirect Perl file handle is global to the current package
When two functions try to open "INFILE" at the same time, it causes a conflict. If two functions use indirect text
Element handle, such as "my$infile", there is no conflict, and there is no need to worry about conflicts in the future.
The * * parameters of "open" can be a reference to an indirect Perl file handle. In Perl5.6.0, if
Parameter is not initialized, Perl automatically creates an indirect Perl file handle and stores it in * * parameters
For example:
Open (my$in,$infile) ordie "Couldnails treadmill close$in!"; while () {# dosomethingwith$_} close$in
Another convenience is that when running out of scope or using undefine, the Perl file handle will
Automatically shut down.
Subfirstline {
Open (my$in,shift) & & returnscalar
# noclose () required
}
[recommended by editors]
The above is all the contents of the article "how to use Perl file handles". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.