I am writing a parser to read in ftp log files and insert into a databse. I have everything working fine, except the legacy billing system being used generates bills for each user instead of the master account. Therefore, as a bandaid, I need to attach an account field to each uid for each insert. I figured I could do this using more if statements within my loop, which seemed to work for one, but as I added an additional it stopped working properly. Any help would be appreciated. Here is the code that I am having trouble with. - while (<FILE>) {
-
($dow, $month, $day, $time, $year, $duration, $clientip, $size, $path, $type, $uid) = split(/\s+/);
-
-
$date = "$dow,$month,$day,$time,$year";
-
-
# ATTACH USERS TO MASTER ACCOUNTS
-
# -------------------------------
-
if ($uid eq "jdoe","bfoo","jjones") {
-
$account = "abc";
-
} elsif ($uid eq "msmith") {
-
$account = "xyz";
-
} elsif ($uid eq "zbills","vgoo") {
-
$account = "asdf";
-
}
-
# MAY NEED TO ADD MANY MORE elsif's OR COULD THESE BE ALL if's?; OR HOW COULD I REFERENCE A TEXT FILE OR DATABASE TABLE TO MATCH UID'S AND RETURN THE ACCOUNT TO BE ATTACHED TO EACH LINE OF LOG FILE BEING PARSED AND INPUT INTO DATABASE?
-
#
-
# CONVERT TYPE TO LEGACY DB METHOD
-
# --------------------------------
-
if ($type eq "o") {
-
$method = RETR;
-
} elsif ($type eq "i") {
-
$method = STOR;
-
}
-
unless ($size eq "-" || $duration eq "-") {
-
$sth->execute($date,$clientip,$duration,$size,$method,$uid,$path,$account) or die "Couldn't execute statement: " . $sth->errstr;
-
}
-
}
1 5952
while (<FILE>)
{
my ($dow, $month, $day, $time, $year, $duration, $clientip, $size, $path, $type, $uid) = split(/\s+/);
my $date = "$dow,$month,$day,$time,$year";
my %uid_uaccount = (
hemmi => 14222,
Jonathan=> 28890,
olav => 33221);
#instead of having a gazillion if statements you just go through the hash:
while (($cuid, $accountno) = each %uid_accountno)
{
# if this part of the hash is what youre looking for, make $account
# the value of this element. And then quit iterating this hash.
if ($cuid == $uid) {$account = $accountno; last;}
}
if ($type eq "o") {$method = RETR;}
if($type eq "i") {$method = STOR;}
unless ($size eq "-" || $duration eq "-")
{
$sth->execute($date,$clientip,$duration,$size,$method,$ uid,$path,$account) or die "Couldn't execute statement: " . $sth->errstr;
}
}
[/code][/quote]
# now each extra user only requires you to add one element to %uid_uaccount.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Shmuel |
last post by:
Is it possible to query multiple statements at once?
Like:
$query = "set @p := 1; select @p + 1";
$results = mysql_query($query);
I'm thinking of PHP4. There is in mysqli the prepare...
|
by: Richard Adams |
last post by:
Is it possible to execute more than one statement in SQL via MDAC
ODBC? I have a fairly complex select I wanted to create a view with,
but trying to send it all as one string with terminators ';'...
|
by: Erik Haugen |
last post by:
This item in the C++ faq:
http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-38.5
discusses macros with multiple statements.
The problem is that a macro such as
#define...
|
by: d.schulz81 |
last post by:
Hi all
how can i manipulate a multiple select into a single select dropdown
field with JavaScript?
thanks
|
by: DG |
last post by:
Hi,
Can anyone advise how to execute multiple statements in a single query
batch. For example-
update customers set customer_name = 'Smith' where customer_name =
'Smyth';
select * from...
|
by: Nabil |
last post by:
I am new to DB2 and here is my situation.
I have 2 temp tables where I am trying to insert data (from 2 select
statements)
DECLARE v_t1 VARCHAR(50);
DECLARE v_t1 VARCHAR(50);
DECLARE stmt1...
|
by: Annie D via AccessMonster.com |
last post by:
Hi,
Is it possible to use multiple statements in SQL?? (I’ve never used it before)
:
I have one query that i'm working with, The statements I want to use are as
below, they all work...
|
by: rayone |
last post by:
Hi folks.
I need advice.
2 options, which do you think is the better option to
display/retrieve/report on the data.
Keep in mind reporting (Crystal), SQL Performance, VB Code, usability,...
|
by: arthy |
last post by:
Hi,
Is it possible to execute multiple statements on to the database using a single dbconnection object.what is the drawback in using .If not possible ,then how can the execution of multiple...
|
by: harsha318 |
last post by:
Hi
I need to have a single query and which can have multiple statements
For eg:
string str = string.Empty;
str = "select * from Customers;Select * from Orders";
iDB2Connection iDB2con =...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |