I’ve run into a problem where one inventory set uses the Dell Service Tag (a 7 digit alphanumeric value) and a different one uses the Dell Express Service Code, a strictly numeric value. Now I need to marry the two inventories.

I’m screwed you think? Well, as it turns out, both numbers actually represent the same value. Only one is Base 10 (the Exp Service Code) and the other is Base 36 (the Service Tag). Which means, if I’m froggy enough, I can write a conversion tool that takes one and outputs the other.

Here is my first crude perl version of the code.  This Perl code will take a file full of Service Tags and spit out the Express Service Codes.

USAGE: ./dell_converter.pl mylist

mylist is just a file with a list of Service Tags. Be aware they have to currently be in upper case.

#!/usr/bin/perl

use strict;
use warnings;

#——————————————————————
# Written by Richard Hickey
# richard.a.hickey@saic.com
# 5 July 2011
#——————————————————————

#——————————————————————
# This program will take a Dell Service Tag and convert it
# into a Dell Express Service Code.
#
# The Service Tag is a Base 36 copy of a Base 10 Service Express Code
# So Server Exp Code 24692084176 base 10, is Service Tag ABC1234 base 36.
# numbers 0-9 are 0-9. Letters A-Z are 10-36.
#
# Service Tag ABC1234 converts to 22453156048
#     A = 36^6 * 10 = 2176782336 * 10 = 21767823360
#     B = 36^5 * 11 = 60466176 * 11 = 665127936
#     C = 36^4 * 12 = 1679616 * 12 = 20155392
#    1 = 36^3 * 1 = 46656 * 1 = 46656
#    2 = 36^2 * 2 = 1296 * 2 = 2592
#    3 = 36^1 * 3 = 36 * 3 = 108
#    4 = 36^0 * 4 = 1 * 4
#
#    21767823360 + 665127936 + 20155392 + 46656 + 2592 + 108 + 4 = 22453156048
#
# So the Service Express Code for ABC1234 is 22453156048
#
# usage dell_converter.pl myfile <enter>
# myfile is a file with a listing of Service Tag Numbers
#——————————————————————

#——————————————————————
# Read in the file
#——————————————————————
while(<>){
chomp;

#——————————————————————
# Variable initialization
#——————————————————————
my $ServiceTag;my @ServiceTag; # just initializing the arrays
my %value; @value{“0″..”9″,”A”..”Z”} = (0..35); #set each character to it’s value
my $base;my @base = (2176782336,60466176,1679616,46656,1296,36,1); #set each location to a 36base value

#——————————————————————
# Main body of the converter will  make sure the first line matches
# what we expect a service tag to look like and do the conversion
#——————————————————————

if(/^[0-9A-Z]{1,7}$/){           # Make sure the line looks like what we expect for a Service Tag
@ServiceTag = split //;      # split the line into component characters

my $ExpressServiceTag = 0;         # set the Express Service Tag value to zero for each iteration
for (my $i=6; $i>=0;$i–){         # count backwards through the arrays  BEWARE the minus minus, or – –  on the $i– looks like a single – not sure why
$ExpressServiceTag = $ExpressServiceTag + $value{$ServiceTag[$i]} * $base[$i];
}

print “$_ $ExpressServiceTag \n”; # $_ still references the Service Tag that was read in.

}
}

Advertisements