Ask a Question related to PERL Beginners, Design and Development.
-
James Edward Gray II #1
Re: required help
I believe you meant to send this message to the Perl Beginner's List.
On Monday, October 6, 2003, at 01:51 AM, vaishali wrote:
Let's see if we can fix it up.> I am having my text file called ldap1.txt in the following format
>
> uid : department : branch
> vaishali.chitale : Corporate Entertainment : Mumbai
> rajesh.chandran : Planet M - Powai (Retail) : pune
>
>
> I have written a code so that I can take department and branch
> according to uid in
> my program but this code is not working .
Good start.> # open ldap1 text file and chunk the elements into a hash
>
> open(F,'<'.$file_name) or die "Can't open $file_name: $!\n";
Why store the whole file in an array so you can later walk it line by> my @file=<F>;
line? Let's just do all our processing right here, instead of the line
above. Here's how I would do it:
my %lp1;
while (<F>) {
my($uid, $department, $branch) = split /\s*:\s*/, $_;
$lp1{$uid} = { department => $department, branch => $branch };
}
Nothing below this line is needed, but I'll go through it with comments> close(F);
anyway
This is the program's main problem. You're splitting the fields and> my %lp1;
>
> for my $file
> (@file) {
> my @lp1=(split(/\s*:\s*/,$file))[0];
then throwing away all but the first one with your indexed list
assignment. That's why you're seeing uninitialized warnings, $lp1[1]
and $lp1[2] never receive a value. You could fix this by removing the
( ... )[0] around your split.
Hope that helps.
James
> $lp1{$lp1[0]}{'department'}=$lp1[1];
> $lp1{$lp1[0]}{'branch'}=$lp1[2];
>
> }
>
> undef @file;
>
> In above code I am not able to print department and branch
> it is giving me error for the following
>
> $lp1{$lp1[0]}{'department'}=$lp1[1];
> $lp1{$lp1[0]}{'branch'}=$lp1[2];
>
> Use of uninitialized value
>
> what is the problem ?
>
>
>
>
>
>
>
> ---
> NOTICE-----------------------------------------------------------------
> ---------------------------------
> This E-mail (including the attachment/(s) if any ) has been scanned
> for viruses and dangerous content. For more information mail to
> [email]mumbai_admin@timesgroup.com[/email]
> -----------------------------------------------------------------------
> ------------------------------------
> ---
> DISCLAIMER-------------------------------------------------------------
> ---------------------------------
> The contents of this E-mail (including the contents of the
> enclosure/(s) or attachment/(s) if any) are privileged and
> confidential material of Bennett, Coleman & Co. Ltd. (BCCL)and should
> not be disclosed to, used by or copied in any manner by anyone other
> than the intended addressee/(s). If this E-mail (including the
> enclosure/(s) or attachment/(s) if any ) has been received in error,
> please advise the sender immediately and delete it from your system.
> The views expressed in this E-mail message (including the
> enclosure/(s) or attachment/(s) if any) are those of the individual
> sender.
> -----------------------------------------------------------------------
> ------------------------------------
>James Edward Gray II Guest
-
Help Required
Hi, I want to deploy my private shared assembly using codebase keeping some of the assemblies in common folder. I am using following tag in... -
ASP help required please
Hey Al I have a stored procedure in SQL server which when exectuated returns a table of results. I would like to be able to pass in the parameters... -
Help required please!
OK, I have Photoshop7 (Uk) and have 80 something images I want to downsize from 3000 x 2000. Do I have to do each one individually? Thanks in... -
what is required for job(?)
is there a list on the web , on what a 3D animator needs to prepare himself with, or what he needs to show, for the job market? thanx....doc -
Job schedular Required for IIS
Hy, I need Job schedular like MSSQL server, I need this functionality on IIS. Is there any concept of threads on IIS? Thank You. -
James Edward Gray II #2
Re: required help
Again, you MUST send these to the Perl Beginner's List, if you want
answers.
On Monday, October 6, 2003, at 10:48 PM, vaishali wrote:
my $address = 'xyz abc <xyz.abc@test.com>';> thanks my problem is solved
> I am having another query.
> I am having mysql and the table is sms_log. In that my sender field
> format is
>
> xyz abc <xyz.abc@test.com>
>
> I want only the part ie after < sign and before @ sign ie only xyz.abc.
> How to extract this part from the above field
my $name;
if ($address =~ /<([^@]+)@/) { $name = $1; }
else { die "Malformed address $address.\n"; }
James
James Edward Gray II Guest
-
Vaishali #3
required help
I am sending the email to the [email]beginners@perl.org[/email] and I am sending to you
also as this is urgent. Using your previous help I can able to solve my
problems.
sorry.
I am having following code and this prints the report in following format
sender: xyz.abc
department: xxx
branch: yyy
--------------------------------------------------------
receiver sent
-------------------------------------------------------
4423432432 2003-09-09 09:09:00
65465466546 2003-08-06 01:10:10
---------------------------------------------------------
Total Cost:
etc
I am having sender,receiver,sent these fields from mysql and department
and branch it is from text file
the format of text file is
uid:department:branch
xyz.abc:xxx:yyy
I am taking sender field from mysql the format of sender field is
xyz abc <xyz.abc@test.com>
from above I am taking part after < sign and before @ sgin ie xyz.abc
and comparing it with text file. if this found then the program take
department and branch and prin the report as given in above format.
I want to calculate total cost ie count the receiver and multiply this
count by Rs.1 ie in above example total receivers are 2 therefore the
total cost is Rs.2
how to do this taks in the following code.
#!/usr/bin/perl -w
$!=1;
use strict;
use DBI;
################################################## #######
# Add in your variable names here
################################################## #######
my $db_name='smsd';
my $db_host='10.100.208.254';
my $db_user='vaishali';
my $db_pass='sms123';
my $table_name='sms_log';
my $file_name='ldap1.txt';
################################################## #######
# open ldap1 text file and chunk the elements into a hash
open(F,'<'.$file_name) or die "Can't open $file_name: $!\n";
my @file=<F>;
close(F);
my %lp1;
#while(@_=split(/\s+:\s+/,<R>))
#while(@_=split(/\s*:\s*/,<R>))
for my $file (@file) {
chomp($file);
my @lp1=(split(/:/,$file));
$lp1{$lp1[0]}{'uid'}=$lp1[0];
$lp1{$lp1[0]}{'department'}=$lp1[1];
$lp1{$lp1[0]}{'branch'}=$lp1[2];
}
undef @file;
# Pull the data from the MySQL database
my $dbh=DBI->connect
("dbi:mysql:$db_name:$db_host",$db_user,$db_pas s)
or die "Could not connect to $db_name: $DBI::errstr";
my $query=qq~
SELECT sender,receiver,sent FROM $table_name group by
sender,receiver,sent~;
my $sth=$dbh->prepare($query);
$sth->execute
or die "Could not execute to $query: $DBI::errstr";
my %seen=();
my $header=
('-' x 58).$/.
q~receiver sent ~.$/.
('-' x 58).$/;
# Now compare MySQL returns to lpad1 set
while (my $row=$sth->fetchrow_arrayref()) {
(my $temp_sender1=$row->[0])=~s/^.*?<|\@.*$//g;
(my $temp_sender2=$row->[0])=~s/^.*?<|\@.*$//g;
if (!$lp1{$temp_sender1}{'department'})
{
$lp1{$temp_sender1}{'department'}="
";
$lp1{$temp_sender1}{'branch'}="
";
}
print $/,$/,'sender
:',$temp_sender2,$/,'Department:',$lp1{$temp_sender1}{'department'},$/,'Branch:',$lp1{$temp_sender1}{'branch'},$/,$header
if(!$seen{$temp_sender2}++);
print $row->[1],(' ' x (28-length($row->[1]))),
$row->[2],(' ' x (22-length($row->[2]))),$/;
}
---NOTICE--------------------------------------------------------------------------------------------------
This E-mail (including the attachment/(s) if any ) has been scanned for viruses and dangerous
content. For more information mail to [email]mumbai_admin@timesgroup.com[/email]
-----------------------------------------------------------------------------------------------------------
---DISCLAIMER----------------------------------------------------------------------------------------------
The contents of this E-mail (including the contents of the enclosure/(s) or attachment/(s) if
any) are privileged and confidential material of Bennett, Coleman & Co. Ltd. (BCCL)and should
not be disclosed to, used by or copied in any manner by anyone other than the intended
addressee/(s). If this E-mail (including the enclosure/(s) or attachment/(s) if any ) has been
received in error, please advise the sender immediately and delete it from your system. The
views expressed in this E-mail message (including the enclosure/(s) or attachment/(s) if any)
are those of the individual sender.
-----------------------------------------------------------------------------------------------------------
Vaishali Guest
-
James Edward Gray II #4
Re: required help
On Tuesday, October 7, 2003, at 11:17 PM, vaishali wrote:
That's why myself and many others read the beginner's list, to fix you> I am sending the email to the [email]beginners@perl.org[/email] and I am sending to
> you also as this is urgent.
up as fast as possible.
Glad I could help.> Using your previous help I can able to solve my problems.
I'm with you this far.> sorry.
>
>
> I am having following code and this prints the report in following
> format
>
> sender: xyz.abc
> department: xxx
> branch: yyy
> --------------------------------------------------------
> receiver sent
> -------------------------------------------------------
> 4423432432 2003-09-09 09:09:00
> 65465466546 2003-08-06 01:10:10
> ---------------------------------------------------------
> Total Cost:
>
>
> etc
>
> I am having sender,receiver,sent these fields from mysql and
> department and branch it is from text file
>
> the format of text file is
>
> uid:department:branch
> xyz.abc:xxx:yyy
>
> I am taking sender field from mysql the format of sender field is
> xyz abc <xyz.abc@test.com>
>
> from above I am taking part after < sign and before @ sgin ie xyz.abc
> and comparing it with text file. if this found then the program take
> department and branch and prin the report as given in above format.
You lost me right here. Sorry, I'm not sure what you're trying to> I want to calculate total cost ie count the receiver and multiply this
> count by Rs.1 ie in above example total receivers are 2 therefore the
> total cost is Rs.2
calculate from what. Can you give an example? In the above text, what
would the total cost equal and what math did you do to get that. I
must be dumb today. :)
This is not needed. Omit it.> how to do this taks in the following code.
>
>
>
> #!/usr/bin/perl -w
>
>
> $!=1;
use warnings;> use strict;
I've already shown you a much better way to handle the above file read> use DBI;
> ################################################## #######
> # Add in your variable names here
> ################################################## #######
> my $db_name='smsd';
> my $db_host='10.100.208.254';
> my $db_user='vaishali';
> my $db_pass='sms123';
> my $table_name='sms_log';
> my $file_name='ldap1.txt';
> ################################################## #######
>
> # open ldap1 text file and chunk the elements into a hash
> open(F,'<'.$file_name) or die "Can't open $file_name: $!\n";
> my @file=<F>;
> close(F);
> my %lp1;
>
> #while(@_=split(/\s+:\s+/,<R>))
> #while(@_=split(/\s*:\s*/,<R>))
>
> for my $file (@file) {
> chomp($file);
> my @lp1=(split(/:/,$file));
> $lp1{$lp1[0]}{'uid'}=$lp1[0];
> $lp1{$lp1[0]}{'department'}=$lp1[1];
> $lp1{$lp1[0]}{'branch'}=$lp1[2];
> }
>
>
> undef @file;
and processing in a previous message.
I don't understand what is going on above, but I don't think it's good.> # Pull the data from the MySQL database
> my $dbh=DBI->connect
> ("dbi:mysql:$db_name:$db_host",$db_user,$db_pas s)
> or die "Could not connect to $db_name: $DBI::errstr";
> my $query=qq~
> SELECT sender,receiver,sent FROM $table_name group by
> sender,receiver,sent~;
> my $sth=$dbh->prepare($query);
> $sth->execute
> or die "Could not execute to $query: $DBI::errstr";
> my %seen=();
> my $header=
> ('-' x 58).$/.
> q~receiver sent ~.$/.
> ('-' x 58).$/;
> # Now compare MySQL returns to lpad1 set
>
> while (my $row=$sth->fetchrow_arrayref()) {
>
>
> (my $temp_sender1=$row->[0])=~s/^.*?<|\@.*$//g;
> (my $temp_sender2=$row->[0])=~s/^.*?<|\@.*$//g;
Why are we setting to variables to the exact same thing?
Are you trying to test if the entry doesn't exist here? That would> if (!$lp1{$temp_sender1}{'department'})
> {
probably be better as:
if (not exists $lp1{$temp_sender1}) {
I like "\n" better than $/, though that's just a stylistic preference.> $lp1{$temp_sender1}{'department'}=" ";
> $lp1{$temp_sender1}{'branch'}=" ";
> }
>
> print $/,$/,'sender
> :',$temp_sender2,$/,'Department:',$lp1{$temp_sender1}{'department'},$/
> ,'Branch:',$lp1{$temp_sender1}{'branch'},$/,$header
> if(!$seen{$temp_sender2}++);
> print $row->[1],(' ' x (28-length($row->[1]))),
> $row->[2],(' ' x (22-length($row->[2]))),$/;
> }
Send, back to the list, some details about the calculation you're
trying to find and I'll try to help you get there.
James
James Edward Gray II Guest
-
James Edward Gray II #5
Fwd: required help
[ forwarded to list by James Gray ]
Begin forwarded message:
> From: vaishali <vaishali.chitale@timesgroup.com>
> Date: Fri Oct 10, 2003 5:06:21 AM US/Central
> To: James Edward Gray II <james@grayproductions.net>
> Subject: Re: required help
> Reply-To: [email]vaishali.chitale@timesgroup.com[/email]
>
> how to define multiple connect statements
>
> Actually I am having one database ie smsd and table sms_log in
> 10.100.208.254.
> I have created one database called smsd and table sms_log1 on
> 10.100.200.47 ie in another machine
>
> I want to insert data from sms_log ie 10.100.208.254 server to
> 10.100.200.47 table ie sms_log1.
>
> how to do this task using perl DBI
>
> fields from sms_log ie 10.100.208.254 are
> sender char(40)
> receiver char(40)
> sent datetime
>
> fields from sms_log1 ie 10.100.200.47 are
> sender char(40),
> receiver char(40),
> sent datetime,
> dept char(40),
> branch char(40)James Edward Gray II Guest
-
Tore Aursand #6
Re: Fwd: required help
On Fri, 10 Oct 2003 08:40:17 -0500, James Edward Gray II wrote:
Well. What have you tried so far? It should be easy as long as you> I want to insert data from sms_log ie 10.100.208.254 server to
> 10.100.200.47 table ie sms_log1.
create two database connections?
--
Tore Aursand <tore@aursand.no>
Tore Aursand Guest



Reply With Quote

