Ask a Question related to PERL Beginners, Design and Development.

  1. #1

    Default 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:
    > 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 .
    Let's see if we can fix it up.
    > # open ldap1 text file and chunk the elements into a hash
    >
    > open(F,'<'.$file_name) or die "Can't open $file_name: $!\n";
    Good start.
    > my @file=<F>;
    Why store the whole file in an array so you can later walk it line by
    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 };
    }
    > close(F);
    Nothing below this line is needed, but I'll go through it with comments
    anyway
    > my %lp1;
    >
    > for my $file
    > (@file) {
    > my @lp1=(split(/\s*:\s*/,$file))[0];
    This is the program's main problem. You're splitting the fields and
    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

  2. Similar Questions and Discussions

    1. 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...
    2. 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...
    3. 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...
    4. 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
    5. 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.
  3. #2

    Default 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:
    > 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 $address = 'xyz abc <xyz.abc@test.com>';
    my $name;
    if ($address =~ /<([^@]+)@/) { $name = $1; }
    else { die "Malformed address $address.\n"; }

    James

    James Edward Gray II Guest

  4. #3

    Default 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

  5. #4

    Default Re: required help

    On Tuesday, October 7, 2003, at 11:17 PM, vaishali wrote:
    > I am sending the email to the [email]beginners@perl.org[/email] and I am sending to
    > you also as this is urgent.
    That's why myself and many others read the beginner's list, to fix you
    up as fast as possible.
    > Using your previous help I can able to solve my problems.
    Glad I could help.
    > 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'm with you this far.
    > 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
    You lost me right here. Sorry, I'm not sure what you're trying to
    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. :)
    > how to do this taks in the following code.
    >
    >
    >
    > #!/usr/bin/perl -w
    >
    >
    > $!=1;
    This is not needed. Omit it.
    > use strict;
    use warnings;
    > 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;
    I've already shown you a much better way to handle the above file read
    and processing in a previous message.
    > # 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;
    I don't understand what is going on above, but I don't think it's good.
    Why are we setting to variables to the exact same thing?
    > if (!$lp1{$temp_sender1}{'department'})
    > {
    Are you trying to test if the entry doesn't exist here? That would
    probably be better as:

    if (not exists $lp1{$temp_sender1}) {
    > $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]))),$/;
    > }
    I like "\n" better than $/, though that's just a stylistic preference.

    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

  6. #5

    Default 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

  7. #6

    Default Re: Fwd: required help

    On Fri, 10 Oct 2003 08:40:17 -0500, James Edward Gray II wrote:
    > I want to insert data from sms_log ie 10.100.208.254 server to
    > 10.100.200.47 table ie sms_log1.
    Well. What have you tried so far? It should be easy as long as you
    create two database connections?


    --
    Tore Aursand <tore@aursand.no>

    Tore Aursand Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139