#!/usr/bin/perl -w # Created by Ben Okopnik on Sat Mar 26 19:00:46 EDT 2011 use strict; for my $ls (qx#/bin/ls -l @ARGV#){ my ($t, $p, $r) = $ls =~ /^(.)([rwxsStT-]+)(\s+\d+\s+\w+.+)$/; print $ls and next unless $p; my $out = 0; my %d = map {split//} qw/sx S- r4 w2 x1 -0/; $out += 01000 if $p =~ y/tT/x-/; $out += 02000 if $p =~ s/(s)(?=.{3})$/$d{$1}/i; $out += 04000 if $p =~ s/(s)(?=.{6})$/$d{$1}/i; for ((100) x 3, (10) x 3, (1) x 3){ $out += $d{$1} * oct($_) if $p =~ s/([rwx-])//; } printf "[%s] %04o %s\n", $t, $out, $r; }