If you are looking to determine which numbers are on every line, the
following code will do that.
The data set you presented didn't have a number that appeared on every
line, so changed one of the numbers in your data set so there'd be some
output.
use strict;
use warnings;
my %hash;
my $lineNum = 0;
my @data = (
'08|10|13|16|19|22|28|32|33|37|41|46|47|50|51|52|53|55|71|76',
'06|11|16|19|20|29|31|35|39|44|50|57|58|59|60|62|71|72|76|77',
'03|05|06|08|09|10|11|16|19|28|31|41|42|43|45|46|56|61|69|79',
'05|07|12|13|15|16|17|19|21|25|41|45|47|48|53|58|63|69|76|79',
'01|02|04|07|08|12|17|19|25|27|29|34|38|44|47|60|62|64|73|75',
'01|04|06|07|08|09|11|13|14|19|25|26|37|39|41|60|61|62|63|80',
'04|07|09|17|19|27|28|29|39|41|46|51|52|54|57|58|60|68|74|80'
);
for( @data ) {
for( split /\|/ ) {
$hash{$_}++;
}
$lineNum++;
}
for( sort keys %hash ) {
if( $hash{$_} == $lineNum ) {
print "$_ was found on every line\n";
}
}
cheers...
john
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
steve silvers
Sent: Wednesday, November 10, 2004 12:44 PM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: RE: Probably need help with a hash to do this
Well, actuall none of the posts are right. Allthough I appreciate all
the
responses. Were looking for I guess a way to put it, is patterns in the
lists. Take the below sample of only 7 lines:
my @data = (
'08|10|13|16|19|22|28|32|33|37|41|46|47|50|51|52|53|55|71|76', # row 1
'06|11|16|19|20|29|31|35|39|44|50|57|58|59|60|62|71|72|76|77', # row 2
'03|05|06|08|09|19|11|16|17|28|31|41|42|43|45|46|56|61|69|79', # row 3
'05|07|12|13|15|16|17|19|21|25|41|45|47|48|53|58|63|69|76|79', # etc...
'01|02|04|07|08|12|17|19|25|27|29|34|38|44|47|60|62|64|73|75',
'01|04|06|07|08|09|11|13|14|19|25|26|37|39|41|60|61|62|63|80',
'04|07|09|17|19|27|28|29|39|41|46|51|52|54|57|58|60|68|74|80'
);
Take each line "row" as seperate data entry. So the first line starts
with
08 and ends with 76. How can we find what "2 numbers", "3 numbers", "4
numbers" etc.. appear the most times together? To keep the example
simple
I'm taking just the first two rows of data.
'08|10|13|16|19|22|28|32|33|37|41|46|47|50|51|52|53|55|71|76', # row 1
'06|11|16|19|20|29|31|35|39|44|50|57|58|59|60|62|71|72|76|77', # row 2
The output just using these two rows would be;
16 - 19 - 50 - 71 - 76 appear together in each row.
But now if we add the third row
'03|05|06|08|09|19|11|16|17|28|31|41|42|43|45|46|56|61|69|79', # row 3
The output using these three rows would be;
16 - 19
Were looking to find the same numbers "pattern" in X amount of rows of
data.
I hope that helps out a bit. It's hard to explain.
Thank you in advance
Steve
>From: "Thomas, Mark - BLS CTR" <[EMAIL PROTECTED]>
>To: 'steve silvers'
><[EMAIL PROTECTED]>,[EMAIL PROTECTED]
>Subject: RE: Probably need help with a hash to do this
>Date: Wed, 10 Nov 2004 14:29:11 -0500
>
>My understanding of your problem is different from the other
responders. I
>believe what you want is the "intersection" of each "row" of numbers.
If
>this is correct, the following works:
>
>#!perl -w
>use strict;
>use List::Compare;
>
>my @data = (
>'08|10|13|16|19|22|28|32|33|37|41|46|47|50|51|52|53|55|71|76|99',
>'06|11|16|19|20|29|31|35|39|44|50|57|58|59|60|62|71|72|76|77|99',
>'03|05|06|08|09|10|11|16|17|28|31|41|42|43|45|46|56|61|69|79|99',
>'05|07|12|13|15|16|17|19|21|25|41|45|47|48|53|58|63|69|76|79|99',
>'01|02|04|07|08|12|17|19|25|27|29|34|38|44|47|60|62|64|73|75|99',
>'01|04|06|07|08|09|11|13|14|19|25|26|37|39|41|60|61|62|63|80|99',
>'04|07|09|17|19|27|28|29|39|41|46|51|52|54|57|58|60|68|74|80|99'
>);
>
># Turn data into a list of lists
>@data = map { [ split /\|/ ] } @data;
>
>my $lc = List::Compare->new( @data );
>
>print "Intersection: ", join ",", $lc->get_intersection;
>
>
>--
>Mark Thomas
>Internet Systems Architect
>_______________________________________
>BAE SYSTEMS Information Technology
>2525 Network Place
>Herndon, VA 20171 USA
>
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
___________________________________________________________________________________________________________
This email and any attachments thereto may contain private, confidential, and
privileged material for the
sole use of the intended recipient. Any review, copying, or distribution of
this email (or any attachments
thereto) by other than the County of Sacramento or the intended recipient is
strictly prohibited.
If you are not the intended recipient, please contact the sender immediately
and permanently
delete the original and any copies of this email and any attachments thereto.
___________________________________________________________________________________________________________
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs