Threads/Queue Help
I am trying to execute a subroutine which acceses database and other things online. Instead of waiting for each response, i want to create a queue of the sub being called 500 times, as subs finish, new ones are added to always keep it at 500 items in the queue being executed at the same time. here is what i have so far. #!/usr/local/bin/perl # Packages Needed use threads; use Thread::Queue; sub doThisLotsofTimes { # Do something here } for my $i (1 .. 500) { $stream->enqueue($i); } $stream->enqueue(undef); $kid = new threads(\&check_num, $downstream, $num); $kid->join; $downstream->enqueue(undef) if $kid; # EOF- if someone could help me out that would be great! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: regex, 1 off...
On Sunday 16 December 2007 11:21, namotco wrote: > > Let's say I want to search some text for "abc123". However, we know > people can make typos and so they could have entered avc123 or abc223 > or sbc123 or bc123 many other combinations... > So I want to search for those possibilities as well. So how would I > go about creating the proper regex? Regular expressions are about matching patterns so you have to define what kind of pattern you are searching for. >From your example you may want something like: / \b (?: .?bc | a.?c | ab.? ) (?: .23 | 1.3 | 12. ) \b /x However much depends on the actual data and the variations that you are expecting. If you are searching for words like those used in the English language then you may want to look at how spell checking software works. John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
regex, 1 off...
Let's say I want to search some text for "abc123". However, we know people can make typos and so they could have entered avc123 or abc223 or sbc123 or bc123 many other combinations... So I want to search for those possibilities as well. So how would I go about creating the proper regex? Thanks! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Date::manip query
pauld wrote: > im using Date::Manip to convert dates and times eg 2007:08:02 12:23 to allow me to sort them, which it does . but I cant see how to get the number back into a human -readable format print scalar localtime($var{STARTTIME}); prints the long string . is there a better way to get just the bits I want , or do I have to parse the string I get from print scalar localtime output ? Have you read the documentation for Date::Manip? The UnixDate() function will do what you want. Something like print UnixDate($date, '%Y:%m:%d %H:%M'); for instance, which will reproduce the date in the format you have shown. HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Date::manip query
On Sunday 16 December 2007 04:31, pauld wrote: > > im using Date::Manip to convert dates and times eg 2007:08:02 12:23 > to allow me to sort them, which it does . > but I cant see how to get the number back into a human -readable > format Use the UnixDate() function that comes with Date::Manip. > print scalar localtime($var{STARTTIME}); prints the long string . is > there a better way to get just the bits I want , or do I have to > parse the string I get from print scalar localtime output ? Use localtime in list context instead. perldoc -f localtime John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Date::manip query
im using Date::Manip to convert dates and times eg 2007:08:02 12:23 to allow me to sort them, which it does . but I cant see how to get the number back into a human -readable format print scalar localtime($var{STARTTIME}); prints the long string . is there a better way to get just the bits I want , or do I have to parse the string I get from print scalar localtime output ? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Calculating Average from a file
[EMAIL PROTECTED] wrote: I've had to change the code as due to the earlier version of perl I am running the open line would not work. I found a workaround on the internet use strict; use warnings; my $file = shift @ARGV || 'cpuuse.out'; my %fh = (); if (-f $file and ! $fh{$file} ) { open($fh{$file}, "<$file") || DisplayError(); # coolness ensues... } my @cpu; while (<$fh>) { my @data = split; push @cpu, $data[4]; } print sum(@cpu) / @cpu; sub sum { my $sum; $sum += $_ foreach @_; return $sum; } however I am getting zero values back and it is erroring obviously about dividing by zero. My input file looks like this. [snip] This is the last part of my script I can't get working. Once this is sorted you may never hear from me again, until the next script I write :) This is why it's important to understand code you're borrowing instead of just copying it and hoping. The snippet you've copied is part of a scheme to cache multiple file handles and reuse them if a file has already been opened. Since you're opening only a single file this is unnecessary and confusing for you. It's also important to take notice of any error or warning messages that Perl is producing as John has already pointed out. If the Perl you're using will accept this open statement open($fh{$file}, "<$file") || DisplayError(); then all you need to do is replace the three-parameter open in my previous code open my $fh, '<', $file or die $!; with open my $fh, $file or die $!; and all should be well. Please try this and come back to this list to say whether you have been successful. HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/