It is the same as a shell script that you can write a sentence at the top level in Perl

Writing statements at the top level in Perl is the same as a shell script. Shell scripts were originally created to describe batch processing, starting with shell commands that interact interactively in the CUI. Therefore, you can write a sentence suddenly. Perl has also adopted this idea.

The ability to write statements suddenly is a feature of scripting languages, and there is no need to define functions. The good thing about scripting languages ​​is that you can write a program immediately by learning how to use a function without knowing how to define it.

Perl can write sentences at the top level

Perl can write statements at the top level.

print "Hello, World! \ N";

Shell scripts can write sentences at the top level

Shell scripts can write statements at the top level.

echo "Hello, World\n"

What is the significance of Perl's ability to write sentences at the top level with reference to shell scripts?

Perl refers to the grammar of some programming languages, but adopted the grammar of shell scripts for the part where you can write sentences suddenly at the top level.

For C, the top level is the function definition. From a parsing point of view, this is pretty because the structure is the same at the top level and below.

main (int argc, char * argv []) {
  
}

Like Perl and the shell, you can write sentences at the top level. This is actually a function, but it automatically turns it into a function. In short, it's syntactic sugar that makes it easy for people to start writing programs.

print "Hello, World! \ N";

Internally, for example, it is supplemented as follows. (It is an image, not an actual implementation)

sub main {
  print "Hello, World! \ N";
}
main ();

When I start writing a program, I just can write it right away, but I want to write this a little right away. It's very convenient when you want to write a one-liner.

Perl is easy, so you referred to your senior shell script in this regard.

Associated Information