Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of the dot in this open() usage in Perl?

Tags:

perl

How can I understand the following usage of the open() function in Perl File I/O?

open(FHANDLE, ">" . $file )

I tried to find this type of syntax in the docs but did not find; please note there is a . (dot) after ">".

All I cannot understand is a use of dot, the rest I know.

like image 696
Vicky Avatar asked Sep 26 '17 12:09

Vicky


People also ask

What does a period mean in Perl?

The period . is the concatenation operator. The equal sign to the right means that this is an assignment operator, like in C. For example: $input .= $_; Does the same as $input = $input .

What does =~ mean in Perl?

=~ is the Perl binding operator. It's generally used to apply a regular expression to a string; for instance, to test if a string matches a pattern: if ($string =~ m/pattern/) {

What is @_ and $_ in Perl?

$_ - The default input and pattern-searching space. @_ - Within a subroutine the array @_ contains the parameters passed to that subroutine. $" - When an array or an array slice is interpolated into a double-quoted string or a similar context such as /.../ , its elements are separated by this value.

What does $@ meaning in Perl?

The variables are shown ordered by the "distance" between the subsystem which reported the error and the Perl process...$@ is set if the string to be eval-ed did not compile (this may happen if open or close were imported with bad prototypes), or if Perl code executed during evaluation die()d.


1 Answers

This is an example of the old, two-argument form of open (which should be avoided now that three-argument open is available). In Perl, . is the append operator. It combines the two strings into a single string.

The line of code you posted is equivalent to open(FHANDLE, ">$file" ), it just uses a different method of combining the > and $file.

The better way to do it these days would be open(my $fhandle, '>', $file), as shown in the documentation you linked to.

like image 97
Dave Sherohman Avatar answered Oct 05 '22 02:10

Dave Sherohman