Hey all,
I am in a bit of spot where someone wants data that's in a mysql db.
The script I am trying to cobble up needs to read a flat file with 2 columns of data
Column1= and 11 digit number and Column2 = date number appears in the deletions file.
Once the file gets read the script loops thru a query to the db, using the enteries in each line.
Anyone have a sec to take a look and offer some help ?
# This script reads a file and creates 2 variables with it by using a
+hash.
# the data is in 2 columns. Column1=msisdn Column2=DeletionDate
# This script may be helpful if expanded to a loop and db query for fi
+guring
# last possible active date.
#
# Sample of the file read by script
# 19992507638 deletions.20060723
# 19993017551 deletions.20060723
#!/usr/bin/perl
use DBI;
$database = "chai";
$hostname = "localhost";
$port = "3306";
$username = "bonezer";
$password = 'monezer';
$dsn = "DBI:mysql:database=$database;host=$hostname;port=$port";
$dbh = DBI->connect($dsn, $username, $password) or die("Could not conn
+ect!");
$sql = "select to_days(substring($dday,11)) - to_days(lastactive) fro
+m user where number = '$msdn' into OUTFILE '/tmp/sp'";
open DATA, "/tmp/SEOUL_NUMBERS";
my %hash;
while( <DATA> ) {
@elements = split / /, $_;
{
$hash{ $elements[0] } = $elements[1];
$hash{ $elements[1] } = $elements[1];
$msdn="$elements[0]\n";
$dday=$elements[1];
$sth = $dbh->prepare($sql);
$sth->execute;
}
}
$dbh->disconnect;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.