Re: can't locate object method via perl package

2013-09-16 Thread Jimi Wills

how does your code look?



Dr Jimi C Wills


Gurunath Katagi gurunath.kat...@gmail.com wrote in message 
news:cak6su7_lffefoh-jtpm-es84p_mgmnydp4pwdpp8dek19is...@mail.gmail.com...

Hi everyone..
I am running a perl program which uses Math::Vector.
But i am getting the following error
Can't locate object method UnitVecPoints via package Math::Vector at 
/usr/local/share/perl5/Math/Vector.pm line 135.


Can anybody look into it and let me know how to proceed ? The module is 
correctly installed.


Thank u
Guruanth 



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Sleep

2013-09-16 Thread Ed Davis
Hi, I might be being a noob but reading the OP, aren't they wanting to call the 
value arbitrarily?  Meaning, e.g. an Ajax call in a web page could send a 
request to find out the time remaining in the sleep. 

I guess that the sleep (which will halt the script) needs to be invoked after 
forking a decrementing counter?  The decrementing counter will run 
asynchronously  and could be queried using Fork::Super bg_eval, but if you are 
asking this question that might be a stretch (it's not something I've used).  
As there is 'always more than one way to do it' I would use a fork and a file:

The simplest method, if it will do what you want would be to use an until loop 
to count down and do the sleeping, but you would need to decide up front 
whether you want to return a value (you could always write it to a file and 
call the contents of the file?).

Need more info on what you want to do with it, but on a basic level, this will 
work.  It passes the sleep time value to countdown and forks that process so 
the rest of the script can proceed. I put the actual 300 sec sleep at the 
bottom, but if you cat countdown.txt at any point it will tell you how long is 
left.  

#!/usr/bin/perl -w

use strict;

my $sleep_timer;
my $count_amount=('10');

if ( ! fork() ) {
countdown($count_amount);
}    Fork the counting process

sub countdown   {
$sleep_timer = shift;
print_remaining($sleep_timer);  ##I've put the printing in a routine 
## as 
we need it in two places
sleep 1;  ### Do the first second sleep before decrementing the counter
### That way it will get all the way down to zero

until ($sleep_timer == '0') {
$sleep_timer--;
print_remaining($sleep_timer);###Pass the current count to our 
printing sub
sleep 1;
}
}

sub print_remaining {
my $counter = shift;
open FH1 ,+countdown.txt;
print FH1 $sleep_timer;
close FH1;
}

### The main part of the script will hold on until the time has 
sleep 10;
print I waited $count_amount seconds to tell you this;


BEWARE using forks that you have some failsafe in place to stop the script 
being run multiple times, or the same sub will overwrite the counter file so 
the number will start to jump around all over the place.

Hope thats useful.

Ed

On 16 Sep 2013, at 00:49, John W. Krahn jwkr...@shaw.ca wrote:

 Shawn H Corey wrote:
 On Sun, 15 Sep 2013 13:00:36 -0700
 Unknown Userknowsuperunkn...@gmail.com  wrote:
 
 If my perl script has a sleep for say 300 seconds, when the sleep is
 being run is there any way i can find the time remaining in the sleep
 say by sending a signal?
 
 Thanks,
 
 Not directly. You have to record the time before the sleep and then you
 can measure how long the sleep lasted.
 
 my $started_sleep = time;
 sleep 300;
 my $time_asleep = time - $started_sleep;
 
 Or just:
 
 my $time_asleep = sleep 300;
 
 
 
 John
 -- 
 Any intelligent fool can make things bigger and
 more complex... It takes a touch of genius -
 and a lot of courage to move in the opposite
 direction.   -- Albert Einstein
 
 -- 
 To unsubscribe, e-mail: beginners-unsubscr...@perl.org
 For additional commands, e-mail: beginners-h...@perl.org
 http://learn.perl.org/
 
 


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Sleep

2013-09-16 Thread Ed Davis
(DOH - Obviously I was using 10 seconds to test!)

On 16 Sep 2013, at 00:49, John W. Krahn jwkr...@shaw.ca wrote:

 Shawn H Corey wrote:
 On Sun, 15 Sep 2013 13:00:36 -0700
 Unknown Userknowsuperunkn...@gmail.com  wrote:
 
 If my perl script has a sleep for say 300 seconds, when the sleep is
 being run is there any way i can find the time remaining in the sleep
 say by sending a signal?
 
 Thanks,
 
 Not directly. You have to record the time before the sleep and then you
 can measure how long the sleep lasted.
 
 my $started_sleep = time;
 sleep 300;
 my $time_asleep = time - $started_sleep;
 
 Or just:
 
 my $time_asleep = sleep 300;
 
 
 
 John
 -- 
 Any intelligent fool can make things bigger and
 more complex... It takes a touch of genius -
 and a lot of courage to move in the opposite
 direction.   -- Albert Einstein
 
 -- 
 To unsubscribe, e-mail: beginners-unsubscr...@perl.org
 For additional commands, e-mail: beginners-h...@perl.org
 http://learn.perl.org/
 
 


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: comparing all the elements of an array

2013-09-16 Thread Nathan Hilterbrand

See below

On 09/15/2013 06:48 PM, Unknown User wrote:
I have an array of numbers, and i want to find the percentage 
difference between all the elements.

Say my @a = ($a,$b,$c);
I need to calculate the percentage difference of element a with b, b 
with c and c with a.
The 3 items above are an example, it can be hundreds of numbers. Is 
there an algorithm already existing for this, so that all elements are 
compared and none are missed?



Thanks


UU,

I am not sure whether or not an existing algorithm is out there or 
not...  in fact, there may very well be a Math::PercentageDiffArray 
module on CPAN..


This bit of ugly code seems to work pretty well, though:

  use warnings;
  use strict;

  my @a = (15, 30, 45, 90, 120, 150);
  my @b;

  foreach my $idx (0..$#a) {
$b[$idx] = (($a[($idx+1) % (scalar @a)] / $a[$idx]) - 1) * 100;
  }

  print map {$_\n} @b;

It was even uglier on the first iteration, so I re-did it this way so 
that it might be a bit clearer.


The index of the first operand ($idx+1) % (scalar @a) simply says use 
the element one greater than the current index, unless it is the last 
element..  and then use a zero.


Nathan

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Sleep

2013-09-16 Thread Charles DeRykus
 On Sun, Sep 15, 2013 at 6:59 PM, Charles DeRykus dery...@gmail.com
 wrote: left: , $start+$sleep -time() };
 ...

Actually,  this is wrong because if sleep(3) is interrupted by any signal
it
will return, so something like this should work, eg

my $secs_to_sleep = 60;
my $start = time();
my $end = $start + $secs_to_sleep;

my $slept;
do  {
  local  $SIG{USR1} = sub{ say time left: , $end - time()};
  my $slept = sleep($secs_to_sleep);
  $secs_to_sleep -= $slept;
} while ( $secs_to_sleep   0 );

-- 
Charles DeRykus


How to Auto Generate range of years (year of birth between 18 and 73)

2013-09-16 Thread mimic...@gmail.com
I have this simple script to automatically print HTML selection option.

#!/usr/bin/env perl

use strict;

for (reverse(1943 .. 1991)){
 print \option value=\$_\$_\\/option\\n;
}


I need to print all the years between 18 and 73 without hard coding the
range in the for loop as in the  above. I am considering the use of
localtime to compute the current year as below  $yr=(localtime)[5], but I
can't think of an easy way to achieved what I want to do.

Any help appreciated.

Mimi


Re: How to Auto Generate range of years (year of birth between 18 and 73)

2013-09-16 Thread mimic...@gmail.com
The following works, but is this the way to go?

#!/usr/bin/env perl

use strict;

my ($min_yr, $max_yr);
$min_yr =(localtime)[5] + 1900 - 18;
$max_yr = (localtime)[5] + 1900 - 73;

for (reverse($max_yr .. $min_yr)){
 print \option value=\$_\$_\\/option\\n;
}


Mimi


On 16 September 2013 14:36, mimic...@gmail.com mimic...@gmail.com wrote:

 I have this simple script to automatically print HTML selection option.

 #!/usr/bin/env perl

 use strict;

 for (reverse(1943 .. 1991)){
  print \option value=\$_\$_\\/option\\n;
 }


 I need to print all the years between 18 and 73 without hard coding the
 range in the for loop as in the  above. I am considering the use of
 localtime to compute the current year as below  $yr=(localtime)[5], but I
 can't think of an easy way to achieved what I want to do.

 Any help appreciated.

 Mimi