Hi all,
I have a data similar to one listed below,(It is stored in a array with comma as delimiter).
For each month and each Department I need to get the status count. I thought of using Hashes but not sure how to get it.
Sampe Input:
ID Status Depar DATE
D123 Good A 12-03-2008
D123 Bad B 13-04-2008
C123 Poor A 12-03-2008
F123 Good B 15-05-2008
V123 Good E 14-04-2008
V123 Poor A 13-02-2008
V123 GOOD A 13-03-2008
Output:
Enter the dept: A ( From User)
for the Month -03
GOOD:2
BAD:0
POOR:1
for the Month -04
GOOD:1
BASD:1
POOR:0
Similarly I need to get this for all the month. Any pointers that can be used to solve will be extremely helpfull...
Thank in Advnace
9 1477 numberwhun 3,509
Recognized Expert Moderator Specialist
Hi all,
I have a data similar to one listed below,(It is stored in a array with comma as delimiter).
For each month and each Department I need to get the status count. I thought of using Hashes but not sure how to get it.
Sampe Input:
ID Status Depar DATE
D123 Good A 12-03-2008
D123 Bad B 13-04-2008
C123 Poor A 12-03-2008
F123 Good B 15-05-2008
V123 Good E 14-04-2008
V123 Poor A 13-02-2008
V123 GOOD A 13-03-2008
Output:
Enter the dept: A ( From User)
for the Month -03
GOOD:2
BAD:0
POOR:1
for the Month -04
GOOD:1
BASD:1
POOR:0
Similarly I need to get this for all the month. Any pointers that can be used to solve will be extremely helpfull...
Thank in Advnace
I don't think you need to go to the extent of using hashes for this, especially if you have each element of your array each containing one of the sample lines (which has all the information you need.
What I would do is simply read in the elements, one by one, then process them for what I needed and format the output after that.
Since this is a learning forum, why not try it and if you get stuck, show us your code and we will try and help you along. Please know that if you do need help, you will need to post your code here, enclosed in code tags.
Regards,
Jeff
The contents of the file is huge.(Around 750 entry) It has many departments also. Not sure if processing them line by line will be helpfull.
Need to decide the logic before starting...Please let me know your views..
Ganon11 3,652
Recognized Expert Specialist
Processing them line by line will be fine, and I'm not sure there's another way to get all the contents of the file.
Your best option would be to read in a line (make sure it's an input line, not the header line telling a reader what data is stored), then use a regular expression to capture the dates/status etc. etc. Once you have separated this information, use whatever you want to store the information - a series of hashes for each data element (date, status, etc.) holding the count as the value and the name as the key (for example, GOOD => 2) would be an elegant solution, provided you know all the statuses are all uppercase/all lowercase/in the same format.
numberwhun 3,509
Recognized Expert Moderator Specialist
The contents of the file is huge.(Around 750 entry) It has many departments also. Not sure if processing them line by line will be helpfull.
Need to decide the logic before starting...Please let me know your views..
Well, that depends on how you look at the grand scheme of things. If the sample data is pretty accurate as to the size of each entry, then the longest line looks to be about 22 Bytes in length. You multiply that times 750 and that works out to about 17K worth of data. Most machines these days have a lot more than 17K of memory, I promise you, unless you are working on such an arcane beast that nobody else would want to touch it.
What I am saying is, unless you are talking about many thousands of lines, this shouldn't be a problem.
As for the format of the input data, is what you have above pretty close? Is the first line always that column titles?
Granted, others here may have other ideas and feel free to use them as you see fit, this is just my approach to the issue.
Regards,
Jeff
KevinADC 4,059
Recognized Expert Specialist
The contents of the file is huge.(Around 750 entry) It has many departments also. Not sure if processing them line by line will be helpfull.
Need to decide the logic before starting...Please let me know your views..
You will have to process them line by line, or if they are already in an array, element by element. There is no getting around that.
Thanks. I have processed line by line for the given department and pushed the contents in an array. When I print the array it looks as follows ( state Month)
GOOD 03 BAD 04 GOOD 03 POOR 04 BAD 02 BAD 03 GOOD 05 BAD 06
Now I need to count for each month(03,04,05,05,06 which are in the array)..
eg: for 03
GOOD:3
BAD:01
POOR:0
Hash wiil be useful for this. I have not worked on hashes any pointers for the same will be helpfull.
KevinADC 4,059
Recognized Expert Specialist
This is the code I have so far...
The output of array will look like this - GOOD 03 BAD 04 GOOD 03 POOR 04 BAD 02 BAD 03 GOOD 05 BAD 06
- open(FH,"sample.txt");
-
my @month = qw(Jan Feb mar Apr may jun Jul Aug Sep OCt Nov Dec);
-
print "Please Enter the Input Qu";
-
$temp=<STDIN>;
-
chop($temp);
-
print "Please Enter the Input Dep";
-
$IDEPT=<STDIN>;
-
chop($IDEPT);
-
while(<FH>)
-
{
-
chomp;
-
if(($temp=~/q1/) && ($_=~/(\d\d)-(\d\d)-(\d\d\d\d)/))
-
{
-
-
if(($2 >= 04) && ($2 <=07) && ($_=~/$IDEPT/))
-
{
-
-
($ID,$DEPT,$STATE,$DATE)=split ',';
-
$Month = substr ($DATE, 3, 2);
-
#push @qua1,$DEPT;
-
push @qua1,$STATE;
-
push @qua1,$Month;
-
}
-
-
}
-
-
}
-
print "@qua1\n";
-
close(FH);
eWish 971
Recognized Expert Contributor
This is basically an illustration on how to use a hash to store the data that then access it. You will need to make changes to make it work for your exact needs. There are other ways of handling this but it will help you get started with hashes.....I hope. - my %data_hash = ();
-
my $file = 'f:/test_file.txt';
-
-
open(my $FILE, '<', $file) || die "Can't open file $file: $!\n";
-
while (<$FILE>) {
-
chomp;
-
-
my ($id, $status, $dept, $date) = split(/ /);
-
my ($day, $month, $year) = split(/\-/, $date);
-
my $formatted_date = $month . '-' . $year;
-
-
$data_hash{$formatted_date}->{$dept}->{$status}++ ;
-
-
}
-
close($FILE);
-
-
foreach my $date (keys %data_hash) {
-
print 'Month / Date: ', $date, "\n";
-
-
foreach my $dept( keys %{$data_hash{$date}}) {
-
print 'Dept: ', $dept, "\n";
-
-
foreach my $status (keys %{$data_hash{$date}->{$dept}}) {
-
print $status, ' = ', $data_hash{$date}->{$dept}->{$status}, "\n";
-
}
-
}
-
print "\n";
-
}
--Kevin
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: ben moretti |
last post by:
hi
i'm learning python, and one area i'd use it for is data management in
scientific computing. in the case i've tried i want to reformat a data
file from a normalised list to a matrix with some...
|
by: spar |
last post by:
I'm converting a Perl script to Python and have run into something I'm
not sure how to do in Python.
In Perl, I am running through a couple loops and inserting values
directly into a complex...
|
by: Jeff |
last post by:
I've created a beast! Here is my data structure:
$VAR1 = 'bunkers';
$VAR2 = {
'items' => ,
\
]
};
$VAR3 = 'simpsons';
$VAR4 = {
|
by: Da-Breegster |
last post by:
Hi. I'm attempting to write a roguelike (think nethack, crawl, angband,
tome, adom, and yes, I suppose even rogue) in Perl and I've ran into a
problem regarding the data structure for the map and...
|
by: Johnny Google |
last post by:
Here is an example of the type of data from a file I will have:
Apple,4322,3435,4653,6543,4652
Banana,6934,5423,6753,6531
Carrot,3454,4534,3434,1111,9120,5453
Cheese,4411,5522,6622,6641
The...
| |
by: Robert Oschler |
last post by:
I am converting a Perl script over to "C" for a potential open source
project. I need some open source "C" code that will give me the same
functionality of a Perl Style associative array:
...
|
by: surfivor |
last post by:
I may be involved in a data migration project involving databases and
creating XML feeds. Our site is PHP based, so I imagine the team might
suggest PHP, but I had a look at the PHP documentation...
|
by: mojo |
last post by:
Hello all;
I'm having trouble with my perl script and need some guidance. I am able to read data from a .csv file using the script and am placing it into an array @field. The data consists of four...
|
by: rhaas |
last post by:
Howdy.
I've been trying to parse the return of XML::TreePP from an xBRL file using perl and Data::Dumper.
The resulting Data::Dumper output looks like this:
$VAR1 = {
'xbrl' =>...
|
by: lilly07 |
last post by:
Hi,
I have a doubt regarding perl hash data. I have a tab delimited as below:
file1.txt
name1 AM bin1
name2 AM bin1
name3 PM bin1
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |