Archive for the 'Perl' Category
Tuesday, December 23rd, 2008
In simpleist terms. Here is a perl script to build a list from a directory.
#!/usr/bin/perl
opendir(DOCS1, "/Users/bradrice/Documents/UAworkFolder/stadium/cams/slideshow/images/quot;);
my @files = grep !/^\.\.?/, readdir DOCS1;
foreach $file(@files) {
print $file . “\n”;
}
Posted in Perl | No Comments »
Monday, January 28th, 2008
I needed a script to backup a workfolder to a Windows network server. I wrote this perl script that can be triggered using cron. First create a mount point. I used /smb/public. So to do so in two steps, mkdir /smb, then mkdir /smb/public. I put my scripts in ~/bin. Put this perl script below [...]
Posted in Mac OS X general, Perl, Shell Script, Unix | No Comments »
Tuesday, July 24th, 2007
I use cpan to install perl modules all the time. I recently installed Perl LWP. Unfortunately the install replaces and important text command file in /usr/bin. The file head was replaced by LWP head and this has caused some problems on my system. I found it out when I tried to install Sun’s Netbeans IDE [...]
Posted in Mac OS X general, Perl, Unix | No Comments »
Monday, July 16th, 2007
I had a very large folder of images that I needed to build a tale of, as well as links for the images. I wrote a perl script to read the directory and build the table based upon the image file names in the folder. For our purposes here I am simplifying the script.
#!/usr/bin/perl
use File::Copy;
my [...]
Posted in Mac OS X general, Perl, Unix | No Comments »
Tuesday, April 10th, 2007
Ever writing code and need to get a list of the input field names in your html document. I wrote this little perl script to parse out a list of names of the input fields.
#!/usr/bin/perl
open (INFILE, ‘
while ($line=) {
chomp $line;
my $input = $line;
if ($input =~ /input /
$input =~ /name=\”(\w*)\”/i;
$input = $1;
print “$input\n” ;
}
}
How it [...]
Posted in Mac OS X general, Perl | No Comments »
Saturday, February 24th, 2007
May seem simple to most folks, but just in case you are looking for an expression to remove the path before a file name here is an expression to start.
[\w/]*/
It searches for all the word characters before the last slash. If you need periods in the path add those to the character class.
Posted in Mac OS X general, Perl, Shell Script, Unix | No Comments »
Wednesday, January 3rd, 2007
I found a good way to make use of a scalar reference in perl. For development when you are using a dev and live server, you can change some settings using a ref.
Here’s what I did recently. In this case I needed two different mount scripts, one for a dev server and one for a [...]
Posted in Applescript, Mac OS X general, Perl, Unix | Comments Off
Thursday, July 27th, 2006
A while back I wrote a post about a ftp shell script. A number of people told me I should use curl instead. Here is one I wrote using both perl and curl to move some files from a site. I start with a list of file names. They don’t have the .pdf extension in [...]
Posted in Mac OS X general, Perl, Shell Script, Unix | Comments Off
Monday, July 24th, 2006
I had to sort directories of pdf files that had identical names except for the last characters before the extension.pdf. Perl has a nice built in sort routine, but when I used it to sort like this:
@sortedlist = sort @listOfFiles;
I would end up with filenames in sort order for the most part except 10 would [...]
Posted in Mac OS X general, Perl | Comments Off
Wednesday, March 29th, 2006
I run into the situation of having to rename so often that I am constantly tweaking my solution. Here I had to remove some extraneous characters on file names that a client had added. All we wanted where the first characters that started with DSFC and then the 4 digits. I had to drop off [...]
Posted in General, Mac OS X general, Perl, Unix | No Comments »
Saturday, March 11th, 2006
I have several handy applications that I use on my mac daily. Obviously a mail app and browser. Safari is very nice. I’m using Apple Mail, but Thunderbird is really a nice mail app, too. But for me, much of the business of computing is storing information, and being able to get to that information [...]
Posted in General, Mac OS X general, Perl, Shell Script, Unix, wordress | No Comments »
Friday, December 16th, 2005
If you ever need to compare two directories to find files missing from one that are in the other, perl can be a good utility to use. You can read into two arrays two directories, then create a hash using the second directory array as keys (this should be the smaller directory). Then use the [...]
Posted in General, Perl, Unix | 2 Comments »
Wednesday, March 9th, 2005
Here is a little script I wrote that you can use to move a list of files. Supply it a list of file names. In this case the file names I was supplied didn’t have .pdf on them, so I had to concatentate that onto the file names. I’ve covered this earlier with respect to [...]
Posted in General, Perl, Unix | 3 Comments »
Friday, July 23rd, 2004
Here is a little perl script that you can use to lowercase text with an uppercase first letter of each word. If you put it in your BBEdit unix filters it will work on any selected text.
#! perl -w
use strict;
while () {
tr/[A-Z]/[a-z]/;
s/\b([a-z])/\u$1/g;
print $_;
}
Posted in General, Perl, Unix | 1 Comment »
Wednesday, July 21st, 2004
You can use Perl’s File::Copy module to move files around your system. The only drawback is that if the files are macbinary and have a resource fork, that portion of the file gets lost. You can use Apples ditto command with –rsrc parameter to move files and maintain the resource.
Following is a perl subroutine I [...]
Posted in General, Mac OS X general, Perl, Unix | 2 Comments »
Sunday, July 18th, 2004
One of the great advantages of OS X is that you can control applications using Applescript. There is a command line version of calling applescript called osascript. The really cool thing is being able to use this command inside of another script such as a perl script or a shell script. One of the things [...]
Posted in Applescript, General, Mac OS X general, Perl, Unix | Comments Off
Friday, July 16th, 2004
The previous tip showed how you can change filenames in a given directory uisng the command line. If you need to use perl to programatically change file names you can use the rename perl function. Often times I need to iterate through a directory and change names of files based on a given condition. Here [...]
Posted in General, Mac OS X general, Perl, Unix | Comments Off