Re: Lottery Regex
Omega -1911 wrote: Thanks Rob, Is this homework? Not hardly! I was sitting here the other day and the thought came to mind as our state lottery has not had a winner in over a year. (The public started thinking that there is a conspiracy because it was exactly a year ago that our state went to computer generated lottery numbers AND there has not been a winner since! -Look up the Hoosier Lottery Drawing). I will give yours as well as the other examples a try and will benchmark the fastest code. Never concern yourself with the speed of a program unless it's running too slowly or you're paying for the run time somehow. By far the most important thing (as long as it works) is how easy it is to understand. Homework though? What gave you that idea? It is my only wanting to expand my mind when dealing with parsing information from a page via regular expressions without the use of a module. Just the style of your post really. You phrased it very like a homework question, in particular the details of the implementation that aren't at all relevant in the statement of a problem: Omega -1911 wrote: Can anyone assist with a regex to pull lottery numbers from a page? With real-world problems it's irrelevant whether the solution involves a regular expression. And: Omega -1911 wrote: What I will need to be able to do is place the most common 5 numbers (before the word "powerball") into an array then place the powerball numbers into another array. Although it's likely that arrays will be involved there's no reason, unless you're setting homework, to say that they must be used. What you want is just the five most frequent ball numbers. Finally: Omega -1911 wrote: All data from the web page is pushed into an array. ( Header and footer info is removed before being pushed into the array.) This is the sort of stuff examiners put into questions to avoid people writing reams of unnecessary code to process data irrelevant to the question. Furthermore it's nonsense if it's a real web page as if it's all in HTML, the headers are the least of the problems, and there are no footers! And as these things occurred to me after I'd coded a complete solution I posted it anyway and asked the question, hoping I shouldn't have done a little less solving and a little more guidance. Cheers, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Lottery Regex
Thanks Rob, Is this homework? Not hardly! I was sitting here the other day and the thought came to mind as our state lottery has not had a winner in over a year. (The public started thinking that there is a conspiracy because it was exactly a year ago that our state went to computer generated lottery numbers AND there has not been a winner since! -Look up the Hoosier Lottery Drawing). I will give yours as well as the other examples a try and will benchmark the fastest code. Homework though? What gave you that idea? It is my only wanting to expand my mind when dealing with parsing information from a page via regular expressions without the use of a module. -Dave -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: File Size Limit in Archive::Perl
San wrote: Is there any way to limit the file size while zipping using Archive::Zip so that it will stop processing a zip operation on a file list when it crosses the maximum file size. Hey San Unfortunately Archive::Zip requires that an archive be written to disk before the compression is performed and the final size can be determined. But it is possible to compress files individually and write them to a temporary file to determine their size, and then add the same archive member to the final archive without repeating the compression. Take a look at the program below, which is written for a Windows system but should be easily portable. HTH, Rob use strict; use warnings; use Archive::Zip qw/AZ_OK/; use File::Temp qw/tempfile/; use constant MB => 1024 * 1024; my $dir = 'C:'; my @files = do { opendir my $fd, "$dir\\" or die $! or die $!; grep -f, map "$dir\\$_", readdir $fd; }; my $zip = Archive::Zip->new; my $total; my $limit = 50*MB; foreach my $file (@files) { my $temp = Archive::Zip->new; my $member = $temp->addFile($file); next unless $member->compressedSize; my $fh = tempfile(); $temp->writeToFileHandle($fh) == AZ_OK or die $!; $zip->addMember($member); $total += $member->compressedSize; die "$total bytes exceeds archive size limit" if $total > $limit; } print "Total archive size: $total bytes\n\n"; $zip->writeToFileNamed('archive.zip') == AZ_OK or die $!; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Lottery Regex
Omega -1911 wrote: Can anyone assist with a regex to pull lottery numbers from a page? The following is one example I have tried: All data from the web page is pushed into an array. ( Header and footer info is removed before being pushed into the array.) The entire goal here is an exercise I was playing with to produce a report of the most common winning lottery numbers. What I will need to be able to do is place the most common 5 numbers (before the word "powerball") into an array then place the powerball numbers into another array. Thanks in advance. @liners = split /(\s\[0-9],\s)Powerball:\s[0-9]/,$data_string; _DATA_ 22, 29, 35, 46, 52, Powerball: 2, Power Play: 5 1, 31, 38, 40, 53, Powerball: 42, Power Play: 2 6, 16, 18, 29, 37, Powerball: 24, Power Play: 2 I hope you're aware that the exercise is futile! The program below may help. All it does is put all five numbers in each line of data into array @balls and then remove the trailing two, copying these into @power. The loop accumulates a frequency count of each ball number into hash %balls. The hash keys (ball numbers) are sorted by descending frequency afterwards into @common and the first five of these values are printed. The results are less than spectacular as the only ball to appear more than once is 29. But this appears at the top of the list so all is well! Is this homework? HTH, Rob use strict; use warnings; my %balls; while () { my @balls = /\d+/g; my @power = splice @balls, -2; print "@balls\n"; print "@power\n"; $balls{$_}++ foreach @balls; } my @common = sort {$balls{$b} <=> $balls{$a}} keys %balls; print "\nMost common:\n"; print "$_\n" foreach @common[0..5]; __DATA__ 22, 29, 35, 46, 52, Powerball: 2, Power Play: 5 1, 31, 38, 40, 53, Powerball: 42, Power Play: 2 6, 16, 18, 29, 37, Powerball: 24, Power Play: 2 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Regex Help
Thank you both Dr.Ruud & Jonathan Lang. I will give both examples a try later today and let you know how it all turns out. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Regex Help
Thank you both Dr.Ruud & Jonathan Lang. I will give both examples a try later today and let you know how it all turns out. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Regex Help
"Jonathan Lang" schreef: > while () { > ($a[0], $a[1], $a[2], $a[3], $a[4], $b) = /(\d+), (\d+), (\d+), > (\d+), (\d+), Powerball: (\d+)/; > push @common, @a; push @powerball, $b; > } A slightly different way to do that, is: while () { if (my @numbers = /(\d+), (\d+), (\d+), (\d+), (\d+), Powerball: (\d+)/) { push @common, @numbers[0..4]; push @powerball, $numbers[5]; } else { ... } } -- Affijn, Ruud "Gewoon is een tijger." -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
File Size Limit in Archive::Perl
Hi All, Is there any way to limit the file size while zipping using Archive::Zip so that it will stop processing a zip operation on a file list when it crosses the maximum file size. Thanks in advance. -A -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Regex Help
Omega -1911 wrote: > @liners = split /(\s\[0-9],\s)Powerball:\s[0-9]/,$data_string; Instead of split, just do a pattern match: ($a[0], $a[1], $a[2], $a[3], $a[4], $b) = /(\d+), (\d+), (\d+), (\d+), (\d+), Powerball: (\d+)/; This puts the first five numbers into the array @a, and puts the powerball number into scalar $b. Note that this tackles a single line of data. To get everything, cycle through the lines using a "while ()" and push the results onto the two arrays as you get them: push @common, @a; push @powerball, $b; In whole, you get: while () { ($a[0], $a[1], $a[2], $a[3], $a[4], $b) = /(\d+), (\d+), (\d+), (\d+), (\d+), Powerball: (\d+)/; push @common, @a; push @powerball, $b; } When you're done, @common is (22, 29, 35, 46, 52, 1, 31, 38, 40, 53, 6, 16, 18, 29, 37), and @powerball is (2, 42, 24). -- Jonathan "Dataweaver" Lang -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Regex Help
On Nov 10, 2007 5:10 PM, Omega -1911 <[EMAIL PROTECTED]> wrote: >What I will need to be able to do > is place the most common 5 numbers (before the word "powerball") into > an array then place the powerball numbers into another array. Thanks > in advance. > > @liners = split /(\s\[0-9],\s)Powerball:\s[0-9]/,$data_string; > > _DATA_ > 22, 29, 35, 46, 52, Powerball: 2, Power Play: 5 > 1, 31, 38, 40, 53, Powerball: 42, Power Play: 2 > 6, 16, 18, 29, 37, Powerball: 24, Power Play: 2 > Hi, I just think the data stru you need is a hash not two arrays.The entire code can be: use strict; use warnings; use Data::Dumper; my %hash; while() { my ($li,$powerb) = /^(.+)\,\s*Powerball\:\s*(\d+)/; $hash{$powerb} = [split/,/,$li]; } print Dumper \%hash; __DATA__ 22, 29, 35, 46, 52, Powerball: 2, Power Play: 5 1, 31, 38, 40, 53, Powerball: 42, Power Play: 2 6, 16, 18, 29, 37, Powerball: 24, Power Play: 2 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Regex Help
Hello, Can anyone assist with a regex to pull lottery numbers from a page? The following is one example I have tried: All data from the web page is pushed into an array. ( Header and footer info is removed before being pushed into the array.) The entire goal here is an exercise I was playing with to produce a report of the most common winning lottery numbers. What I will need to be able to do is place the most common 5 numbers (before the word "powerball") into an array then place the powerball numbers into another array. Thanks in advance. @liners = split /(\s\[0-9],\s)Powerball:\s[0-9]/,$data_string; _DATA_ 22, 29, 35, 46, 52, Powerball: 2, Power Play: 5 1, 31, 38, 40, 53, Powerball: 42, Power Play: 2 6, 16, 18, 29, 37, Powerball: 24, Power Play: 2 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: About FASTA file
On Nov 8, 3:42 am, [EMAIL PROTECTED] (Auxence Sima) wrote: > i have Sequence Data in a file that i named " OUTPUT.TXT",and hereis my > question. I would like to create a FASTA data file, and i wonder how to > process. do i have to just take out the info inside the OUTPUT.TXT, and keep > only Sequences, and then put them ina FASTA format?? DO i keep the same > name for the data file??? > > the second question is : After i have created the fasta file, will i read > the info just the same way i would with TXT file??? > > __ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection > aroundhttp://mail.yahoo.com You may also want to check: the BioPerl project @ http://www.bioperl.org/wiki/Main_Page the BioPerl mailing list @ http://lists.open-bio.org/mailman/listinfo/bioperl-l -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Lottery Regex
Hello, Can anyone assist with a regex to pull lottery numbers from a page? The following is one example I have tried: All data from the web page is pushed into an array. ( Header and footer info is removed before being pushed into the array.) The entire goal here is an exercise I was playing with to produce a report of the most common winning lottery numbers. What I will need to be able to do is place the most common 5 numbers (before the word "powerball") into an array then place the powerball numbers into another array. Thanks in advance. @liners = split /(\s\[0-9],\s)Powerball:\s[0-9]/,$data_string; _DATA_ 22, 29, 35, 46, 52, Powerball: 2, Power Play: 5 1, 31, 38, 40, 53, Powerball: 42, Power Play: 2 6, 16, 18, 29, 37, Powerball: 24, Power Play: 2 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/