Advertisement

08.17.2008 at 10:32PM PDT, ID: 23655476
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.1

Data Manipulation

Asked by APNFSSC in Perl Programming Language

Tags:

Hi,

I'm writing a script that map's some data between different codes and then copare the child object's against a database.

The structure of the data I would like to get to is something like

pub_key=>
                    date=>
                                 production_number
                                 production_number
                   date=>
                                 production_number
                                 production_number

Below is the data::dumper output from print Dumper(\@keepers); Everything after that part is just me experimenting.

          {
            'date' => '2008-08-07',
            'production_number' => '1370846ay',
            'pub_key' => '1199'
          },
          {
            'date' => '2008-09-11',
            'production_number' => '1763033aa',
            'pub_key' => '1199'
          },
          {
            'date' => '2008-09-11',
            'production_number' => '1767751ag',
            'pub_key' => '1199'
          },
          {
            'date' => '2008-09-11',
            'production_number' => '1780974aa',
            'pub_key' => '1199'
          },
          {
            'date' => '2008-08-12',
            'production_number' => '1582934aa',
            'pub_key' => '1199'
          },
          {
            'date' => '2008-08-12',
            'production_number' => '1609352aa',
            'pub_key' => '1199'
          },
          {
            'date' => '2008-08-12',
            'production_number' => '1654489ag',
            'pub_key' => '1199'
          },
          {
            'date' => '2008-09-06',
            'production_number' => '1756409aa',
            'pub_key' => '48'
          },
          {
            'date' => '2008-09-06',
            'production_number' => '1756646aa',
            'pub_key' => '48'
          },
          {
            'date' => '2008-09-06',
            'production_number' => '1760794ab',
            'pub_key' => '48'
          },
          {
            'date' => '2008-08-07',
            'production_number' => '1380961aa',
            'pub_key' => '48'
          },
          {
            'date' => '2008-08-07',
            'production_number' => '1621049aa',
            'pub_key' => '48'
          }

What I am trying to do is get the data it shape so that I can access an array of production_numbers for a given pub_key and date. Also I need to pull a list of unique pub_keys and date's out from this output.

I've been going through this for a couple of days now and am totally confused as to the best way to do it. I've attached my code. Once I have the data in shape then I will compare data to a table in a database.

The input file has about 50000 records in it, the production_numbers for each pub_key and date need to be checked against a table in a database. So what I was hoping to do was pull the same data out of the database and put it into an array and have perl do the comparison and show me the differences.

I hope this makes sense.

I know that my script is all over the place, I've been adding and removing code so it's only just an example or where I'm upto.Start Free Trial
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:
#!/usr/bin/perl
use DBI;
use Date::Manip;
use Math::Round qw(:all);
use String::ShellQuote;
use File::Copy;
use File::Copy::Recursive qw(fcopy rcopy dircopy fmove rmove dirmove);
use Archive::Zip;
use File::Basename;
use File::stat;
use Data::Dumper;
use XML::Pastor;
use XML::Dumper;
require "/asx/asx_system/interface_subs.pl";
require "/asx/adservices/asx_globals.pl";
$logging=1;
$script_name="amc_bulk_edition";
my ($numArgs, $inputfile, $INFILE);
$numArgs = $#ARGV + 1;
if ($numArgs == 1){
        $inputfile=$ARGV[0];
        print_this("");
        print_this("Input Booking File:\t$inputfile");
}else {
print "Usage:\n";
print "adm_bulk_edition.pl /data1/queuesin/Edition/Bulk/input/updatefilename.txt\n";
exit_and_disconnect(1);
}
unless(-e $inputfile){
        print_this("Error opening input $inputfile");
        exit_and_disconnect(1);
}
        $TheFile=basename($inputfile);
        $TheDir=dirname($inputfile);
        print_this("Input File Name:\t$TheFile");
        print_this("Input Directory:\t$TheDir");
        `dos2unix "$inputfile"`;
        @asx_configured_pubs;
        @attrs = qw(amc_code pub_key cci_code type);
        my @input;
        get_publications();
        get_special_publications();
        @pubs_by_type = @asx_configured_pubs;
        input("$inputfile");
        print Dumper(\@keepers);
        my $a = bless (\@keepers, 'XML::Pastor::NodeArray');
        my $h = $a->hash('pub_key', 'date');
        $xml = dump_xml(\$h);
        print Dumper($xml);
sub input {
        open(INFILE, "$inputfile") || die "Error opening input $infile: $!";
                while (<INFILE>){
                        chomp;
                        $_ =~ s/\t/_/;
                        $_ = lc($_);
                        my %rec;
                        ($class, $pub_code, $day, $month, $year, $production_number) = split /_/;
                        $code = "$pub_code"."_"."$class";
                        convert_month("$month");
                        $month = $nmonth;
                        $date = "$year"."-"."$month"."-"."$day";
                        my $file_no = scalar(@pubs_by_type);
                        $looprec=undef;
                        for (my $i=0; $i < $file_no; $i++){
                                if ((($pubs_by_type[$i]{'type'} eq 'sectioned' )||($pubs_by_type[$i]{'type'} eq 'special' ))&&($pubs_by_type[$i]{'amc_code'} eq $code)){
                                        #print "$pubs_by_type[$i]{'amc_code'} is a sectioned publication and exists in the hash contained in element $i of the array.\n";
                                        $looprec="$pubs_by_type[$i]{'pub_key'},$date,$production_number";
                                        last;
                                }else{
                                        $ncode = "$pub_code"."_rodi";
                                        if (($pubs_by_type[$i]{'type'} eq 'normal' )&&($pubs_by_type[$i]{'amc_code'} eq $ncode)){
                                                #print "$pubs_by_type[$i]{'amc_code'} is a normal publication and exists in the hash contained in element $i of the array.\n";
                                                $looprec="$pubs_by_type[$i]{'pub_key'},$date,$production_number";
                                                last;
                                        }else{
                                                next;
                                        }
                                }
                        }
                        if($looprec){
                                @kpr = qw(pub_key date production_number);
                                my $newloop = "$looprec";
                                my %keep;
                                @keep{@kpr} = split(/,/, $newloop);
                                push @keepers, \%keep;
                        }else{
                                $looprec="$code,$date,$production_number,cannot map";
                                my $newloop = "$looprec";
                                push @nomaps, $newloop;
                        }
                        }
        close(INFILE);
}
sub get_publications {
                my $select_rop_pub_codes = $dbh->prepare("select publication_key, cci_code, amc_code, section from adm_master_publications WHERE pub_type_key = '1' and booking_zone_key <> '16'");
                        $select_rop_pub_codes->execute();
                while($subref = $select_rop_pub_codes->fetchrow_hashref()){
                my %rec;
                my $pub_key=$subref->{'publication_key'};
                my $cci_code=$subref->{'cci_code'};
                my $amc_code=$subref->{'amc_code'};
                my $section=$subref->{'section'};
                my $sec_code = "$amc_code"."_"."$section";
                        if("$section" eq "rodi"){
                                my $looprec = "$sec_code,$pub_key,$cci_code,normal";
                                my $newloop = "$looprec";
                                @rec{@attrs} = split(/,/, $newloop);
                                push @asx_configured_pubs, \%rec;;
                        }else{
                                my $looprec = "$sec_code,$pub_key,$cci_code,sectioned";
                                #print_this("$sec_code,$pub_key,$cci_code,sectioned");
                                my $newloop = "$looprec";
                                @rec{@attrs} = split(/,/, $newloop);
                                push @asx_configured_pubs, \%rec;;
                        }
                }
                $select_rop_pub_codes->finish();
}
 
sub get_special_publications {
                my $select_special_pub_codes = $dbh->prepare("select publication_key, cci_code, amc_code, amc_section from adm_master_amc_special_pub_mapping");
                        $select_special_pub_codes->execute();
                while($subref = $select_special_pub_codes->fetchrow_hashref()){
                my %rec;
                my $pub_key=$subref->{'publication_key'};
                my $cci_code=$subref->{'cci_code'};
                my $amc_code=$subref->{'amc_code'};
                my $section=$subref->{'amc_section'};
                        $sec_code = "$amc_code"."_"."$section";
                        my $looprec = "$sec_code,$pub_key,$cci_code,special";
                        my $newloop = "$looprec";
                        @rec{@attrs} = split(/,/, $newloop);
                        push @asx_configured_pubs, \%rec;;
                }
                $select_special_pub_codes->finish();
}
 
 
        exit(0);
[+][-]08.18.2008 at 06:54AM PDT, ID: 22251803

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.18.2008 at 08:14PM PDT, ID: 22257024

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.18.2008 at 08:23PM PDT, ID: 22257051

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.19.2008 at 02:23PM PDT, ID: 22264021

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.19.2008 at 02:54PM PDT, ID: 22264257

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.19.2008 at 03:02PM PDT, ID: 22264313

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.19.2008 at 09:13PM PDT, ID: 22266099

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.19.2008 at 09:22PM PDT, ID: 22266141

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.21.2008 at 07:27AM PDT, ID: 22279888

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.21.2008 at 03:31PM PDT, ID: 22284946

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.25.2008 at 10:53AM PDT, ID: 22307547

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Perl Programming Language
Tags: Perl
Sign Up Now!
Solution Provided By: Adam314
Participating Experts: 1
Solution Grade: A
 
 
[+][-]08.25.2008 at 03:37PM PDT, ID: 22309966

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628