Time::Piece
is my preferred perl module for handling dates. Here is how it can be used to convert between UTC and the local time, even for past dates which may have crossed the current daylight savings time status.
#Perl
-
UTC/Local Date Conversion in Perl With Time::Piece
-
Regex is a Programming Superpower!
In an August 15 tweet, @iamdevloper, a very funny programmer-humor account, asked which technology you wouldn’t bother to learn over again: JavaScript, Regex, Kubernetes, or PHP. Never mind the completely obvious answer (if you aren’t in operations at Google, you probably don’t need Kubernetes), I was blown away on how many of the responders admitting to not knowing Regex.
-
Using ack to search Apache web logs
The
ack
utility uses Perl regular expressions to efficiently search source code, with smart defaults to limit the results to what you expect.One of the ways I use it is to search our Apache web log files. The logs capture all requests, including ones for images, style sheets, fonts, and javascript files. But usually I’m only interested in who visited which web pages, including CGI scripts.
I’ve added a Bash function to my
.bashrc
file,acklog
, that filters out the extraneous files automatically:# ack (grep) for scripts in apache function acklog() { ack "$@" | ack -v '\.(css|eot|gif|ico|jpe?g|js|png|svg|swf|webp|woff2?|xml)[? ]' }
-
Installing ODBC on Linux for MSSQL and AS400 DB2
At work, we use Microsoft SQL Server and IBM AS400 databases. Here’s how I set our Linux boxes to allow them to connect to the databases through ODBC. There are seperate instructions for the Debian and Ubuntu (9.10 Karmic Koala) and Red Hat Enterprise Linux (RHEL4 and RHEL5) distributions.
ODBC connections require several layers of software to work. The bottom layer consists of the individual ODBC drivers for each database system. Our top layer is the DBI/DBD interface for Perl. In between these layers is the ODBC driver manager, which keeps track of the DSN’s and their corresponding ODBC drivers.
Packages and Software to Install
Ubuntu Version (tested on 9.10 Karmic Koala)
Debian Version (“unstable” distribution)
We use unixODBC as our ODBC driver manager. First, install unixODBC:
NOTE: Perl’s DBD::ODBC module requires the developer’s version of unixODBC, so install that one.
# apt-get install unixodbc-dev
-
Returing null Columns from iSeries AS400 with Perl DBI
We’re having an issue with database queries to the iSeries AS400 through Perl using DBI and DBD::ODBC. The issue occurs when the SQL statement contains an outer join and the query returns rows with NULL columns:
my $sql_query = qq|select PRSK01, PSTA15 from TESTHA.POLMAST left join TESTHA.P15POLDP on POLC01 = PPOL15 where POLC01 = 003950136|; # Execute the sql query my $sth = $dbh->prepare( $sql_query ) or die $sql_query, "<BR>\n", $DBI::errstr; my $data = $dbh->selectall_arrayref( $sth, {Columns=>{}}, @sql_data ) or die $sql_query, "<BR>\n", $sth->errstr;
The error returned is:
DBD::ODBC::db selectall_arrayref failed: st_fetch/SQLFetch (long truncated DBI attribute LongTruncOk not set and/or LongReadLen too small) (SQL-HY000)
-
Notes from the Perl FAQ
Like the fellow that never read his car’s owner’s manual, I had never read the entire Perl FAQ. I finally did it over the holidays, and these are some notes that I took.
-
Calling a Perl CGI script from within another CGI script
Awhile back we had an issue where a coworker wanted to use one of my Perl CGI scripts inside of her scripts, using the backticks method to have it spit its output to the webpage. But for some reason, my script refuse to recognize the arguments she was passing it. The weird thing was, if we ran her script from the command line, everything worked fine.
The issue is in the way CGI.pm detects whether it is being called from a web browser or from the command line. It checks for the presence of the REQUEST_METHOD environmental variable. If it is present, CGI knows to get its arguments from the web browser.
-
Using LWP::Simple to retrieve binary data
We have a Perl CGI script at work that acts as a proxy. It grabs a pkcs12 digital certificate file from an internal server and delivers it to a user through his or her web browser. The pkcs12 file is in binary format.
Everything worked fine until we put the code on a new server. Suddenly, the files downloaded by the web users were corrupted. We also began seeing the following warning in the log files:
Wide character in print at download.cgi line 124.
Here is the code…
-
Things I always need to look up in Perl
Here are some random Perl things I always need to look up:
-
Perl Modules Primer
Splitting a Perl application into seperate files can be trickier than doing it in other languages, like C or C++, but it is still an important part of producing maintainable code.