Skip to content

Ruling the world with Perl and Excel

In Chapter 12 of Learning Perl, we have an exercise for people to practice using the file test operators. Our answer, which can only use the stuff we've covered in the book to that point, is simple:

foreach my $file (@ARGV) {
	my $attribs = &attributes($file);
	print "'$file' $attribs.\n";
	}

sub attributes { 
	my $file = shift @_; 
	return "does not exist" unless -e $file;

	my @attrib;
	push @attrib, "readable" if -r $file;
	push @attrib, "writable" if -w $file;
	push @attrib, "executable" if -x $file;
	return "exists" unless @attrib;
	'is ' . join " and ", @attrib;
	}

But I usually then redo this to show the same problem creating an Excel file with the same data. Most of you probably already know that the Universe runs on Excel. If you can programmatically create Excel files, you're half way to controlling the Universe.

This still uses only what we cover in Learning Perl since we have a chapter on using modules, but there's still a lot of fancy things I'm doing in there that I wouldn't expect from someone in their first week with Perl.

Now the output is manager and executive friendly: