in reply to Re^4: How to open SQL 2005 errorlog?
in thread How to open SQL 2005 errorlog?
I would just switch the open mode, depending on whether it's a 2005 or pre-2005 logfile. In its most simple case, looking for the "2005" in the pathname
my $openmode = $sqlErrorlog =~ /2005/ ? ">:encoding(utf-16)" : ">"; unless (open LOG, $openmode, $sqlErrorlog) { ...
(or, as a refinement, you could also check if the year is >= 2005 — presuming they switched to unicode with SQL Server 2005, and future versions will adhere to the same naming scheme, i.e. 2007, 2009, ... though that might be too many presumptions :)
However, that approach is kinda cheating, and not generally recommended programming practice (reason: when you/someone happens to change the pathname some time in the future, it's very unlikely you're going to remember this curious dependency buried deep down in the code...).
So, another way would be to test for the existence of the BOM, and if there, set UTF-16 mode. Actually - as I only recently learned myself - there's already a module for this: File::BOM, which handles the issue even more generally... (see the docs for examples).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: How to open SQL 2005 errorlog?
by jc7 (Initiate) on Jun 08, 2007 at 20:50 UTC | |
by almut (Canon) on Jun 08, 2007 at 22:40 UTC | |
by jc7 (Initiate) on Jun 12, 2007 at 16:35 UTC |