Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Script for a URL that constantly changes

by pvaldes (Chaplain)
on Oct 19, 2011 at 23:57 UTC ( #932528=note: print w/ replies, xml ) Need Help??


in reply to Script for a URL that constantly changes

I'm trying to use this URL

Define use...

Where it says $sku, that will change constantly via a database

Then you probably want to interact with the database in any way: use DBI

my @sku = ('CODE TO THE DATABASE')

Good try...

my %code = 'CODE TO SOLVE YOUR PROBLEM HERE'; ;-)

Aha, question updated with some real code, let's see...

looks like a work for a hash... my @sku = ('NUMBER') is not what you want probably; first of all because @ mean a list of elements, not a single number, and also because a %hash is much better here. If you define @sku as an array you could have by mistake the same number for two products (and this is a BIG problem), but a hash will not permit you to do this. The number $sku is the key (unique) and the catalog ref is the value.

so the first thing that you should try to fix is these two lines.

my @sku = ('NUMBER'); for my $sku (@sku) {...

Instead connect to the database and prepare something like: select field2 for mytable where field1 = ? and fill the gap with the correct number sku with execute($sku). Read the manual of DBI for the details

finally when you have your hash you could write something like this

https...partnumber=$sku...catalog_number=$hash{$sku}&inE=1&highlight...


Comment on Re: Script for a URL that constantly changes
Select or Download Code
Replies are listed 'Best First'.
Re^2: Script for a URL that constantly changes
by semrich (Initiate) on Oct 20, 2011 at 15:52 UTC

    I have it connecting to the database like this:

    use DBI; use DBD::ODBC; my $conn_string = "driver={SQL Server};Server=SERVER NAME;Database=DB +NAME"; my $dbh = DBI->connect( "DBI:ODBC:$conn_string" ) or die $DBI::errstr; # get each SKU my ($sth, $stmt ); my $count=0; $stmt = qq { select sku from TABLE NAME }; $sth = $dbh->prepare ($stmt); $sth->execute ();
    I believe this is working, because I did a trial run of it. Do you have a suggestion as to where I can look up how to write a hash? Thank you for all your help!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://932528]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2015-07-29 05:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (260 votes), past polls