Prefetch Technologies // Keeping your cache lines cozy

Archive

Posts in Perl

Printing ranges with Perl

perlOct 7, 2005 1 min read

When developing Perl scripts, it is often useful to process a range of characters or numbers. This is easily accomplished with Perl's ".." range operator: Perl seems to contain just about everything, and is definitely the Cadillac of programming lanaguages.

$ read more →

Stupid Perl mistake

perlSep 26, 2005 1 min

While messing around with Perl I ran into the following error: I asked Perl guru Peter Marschall if he knew what was wrong with this statement, and Peter mentioned that 'print' is trying to use the '(' and ')' to enclose it's argument list (which is not applicable here). Since I am still learning Perl, I don't feel bad making mistakes (I am learning lots!)!

$ read more →

Optimizing Perl code (localtime)

perlSep 23, 2005 1 min

While updating some Perl code I wrote quite some time back, I came across the following: my ($sec, $min, $hour, $day, $month, $year, $wd, $day, $dst) = localtime(time); print $year + 1900 . " "; This code is rather wasteful, especially when the program only needs the year. A much simpler solution is to put the localtime() result into array context, and index into it: $year = (localtime)[5] + 1900; print "$year "; I am currently reading two Perl books, and it amazes me just how versatile Perl is!

$ read more →

Perl and greediness

perlSep 19, 2005 1 min

When a regular expression uses the '' wild card operator to match text, the regular expression will attempt to match as much as possible when applying the regular expression. Given the the following Perl code with the regular expression "(Some.text)": We see that by default Perl will match from the word "Some" to the right-most word "text.": In regular expression parlance, this is considered a "greedy" regular expression since it attempts to match as much as possible. This is not ideal in most situations, and is easily fixed with Perl's '?' operator: In this example Perl will no longer become greedy when evaluating the expression, and will attempt to match up to the left-most occurrence of the string element prefaced by '?'. Regular expressions are amazingly cool, but sometimes it feels like witchcraft when developing the right regex incantation to solve complex problems.

$ read more →

Generating random passwords with Perl

perlSep 15, 2005 1 min

While performing some house cleaning this evening, I came across the following Perl nugget: This awesome little 3-line script will produce random 8-character alphanumeric passwords: I wish I knew where I grabbed this from so I could publicly thank the author.

$ read more →