First of all, I'm not really sure what XOR is? (exclusive or) Rather, I'm not really sure why it's so important. 11010101 & 10101010 yields 01111111 but big wow! And after that is cleared up, why is it necessary to perform: $mode & 07777 I was hoping $mode would be equal to something like: $mode = 0642

AND, OR, and XOR are logical operators. They all take two arguments each of which has the value 'TRUE' or 'FALSE'.

AND returns TRUE if both arguments are TRUE

OR returns TRUE if at least one of the arguments is TRUE

XOR returns TRUE if either argument is TRUE and the other is FALSE.

Perl defines two symbols for each of these (They differ only in presidence.)

Perl also defines three "Bitwise Operators". Their exact behavior depends on whether the arguments are numbers or strings. Your question seems to deal only with numbers. Inside the computer, numbers are stored in base two. (Only the 'digits' 0 and 1 are used). Perl allows base 8 (octal) and base 16 (Hex) as 'shorthand' way to write binary numbers. The operators do thir usual thing on each bit position. (One is TRUE, zero is FALSE)

Lets look at your example of exclusive or. I assume that you intend your numbes to be binary.

Code

Arg1: 11010101 Arg2: 10101010

Result: 01111111

In the first column, both arguments are true so the result is false. In all the other columns, only one of the arguments is true, so the result is true.

Part of your confusion is that atleast in Perl, they symbol '&' is not the symbol for bitwise or. It is the symbol for bitwise and.

Repeating your example for and we see:

Code

Arg1: 11010101 Arg2: 10101010

Result: 10000000

In the code you show, the variable $mode probably contains other information in the high order bits. The & 07777 discards all but the last twelve bits which are enough to hold mode numbers as large as 4095. Good Luck, Bill

So then what exactly does the stat function return? Can you: $l = stat($file) print Data::Dumper($l)

what exactly is (stat($file))[2]??

Is it a scalar, a hash, binary number, octal?

I know it returns a list of ten variables. I was under the impression that when perldoc stated that the third value it returned was the permissions, that was what it meant. It should have state something much clearer.