Re: Regex help

2007-11-25 Thread Todd
See the codes below. The trick here is that $& is an special var used
to capture the total match string.
So in this case, the /[$&]/ regexp literal is equal to /
[.type=xmlrpc&]/.

#!/bin/perl
$url = 'http://abc.com/test.cgi?TEST=1&.type=xmlrpc&type=2';
($r1) = $url =~ /\.type=(.+?)(&|$)/;
print "\$&=$&\n";
($r2) = $url =~ /\.type=(.+?)[$&]/;

print "\$r1=$r1\n\$r2=$r2\n"

__DATA__
$&=.type=xmlrpc&
$r1=xmlrpc
$r2=x


-Todd


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




Re: Regex help

2007-11-25 Thread John W . Krahn
On Saturday 24 November 2007 22:59, Todd wrote:
> See the codes below. The trick here is that $& is an special var used
> to capture the total match string.
> So in this case, the /[$&]/ regexp literal is equal to /
> [.type=xmlrpc&]/.

Right.  And that is a character class which says to match *one* 
character, either '.' or '=' or '&' or 'c' or 'e' or 'l' or 'm' or 'p' 
or 'r' or 't' or 'x' or 'y'.


> #!/bin/perl
> $url = 'http://abc.com/test.cgi?TEST=1&.type=xmlrpc&type=2';
> ($r1) = $url =~ /\.type=(.+?)(&|$)/;
> print "\$&=$&\n";
> ($r2) = $url =~ /\.type=(.+?)[$&]/;
>
> print "\$r1=$r1\n\$r2=$r2\n"
>
> __DATA__
> $&=.type=xmlrpc&
> $r1=xmlrpc
> $r2=x

Which is why $r2=x because (.+?) matches the 'x' after '.type=' and 
[.type=xmlrpc&] matches the 'm' after '.type=x'.

Also, using $& (or $` or $') slows down all regular expressions in the 
program.



John
-- 
use Perl;
program
fulfillment

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




webcrawler - a concise idea but I need a little help.

2007-11-25 Thread Tobias L
Hi.

I have got a little bit more serious idea than my last one, as an
enthusiatisk chess player I would like if I could download a lot of .pgn
files from the web.
But I don't how to do some pseudo code could be like


open_internet_connection
{
open_some_site
search(*.pgn)
download(*.pgn)
}


but this should be done on a whole bunch of files.
- btw. Just give me a hint on what sort of modules I need I can read and
learn myself.
or better yet where is there a decent search page for cpan ?
Can't find any.

Greetings Denmark


Re: webcrawler - a concise idea but I need a little help.

2007-11-25 Thread Tom Phoenix
On 11/25/07, Tobias L <[EMAIL PROTECTED]> wrote:

> But I don't how to do some pseudo code could be like
>
>
> open_internet_connection
> {
> open_some_site
> search(*.pgn)
> download(*.pgn)
> }

Sounds like you want WWW::Mechanize.

http://search.cpan.org/dist/WWW-Mechanize/

> or better yet where is there a decent search page for cpan ?

Besides search.cpan.org? What do you find if you type "search cpan"
into your favorite search engine?

Cheers!

--Tom Phoenix
Stonehenge Perl Training

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




Date and Time and Function calls

2007-11-25 Thread AndrewMcHorney

Hello

 I am looking for a perl function or functions that will give me the 
date and time. I am going to use the results to create a unique file name.


Andrew


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




Re: Date and Time and Function calls

2007-11-25 Thread yitzle
time will give you the number of seconds since the epoch. This is good
so long as you don't expect to create two files in one second.
http://perldoc.perl.org/functions/time.html

"For measuring time in better granularity than one second, you may use
either the Time::HiRes module (from CPAN, and starting from Perl 5.8
part of the standard distribution)"
http://perldoc.perl.org/perlfaq8.html#How-can-I-measure-time-under-a-second%3f

An alternative might be to get a random number, and use that.

On Nov 24, 2007 11:44 AM, AndrewMcHorney <[EMAIL PROTECTED]> wrote:
> Hello
>
>   I am looking for a perl function or functions that will give me the
> date and time. I am going to use the results to create a unique file name.
>
> Andrew

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




Re: Date and Time and Function calls

2007-11-25 Thread Tom Phoenix
On 11/24/07, AndrewMcHorney <[EMAIL PROTECTED]> wrote:

>   I am looking for a perl function or functions that will give me the
> date and time.

Are you looking in the perlfunc manpage? Type 'perldoc perlfunc' at a
prompt (or into your favorite search engine) to get started.

> I am going to use the results to create a unique file name.

Even if you have the time to the second, there may be another process
active during the same second. One common and easy way to do what I
think you want is to include the process ID (PID) and some small
string (such as your program name), along with $^T as as the time.
Even though process IDs are eventually reused, the process ID is a
unique value while the program runs. If my program were named fred, I
might use something like this:

  my $unique_file_name = "fred.$^T.$$";

Perl's special variables, such as $$ and $^T, are documented in the
perlvar manpage.

Cheers!

--Tom Phoenix
Stonehenge Perl Training

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




Re: Date and Time and Function calls

2007-11-25 Thread rahed
AndrewMcHorney <[EMAIL PROTECTED]> writes:

> Hello
>
>  I am looking for a perl function or functions that will give me the
> date and time. I am going to use the results to create a unique file
> name.

There are many posibilities depending on uniqueness,
this is quite similar:

$randnum  = 1000 + int rand(9000);
$filename = time.'_'.$randnum;

-- 
Radek


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




Re: Date and Time and Function calls

2007-11-25 Thread Dr.Ruud
rahed schreef:
> AndrewMcHorney:

>>  I am looking for a perl function or functions that will give me the
>> date and time. I am going to use the results to create a unique file
>> name.
> 
> There are many posibilities depending on uniqueness,
> this is quite similar:
> 
> $randnum  = 1000 + int rand(9000);
> $filename = time.'_'.$randnum;

You could put that inside a "while (1) {}", 
that also contains a "-e $filename or last;",
but even then you would still risk a race condition. 

-- 
Affijn, Ruud

"Gewoon is een tijger."

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




Re: Date and Time and Function calls

2007-11-25 Thread Martin Barth
Hi Andrew,

I would suggest http://search.cpan.org/~tjenness/File-Temp-0.19/Temp.pm

HTH Martin

On Sat, 24 Nov 2007 08:44:18 -0800
AndrewMcHorney <[EMAIL PROTECTED]> wrote:

> Hello
> 
>   I am looking for a perl function or functions that will give me the 
> date and time. I am going to use the results to create a unique file name.
> 
> Andrew

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




perl_eval_pv function crashing when creating Perl subroutine from a char string in CPP program

2007-11-25 Thread Borse, Ganesh
Hi,

I am trying to create Perl subroutine in my C++ program, source code of which 
is given below -- attempt to embed Perl in C++ program.
I cannot use the perl script file for this because the expressions to be 
evaluated are stored in database & are to be loaded at runtime.

This program compiles fine. Command line for that is also given.

But, program crashes when it calls perl_eval_pv function. When I ran it in GDB, 
I got this back trace.

May I please know:
1) Is this correct way to create Perl subroutines in embedded Perl in C?
2) Why is this program is crashing when perl_eval_pv?
A) How to resolve this problem of crash?
-- should I link any more library or compile the Perl on my machine?

Please help.
Thanks in advance for help & guidance.

Regards,
Ganesh

Compilation command:
g++ -g3 -ggdb -Dbool=char -DHAS_BOOL 
-I/usr/lib/perl5/5.8.0/i386-linux-thread-multi/CORE 
-L/usr/lib/perl5/5.8.0/i386-linux-thread-multi/CORE -L/usr/lib -L. -lperl -lm 
-lnsl -lgdbm -ldb -ldl -lpthread -lc -lcrypt -lutil testeval.cpp
rpm -qf /usr/bin/perl
perl-5.8.0-88.4
Program source code:
#include 
#include 
static PerlInterpreter *my_perl;
main()
{
my_perl = perl_alloc();
perl_construct(my_perl);

char peExpr[] =\
"sub isSizeSmall($size,$vol,$ADV,$prod)\n"\
"{\n"\
"my ($size,$vol,$ADV,$prod) =  @_;\n"\
"if ( ($size < 1000) && ($vol < (0.001 * $ADV)) && ($prod =~ m/Stock/)){\n"\
"   return 10;\n"\
"   } else {\n"\
"   return 11;\n"\
"   }\n"\
"}\n";
 printf("expression: \n[%s]\n",peExpr);
 // Parse this subroutine & add to interpreter
 perl_eval_pv(peExpr,TRUE);
 // now call this subroutine with 4 input arguments in an array
 char *peArgs[] = { "100","1000","10","\"Stock\""};
 perl_call_argv("isSizeSmall",G_ARRAY,peArgs);
 perl_destruct(my_perl);
 perl_free(my_perl);
}
Gdb backtrace output when the program got SIGSEGV:
LD_LIBRARY_PATH=/usr/lib/perl5/5.8.0/i386-linux-thread-multi/CORE:$LD_LIBRARY_PATH
Using host libthread_db library "/lib/tls/libthread_db.so.1".
(gdb) run 
Starting program: /home/gborse/prgs/bakup/perl/a.out 
[Thread debugging using libthread_db enabled]
[New Thread -1223159680 (LWP 23628)]
expression: 
[sub isSizeSmall($size,$vol,$ADV,$prod)
{
my ($size,$vol,$ADV,$prod) =  @_;
if ( ($size < 1000) && ($vol < (0.001 * $ADV)) && ($prod =~ m/Stock/)){
  return 10;
   } else {
   return 11;
   }
}]
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1223159680 (LWP 23628)]
0xb757fa90 in S_doeval (my_perl=0x8049c48, gimme=0, startop=0x0) at 
pp_ctl.c:2774
2774pp_ctl.c: No such file or directory.
in pp_ctl.c
Current language:  auto; currently c
(gdb) bt
#0  0xb757fa90 in S_doeval (my_perl=0x8049c48, gimme=0, startop=0x0) at 
pp_ctl.c:2774
#1  0xb7581412 in Perl_pp_entereval (my_perl=0x8049c48) at pp_ctl.c:3353
#2  0xb74e678f in S_call_body (my_perl=0x8049c48, myop=0xbfffa370, is_eval=1) 
at perl.c:2064
#3  0xb74e69d2 in Perl_eval_sv (my_perl=0x8049c48, sv=0x0, flags=0) at 
perl.c:2129
#4  0xb74e6c1a in Perl_eval_pv (my_perl=0x8049c48, p=0x0, croak_on_error=1) at 
perl.c:2188
#5  0x08048804 in main () at testeval.cpp:31
(gdb) 
//-

==
Please access the attached hyperlink for an important electronic communications 
disclaimer: 

http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
==