Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use int() in a Perl chmod?

Tags:

chmod

perl

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
like image 254
Rob Wells Avatar asked Feb 26 '14 15:02

Rob Wells


1 Answers

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.

like image 120
ikegami Avatar answered Sep 22 '22 08:09

ikegami