Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

perl and switching between different version servers

by phineas629 (Novice)
on Nov 21, 2012 at 15:32 UTC ( #1004943=perlquestion: print w/replies, xml ) Need Help??
phineas629 has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I'm new to perl. I apologize as I'm sure I'm breaking some of the rules for posting. I am jumping in head first and hoping to learn from your generosity. My problem is I've been left with a perl script by the programmer and the following directions:"switch from sql server 2005 to sql 2000 to run the perl script."

My question "Is there a better way to work around this without having to change between different versions of servers?" (I assume it is because of the win32 odbc connection being the reason. But I don't know anything.)

############################################# #this program is used to update the pricing # #for the portal websites # # # ############################################# use WIN32::ODBC; use strict; my $Company = $ARGV[0]; chomp $Company; $Company = uc($Company); unless($Company){ print "Usage portal_price.pl [Company code]\n"; print "no Company code entered\n"; die; } my %parts; ########################################### #***enter Company code and BD names here******# ########################################### my %dbs; $dbs{"01"}= "PTL_ABC"; $dbs{"03"}= "PTL_DEF"; $dbs{"04"}= "PTL_GHI"; $dbs{"07"}= "PTL_JKL"; $dbs{"08"}= "PTL_MNO"; $dbs{"10"}= "PTL_PQR"; $dbs{"11"}= "PTL_STU"; $dbs{"12"}= "PTL_VWX"; $dbs{"13"}= "PTL_YZA"; my $uid = "phineas"; my $pwd = "12345"; my $driver = "SQL Server"; #my $server = "111.111.111.111"; my $server = "111.111.111.111"; my $DSN = $dbs{$Company}; my $connection = new Win32::ODBC("Driver=$driver;Database=$DSN;Server= +$server;Trust_Connection=Yes;uid=$uid;pwd=$pwd") || Win32::ODBC::Dump +Error(); ############################ #look up price location # ############################ open(DDD, "< z:\\Companys\\$Company\\data.dir") || die "cannot open da +ta.dir: $!"; my $price_loc; while (my $ddd_line = <DDD>){ chomp $ddd_line; next if ($ddd_line =~m/^%/); next unless ($ddd_line =~m/price/i); $price_loc = $ddd_line; } close(DDD); ############################## #parse the price and store the # #values in the price object # ############################## print "Parsing price.in\n"; open(price, "< $price_loc") || die "cannot open price: $!"; while(my $price_line = <price>){ chomp $price_line; my ($pn, $cost, $msrp) = split(/\|/, $price_line); unless($parts{"$pn"}){ $parts{"$pn"} = eval {price::new price(); } or die ($@); } while($cost){ $cost=~s/^(\w)(\d*)//; $parts{"$pn"}->price::Cost($1, $2); $parts{"$pn"}->price::Ccodes($1); } while($msrp){ $msrp=~s/^(\w)(\d*)//; $parts{"$pn"}->price::Msrp($1, $2); $parts{"$pn"}->price::Mcodes($1); } } print "DONE Parsing price.in\n"; close(price); ################################## #for each part num update the DB # #with new pricing # # # ################################## print "Clearing out D_MSRP field\n"; $connection->Sql("UPDATE pegged SET D_MSRP = ''") && Win32::ODBC::Dump +Error(); print "\nUpdating $DSN with USA pricing\n"; foreach my $key (sort keys %parts){ print "Evaluating $key - "; my $msrp = $parts{"$key"}->price::Msrp("D"); print "Have price $msrp - "; if($msrp){ $connection->Sql("UPDATE pegged SET D_MSRP = '$msrp' WHERE pegged_p +artname = '$key'") && Win32::ODBC::DumpError(); } print "added to SQL DB\n"; } print "Closing DB connection\n"; $connection->Close(); print "Connection closed\n\n"; ########################################## #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@# #@ MODEL CLASS PACKAGE DEFINITION @# #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@# ########################################## package price; use strict; ##################### #CONSTRUCTOR # ##################### sub new{ my ($class) = @_; my $self={ _c_code => undef, _A_cost => undef, _B_cost => undef, _C_cost => undef, _D_cost => undef, _E_cost => undef, _J_cost => undef, _K_cost => undef, _L_cost => undef, _M_cost => undef, _N_cost => undef, _P_cost => undef, _Q_cost => undef, _E_cost => undef, _S_cost => undef, _Y_cost => undef, _Z_cost => undef, _m_code => undef, _A_msrp => undef, _B_msrp => undef, _C_msrp => undef, _D_msrp => undef, _E_msrp => undef, _J_msrp => undef, _K_msrp => undef, _L_msrp => undef, _M_msrp => undef, _N_msrp => undef, _P_msrp => undef, _Q_msrp => undef, _E_msrp => undef, _S_msrp => undef, _Y_msrp => undef, _Z_msrp => undef }; bless $self, ref($class) || $class; return $self; } ########################################## #function to set and return COST # ########################################## sub Cost{ my( $self, $currency, $value) = @_; if($value){ $value = $value / 100; if ($value !~m/\./){ $value .= ".00"; }elsif($value =~m/\.\d$/){ $value .= 0; } $value =~s/^0*//; } $currency = uc($currency); $self->{"_${currency}_cost"} = $value if defined($value); return $self->{"_${currency}_cost"}; } ############################################ #function to set and return the MSRP # ############################################ sub Msrp{ my( $self, $currency, $value) = @_; if($value){ $value = $value / 100; if ($value !~m/\./){ $value .= ".00"; }elsif($value =~m/\.\d$/){ $value .= 0; } $value =~s/^0*//; } $currency = uc($currency); $self->{"_${currency}_msrp"} = $value if defined($value); return $self->{"_${currency}_msrp"}; } ############################################## #function to set and return the used c_codes # ############################################## sub Ccodes{ my( $self, $code) = @_; $code = uc($code); $self->{"_c_code"} .= $code if(defined($code) && $self->{"_c_code"} +!~m/$code/); return $self->{"_c_code"}; } ############################################## #function to set and return the used m_codes # ############################################## sub Mcodes{ my( $self, $code) = @_; $code = uc($code); $self->{"_m_code"} .= $code if(defined($code) && $self->{"_m_code"} +!~m/$code/); return $self->{"_m_code"};

Replies are listed 'Best First'.
Re: perl and switching between different version servers
by marto (Bishop) on Nov 21, 2012 at 15:53 UTC

    "My problem is I've been left with a perl script by the programmer and the following directions:"switch from sql server 2005 to sql 2000 to run the perl script."

    So are you currently running SQL server 2005? Does this code actually work as you expect it to? Have you considered asking the programmer who wrote this for an explanation of this? I don't see any SQL which I think would require one version of SQL Server over the other. Could there be problems with the ODBC drivers/DSNs on your system?

      Hi Marto,

      Does it have anything to do with the connection using WIN32::ODBC;? Should I consider connecting to through the DBI module instead? The programmer is no longer around and I'm just stuck with this code.

      thanks

        Please consider answering the questions I asked regards the code.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1004943]
Approved by marto
help
Chatterbox?
[atcroft]: james28909: What about October 5, 1582?
[stevieb]: atcroft: "Make both hands into fists..."... is something my Ma taught me in our native lang, but I was to ignorant and young to pay attention. Thanks for that :)
[atcroft]: stevieb: Sad to say that I only recently learned that particular trick, but I have since found it very useful.... :)
[james28909]: ill be back with a solution eventually
[stevieb]: it's a reminder to re-inforce it :P
[atcroft]: james28909: That particular questions was a bit of trick, actually (depending on the country you are in). More interesting is, if you are trying to subtract from an epoch time, for instance, you might have to consider when/if DST occurs for a location,
[atcroft]: because you may have to adjust the number of seconds you change from an epoch from 86400 (not to mention leap seconds)....
[atcroft]: james28909: Although if your program is using a database, you might be able to "pass the buck" to the database and ask it to do the date change for you....

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2017-04-29 04:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (531 votes). Check out past polls.