Trying on #!/usr/bin/perl

This morning I was having one of those “this should be easier” moments while working on website.

After uploading a PDF using Interarchy, it’s easy to copy the FTP URL or the public URL, but neither is exactly what I need to make a working link. I would end up with one of two things, a public URL:

http://www.someDomain.com/somedirectory/filename.pdf

…or the FTP URL:

ftp://fooBar@/www/someDirectory/fileName.pdf

The first one would require a little more work to add a directory in right spot in the middle of the URL so I opted for the second option, which would allow me to delete a string from the beginning and replace it with one that suits my purposes.

Here is the TextExpander snippet that does the work:

#!/usr/bin/perl
// I don't know why, but "use strict" seems like it should be there
use strict;
// Grab the clipboard item snatched from Interarchy
my($text);
$text = `pbpaste`;
// Search for the part I don't want and replace with what I do want
$text =~ s/ftp://fooBar@/http:///g;
// Paste it into place
print "$text";
// This isn't perl. This is a TextExpander placeholder to delete the space I use to
// delete the space I use to activate the snippet.
%-

Some of you are probably cringing right now. I’m sure there is a better way to do this, but I figured it out on my own (well, with a little help from several websites) and it does exactly what I need it to do.

Isn’t that what it’s all about?