Vicky Vicky - 5 months ago 38
Perl Question

File open syntax in perl

Can someone help me understand this syntax of open function in Perl File I/O ?

open(FHANDLE, ">" . $file )

I tried to find this type of syntax here but did not find , please note there is a .(dot) after ">" .
All I cannot understand is a use of dot , rest I know.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download