Match Operator Example With Assignments
Match Operator Example With Assignments
- Include the -g option to print the group name when using a BSD version of ls.
- Can use parentheses to assign positional parameters
- In our pattern match, variables are created for modes, link count, user id, group id, and filename.
open (INFILTER, "ls -lg | tail +2 |") ||
die "couldn't run ls ";
die "will not overwrite $outfilename" if -e logfile;
open(OUTPUT,">logfile") || die "cannot create logfile";
while (){
($perms, $linkcnt, $user, $group, $file) =
/(^[d-][rwx-]{9})\s*(\d+)\s*(\w+)\s*(\w+).*\d+\s([A-Za-z0-9._]+)$/;
printf OUTPUT "%s:\n\t%s\t%s\t%s\n\n", $file, $user, $group, $perms;
}