undefined value error
I got the following error when one cgi file 'test.cgi' was called from HTML: Can't call method sequence on an undefined value However I can run 'test.cgi' with command 'perl test.cgi' correctly. Can anybody help me figure out the problem? The following is my code: error happened on bold lines. thanks, #!/usr/bin/perl use CGI; use CGI::Carp qw(fatalsToBrowser); use warnings; use diagnostics; use DNAalign; use fastream; use DNAseq; print Content-type: text/html\n\n; print htmlheadtitlePerl CGI Example # 2; print /title/headbodyh1; print Alignment Result /h1p; print pre; chdir(/srv/www/httmp/default/chromat_dir); my $seq1=fastream-new(default.fasta.screen.contigs); my $seq2=fastream-new(secondFile); my $test1=$seq1-next_seq(); my $test2=$seq2-next_seq(); my $s1=$test1-sequence(); my $s2=$test2-sequence(); print input1===$s1\n; print input2===$s2\n; ($sa,$sb)=DNAalign::align($test1,$test1); $result1=$sa-sequence(); $result2=$sb-sequence(); print \n; print result1=== $result1\n; print result2=== $result2\n; print /pre; print /p; print /body/html; Xiangli Zhang (Justin) 306-310 Decaire Street, Coquitlam BC, Canada, V3K 6X1 phone: 604-9399181 - Post your free ad now! Yahoo! Canada Personals
undefined value error
I got the following error when one cgi file 'test.cgi' was called from HTML: Can't call method sequence on an undefined value However I can run 'test.cgi' with command 'perl test.cgi' correctly. Can anybody help me figure out the problem? The following is my code: error happened on bold lines. thanks, #!/usr/bin/perl use CGI; use CGI::Carp qw(fatalsToBrowser); use warnings; use diagnostics; use DNAalign; use fastream; use DNAseq; print Content-type: text/html\n\n; print htmlheadtitlePerl CGI Example # 2; print /title/headbodyh1; print Alignment Result /h1p; print pre; chdir(/srv/www/httmp/default/chromat_dir); my $seq1=fastream-new(default.fasta.screen.contigs); my $seq2=fastream-new(secondFile); my $test1=$seq1-next_seq(); my $test2=$seq2-next_seq(); my $s1=$test1-sequence(); my $s2=$test2-sequence(); print input1===$s1\n; print input2===$s2\n; ($sa,$sb)=DNAalign::align($test1,$test1); $result1=$sa-sequence(); $result2=$sb-sequence(); print \n; print result1=== $result1\n; print result2=== $result2\n; print /pre; print /p; print /body/html; Xiangli Zhang (Justin) 306-310 Decaire Street, Coquitlam BC, Canada, V3K 6X1 phone: 604-9399181 Xiangli Zhang (Justin) 306-310 Decaire Street, Coquitlam BC, Canada, V3K 6X1 phone: 604-9399181 - Post your free ad now! Yahoo! Canada Personals
Re: undefined value error
Xiangli Zhang wrote: I got the following error when one cgi file 'test.cgi' was called from HTML: Can't call method sequence on an undefined value However I can run 'test.cgi' with command 'perl test.cgi' correctly. Can anybody help me figure out the problem? Well, you are not even letting us know from which line that error message comes... I don't know anything about those modules you are using, but I suppose that their docs describe how to check for success. There is where I would start the debugging work. A mailing list should be the *last* resort. -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
undefined value error
Hi, Gunnar: The error happened on lines with *** Error happened when the method sequence was called. It said $sa, $sb are undefined value. But when i run the called cgi from command line (linux terminal), the output is correct as expected. Which means in the browser running of this cgi, $sa, $sb did not get value? The modules I am using are self-programmed module for DNA sequencing. thanks, #!/usr/bin/perl use CGI; use CGI::Carp qw(fatalsToBrowser); use warnings; use diagnostics; use DNAalign; use fastream; use DNAseq; print Content-type: text/html\n\n; print htmlheadtitlePerl CGI Example # 2; print /title/headbodyh1; print Alignment Result /h1p; print pre; chdir(/srv/www/httmp/default/chromat_dir); my $seq1=fastream-new(default.fasta.screen.contigs); my $seq2=fastream-new(secondFile); my $test1=$seq1-next_seq(); my $test2=$seq2-next_seq(); my $s1=$test1-sequence(); my $s2=$test2-sequence(); print input1===$s1\n; print input2===$s2\n; ($sa,$sb)=DNAalign::align($test1,$test1); ***$result1=$sa-sequence(); ***$result2=$sb-sequence(); print \n; print result1=== $result1\n; print result2=== $result2\n; print /pre; print /p; print /body/html; Xiangli Zhang (Justin) 306-310 Decaire Street, Coquitlam BC, Canada, V3K 6X1 phone: 604-9399181 - Post your free ad now! Yahoo! Canada Personals
Re: undefined value error
Xiangli Zhang wrote: The error happened on lines with *** Error happened when the method sequence was called. It said $sa, $sb are undefined value. But when i run the called cgi from command line (linux terminal), the output is correct as expected. Which means in the browser running of this cgi, $sa, $sb did not get value? The modules I am using are self-programmed module for DNA sequencing. Then you'd better look for the problem in those modules, right? Even if I haven't seen them, I suspect that you have not properly checked for success when for instance opening files. So that's what I recommend you to do: Revise the code in the modules, and make sure you capture possible failures when they occur. -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Calling Perl from C - Problem with DynaLoader
Hi, I am trying to call Perl from C. I hit a problem when I try to load dynamic librarires. I have taken the following code from the PerlEmbed documentation (http://www.perldoc.com/perl5.8.4/pod/perlembed.html) but cannot get it to compile. I am trying to play with parameters to the gcc compiler but so far with no luck. Here are the contents of my c file: #include EXTERN.h #include perl.h static void xs_init (pTHX); EXTERN_C void boot_DynaLoader (pTHX_ CV* cv); EXTERN_C void boot_Socket (pTHX_ CV* cv); EXTERN_C void xs_init(pTHX) { char *file = __FILE__; /* DynaLoader is a special case */ newXS(DynaLoader::boot_DynaLoader, boot_DynaLoader, file); newXS(Socket::bootstrap, boot_Socket, file); } static PerlInterpreter *my_perl; int main(int argc, char **argv, char **env) { char *my_argv[] = { , sxiconn.pl }; my_perl = perl_alloc(); perl_construct(my_perl); printf (Loading Perl sxiconn.pl file...\n) ; perl_parse(my_perl, xs_init, argc, my_argv, NULL); printf (Loaded Perl file.\n) ; perl_destruct(my_perl); perl_free(my_perl); } Any suggestions?
Undefined symbol boot_DynaLoader, boot_Socket
Hi, I am trying to call Perl from C. I hit a problem when I try to load dynamic librarires. I have taken the following code from the PerlEmbed documentation (http://www.perldoc.com/perl5.8.4/pod/perlembed.html) but cannot get it to compile. This seems to be widely used stuff, so it sholdnt be this hard to get it to work!! Here are the contents of my c file: -- #include EXTERN.h #include perl.h static void xs_init (pTHX); EXTERN_C void boot_DynaLoader (pTHX_ CV* cv); EXTERN_C void boot_Socket (pTHX_ CV* cv); EXTERN_C void xs_init(pTHX) { char *file = __FILE__; dXSUB_SYS; /* I have also added this line as I have seen it in many examples. I dont know what it does but it doesnt affect the error message */ /* DynaLoader is a special case */ newXS(DynaLoader::boot_DynaLoader, boot_DynaLoader, file); newXS(Socket::bootstrap, boot_Socket, file); } static PerlInterpreter *my_perl; int main(int argc, char **argv, char **env) { char *my_argv[] = { , sxiconn.pl }; my_perl = perl_alloc(); perl_construct(my_perl); printf (Loading Perl sxiconn.pl file...\n) ; perl_parse(my_perl, xs_init, argc, my_argv, NULL); printf (Loaded Perl file.\n) ; perl_destruct(my_perl); perl_free(my_perl); } I compile with: -- gcc -O2 -R /usr/local/lib/perl5/5.8.4/sun4-solaris/CORE -L/usr/local/lib -I/usr/local/lib/perl5/5.8.4/sun4-solaris/CORE -L/usr/local/lib/perl5/5.8.4/sun4-solaris/CORE /usr/local/lib/perl5/5.8.4/sun4-solaris/auto/DynaLoader/DynaLoader.a -I/usr/local/include -o temp temp.c -lperl -lsocket -lnsl -ldl -lm -lc gccoutput 21 The error message is as follows: -- Undefined first referenced symbol in file boot_DynaLoader /var/tmp//ccbgVfzA.o boot_Socket /var/tmp//ccbgVfzA.o ld: fatal: Symbol referencing errors. No output written to temp collect2: ld returned 1 exit status Any suggestions would be greatly appreciated! Many thanks, Paul mailto:[EMAIL PROTECTED]
Re: Calling Perl from C - Problem with DynaLoader
In article [EMAIL PROTECTED], [EMAIL PROTECTED] (Paul Boyce) writes: I am trying to call Perl from C. I hit a problem when I try to load dynamic librarires. This is not a beginner level question. You'll find more experts who have the knowledge to answer it over on comp.lang.perl.misc. At least, there are many such people posting there who I have never seen posting here. -- Peter Scott http://www.perldebugged.com/ *** NEW *** http://www.perlmedic.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
speed up string matching
Hi! I need to match an expression and its reverse to a very long string. When a match occurs all matching should stop and the position of the match should be returned. Question1: can I match the forward and reverse expression to the string on the same time and thereby save half the time it normally would take to find a match or does the matching just get slower? Question2: is the fork function what I should use in order to match a string with multiple expressions simultaneously? Thanks to all helpers!
Image::Magick problem
Hi there, I hope someone is using Image::Magick here. I just installed it (win xp, active Perl...), I'm trying to anotate some text, here is my example script: use Image::Magick; my $colour1 = (ff); my $colour2 = (ff); my $text = (Hello World); my $image=Image::Magick-new; $image-Set(size='30x180'); $image-Read(gradient:#$colour1-#$colour2); $image-Raise('3x3'); $image-Rotate(-90); $image-Annotate(text=$text,font='@c:/windows/fonts/arial.ttf',pen='black', gravity='Center',pointsize=18); $image-Write('1.png'); undef($image); 1.png is written, gradient is good, but no text there! When I turned on warnings, no wanrnings displayed. Also I tried in cmd: montage -geometry +0+0 -background skyblue -label Faerie Dragon 1.png 2.png but again, no text is rendered into destination. I don't know where is problem, maybe my instalation is bad ? Could someone try these examples ? I am using ImageMagick-6.0.8-Q16 Thanks a lot P.S.: I have also Ghost Script installed, it is needed for this purpose ? (render text into image) /Brano -=x=- Skontrolované antivírovým programom NOD32 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: speed up string matching
C R wrote: I need to match an expression and its reverse to a very long string. When a match occurs all matching should stop and the position of the match should be returned. Question1: can I match the forward and reverse expression to the string on the same time and You can make use of alternation (the '|' character). thereby save half the time it normally would take to find a match or does the matching just get slower? Intuitively I'd guess it's faster, but to know you need to do a benchmark. Question2: is the fork function what I should use in order to match a string with multiple expressions simultaneously? Aha, did you mean at the same time in that sense? Maybe, if the string is really, really log. You may e.g. want to check out the module Parallel::ForkManager. -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: starting position of RE match
On Wednesday, Sep 22, 2004, at 08:05 US/Central, Jenda Krynicky wrote: Which means it's actually much easier than I had you believe: $s = sasas dfgfgh asasas asedsase; while ($s =~ /(?=sas)/g) { print pos=,pos($s), = ',substr($s,pos($s),3),'\n; } Based on your example, I was able to transform this: $ perl -e '$foo=bb; $re=aa ; for ($bar=index($foo, $re); $bar = 0 ; $bar=index($foo, $re, $bar+1)) { print $bar, \t } print \n ; ' into this: $ perl -e '$foo=bb; $re=qr/(?=aa)/ ; while($foo =~ /$re/g) { print pos($foo), \t } print \n ; ' Works exactly as I had hoped, and I understand this one. Will study your other examples with \G. I still don't understand those. Will probably just take a little time and experimenting. Thanks for your help. Regards, - Robert OpenSource for Windows, Linux, and Mac OS/X http://www.cwelug.org/downloads -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Optimize Problem
Dear All I am using this script to get my maillog information ## %IP_LOG=(); open (LOG,/var/log/maillog); foreach (LOG) { if (/Sep 20/) { $IP_LOG{$_}++; } } ## I found this script will take 3-4 second when my log file in 40MB But I try using gerp Sep 20 /var/log/maillog in bash shell, it take 0.8 sec only. Did any one know how to optimize the script to have better performance. Thanks all -- - Are you still wasting your time with spam?... There is a solution! Protected by GIANT Company's Spam Inspector The most powerful anti-spam software available. http://mail.spaminspector.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: speed up string matching
Hi, c r [EMAIL PROTECTED] asked: I need to match an expression and its reverse to a very long string. When a match occurs all matching should stop and the position of the match should be returned. Could you please illustrate this with an example or two? Unless you specify the /g modifier, the RE engine stops at the first match. Use the pos function to find the position of the match. Question1: can I match the forward and reverse expression to the string on the same time and thereby save half the time it normally would take to find a match or does the matching just get slower? Well, you'd have to merge your expressions somehow - the easiest way would be to try and match /expr-a|expr-b/ but then I suspect that for all but simple cases two separate matches would be faster. Question2: is the fork function what I should use in order to match a string with multiple expressions simultaneously? Well, there is a certain overhead involved in keeping your processes synchronized that would only be outweighed if you had a multi CPU machine where both processes could run at once in the first place. Even then it's a hassle. If I were you I'd focus my energy in optimizing the expression. If you're going to match many long strings with the same RE, you could use the /o modifier to benefit. Also, you could try wether a study() of the input strings speeds things up. HTH, Thomas -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Daemon that starts other Daemons
Hi perl-people, I'm not sure if this is beginners stuff, but I'll post here 'cause it's the only list I'm subscribed to at the moment. I'm writing a script that will daemonize itself, and then watch some processes. If one of those processes die, it will start it again. So, I've been reading the perlipc docs and I found this handy code on proper daemonization: use POSIX 'setsid'; sub daemonize { #it's polite for daemons to chdir to root so that they #don't prevent a filesystem from being unmounted chdir '/' or die Can't chdir to /: $!; #it's also polite for daemons to redirect all output to #/dev/null so users don't get random output open STDIN, '/dev/null' or die Can't read /dev/null: $!; open STDOUT, '/dev/null' or die Can't write to /dev/null:$!; #the parent get's the new child's pid back, the child gets '0' back defined( my $pid = fork ) or die Can't fork: $!; #here's where I start having problem. This code assumes that #the parent will be exiting, thus leaving the child able #to run setsid exit if $pid; setsid or die Can't start a new session: $!; open STDERR, 'STDOUT' or die Can't dup STDOUT: $!; } perlipc goes on to explain: The fork() has to come before the setsid() to ensure that you aren't a process leader (the setsid() will fail if you are). So, my question is, how do I implement this code WITHOUT the parent process dieing? --Errin -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Daemon that starts other Daemons
On Thu, 23 Sep 2004 11:23:16 -0500, Errin Larsen [EMAIL PROTECTED] wrote: Hi perl-people, SNIP So, my question is, how do I implement this code WITHOUT the parent process dieing? --Errin I found that (at least on the Solaris OS that I'm working on) that the setsid function will setup a new session UNLESS: The calling process is already a process group leader, or the process group ID of a process other than the calling process matches the process ID of the calling process. So, I think that's saying that as long as the process (the child) does not have any children of it's own, then I'll be ok with the above code! Is that what the blurb above is saying? (Why are UNIX docs always so darn hard to read!!?) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Optimize Problem
Millhost said: Dear All I am using this script to get my maillog information ## %IP_LOG=(); open (LOG,/var/log/maillog); foreach (LOG) { if (/Sep 20/) { $IP_LOG{$_}++; } } ## I found this script will take 3-4 second when my log file in 40MB But I try using gerp Sep 20 /var/log/maillog in bash shell, it take 0.8 sec only. Did any one know how to optimize the script to have better performance. Like this from Learning Perl: #!/usr/bin/perl -w use strict; while () { chomp; if (/Sep 20/) { print Matched: |$`$$'|\n; # Mystery code! See the text. } else { print No match.\n; } } Thanks all -- - Are you still wasting your time with spam?... There is a solution! Protected by GIANT Company's Spam Inspector The most powerful anti-spam software available. http://mail.spaminspector.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Optimize Problem
Millhost said: Dear All I am using this script to get my maillog information ## %IP_LOG=(); open (LOG,/var/log/maillog); foreach (LOG) { if (/Sep 20/) { $IP_LOG{$_}++; } } ## I found this script will take 3-4 second when my log file in 40MB But I try using gerp Sep 20 /var/log/maillog in bash shell, it take 0.8 sec only. Try using while(), so it processes it straight away. I think I am correct in saying, foreach reads in the whole file first? Did any one know how to optimize the script to have better performance. Thanks all -- - Are you still wasting your time with spam?... There is a solution! Protected by GIANT Company's Spam Inspector The most powerful anti-spam software available. http://mail.spaminspector.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
XMLin() not finding XML::SAX or XML::Parser modules Problem
Hi, XMLin() requires either XML::SAX or XML::Parser at line number blah blah. I actually copied these two perl modules in the right place but still then my script is not able to find these.(in @INC). I'm trying to call this XMLin() function from another perl module. Am i missing anything here? Any pointers? Thanks a ton -Ajey -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: XMLin() not finding XML::SAX or XML::Parser modules Problem
On Thu, 23 Sep 2004, Ajey Kulkarni wrote: XMLin() requires either XML::SAX or XML::Parser at line number blah blah. I actually copied these two perl modules in the right place but still then my script is not able to find these.(in @INC). What is XMLin() ? Ahh, I see, it's a method provided by XML::Simple: http://www.perldoc.com/perl5.6.1/lib/XML/Simple.html#XMLin() Ok, so, how did you get XML::Simple installed without one or the other of the two required modules? Did you manually copy, or `force install`? It sounds like all three modules may be out of whack. The easiest approach is to install them all with the CPAN shell. $ sudo perl -MCPAN -e shell If you haven't run this before, you will spend the next five minutes or so answering questions about your environment. In most cases, you can just hit enter to accept the defaults that are suggested to you. Once setup is complete, the shell launches with a cpan prompt. You need to install one of the prerequisites, then XML::Simple : cpan install XML::Parser cpan install XML::Simple Once these complete, programs using XML::Simple methods such as XMLin() should begin to work normally. -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Daemon that starts other Daemons
Hi perl-people, I'm not sure if this is beginners stuff, but I'll post here 'cause it's the only list I'm subscribed to at the moment. A stretch, but there have been more complex topics discussed. This is pretty much a catch all and some of the experts will probably appreciate not answering the same how do I delete an element of an array question :-). I'm writing a script that will daemonize itself, and then watch some processes. If one of those processes die, it will start it again. So, I've been reading the perlipc docs and I found this handy code on proper daemonization: Great docs... however... use POSIX 'setsid'; sub daemonize { #it's polite for daemons to chdir to root so that they #don't prevent a filesystem from being unmounted chdir '/' or die Can't chdir to /: $!; #it's also polite for daemons to redirect all output to #/dev/null so users don't get random output open STDIN, '/dev/null' or die Can't read /dev/null: $!; open STDOUT, '/dev/null' or die Can't write to /dev/null:$!; #the parent get's the new child's pid back, the child gets '0' back defined( my $pid = fork ) or die Can't fork: $!; #here's where I start having problem. This code assumes that #the parent will be exiting, thus leaving the child able #to run setsid exit if $pid; setsid or die Can't start a new session: $!; open STDERR, 'STDOUT' or die Can't dup STDOUT: $!; } perlipc goes on to explain: The fork() has to come before the setsid() to ensure that you aren't a process leader (the setsid() will fail if you are). So, my question is, how do I implement this code WITHOUT the parent process dieing? --Errin Actually you want the parent process to die... or at least exit, then your child process is the session leader and will do everything else you need, aka fork more children in your case. Essentially you want to make it so that the tty/shell (whatever) no longer thinks it has absentee children so that it can exit cleanly, by daemonizing your process essentially becomes a child of the kernel, which will always be running (until shutdown that is). However, the best advice NOT given by perldoc perlipc is to use the Proc::Daemon::Init module, it is incredibly easy and takes care of all of the code you mention above by itself, in a neat package that you don't have to worry about the internals of. It is available through CPAN as usual, and despite its incredibly low release number (if you are into that hole thing) I have never had problems with it. Two additional comments, that you are likely to stumble across: 1. How do I get back to my process after it has daemonized, how do I stop it, etc? This is where you will likely want to get into writing a pid file to the disk so that your process can be looked up and signaled, and/or to prevent two copies of your daemon running, or at least trying to work on teh same resources. 2. How do I do logging, etc.? Check out the very, very excellent Log::Log4perl suite, it is incredible and can accomplish just about all of your logging needs. Of course I have already mentioned POE but I will plug it again. http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Daemon that starts other Daemons
On Thu, 23 Sep 2004 11:23:16 -0500, Errin Larsen [EMAIL PROTECTED] wrote: Hi perl-people, SNIP So, my question is, how do I implement this code WITHOUT the parent process dieing? --Errin I found that (at least on the Solaris OS that I'm working on) that the setsid function will setup a new session UNLESS: The calling process is already a process group leader, or the process group ID of a process other than the calling process matches the process ID of the calling process. So, I think that's saying that as long as the process (the child) does not have any children of it's own, then I'll be ok with the above code! Is that what the blurb above is saying? (Why are UNIX docs always so darn hard to read!!?) That is the way I read it, though see the suggestion in my other post... http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
How to slice a split directly?
This works and does what I want it to: perl -e '@x = split(\\., a.b.c); print $x[0];' Why does not this work? perl -e 'print @{split(\\., a.b.c)}[0];' Is there a compact way to take a slice of a split (or other function that returns an array) without creating a temporary variable? Thanks, Siegfried -- 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 slice a split directly?
On Thu, 23 Sep 2004 13:43:08 -0600, Siegfried Heintze [EMAIL PROTECTED] wrote: This works and does what I want it to: perl -e '@x = split(\\., a.b.c); print $x[0];' Why does not this work? perl -e 'print @{split(\\., a.b.c)}[0];' Because split doesn't return an array reference, it returns a list. print( (split(/\./, a.b.c))[0] ); Is there a compact way to take a slice of a split (or other function that returns an array) without creating a temporary variable? Thanks, Siegfried -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- -will http://www.wgunther.tk (the above message is double rot13 encoded for security reasons) Most Useful Perl Modules -strict -warnings -Devel::DProf -Benchmark -B::Deparse -Data::Dumper -Clone -Perl::Tidy -Beautifier -DBD::SQLite -- 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 slice a split directly?
From: Siegfried Heintze [EMAIL PROTECTED] This works and does what I want it to: perl -e '@x = split(\\., a.b.c); print $x[0];' Why does not this work? perl -e 'print @{split(\\., a.b.c)}[0];' Is there a compact way to take a slice of a split (or other function that returns an array) without creating a temporary variable? perl -e 'print ((split(\\., a.b.c))[0]);' It's a bit tricky. The outermost braces belong to print(), the next ones enclose the call to split() so that it can be sliced and the innermost enclose the parameters for split(). Only the innermost may be left out. This makes the slicing of function result a bit clearer I think: ($hour, $minute, $sec) = (localtime())[2,1,0]; Jenda = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Calling Perl From Java?
I did a google search on calling Perl from Java. I found one site (http://ebb.org/perljvm/) that suggested the most promising project tackling this problem had been abandoned. The traditional approach is apparently very cumbersome: Have Java call C and C all Perl. This sounds very tedious. Does this sum up the situation? Thanks, Siegfried -- 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 slice a split directly?
This works and does what I want it to: perl -e '@x = split(\\., a.b.c); print $x[0];' Why does not this work? perl -e 'print @{split(\\., a.b.c)}[0];' Is there a compact way to take a slice of a split (or other function that returns an array) without creating a temporary variable? Thanks, Siegfried Sometimes when working out this kind of detail it is helpful to make a full script and activate strict/warnings. In the above case you get the following, perl -Mstrict -w -e 'print @{split(\\., a.b.c)}[0];' Use of implicit split to @_ is deprecated at -e line 1. Can't use string (3) as an ARRAY ref while strict refs in use at -e line 1. Essentially Csplit returns a list, the construct C@{ } is a way to slice into a hash, which you don't have. So you need to slice into a list, which in this case is done like, perl -Mstrict -w -e 'print ((split(\\., a.b.c))[0]);' Notice the extra set of parens, otherwise you get a syntax error because Cprint would otherwise use the first set as an argument list. HTH, http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: speed up string matching
c r [EMAIL PROTECTED] wrote:Thanks for replying! Are you certain that using the module makes the simultaneous matching faster than a sequential and to what degree (roughly)? Gunnar Hjalmarsson [EMAIL PROTECTED] wrote: C R wrote: I need to match an expression and its reverse to a very long string. When a match occurs all matching should stop and the position of the match should be returned. Question1: can I match the forward and reverse expression to the string on the same time and You can make use of alternation (the '|' character). thereby save half the time it normally would take to find a match or does the matching just get slower? Intuitively I'd guess it's faster, but to know you need to do a benchmark. Question2: is the fork function what I should use in order to match a string with multiple expressions simultaneously? Aha, did you mean at the same time in that sense? Maybe, if the string is really, really log. You may e.g. want to check out the module Parallel::ForkManager. -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Daemon that starts other Daemons
-- Forwarded message -- From: Errin Larsen [EMAIL PROTECTED] Date: Thu, 23 Sep 2004 16:30:21 -0500 Subject: Re: Daemon that starts other Daemons To: Wiggins d Anconia [EMAIL PROTECTED] Hi again, Ok ... so with some research and playi^H^H^H^H^Htesting I've found the answer to what's really been bothering me. If I fork(), I get the PID of the resulting child. However, if THAT child runs and external command, how do I get the (now grand)child's PID. The answer I was looking for was a deeper understanding of exec(). by fork()ing a child and having that child run exec(), the exec()ed command will have the SAME process ID as the original child. In actuality, the exec()ed command is NOT a grandchild, but has taken over the original child's process and all it's environment (STDIN, STDOUT, %ENV, etc.). That's what I needed to know! Now, if I just collect and keep the child's PID, when I run the exec() I'll have the PID of whatever command was exec()ed. Also, with some experimenting, the setsid() doesn't NEED the original parent to die to work, it just needs the child to be forked before it runs setsid(). In other words, if you try to run setsid() BEFORE you fork the child (in an attempt to give both the child and the parent the same session and group ID, perhaps) it will fail. If you instead have the child run setsid() after it is fork()ed, it will run fine, whether the parent is dead or not! YAY!! On Thu, 23 Sep 2004 13:30:08 -0600, Wiggins d Anconia [EMAIL PROTECTED] wrote: On Thu, 23 Sep 2004 11:23:16 -0500, Errin Larsen [EMAIL PROTECTED] wrote: Hi perl-people, SNIP So, my question is, how do I implement this code WITHOUT the parent process dieing? --Errin SNIP Thanks for the help, Wiggins. I agree this would all be easier if I just went a grabbed a module, but for (probably strange) reasons I'd rather not go into, I want to do this from scratch. Also, this has been extremely helpful in teaching me what's going on with the backticks, system(), fork() and exec() functions. This process has really helped me along with my Perl education. Also, I realized that the ORIGINAL parent needs to die (So as to disassociate the daemons from the calling terminal/process), but I was looking for a daemon that would run, start other servers, and that hang around monitoring them. I think we're talking about the same thing here, just I didn't explain it will originally. Now, I just need to implement some code to dump a file with PIDs into /var/run! Thanks for the suggestions/help and I'll get working on it now! --Errin -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Daemon that starts other Daemons
Hi again, Ok ... so with some research and playi^H^H^H^H^Htesting I've found the answer to what's really been bothering me. If I fork(), I get the PID of the resulting child. However, if THAT child runs and external command, how do I get the (now grand)child's PID. The answer I was looking for was a deeper understanding of exec(). Yep. Playing is the best way to go. by fork()ing a child and having that child run exec(), the exec()ed command will have the SAME process ID as the original child. In actuality, the exec()ed command is NOT a grandchild, but has taken over the original child's process and all it's environment (STDIN, STDOUT, %ENV, etc.). That's what I needed to know! Now, if I just collect and keep the child's PID, when I run the exec() I'll have the PID of whatever command was exec()ed. Correct. Also, with some experimenting, the setsid() doesn't NEED the original parent to die to work, it just needs the child to be forked before it runs setsid(). In other words, if you try to run setsid() BEFORE you fork the child (in an attempt to give both the child and the parent the same session and group ID, perhaps) it will fail. If you instead have the child run setsid() after it is fork()ed, it will run fine, whether the parent is dead or not! YAY!! Yep again, making the child a session leader doesn't mean that the parent must go away, more that if it wants to it can. Which is a subtle but important distinction. On Thu, 23 Sep 2004 13:30:08 -0600, Wiggins d Anconia [EMAIL PROTECTED] wrote: On Thu, 23 Sep 2004 11:23:16 -0500, Errin Larsen [EMAIL PROTECTED] wrote: Hi perl-people, SNIP So, my question is, how do I implement this code WITHOUT the parent process dieing? --Errin SNIP Thanks for the help, Wiggins. I agree this would all be easier if I just went a grabbed a module, but for (probably strange) reasons I'd rather not go into, I want to do this from scratch. Also, this has been extremely helpful in teaching me what's going on with the backticks, system(), fork() and exec() functions. This process has really helped me along with my Perl education. Definitely. You are essentially taking the same path through the madness that I did 2 years ago or so, first attempting to understand the reasons and lowlevels, reading lots of docs and making lots of mistakes. Once I figured it out I was very glad because of the amount I learned, but then opted for the module mostly to prevent code maintenance, hassles, etc. We already had roughly 40 other dependencies, and considering it was probably the easiest to install I wasn't concerned about Just Another Module (hmph, JAM, that works pretty well in the glue analogy ;-)). Also, I realized that the ORIGINAL parent needs to die (So as to disassociate the daemons from the calling terminal/process), but I was looking for a daemon that would run, start other servers, and that hang around monitoring them. I think we're talking about the same thing here, just I didn't explain it will originally. Now, I just need to implement some code to dump a file with PIDs into /var/run! Thanks for the suggestions/help and I'll get working on it now! Agreed and yep. --Errin http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Daemon that starts other Daemons
On Thu, 23 Sep 2004, Errin Larsen wrote: [] I was looking for a daemon that would run, start other servers, and that hang around monitoring them. In other words, you want something that works like Apache [1.x]. * To launch Apache, you run apachectl, a shell script. * apachectl launches a parent httpd process, which in turns spawns a pool of listener httpd child processes. * apachectl goes away then, and the parent httpd supervises the operation of the server from then on. Granted, the interesting bits are all done in C or something, so that may not help you here, but it's the model you're looking for. -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: speed up string matching
c r [EMAIL PROTECTED] wrote:Thanks for replying! Thomas Bätzler [EMAIL PROTECTED] wrote: Hi, c r asked: I need to match an expression and its reverse to a very long string. When a match occurs all matching should stop and the position of the match should be returned. Could you please illustrate this with an example or two? Don't mind the lack of position return. I have: $expres = '10_normal_characters'; $rev_expres = reverse $expres; $long_string = 'ARGBB...'; if ($long_string =~ /$expres/i) { next;} if ($long_string =~ /$rev_expres/i) {next;} (the next function takes a different $expres reverses it and does the matching procedure again. This is repeted many thounsands of times and it takes days to finish). Unless you specify the /g modifier, the RE engine stops at the first match. Use the pos function to find the position of the match. Question1: can I match the forward and reverse expression to the string on the same time and thereby save half the time it normally would take to find a match or does the matching just get slower? Well, you'd have to merge your expressions somehow - the easiest way would be to try and match /expr-a|expr-b/ but then I suspect that for all but simple cases two separate matches would be faster. Question2: is the fork function what I should use in order to match a string with multiple expressions simultaneously? Well, there is a certain overhead involved in keeping your processes synchronized that would only be outweighed if you had a multi CPU machine where both processes could run at once in the first place. Even then it's a hassle. So in order to match a very long string with multiple expressions simultaneously and faster than the matching procedure I have described above I need multiple computers? If I were you I'd focus my energy in optimizing the expression. If you're going to match many long strings with the same RE, you could use the /o modifier to benefit. Also, you could try wether a study() of the input strings speeds things up. I don't know the study function, but I doubt it can solve the problem to satisfatory. please correct me if I am wrong! I acknowledge that this is a serious programming challenge. Do you have any other ideas of how to tackle this problem (what about other hardware)? HTH, Thomas
Re: Daemon that starts other Daemons
On Thu, 23 Sep 2004, Errin Larsen wrote: [] I was looking for a daemon that would run, start other servers, and that hang around monitoring them. In other words, you want something that works like Apache [1.x]. * To launch Apache, you run apachectl, a shell script. * apachectl launches a parent httpd process, which in turns spawns a pool of listener httpd child processes. * apachectl goes away then, and the parent httpd supervises the operation of the server from then on. Granted, the interesting bits are all done in C or something, so that may not help you here, but it's the model you're looking for. -- Chris Devers If you really want to get into it, Network Programming with Perl has excellent coverage of various common types of daemons and how to write them in Perl. Don't know if you have the resources or time but it is worth a look if the interest is there. My very unprofessional and non-expert review of it is here: http://danconia.org/cgi-bin/request?handler=Content;content=Site_Bookshelf_Book;id=26 http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: speed up string matching
[ Please 'bottom-post', i.e. type your reply below the quoted part of the message you are replying to. Also, don't quote the whole message, but only the part(s) needed for context. ] C R wrote: Gunnar Hjalmarsson wrote: C R wrote: Question2: is the fork function what I should use in order to match a string with multiple expressions simultaneously? Maybe, if the string is really, really log. You may e.g. want to check out the module Parallel::ForkManager. Are you certain that using the module makes the simultaneous matching faster than a sequential and to what degree (roughly)? Certain? Certainly not. :) It depends, among other things, on your systems ability to run parallel processes and on the size of the string you want to parse. -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- 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 slice a split directly?
From: Wiggins d Anconia [EMAIL PROTECTED] This works and does what I want it to: perl -e '@x = split(\\., a.b.c); print $x[0];' Why does not this work? perl -e 'print @{split(\\., a.b.c)}[0];' Is there a compact way to take a slice of a split (or other function that returns an array) without creating a temporary variable? Thanks, Siegfried Sometimes when working out this kind of detail it is helpful to make a full script and activate strict/warnings. In the above case you get the following, perl -Mstrict -w -e 'print @{split(\\., a.b.c)}[0];' Use of implicit split to @_ is deprecated at -e line 1. Can't use string (3) as an ARRAY ref while strict refs in use at -e line 1. Essentially Csplit returns a list, the construct C@{ } is a way to slice into a hash, which you don't have. There'd have to be a name of a variable between the @ and the opening curly brace for that to be a hash slice. This way its an array dereference: @arr = (1,2,3); $rArr = [EMAIL PROTECTED]; @other = @{$rArr}; Of course in this case you do not need the braces. You'd use the @{} if the thing you need to dereference is more complex, for example if you need to dereference a function result. So print join(', ', @{function('returning', 'arrayref')}); would be correct, just like print join(', ', @{function('returning', 'arrayref')}[1,2,4,7]); If you'd want just one item from the referenced array you would of course use ${}[] instead: print ${function('returning', 'arrayref')}[2]; In this case the function doesn't return a reference, but a list so there is no point in trying to dereference anything :-) This is where the Can't use string (3) as an ARRAY ref while strict refs in use at -e line 1. message comes from. The split() is evaluated in scalar context and thus returns the number of elements found in the string. And then the code tries to do this: perl -e 'print @{3}[0];' Jenda = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: speed up string matching
Gunnar Hjalmarsson [EMAIL PROTECTED] wrote: Gunnar Hjalmarsson wrote: C R wrote: Question2: is the fork function what I should use in order to match a string with multiple expressions simultaneously? Maybe, if the string is really, really log. You may e.g. want to check out the module Parallel::ForkManager. Are you certain that using the module makes the simultaneous matching faster than a sequential and to what degree (roughly)? Certain? Certainly not. :) It depends, among other things, on your systems ability to run parallel processes and on the size of the string you want to parse. I have an average personal computer. At the moment the size of the string can get up to about 600.000 characters, but in the future it will get much larger than 100 MB. -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: XMLin() not finding XML::SAX or XML::Parser modules Problem
Please send all replies to the list, not me directly. Thanks. On Thu, 23 Sep 2004, Ajey Kulkarni wrote: Thanks a bunch Chris. I FORCED the pms to be copied. I'll try to install this and get it running. It usually isn't a good idea to force an install unless you understand what the error you're getting means and are confident that in a given case it can be safely ignored. In this case, the README file is clear that you need to have one of the two modules you noted in order for things to work. If you skip that step, then, well, things won't work. On the bright side, you probably don't have to reinstall XML::Simple; once the support module[s] is/are in place, XMLin(...) should work. Or at least that's what it seems like will happen... -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: speed up string matching
C R wrote: Gunnar Hjalmarsson wrote: C R wrote: Are you certain that using the module makes the simultaneous matching faster than a sequential and to what degree (roughly)? Certain? Certainly not. :) It depends, among other things, on your systems ability to run parallel processes and on the size of the string you want to parse. I have an average personal computer. At the moment the size of the string can get up to about 600.000 characters, but in the future it will get much larger than 100 MB. I still can't tell. Maybe somebody else is able to give you guidance, but why don't you simply try it if you want to explore that option? -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
import from text file to mysql
how to import text file to mysql using PERL ?. This e-mail and any attachments may contain confidential and privileged information. If you are not the intended recipient, please notify the sender immediately by return e-mail, delete this e-mail and destroy any copies. Any dissemination or use of this information by a person other than the intended recipient is unauthorized and may be illegal. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: import from text file to mysql
On Fri, 24 Sep 2004, Roime bin Puniran wrote: how to import text file to mysql using Perl ?. What is in the text file? We can't begin to help you without knowing what the file contains. Ignoring Perl for a minute, have you considered using the MySQL command line tool `mysqlimport` ? It has lots of options and may be easier to use than Perl, at least in this case. Maybe. Documentation for it can be found at http://dev.mysql.com/doc/mysql/en/mysqlimport.html, among other places. -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: import from text file to mysql
i have several packet that captured from monitoring process...Then we save it in txt format...And now, i need to import it into mysql, by that way i can make a report esily...How i can import it using PERL ?... Thanks -Original Message- From: Chris Devers [mailto:[EMAIL PROTECTED] Sent: Fri 9/24/2004 10:39 AM To: Roime bin Puniran Cc: Perl Beginners List Subject:Re: import from text file to mysql On Fri, 24 Sep 2004, Roime bin Puniran wrote: how to import text file to mysql using Perl ?. What is in the text file? We can't begin to help you without knowing what the file contains. Ignoring Perl for a minute, have you considered using the MySQL command line tool `mysqlimport` ? It has lots of options and may be easier to use than Perl, at least in this case. Maybe. Documentation for it can be found at http://dev.mysql.com/doc/mysql/en/mysqlimport.html, among other places. -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response This e-mail and any attachments may contain confidential and privileged information. If you are not the intended recipient, please notify the sender immediately by return e-mail, delete this e-mail and destroy any copies. Any dissemination or use of this information by a person other than the intended recipient is unauthorized and may be illegal. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: import from text file to mysql
* Please don't top-quote. * Perl is a language, perl is a program, PERL isn't a word. On Fri, 24 Sep 2004, Roime bin Puniran wrote: i have several packet that captured from monitoring process...Then we save it in txt format...And now, i need to import it into mysql, by that way i can make a report esily...How i can import it using PERL ?... I still have no idea what your file looks like. I have a vague idea what data the file contains, but that's really not the important thing. Is the text a comma-separated format? Is it XML? Some kind of freeform log file like the Unix syslog or Apache's log? tcpdump output? You have to give a small but representative sample of what the data in the file looks like. Also, you have to show what you have tried so far. Have you written code to open the file, make sense of the data, and insert it in the database? Or were you just hoping that we would do all of that for you? You need to at least make an attempt to solve the problem -- it's okay if you get stuck, but there has to be some code to start with. -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
LM an NT hashes
I wonder if someone has perl functions to make LM and NT hashes that samba uses. Best regards, LD -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: import from text file to mysql
I am sorry that not showing u a detail at least, about my text file...Here is te sample of my text file... === 1.200.200.202.157 2.200.200.250.7 3.0 4.255 5.8 6.1109 7.0 8.0 9.1095648052.771 10.1095648052.979 11.1417 12.445 13.27 14.6 15.0 16.0 17.0 18.0 19. 20.0 21.0 22.0 23.11900024.0 25.0 26.0 27.32 1.200.200.202.157 2.200.200.250.7 3.0 4.255 5.2 6.92 7.0 8.0 9.1095648052.770 10.1095648052.771 11.1413 12.445 13.17 14.6 15.0 16.0 17.0 18.0 19. 20.0 21.0 22.0 23.024.0 25.0 26.0 27.0 1.200.200.245.239 2.200.200.255.255 3.0 4.255 5.6 6.468 7.0 8.0 9.1095648052.402 10.1095648052.847 11.137 12.137 13.0 14.17 15.0 16.0 17.0 18.0 19. 20.0 21.0 22.0 23.024.0 25.0 26.0 27.32 1.200.200.101.1 2.200.200.255.255 3.0 4.255 5.1 6.243 7.0 8.0 9.1095648061.059 10.1095648061.059 11.138 12.138 13.0 14.17 15.0 16.0 17.0 18.0 19. 20.0 21.0 22.0 23.024.0 25.0 26.0 27.32 1.200.200.100.97 2.200.200.255.255 3.0 4.255 5.3 6.234 7.0 8.0 9.1095648053.622 10.1095648055.122 11.137 12.137 13.0 14.17 15.0 16.0 17.0 18.0 19. 20.0 21.0 22.0 23.024.0 25.0 26.0 27.32 == But there is no problem about the data i think..And sorry because i am not customize it first...:)The big matter is how can i import a text file into mysql...I just wrote some code ...Here is my code... #!/usr/bin/perl use DBI; use IO::Socket; ### #import.pl #Roime Bin Puniran #Telekom RnD ### $local = IO::Socket::INET-new( Proto = 'tcp', LocalAddr = '***', Reuse = 1 ) or die $!; $local-listen(); $local-autoflush(1); print ..Testing...\n; #my $addr; while($addr=$local-accept()) { printConnect From : , $addr-peerhost(); #Display Message print Port : , $addr-peerport(), \n; my $dbh=DBI-connect('dbi:mysql:test', 'root','')|| die Error opening database: $DBI::errstr\n; print I think it's connect !.; my $sth=$dbh-prepare( LOAD DATA LOCAL INFILE /home/roime/MYSQL_PERL/IN_NETWORK/packet.txt INTO TABLE flow FIELDS TERMINATED BY ',' ); $sth-execute(); $set-finish(); $dbh-disconnect || die Failed to connect..; $dbh-disconnect || die Error opening database: $DBI::errstr\n; my $result; while($addr) { last if m/^end/gi; print Received : $_; print $addr $_; $result += $_; } chomp; if(m/^end/gi) { my $send = result; print $addr $send\n; print Result: $send\n; } print Closed connection\n; close $addr; print At your serviceWaiting Please !!..\n; } == i just used this below method to import it into mysql, instead of mysqlimport... my $sth=$dbh-prepare( LOAD DATA LOCAL INFILE /home/roime/MYSQL_PERL/IN_NETWORK/packet.txt INTO TABLE flow FIELDS TERMINATED BY ',' ); But i receive this message when i compiled it.. String found where operator expected at import.pl line 34, near TERMINATED BY ',' (Might be a runaway multi-line string starting on line 33) (Missing semicolon on previous line?) syntax error at import.pl line 34, near TERMINATED BY ',' Execution of import.pl aborted due to compilation errors. Do you have any suggestion ?... This e-mail and any attachments may contain confidential and privileged information. If you are not the intended recipient, please notify the sender immediately by return e-mail, delete this e-mail and destroy any copies. Any dissemination or use of this information by a person other than the intended recipient is unauthorized and may be illegal. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: import from text file to mysql
my $sth=$dbh-prepare( LOAD DATA LOCAL INFILE /home/roime/MYSQL_PERL/IN_NETWORK/packet.txt INTO TABLE flow FIELDS TERMINATED BY ',' ); here you had forgot escape the double quotes,should be escaped quotes: \/home/roime/MYSQL_PERL/IN_NETWORK/packet.txt\ my $sth=$dbh-prepare( LOAD DATA LOCAL INFILE \/home/roime/MYSQL_PERL/IN_NETWORK/packet.txt\ INTO TABLE flow FIELDS TERMINATED BY ',' ); -Original Message- From: Roime bin Puniran [mailto:[EMAIL PROTECTED] Sent: Friday, September 24, 2004 8:57 AM To: Perl Beginners List Subject: RE: import from text file to mysql I am sorry that not showing u a detail at least, about my text file...Here is te sample of my text file... === 1.200.200.202.157 2.200.200.250.7 3.0 4.255 5.8 6.1109 7.0 8.0 9.1095648052.771 10.1095648052.979 11.1417 12.445 13.27 14.6 15.0 16.0 17.0 18.0 19. 20.0 21.0 22.0 23.11900024.0 25.0 26.0 27.32 1.200.200.202.157 2.200.200.250.7 3.0 4.255 5.2 6.92 7.0 8.0 9.1095648052.770 10.1095648052.771 11.1413 12.445 13.17 14.6 15.0 16.0 17.0 18.0 19. 20.0 21.0 22.0 23.024.0 25.0 26.0 27.0 1.200.200.245.239 2.200.200.255.255 3.0 4.255 5.6 6.468 7.0 8.0 9.1095648052.402 10.1095648052.847 11.137 12.137 13.0 14.17 15.0 16.0 17.0 18.0 19. 20.0 21.0 22.0 23.024.0 25.0 26.0 27.32 1.200.200.101.1 2.200.200.255.255 3.0 4.255 5.1 6.243 7.0 8.0 9.1095648061.059 10.1095648061.059 11.138 12.138 13.0 14.17 15.0 16.0 17.0 18.0 19. 20.0 21.0 22.0 23.024.0 25.0 26.0 27.32 1.200.200.100.97 2.200.200.255.255 3.0 4.255 5.3 6.234 7.0 8.0 9.1095648053.622 10.1095648055.122 11.137 12.137 13.0 14.17 15.0 16.0 17.0 18.0 19. 20.0 21.0 22.0 23.024.0 25.0 26.0 27.32 == But there is no problem about the data i think..And sorry because i am not customize it first...:)The big matter is how can i import a text file into mysql...I just wrote some code ...Here is my code... #!/usr/bin/perl use DBI; use IO::Socket; ### #import.pl #Roime Bin Puniran #Telekom RnD ### $local = IO::Socket::INET-new( Proto = 'tcp', LocalAddr = '***', Reuse = 1 ) or die $!; $local-listen(); $local-autoflush(1); print ..Testing...\n; #my $addr; while($addr=$local-accept()) { printConnect From : , $addr-peerhost(); #Display Message print Port : , $addr-peerport(), \n; my $dbh=DBI-connect('dbi:mysql:test', 'root','')|| die Error opening database: $DBI::errstr\n; print I think it's connect !.; my $sth=$dbh-prepare( LOAD DATA LOCAL INFILE /home/roime/MYSQL_PERL/IN_NETWORK/packet.txt INTO TABLE flow FIELDS TERMINATED BY ',' ); $sth-execute(); $set-finish(); $dbh-disconnect || die Failed to connect..; $dbh-disconnect || die Error opening database: $DBI::errstr\n; my $result; while($addr) { last if m/^end/gi; print Received : $_; print $addr $_; $result += $_; } chomp; if(m/^end/gi) { my $send = result; print $addr $send\n; print Result: $send\n; } print Closed connection\n; close $addr; print At your serviceWaiting Please !!..\n; } == i just used this below method to import it into mysql, instead of mysqlimport... my $sth=$dbh-prepare( LOAD DATA LOCAL INFILE /home/roime/MYSQL_PERL/IN_NETWORK/packet.txt INTO TABLE flow FIELDS TERMINATED BY ',' ); But i receive this message when i compiled it.. String found where operator expected at import.pl line 34, near TERMINATED BY ',' (Might be a runaway multi-line string starting on line 33) (Missing semicolon on previous line?) syntax error at import.pl line 34, near TERMINATED BY ',' Execution of import.pl aborted due to compilation errors. Do you have any suggestion ?... This e-mail and any attachments may contain confidential and privileged information. If you are not the intended recipient, please notify the sender immediately by return e-mail, delete this e-mail and destroy any copies. Any dissemination or use of this information by a person other than the intended recipient is unauthorized and may be illegal. -- To
regex help
Gidday all, Im trying to write a regex to convert spaces to underscores and ampersands to 'and' can someone help. $safeString = News Events; $safeString =~ s//and/g; $safeString =~ s/\s/_/g; Regards Colin This E-Mail is intended only for the addressee. Its use is limited to that intended by the author at the time and it is not to be distributed without the author's consent. Unless otherwise stated, the State of Queensland accepts no liability for the contents of this E-Mail except where subsequently confirmed in writing. The opinions expressed in this E-Mail are those of the author and do not necessarily represent the views of the State of Queensland. This E-Mail is confidential and may be subject to a claim of legal privilege. If you have received this E-Mail in error, please notify the author and delete this message immediately. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: regex help
I worked it out myself $safeString = News Events; $safeString =~ s!!and!g; $safeString =~ s!\s!_!g; thank you Colin -Original Message- From: Johnstone, Colin Sent: Friday, September 24, 2004 3:32 PM To: [EMAIL PROTECTED] Subject: regex help Gidday all, Im trying to write a regex to convert spaces to underscores and ampersands to 'and' can someone help. $safeString = News Events; $safeString =~ s//and/g; $safeString =~ s/\s/_/g; Regards Colin This E-Mail is intended only for the addressee. Its use is limited to that intended by the author at the time and it is not to be distributed without the author's consent. Unless otherwise stated, the State of Queensland accepts no liability for the contents of this E-Mail except where subsequently confirmed in writing. The opinions expressed in this E-Mail are those of the author and do not necessarily represent the views of the State of Queensland. This E-Mail is confidential and may be subject to a claim of legal privilege. If you have received this E-Mail in error, please notify the author and delete this message immediately. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: regex help
On Fri, 2004-09-24 at 11:01, Johnstone, Colin wrote: Gidday all, Im trying to write a regex to convert spaces to underscores and ampersands to 'and' can someone help. $safeString = News Events; $safeString =~ s//and/g; $safeString =~ s/\s/_/g; Regards Colin What you have written is perfectly fine .. why do you think it will not work ? you may consider however writing '\' instead of '' Bye Ram -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response