Re: how to sleep 100 miliseconds?

2005-12-06 Thread Elie De Brauwer

TOKO wrote:
hi. I'm new at perl and am looking for solution of let script sleep for 
few miliseconds. I tried sleep(0.1); but it does not work :) as I 
thought. than I found this solution: select undef, undef, undef, .01; 
but it freezes script and it does not continue.

Thanks for any ideas. TOKO



You could use Time::HiRes which is also mentioned in perldoc -f sleep. 
Sleep only works with a granularity of one second.


http://search.cpan.org/~jhi/Time-HiRes-1.83/HiRes.pm

hth
E.
--
Elie De Brauwer


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Archive

2005-12-02 Thread Elie De Brauwer

Brent Clark wrote:

Hi

Anyone know if theres an archive link for this mailing list.

Kind Regards
Brent Clark



What about http://groups.google.com/group/perl.beginners?lnk=sg ?

hth
E.

--
Elie De Brauwer


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: You've read the Llama, now what?

2005-11-28 Thread Elie De Brauwer

Paul Lalli wrote:

On 11/27/05, Tom Yarrish [EMAIL PROTECTED] wrote:



I've been reading this list for a while, and I've been trying to
learn perl on my own for quite some time.  However, my job doesn't
really (from my vantage point at least) allow me to do any sort of
programming (by that I mean my day to day work is more administrative
and project related versus writing any code).  So it makes it
difficult for me to apply what I've read from the O'Reilly books to
real world problems (and I've read the Llama book a few times).
My main issue has been trying to come up with a way to build up any
type of perl skills, and I know to do that requires writing code.
However it's been difficult for me to come up with something to
write.



Tom,

I do use Perl all day long just about every day, so I'm definately not
in your situation.  However, you may be interested in sites such as
the Perl Quiz of the Week found at: http://perl.plover.com/qotw/

They send out two quizzes every week (one beginner and one more
advanced).  You can try to solve the quiz and send in your solution. 
After a week, the various solutions are discussed.


Hope this helps,
Paul Lalli



Hello,

The site looks rather dead. There is no trace of a quiz more recent than 
october 2004 :(


gr
E.

--
Elie De Brauwer


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: about regex

2005-11-16 Thread Elie De Brauwer

Rafael Morales wrote:

Hi list !!!

This is my trouble, I have a file with this output:

[11/14/05 22:52:10:130 GMT] 686b4b72 SystemOut O POST: 
https://198.104.159.77/ssldocs/ws/xt_vm_transkods.alia?brand=KO-BRperson_id=14560115password=teatrotrans_id=2amount=10trans_date=2005-11-14
 20:52:10trans_log=113200873013026tp_Kodes=1
[11/14/05 22:52:10:268 GMT] 686b4b72 SystemOut O RESP: 
ia_error=0vm=60in_auction=0pc_count=6
[11/14/05 22:52:10:293 GMT] 686b4b72 SystemOut O ZIPCODE:1212
[11/14/05 22:52:10:309 GMT] 686b4b72 SystemOut O WS:RedeemCode Params: 
pincode='4DPJQFVCXLRNIA' redeem_date='2005-11-14 10:52:09' person_id='14560115' 
brand='KO-BR' js_error=0vm=60pc_count=6
[11/14/05 22:52:10:377 GMT] 5636cb62 SystemOut O Algoritmo: H
[11/14/05 22:52:10:378 GMT] 5636cb62 SystemOut O Semilla del nuevo 
algoritmo:-1


And my match is in last line (the :-1), but I need that line and the two lines 
above. my question is how do I get that two lines above ???

Regards and Thanks a lot !!!



You could for example do that by buffering them. Following example reads 
from standard input. No that you should replace the regexp by something 
with more meaning in your context. This application also assumes that 
there will be at least three lines of input.


my $a=STDIN;
chomp $a;
my $b=STDIN;
chomp $b;
my $c=STDIN;
chomp $c;
while($c !~ /-1$/){
$a=$b;
$b=$c;
$c=STDIN;
chomp $c;
}
if($c =~ /-1$/){
print $a\n$b\n$c\n;
}else{
print Not found\n;
}

hth
E.
--
Elie De Brauwer


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: What is $ (can´t find it in the Camelbook)

2005-11-10 Thread Elie De Brauwer

Angerstein wrote:

Hello there,
I found the $ Scalar in some examples but I can´t figure out what they are
for.

Could someone tell me what $ is?




perldoc perlvar
 $LIST_SEPARATOR
 $  This is like $, except that it applies to array and slice val-
 ues interpolated into a double-quoted string (or similar inter-
 preted string).  Default is a space.  (Mnemonic: obvious, I
 think.)

hth
E.

--
Elie De Brauwer


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




waitpid() and exitcode 8 ?

2005-11-07 Thread Elie De Brauwer

Hello list,

I recently encountered a small oddity.  Suppose I have a process A:

#!/usr/bin/perl

use strict;

print Hello \n;
sleep 1;
print Goodbye\n;
exit 9;

Simply shows some out and gives a certain exit code. A second process, 
simply calls fork, execs the child in a process and waits for the child 
in the other process. In Perl this can look like this:


my $cmd = /home/user/proces.pl;
my $pid = fork();
if($pid == 0){
print Hi I'm a child\n;
exec $cmd or die Failed to run $cmd\n;
}else{
print Hi I'm a parent waiting for child with PID: $pid\n;
my $ret = waitpid($pid,0);
print $pid exited with code . ($?8) .\n;
}

The oddity i located in the last line. It seemd that I had to divide $? 
by 256 (or shift over 8 positions to the right) to get the correct exit 
code. So my question is:

a) Is there an other way to wait for a child to die and get the exit code
b) Can someone explain the odd behaviour of the exit code ?

greetings
E.

--
Elie De Brauwer


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: waitpid() and exitcode 8 ?

2005-11-07 Thread Elie De Brauwer

John W. Krahn wrote:

Elie De Brauwer wrote:


Hello list,



Hello,



I recently encountered a small oddity.  Suppose I have a process A:

#!/usr/bin/perl

use strict;

print Hello \n;
sleep 1;
print Goodbye\n;
exit 9;

Simply shows some out and gives a certain exit code. A second process,
simply calls fork, execs the child in a process and waits for the child
in the other process. In Perl this can look like this:

my $cmd = /home/user/proces.pl;
my $pid = fork();
if($pid == 0){
   print Hi I'm a child\n;
   exec $cmd or die Failed to run $cmd\n;
}else{
   print Hi I'm a parent waiting for child with PID: $pid\n;
   my $ret = waitpid($pid,0);
   print $pid exited with code . ($?8) .\n;
}

The oddity i located in the last line. It seemd that I had to divide $?
by 256 (or shift over 8 positions to the right) to get the correct exit
code. So my question is:
a) Is there an other way to wait for a child to die and get the exit code
b) Can someone explain the odd behaviour of the exit code ?



Have you read the perl documentation on the functions and variables you are 
using?

perldoc perlipc

- Read it

perldoc perlvar

- Didn't read it

perldoc -f fork

- Read it

perldoc -f exec

- Read it

perldoc -f waitpid

- Read it





And as murphy'd say, perldoc perlvar contained what i was looking for:
 $?  The status returned by the last pipe close, backtick (``) com-
 mand, successful call to wait() or waitpid(), or from the sys-
 tem() operator.  This is just the 16-bit status word returned
 by the wait() system call (or else is made up to look like it).
 Thus, the exit value of the subprocess is really ($?  8),
 and $?  127 gives which signal, if any, the process died
 from, and $?  128 reports whether there was a core dump.
 (Mnemonic: similar to sh and ksh.)

Thanks for the pointer


--
Elie De Brauwer



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: white space between roam and act

2005-10-19 Thread Elie De Brauwer

K.Moeng wrote:

Hello again,

I have rephrased my question from yesterday,

I want to be able to ignore the white space in between ROAM and ACT
that is return the query as ROAM ACT without falling to the else statement.

$msg = $ARGV[0];

$msg =~ s/\/' /ig;

$found = 0;

if ($msg =~ /roam act/i)
{
 $name = 'ACTivated';
 $found = 1;
}

elsif ($msg =~ /roam dact/i)

{
 $name = 'DeACTivated';
 $found = 1;
 }

 if ($found == 1)

print .Thank you..\n;
}

else
{
 print Sorry. Your request has not been sent for Roaming.\n;
}




Hello,

So you basicly mean to match  FOOroama number of spacesactBAR ?

if( $msg =~ /roam +act/i) will match a number of spaces larger than or 
equal to 1: roam act and roam  act but not roamact
if( $msg =~ /roam *act/i) will match zero or more spaces:  roam act and 
roam  act and roamact

while the code you wrote
if( $msg =~ /roam act/i) will match exactly one space so only roam act

I also assume you are aware that your if ($found) block is in the 
wrong place as it should be beneath the else (or another one should be 
added in the first if block.


Or do you still mean something else ?

hth
E.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: white space between roam and act

2005-10-19 Thread Elie De Brauwer

Elie De Brauwer wrote:

K.Moeng wrote:


Hello again,

I have rephrased my question from yesterday,

I want to be able to ignore the white space in between ROAM and ACT
that is return the query as ROAM ACT without falling to the else 
statement.


$msg = $ARGV[0];

$msg =~ s/\/' /ig;

$found = 0;

if ($msg =~ /roam act/i)
{
 $name = 'ACTivated';
 $found = 1;
}

elsif ($msg =~ /roam dact/i)

{
 $name = 'DeACTivated';
 $found = 1;
 }

 if ($found == 1)

print .Thank you..\n;
}

else
{
 print Sorry. Your request has not been sent for Roaming.\n;
}

I also assume you are aware that your if ($found) block is in the 
wrong place as it should be beneath the else (or another one should be 
added in the first if block.




- Actually you have a missing { after your last if which my 'still too 
early in the morning mental perl interpreter' didn't see the first time.



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: how to find missing value.

2005-10-10 Thread Elie De Brauwer

Robin wrote:

On Tuesday 11 October 2005 00:54, Suvajit Sengupta wrote:


 If the array A is a list of consecutive N natural numbers,
then missing number,n = Sum of N natural numbers + Sum of the numbers
in Array A.


That's a nice solution. It can be enhanced slightly with the use of that 
thing that someone famous came up with (was it Gauss?):
Assumptions: 
 1) the set of numbers would be consecutive if it were sorted, with the 
exception of the missing number.

 2) the list starts at 1 (although the 1 can be missing, that's OK)

Work out the sum of the numbers in the list, assuming it was complete:
 $sum = ($list[-1] + 1)*((@list + 1) / 2)
Work out the real sum of the values in the list:
 foreach (@list) { $realSum += $_; }
Find the missing number:
 $missing = $sum - $realSum;

Because I should be doing something else but can't be bothered, I'll break 
down the first part and explain it. It's really quite neat.


Imagine a complete list of numbers: 1+2+3+4+5+6+7=28
This can also be represented as: (1+7)+(2+6)+(3+5)+(4)=28
Note also that 1+7=8, 2+6=8 and so on, the exception being the 4, but 
we'll deal with that soon.

Now, we have as many of those pairs as we have (numbers in the list)/2
If you happen to have an odd-numbered list (such as above), you end up 
having an x.5 result. That takes care of the 4 (given 8*0.5=4).
So you take the value from the pairs, in this case 8, multiply it by the 
number of pairs, in this case 3.5 ... and you have the sum of the numbers 
in the list.


Clearly, the difference between this value and the actual sum must be the 
missing number. So you can get your solution in O(n) time rather than 
O(n^2).


Cool huh? :)

(BTW: my not knowing the above solution would have been to sort the 
list, then search for the missing one.)




True but if you already have a sorted list with only one missing value 
you can get to the result even faster. Even in O(lg(n)) time (log_2 (n)) 
that is. E.g:


use POSIX;
use strict;

# Array is an array going from 0 to $end with one value missing
my @array = qw/0 1 2 3 4 5 7 8 9 10 11 12 13/;
my $begin = 0;
my $end = 13;

while($begin != $end){
my $n = floor(($begin+$end)/2);
if($array[$n] != $n){
# Go to the left
# If else logic is needed to reach the stop condition
if($end==$n){
$end--;
}else{
$end=$n;
}
}else{
# Go to the right
if($begin==$n){
$begin++;
}else{
$begin=$n;
}

}
}

print $begin .  is missing\n;

(I agree on the btw)

gr
E

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Trying to undertsand a Program

2005-10-06 Thread Elie De Brauwer

Gladstone Daniel - dglads wrote:
Can someone help me understand what this line does? 


my ($tablename, $filepath, $ifilename, $ojob) = @ARGV;

Can someone give me a good place to look verbs up so I can get a 
Better understanding of this program. 


I have ordered a book but it will take a week or more



This declares the variables $tablename, $filepath, $ifilename and $ojob. 
 It copies values from the array @ARGV to there variables so taht

my $tablename = $ARGV[0];
my $filepath = $ARGV[1];
my $ifilename = $ARGV[2];
my $ojob = $ARGV[3];

And @ARGV is the array of all parameters passed. So if you start your 
script with ./script.pl 1 2 3 4 then 1,2,3 and 4 will be assigned to the 
variables.


http://learn.perl.org will get you started until your book has arrived.

hth
E.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: somebody help me

2005-10-04 Thread Elie De Brauwer

The Roopak Times wrote:

Hi All
 I'm just a beginner with perl.
i was taking my initial lectures so i tried to make a program to slice a
value from an array.
 the program was like this:
 use warnings;
use strict;
my @array;
@array=qw( the quick brown fox ran over the lazy dog);
print $array(4)\n;
 This program does not show any result, besides it give me an error to
declare the variable $array.
 I'm using perl 5.8.7 with windows XP.
Plz tell me the reason and the solution for the above problem.
 -
Thankx  Regards

Roopak Kr Prajapat



Hello,

Using print $array[4]\n; solves your problem.

greetings
E.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Creating a hash from a name stored in a variable ...

2001-08-09 Thread Elie De Brauwer

I searched google, asked some people on irc but no-one could answer me.

$max_index  is a value gotten from a database which contains the number of 
entry's 

for($i = 0, $i  $max_index, $i++){
 %data$1{name} = #get the name from the database matching the index 
and store 
it here ...  
}

This is very simplistic in not working code what i want to do. I want to 
generate a hash variable name. %data1, %data2  where the numbers are read 
from a variable  How can i do this ?
-- 
==
 real men do it in perl ;)

 De Brauwer Elie 
   [EMAIL PROTECTED]
==

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




DBI question (again)

2001-08-02 Thread Elie De Brauwer

Extracted from the perl cookbook

use DBI;

$dbh = DBI-connect('DBI:driver:database', 'username', 'auth',
{ RaiseError = 1, AutoCommit = 1});
$dbh-do($SQL);
$sth = $dbh-prepare($SQL);
$sth-execute();
while (@row = $sth-fetchrow_array) {
# ...
}
$sth-finish();
$dbh-disconnect();

Concerning this code i have some questions ( i thinks it is very badly 
documented in the man pages)

-what does '-' stand for ?
- what does prepare do ?
- is there a _GOOD_ documentation about this ? I just want some sample code 
how to make some selects that return multiple data, and than see how the 
multiple rows are handled with ...

-- 
==
 real men do it in perl ;)

 De Brauwer Elie 
   [EMAIL PROTECTED]
==

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




use Filter::decrypt;

2001-08-01 Thread Elie De Brauwer

When i read the perlfaqs and some documents they all said that  use 
Filter::decrypt;  is an insufficient way to protect your code. Now i want to 
know, how can i reverse this ? 
I have a .pl file encrypted with use Filter::decrypt; how can i make these 
back human readable ?

-- 
==
 real men do it in perl ;)

 De Brauwer Elie 
   [EMAIL PROTECTED]
==

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]