Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

does "STDIN" written in <> effect behaviour of perl program?

Tags:

perl

I've two perl scripts, both of them wait for user to enter some input as below,

Does both of them are same ? Does "STDIN" written in <> are just to for user-readability of code ? If not please tell me the differences.

a) $in = <STDIN>;

b) $in = <>;
like image 613
aravind ramesh Avatar asked Dec 27 '12 07:12

aravind ramesh


People also ask

What is$@ in Perl?

$@ The Perl syntax error or routine error message from the last eval, do-FILE, or require command. If set, either the compilation failed, or the die function was executed within the code of the eval.

How is Perl executed?

On Win32 systems, if you double-click on the icon for the Perl executable, you'll find yourself in a command-prompt window, with a blinking cursor. You can enter your Perl commands, indicating the end of your input with CTRL-Z, and Perl will compile and execute your script.


2 Answers

The form <FILEHANDLE> will only read from FILEHANDLE.

The form <> will read from STDIN if @ARGV is empty; or from all the files whose names are still in @ARGV which contains the command line arguments passed to the program.

like image 76
Moritz Bunkus Avatar answered Sep 21 '22 18:09

Moritz Bunkus


<> is shorthand for <ARGV>. And ARGV is a special filehandle that either opens and iterates through all of the filenames specified in @ARGV (the command-line arguments) or gets aliased to STDIN (when @ARGV is empty).

like image 41
mob Avatar answered Sep 21 '22 18:09

mob