Persuade Perltidy to Leave Only Space

I use Perltidy to reformat some of my old Perl files in a style that is closer to my current settings. I ran into a problem with this snippet:

Fcntl::S_IRUSR & $mode 

Perltidy insists on removing the space after the & token, resulting in:

 Fcntl::S_IRUSR &$mode 

... which, in my opinion, is a thorn. What can I do to convince Perltidy to leave this single space? I even tried the -fws option -fws no avail.

I am using Perltidy 20101217, which is apparently the latest version.

EDIT:

A few additional observations:

  • Using the --indent-only ( -io ) -io does not remove the above space.

  • This issue does not affect the following equivalent snippet:

     $mode & Fcntl::S_IRUSR 

EDIT 2:

I ended up reordering the arguments to the & operator, as this seems to be working on the Perltidy problem currently. In addition, this approach does not require the addition of extra parentheses or any other tokens that could help Perltidy do the โ€œRight Thingโ€, but they would certainly confuse me in the end.

UPDATE:

I contacted Steve Hancock, author of Perltidy, on this subject. From his answer:

I checked, and the problem is that in this case, as a sigil function. The main problem is that perltidy does not see prototypes for other modules, even built-in ones, so it should be guessed when it comes to something like "Fcntl :: S_IRUSR". In other words, he does not know if this is a function call or a constant, and he must guess. When you canceled the order, it eliminated the ambiguity on &.

Thanks for the note. I will see if I can come up with a fix to fix this.

+4
source share
1 answer

He certainly thinks wrong

 Fcntl::S_IRUSR & $mode 

means

 Fcntl::S_IRUSR(&$mode) 

You can probably fool him using

 (Fcntl::S_IRUSR) & $mode 

or

 Fcntl::S_IRUSR() & $mode 
+5
source

Source: https://habr.com/ru/post/1379229/


All Articles