what does the $mode save when using stat in perl -


guys im trying see permission of file in perl using stat.

so when did

foreach (@original_files) {     my($dev, $ino, $mode, $nlink, $uid, $gid, $rdev,       $size, $atime, $mtime, $ctime, $blksize, $blocks) = stat ($_);      print "$mode \n"; } 

this outputs:

33204 corresponds permission -rw-rw-r-- 

which cant understand why 33204. <-- this first question

next tried converting $mode octal know number system umask.

this code:

printf ("%0\n",$mode); 

now outputs 100664 quite undersand last 3 digits (rw-rw-r--) dont understand did first 3 digits come ( 100 in 100664) that second question

lastly tried code again:

printf ("%o\n", $mode & 775); #im not sure 775, or 577 

that last code desired. outputs 664. , question why when , $mode forgot value (775 or something) outputs right permission.?

and ot question too: what difference of $_ , @_?

from web host's man 2 stat mode:

s_ifmt     0170000   bit mask file type bit fields s_ifsock   0140000   socket s_iflnk    0120000   symbolic link s_ifreg    0100000   regular file s_ifblk    0060000   block device s_ifdir    0040000   directory s_ifchr    0020000   character device s_ififo    0010000   fifo s_isuid    0004000   set uid bit s_isgid    0002000   set-group-id bit (see below) s_isvtx    0001000   sticky bit (see below) s_irwxu    00700     mask file owner permissions s_irusr    00400     owner has read permission s_iwusr    00200     owner has write permission s_ixusr    00100     owner has execute permission s_irwxg    00070     mask group permissions s_irgrp    00040     group has read permission s_iwgrp    00020     group has write permission s_ixgrp    00010     group has execute permission s_irwxo    00007     mask permissions others (not in group) s_iroth    00004     others have read permission s_iwoth    00002     others have write permission s_ixoth    00001     others have execute permission 

(note leading 0 means numbers octal numbers.)

you can see 7 fields in mode word.

s_ifmt   file type s_isuid  set uid bit s_isgid  set-group-id bit s_isvtx  sticky bit s_irwxu  owner permissions s_irwxg  group permissions s_irwxo  other permissions 

if view mode fields instead of number (0x81b4 = 33204 = 0100664 = 0b1000000110110100), get:

s_ifmt:  s_ifreg (regular file) s_isuid: 0 (no set uid bit) s_isgid: 0 (no set-group-id bit) s_isvtx: 0 (no sticky bit) s_irwxu: s_irusr | s_iwusr (user has rw) s_irwxg: s_irgrp | s_iwgrp (group has rw) s_irwxo: s_iroth (other has r) 

doing & 0777 same doing & (s_irwxu | s_irwxg | s_irwxo) extracts fields containing various permission.


$_ variable refers $main::_. it's set constructs (foreach loop, map, grep) , used default many operators (e.g. say; means say $_;).

the elements of @_ aliased parameters passed sub being executed. e.g. $_[0] , $x contains 4 in sub f { ($x) = @_; ... } f(4);


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -