6

Why would you need to use the int() function when setting the perms on a file in Perl?

die "blab, blah"
    if (! chmod(int(0664), $tmp_file));

I can understand the use of oct() as in the following perldoc example:

$mode = "0644"; chmod(oct($mode), $tmp_file);

but the int() function?

Edit

Just for completeness, here's the recommendation from perldoc -f chmod ...

$mode = 0644;   chmod $mode, "foo";      # this is best
Rob Wells
  • 36,220
  • 13
  • 81
  • 146

1 Answers1

10

It makes absolutely no sense. 0664 already results in an integer.

$ perl -MDevel::Peek -e'Dump(0664)'
SV = IV(0x7a6118) at 0x7a6128
  REFCNT = 1
  FLAGS = (PADTMP,IOK,READONLY,pIOK)
  IV = 436

IOK signals the scalar contains an integer value.

It's surely the result of someone starting with oct("0644") but not quite understanding what they were doing when they moved away from using a string.

ikegami
  • 367,544
  • 15
  • 269
  • 518