reads database and counts how many times a value i

  • 15 years ago

    Hi,


     I am having trouble with array and hash within my program.  My is compile and run but it didn't give me a result that I want.  Would you be so kind to help me out, please?  I've attach code and sample of output


    Thx


    here is an example.


    EX:


    Read Database


    1\tApple\tRed
    1\tStrawberry\tRed
    3\tBanana\tYellow
    4\tGrape\tPurple


    The results would be
    Red=2
    Yellow=1
    Purple=1




    !/usr/bin/perl


    #


    push(@INC,"../lib");
    require "edams.pl";

    *************************


    Setting network path on EDAMS root directory.


    *************************


    local ($columnNumber,$databaseName)= "$ENV{'EDAMSROOT'}/data/cmcounttest_database.data";

    ************************


    Main program


    ************************


    &info; #get info
    local @data=&readTEXT($columnNumber, $databaseName); # read database
    &count
    data(@data);

    &add($total_result);


    *********************


    info subroutine


    *********************


    sub info
    {
    while(@ARGV)
    {
    $arg = shift(@ARGV); # shift ARGV element eq arg
    if ($arg eq "-c")
    {
    $columnNumber = shift(@ARGV); #The @ARGV array is then shifted

    removing -c


    }
    elsif ($arg eq "-f")
    {
    $databaseName = shift(@ARGV);
    }
    else
    {
    print "Illegal Characters '$arg'\n";
    }
    }

    print "columnNumber is $columnNumber\n";


    print "databaseName is $databaseName\n";


    return ($columnNumber,$databaseName);
    }

    exit;


    **********************


    Read Text subroutine to read data from DB.


    **********************


    sub readTEXT
    {
    local($text)[email protected]
    ;

    print "text number $text\n";


    local(*TEXT, @context);


    open(TEXT, "<$text") || die "can't open $text\n";

    print "text is $text";


    @context = <TEXT>;

    print "context is $context\n";


    close (TEXT);

    print "TEXT is $TEXT\n";




    return @context;
    }

    exit;


    *********************


    Subroutine for count and all airthematic are happen here.


    *********************


    sub countdata
    {
    local(@data)[email protected]
    ;
    local(@wholenumber);
    local(%result);
    $count = 0;
    local $ordernumber = keys %ORDER;

    print "order number is $ordernumber\n";



    foreach(@data)
    {#print "data is $_";


    if ($_ =~ /\n$/) { chop ($_); }

    pushes ordernumber onto the end of the array @wholenumber


    (push(@wholenumber, (split (/\t/, $_,$ordernumber)))); #split into array
    }

    exit;


    print "ordernumber is $ordernumber\n";



    foreach(@wholenumber)
    {#print "wholenumber is $wholenumber\n";
    $key=$ORDER{$count};
    $result{$key}=($_);


    print "$key $_\n";

    print "$result \n";


    $count++;


    if($count == $ordernumber)
    {
    $count=0;
    &add(%result);
    }
    }

    print "Result is $result\n";


    }

    exit;


    sub add
    {
    local(%result) [email protected];
    my $total
    result = (%result);
    print "Result is $total_result \n";

    return ($total_result);


    }

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“I invented the term Object-Oriented, and I can tell you I did not have C++ in mind.” - Alan Kay