Re: Couple of newbie questions
On Tue, 16 Jul 2002 12:53:33 -0400, [EMAIL PROTECTED] (Kerr Wall) wrote: Hi All, What is the best way to test and debug? My vote is to use the ptkdb module. It is a graphical tk debugger for perl. It's beautiful, you can make break points, and list variable values; just watch the variables change as you step thru the script. It works remotely for cgi too. There are a bunch of tutorials on how to use it out there. Do a google search for ptkdb cgi tutorial. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
formate text sequence
hi, does anyone know a function or a module which i can use to format a text which i get in a string. i would like to get lines of 40 letters out of the string which are surrounded by p and /p; the result should be stored in an string. short example with 3-letter-lines: $input = 'ABCDEFGHI'; --- $output = 'pABC/ppDEF/ppGHI/p' cu konrad -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
HTML tags - module
Hi all, I want to get a web page and remove all the HTML tags from it, then save the visible text only. Like saving the file as text from Internet Explorer. Do you know a Perl module that can help me to find and remove all the HTML tags? I was thinking to use regular expressions, but I may forget a lot of things. Thank you. Teddy Center: http://teddy.fcc.ro/ Mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: formate text sequence
Konrad, Is this what your looking for? -- my $input = 'ABCDEFGHI'; my $output = $input; $output =~ s/(\w{3})/\p\$1\\/p\/g; print qq^\$input = $input\n^; print qq^\$output = $output\n^; -- To make it 40 characters instead of 3, simply change the 3 to a 40 in the {}'s Out put from this is -- $input = ABCDEFGHI $output = pABC/ppDEF/ppGHI/p -- Regards, David - Original Message - From: Konrad Foerstner [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, July 17, 2002 9:43 AM Subject: formate text sequence hi, does anyone know a function or a module which i can use to format a text which i get in a string. i would like to get lines of 40 letters out of the string which are surrounded by p and /p; the result should be stored in an string. short example with 3-letter-lines: $input = 'ABCDEFGHI'; --- $output = 'pABC/ppDEF/ppGHI/p' cu konrad -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: HTML tags - module
--- Octavian Rasnita [EMAIL PROTECTED] wrote: Hi all, I want to get a web page and remove all the HTML tags from it, then save the visible text only. Like saving the file as text from Internet Explorer. Do you know a Perl module that can help me to find and remove all the HTML tags? I was thinking to use regular expressions, but I may forget a lot of things. You can also use HTML::TokeParser::Simple for this: use HTML::TokeParser::Simple; my $p = HTML::TokeParser::Simple-new( $somefile ); my $token; # skip to the body do { $token = $p-get_token; } until ( $token-is_start_tag( 'body' ) ); while ( my $token = $p-get_token ) { next unless $token-is_text; # skip non-visible stuff print $token-return_text; } Cheers, Curtis Ovid Poe = Ovid on http://www.perlmonks.org/ Someone asked me how to count to 10 in Perl: push@A,$_ for reverse q.e...q.n.;for(@A){$_=unpack(q|c|,$_);@a=split//; shift@a;shift@a if $a[$[]eq$[;$_=join q||,@a};print $_,$/for reverse @A __ Do You Yahoo!? Yahoo! Autos - Get free new car price quotes http://autos.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
multi-page form and cgi.pm
I have been given the task of creating a multi-page form that will consist of 4 parts. The final page will the list out everything that the users have entered and ask if they would like to go back to any of the 4 sections to update the information. Once the users are satisfied with the final product, they will print it out. I know how to do this with multiple scripts and html forms and hidden fields. However, I would like to try to use one script with subroutines. I guess my main stumbling block is passing hidden form fields between subroutines. Can anyone offer me a simple example of how to go about passing a form field from one subroutine to another subroutine where it is a hidden field using cgi.pm? And/Or, can anyone point me in toward an applicable tutorial? Thanks in advance, Andrew -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: multi-page form and cgi.pm
First, you can use cookies, temp files. with multiple scripts and html forms and hidden fields. Do you mean that's a CGI script ? or Javascript ? However, I would like to try to use one script with subroutines. I guess my main stumbling block is passing hidden form fields between subroutines. What difference when a CGI script receive those data ? whatever textarea, raido, hidden, text, still a name=value pair, isn't it ? =) Can anyone offer me a simple example of how to go about passing a form field from one subroutine to another subroutine where it is a hidden field using cgi.pm? It's quite confuse for passing a form field do you mean , value ? if you want to passing values in subs, here you are : sub entryA { my ($entry) = shift ; my $result = ''; . return $result} # MAIN my $data = '' if ($model_no) { $data = entryA($model_no) ;. } Again, there is no different for hidden or not. Hidden is also name=value pair, the difference is only visitors can't see the data. Rgds, Connie -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: The True Guide to Learning Perl was Re: Thank You! :)
Hi everybody, I don't understand why you guys making things so complex. Perl is language and I think that should be all. :-) Whatever the habbits on Perl, is just as simple as how we learn our mother tongue. On the learning side, we began with A, B, C , while on the practical side, we began with papa, mama, pepe We never can say, 'I've completely learnt a language', With the interaction with trends, needs, new 'words' are then created. Of casue, when we speak, we have to express it with clearly, logically, and the best can make wordings have stand alone meaning. What they are stricts, warnings, and modules. Depends on our learning level and situation, we sometimes no need to tell everything so strict, of cause, it's better if possible and doable. We can't survive with language, so, for a language, its highest piority should be able to express, but not how pretty we've organized in our speech. Demons are everywhere, but they may not be ugly faced, maybe nicely masked. So how could you determine what are demons ? It finally goes to the point What is your level. That's why even we know where's the point to say What the fu*k... in this list, we won't say this, because we know what is demon. Perl is a language. And languages are alive. To use a language, we can choose to be casual, be beautiful, be formal, be informal . Depending on what the situation you are, and adjust the stict level to fit the best way to express yourself. You should strict the strict, not let strict to strict you. Orthodox is good, practise is good, but they are not the point for a beginner's advise, but LOVE IT. To let a beginner love it, let it be a easy language which can stick with every step on their road of learning and ways of working. While we love it, we will have the incentive to improving our skill, naturally. Making things too harsh at the beginning, is just equal to self creating a demon to guide us to HATE IT. Happy Perl programming and good luck for all yours codes, Exile ( Connie's brother ) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Fwd: Re: undefined symbol: Perl_Gthr_key_ptr
please see perl -V output: Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration: Platform: osname=linux, osvers=2.4.7-10, archname=i686-linux-thread uname='linux linux72 2.4.7-10 #1 thu sep 6 17:27:27 edt 2001 i686 unknown ' config_args='-Dusethreads -Duse5005threads -des' hint=recommended, useposix=true, d_sigaction=define usethreads=define use5005threads=define useithreads=undef usemultiplicity=undef useperlio=undef d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef Compiler: cc='cc', ccflags ='-D_REENTRANT -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O2', cppflags='-D_REENTRANT -fno-strict-aliasing -I/usr/local/include' ccversion='', gccversion='2.96 2731 (Red Hat Linux 7.1 2.96-98)', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=4, usemymalloc=n, prototype=define Linker and Libraries: ld='cc', ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib libs=-lnsl -lgdbm -ldb -ldl -lm -lpthread -lc -lcrypt -lutil perllibs=-lnsl -ldl -lm -lpthread -lc -lcrypt -lutil libc=/lib/libc-2.2.4.so, so=so, useshrplib=false, libperl=libperl.a Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic' cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib' Characteristics of this binary (from libperl): Compile-time options: USE_THREADS USE_LARGE_FILES PERL_IMPLICIT_CONTEXT Built under linux Compiled at Jul 15 2002 09:31:13 @INC: /usr/local/lib/perl5/5.6.1/i686-linux-thread /usr/local/lib/perl5/5.6.1 /usr/local/lib/perl5/site_perl/5.6.1/i686-linux-thread /usr/local/lib/perl5/site_perl/5.6.1 /usr/local/lib/perl5/site_perl . --- Paul Johnson [EMAIL PROTECTED] wrote: Date: Tue, 16 Jul 2002 11:05:09 +0200 From: Paul Johnson [EMAIL PROTECTED] To: Sajith K [EMAIL PROTECTED] Subject: Re: undefined symbol: Perl_Gthr_key_ptr On Mon, Jul 15, 2002 at 09:01:30PM -0700, Sajith K wrote: thanks paul ! i used nm to search for the symbol in the lib files in my system but couldn't find any. could you please tell me which library should have it defined ? I would imagine it should be in perl itself. i did compiled perl source with thread support, but it didn't work As I mentioned, you'll need to send the output of perl -V and some relevant parts of your program. Please ask directly to the list so everyone can benefit and help. I may not be able to answer personally for all sorts of reasons. regards sajith --- Paul Johnson [EMAIL PROTECTED] wrote: On Mon, Jul 15, 2002 at 10:42:35AM -0700, Sajith K wrote: i am trying to use perl with a public domain tool. on executiong use PLSTAF; i am getting the following error: /usr/bin/perl: error while loading shared libraries: /usr/lib/perl5/5.6.0/libPLSTAF.so: undefined symbol: Perl_Gthr_key_ptr could you please help me out with this problem ? At a guess, I would say that the version of perl you are using is different to the version the module was compiled with. It looks like you should be using a threaded perl. But I would imagine that you'll really need to provide the output of perl -V and at least the start of your program in order for anybody to help further. -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net __ Do You Yahoo!? Yahoo! Autos - Get free new car price quotes http://autos.yahoo.com -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net __ Do You Yahoo!? Yahoo! Autos - Get free new car price quotes http://autos.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Strange tie Problem
[EMAIL PROTECTED] (Nikola Janceski) writes: Long-shot guess The first element is a filehandle (or reference to one) and once the filehandle is closed the element is now uninitialized. The filehandle is closed in DESTORY of the package, so could happen till untie is called or the array goes out of scope. As the scope of the @array var is till the end of the file, I do not see how this could happen? I think the module didn't splice out that element. I don't understand this? Maybe, you could elaborate /guess Guess 2 You have no value for that element from the data you are tying. As the argument is the test file itself, it has 6 lines. /guess 2 What does $array[0] have? #!/usr/bin/perl -w have you tried debugging or Data::Dumper to see what @array consistes of? this is only a warning, you can turn off warnings to avoid the message if that's all you wanted. Actually, I get all the lines, except the second ( $array[1] ). However, if I try to print the array slice @array[0,2,3,4,5] I still get the warning and I get line 0 ( becauseof undef = 0 conversion ). Anyway, turning warnings off is pretty bad :-) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: find biggest number (new try :) )
Are you looking for how many elements the array has? If so: $lastElement = $#array; Konrad Foerstner [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... sorry a small but important mistake Im looking for a method to extract the biggest element (number) out of array. Does anyone know a function for that? cu Konrad --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.377 / Virus Database: 211 - Release Date: 7/15/2002 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Can get script to print to command prompt no matter what I try
I just tried it, and it does not work for me either. I too run on win2k. I have always just put the code in a file or a module and executed it that way. At least if you save them you will have a record of your progress. Cory [EMAIL PROTECTED] wrote in message 001c01c22d40$b4107710$7c33aa18@panther2">news:001c01c22d40$b4107710$7c33aa18@panther2... I have tried numerous variations of this simple script: print (hello\n); perl -e print qq~Hello\n~ C:\ perl print Hello\n; then press 'controll Z' print hello; and press 'control C' Nothing works. I can run a pre written script, but that is it. I have the camel book and none of the sample scripts will run. HELP!!! Cory Moore Campaign Manager Pat Ahumada for Congress www.patforcongress.com www.americanvirtue.com --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.377 / Virus Database: 211 - Release Date: 7/15/2002 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: find biggest number (new try :) )
Lance wrote: Are you looking for how many elements the array has? If so: $lastElement = $#array; That does NOT give you the number of elements in an array. That gives you the index of the last element in the array. $ perl -le' @array = qw/ a b c d e f /; print q(The number of elements in @array is ), scalar @array; print q(The last element in @array is at ), $#array; ' The number of elements in @array is 6 The last element in @array is at 5 John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Can get script to print to command prompt no matter what I try
O.K. - I run Perl on win2k - screen dumps follow: C:\PATH PATH=C:\Perl\bin\;C:\Tcl\bin;.. C:\perl -e print qq~Hello\n~ Hello C:\perl print hello\n hello ^C C:\ So, Perl works. Now, I have some scripts (one of which is called 'example.pl' - the one from the start of 'Learning Perl') in a directory called MyPerl on c:\ This script is: #!perl @lines = `c:\\Perl\\bin\\perldoc -u -f atan2`; foreach (@lines) { s/\w([^]+)/\U$1/g; print; } So to run this script... C:\cd MyPerl C:\MYPERLexample.pl =over 8 =item atan2 Y,X Returns the arctangent of Y/X in the range -PI to PI. For the tangent operation, you may use the MATH::TRIG::TAN function, or use the familiar relation: sub tan { sin($_[0]) / cos($_[0]) } =back C:\MYPERL This scripts runs fine from the command window - remember that if you just double click on a script from file manager, it will just fire up a command window for long enough to run the script - you need to open a command window (Start - Run - Command) and then change directory to where your script is saved and then execute the script by typing its name (with extension). You could also specify the full path to the script from the command prompt - i.e. c:\MyPerl\example.pl hth Matt - ** Matt Wetherill University of Salford [EMAIL PROTECTED] mobile: +44 7812 016059 office: +44 161 295 5853 ** Never try to teach a pig to sing it wastes your time and it annoys the pig. - Anon. --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.377 / Virus Database: 211 - Release Date: 15/07/2002 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
# question
($uno,$due,$tre,$quattro,$cinque,$sei) = split (/\s+/); s/\#//; print $sei; Is it right to have $sei without #? thanks -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Multi-dimensional arrays and subroutines
Hi Guys I was wondering if you could help me. I have a multi-dimensional array and I would like to pass it to a subroutine as follows : my multi_array = ([1,2,3,4], [5,6,7,8]); my result = process_array(multi_array); print The result is : result\n; sub process_array { my array_processed; my array_given = $_[0]; $select_data = select A, B, C, D from Table X where A = ? and B = ? and C = ? and D = ?; $sth = $dbh-prepare($select_data) or die Can't prepare SQL statement: , $dbh-errstr(), \n; for (array_given) { $sth-bind_param(1, $_-[0]); $sth-bind_param(2, $_-[1]); $sth-bind_param(3, $_-[2]); $sth-bind_param(4, $_-[3]); $sth-execute(); $sth-bind_columns(undef, \$A, \$B, \$C, \$D); while ($sth-fetch()) { $new_array = join(|, $A, $B, $C, $D); unshift(array_processed, $new_array); } } $sth-finish(); return array_processed; } I am expecting as output the following : The result is 1,2,3,4 The result is 5,6,7,8 The actual output I am getting is : The result is 1,2,3,4 What happened to 5,6,7,8 ? I would be most grateful for any advice. Thanks in advance Tony
Re: # question
Hello, - Original Message - From: Francesco Guglielmo [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, July 17, 2002 4:35 AM Subject: # question ($uno,$due,$tre,$quattro,$cinque,$sei) = split (/\s+/); s/\#//; You probably want to write: $sei=~s/\#//; Shawn print $sei; Is it right to have $sei without #? thanks -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: # question
Many thanks!!! Shawn wrote: Hello, - Original Message - From: Francesco Guglielmo [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, July 17, 2002 4:35 AM Subject: # question ($uno,$due,$tre,$quattro,$cinque,$sei) = split (/\s+/); s/\#//; You probably want to write: $sei=~s/\#//; Shawn print $sei; Is it right to have $sei without #? thanks -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Multi-dimensional arrays and subroutines - PLEASE IGNORE PREVIOUS EMAIL
Hi Guys I have just resolved the problem. The problem was the array variable array_given in the subroutine. I replaced : my @array_given = $_[0]; with my @array_given = @_; It works fine. Thanks for the help. Tony -Original Message- From: Ho, Tony Sent: Wednesday, July 17, 2002 11:43 AM To: '[EMAIL PROTECTED]' Subject: Multi-dimensional arrays and subroutines Hi Guys I was wondering if you could help me. I have a multi-dimensional array and I would like to pass it to a subroutine as follows : my @multi_array = ([1,2,3,4], [5,6,7,8]); my @result = process_array(@multi_array); print The result is : @result\n; sub process_array { my @array_processed; my @array_given = $_[0]; $select_data = select A, B, C, D from Table X where A = ? and B = ? and C = ? and D = ?; $sth = $dbh-prepare($select_data) or die Can't prepare SQL statement: , $dbh-errstr(), \n; for (@array_given) { $sth-bind_param(1, @$_-[0]); $sth-bind_param(2, @$_-[1]); $sth-bind_param(3, @$_-[2]); $sth-bind_param(4, @$_-[3]); $sth-execute(); $sth-bind_columns(undef, \$A, \$B, \$C, \$D); while ($sth-fetch()) { $new_array = join(|, $A, $B, $C, $D); unshift(@array_processed, $new_array); } } $sth-finish(); return @array_processed; } I am expecting as output the following : The result is 1,2,3,4 The result is 5,6,7,8 The actual output I am getting is : The result is 1,2,3,4 What happened to 5,6,7,8 ? I would be most grateful for any advice. Thanks in advance Tony
Re: in-place edit prefix?
Chas, et al -- ...and then Chas Owens said... % % On Tue, 2002-07-16 at 08:25, David T-G wrote: ... % program, though, I'd like even more to be able to define a *prefix* for % the original file so that instead of file.bak I have .#file after an edit ... % % snip href=perldoc perlrun % If the extension doesn't contain a *, then it is % appended to the end of the current filename as a suf % fix. If the extension does contain one or more * % characters, then each * is replaced with the cur % rent filename. % /snip Oooh! Hey, that's lovely; it's exactly what I need. And I have another reference to check! :-) (um, wait a minute...). Anyone know if that's new in 5.6 or so (since Camel 2e) or did the Camel book just leave it out? Thanks HAND :-D -- David T-G * It's easier to fight for one's principles (play) [EMAIL PROTECTED] * than to live up to them. -- fortune cookie (work) [EMAIL PROTECTED] http://www.justpickone.org/davidtg/Shpx gur Pbzzhavpngvbaf Qrprapl Npg! msg27826/pgp0.pgp Description: PGP signature
Re: Can get script to print to command prompt no matter what I try
I have tried numerous variations of this simple script: print (hello\n); perl -e print qq~Hello\n~ C:\ perl print Hello\n; then press 'controll Z' print hello; and press 'control C' You have to enter CTRL+Z and ENTER on an empty line: C:\ perl print Hello\n; ENTER CTRL+Z ENTER Jenda === [EMAIL PROTECTED] == http://Jenda.Krynicky.cz == There is a reason for living. There must be. I've seen it somewhere. It's just that in the mess on my table ... and in my brain I can't find it. --- me -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Repeat scanning a captured value (string)
Greetings, We are currently moving from Omnimark to PERL so I guess it's time to learn some PERL. Giving the following scenario, I am wondering if PERL can cope with the following scenario and, if so, what would the code look like: Input Text: pText of article... pAnd it says in Documents 1,2,3 and 4 where to go/p pEnd of article... Desired Output: pText of article... pAnd it says in Documents A HREF=Doc11/A,A HREF=Doc22/A,A HREF=Doc33/A and A HREF=Doc44/A where to go/p pEnd of article... Basically, I need it to find a pattern anchored by word Documents followed by an undetermined number of #'s, some separated by commas and/or the word 'and' We were able to do this in Omnimark by capturing the whole string anchored by word Documents followed by an undetermined number of #'s, some separated by commas and/or the word 'and', assigning it to a variable the 'scanning' it and matching the numbers and putting links around them. For reference, following is the Omnimark code that easily accomplishes this: Omnimark Code: find ('Documents' WS*) = pCite (digit+ ('.' digit+)? ((',' WS*) OR (WS* ('and' OR 'through') WS*))*)+ = pSeries output pCite repeat scan pSeries match (digit+ ('.' digit+)?) = pValidLink output 'A HREF=Doc' || pValidLink || '' || pValidLink || '/A' match any = pLeftOver output pLeftOver again Is this possible in PERL? Are there any better languages for predominantly text transformation? Thanks for any help, input. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Comparison of two log files.
Hello listers, I would like to submit a script I have written and it does work. However I am sure that it can be: a. Shorter b. Faster As you will see it is not very well written. Certainly nothing compared to some of the listers code I have seen here. I am new at perl so here goes. Some of you might recognise the sample a part of a Oracle export log, which it is. Now I am not confident enough to use the unedited log and stripping it with perl(maybe oneday), anyway that has already been done with tools like grep and cut. Script #Perl Script to Compare two backup logs and then identify # substantial differences in changed tables. use strict; use warnings; #Open the newer backup log. open FILE, C:/tmp/max_grow/max1.log or die Cann't open : $!; while(FILE){ chomp; #Input to be divided in two: #Sample of file is - # APPDOCTYPE 43 #APPLAUNCH 16 # APTRANS 1245 # ARCHIVE 0 # ASICUST 24 # ASILINK 5 # ASSETATTRIBUTE736 # ASSETCLASS 1667 #ASSIGNMENT 60648 #ATTENDANCE 103193 #Divide the input into two groups s/(.*\D)+(.*\d)/$2 $1/; #Pass the two groups to variables my $value1 = $2; my $tblnam1 = $1; #Remove all unnecessary spaces. for ($tblnam1) { s/^\s+//; s/\s*$//;} for ($value1) { s/^\s+//; s/\s*$//;} #Open the older log open FILE2, C:/tmp/max_grow/max4.log or die Cann't open : $!; while(FILE2){ chomp; s/(.*\D)+(.*\d)/$2 $1/; my $value2 = $2; my $tblnam2 = $1; for ($tblnam2) { s/^\s+//; s/\s*$//;} for ($value2) { s/^\s+//; s/\s*$//;} # Compare the two logfiles here. if($tblnam1 eq $tblnam2) { my $diff = $value2 - $value1; if($diff 1000){ print $tblnam1 :The difference is $diff\n; } } } } /End Script Looking forward to your comments, and learning the right way. Rgds Denham Eva Oracle DBA In UNIX Land On a quiet Night, you can hear the Windows machines reboot. DISCLAIMER This message is for the named person's use only. It may contain confidential, proprietary or legally privileged information. No confidentiality or privilege is waived or lost by any mistransmission. If you receive this message in error, please immediately delete it and all copies of it from your system, destroy any hard copies of it and notify the sender. You must not, directly or indirectly, use, disclose, distribute, print, or copy any part of this message if you are not the intended recipient. TFMC, its holding company, and any of its subsidiaries each reserve the right to monitor and manage all e-mail communications through its networks. Any views expressed in this message are those of the individual sender, except where the message states otherwise and the sender is authorized to state them to be the views of any such entity. _ This e-mail message has been scanned for Viruses and Content and cleared by MailMarshal For more information please visit www.marshalsoftware.com _
Re: Books on Network programming in Perl...
On Tuesday, July 16, 2002, at 08:18 , Parag Dhake wrote: [..] I'm new to this mailing list (and to the world of Perl, as well) Would appreciate if you can suggest me some good books on Network programming in Perl. It all sorta depends on where you are jumping off the cliff. One can always start with perldoc Socket to go over the basic dope on 'your friend the socket' in perl. As well as perldoc perlipc if you are already aware of the basic networking tricks - otherwise you will probably want to start where most of us did: Most of us started with either Tannenbaum and/or Stevens cf: http://www.bookpool.com/.x/4yrty8k80m/sm/013490012X as our backbone for 'what is network programming' to begin with. You will of course want to own and read: the 3rd Edition of Perl, and then at least Advanced Perl Programming http://www.oreilly.com/catalog/advperl/ Go into depth on your friend the socket and TLI - transport layer interfaces - decide if you want to live at this layer or want to say, uh, do it in perl and stay with the modules that are in hand for encapsulating most of this 'grunt work' so that you can focus on 'the mission'. cf: http://search.cpan.org/Catalog/Networking_Devices_IPC/ there is now even a Perl and LWP book out: http://www.oreilly.com/catalog/perllwp/ probably one of the fun ways to begin the process of 'network programming' - build a webBot - get it to fetch you everything you wanted to know about... Or read up on the mod_perl stuff and perldoc CGI and build the stuff for the webServer Side of it Learn how to use simple fun HTTP based tricks to execute stuff on a remote host... [..] Do you think Perl is the best language for network programming ?. I don't think that I would pick it as my first choice for say write T1 Line Card Interfaces, and their kernel devices... And the same would probably hold true for OC3-OC48 fiber devices But I am hacking up a 'jobBot' to illustrate how to do some of the fun of automating the job hunt - in perl: http://www.wetware.com/drieux/pbl/perlTrick/CBO/jobBot/ I used it to help a friend get the DHCP external IP Address off a DI704 - http://www.wetware.com/drieux/CS/Proj/DI704/ Perl Clearly beats SNOT out of trying to write database query solutions, than say trying to hack that in /bin/sh - if that is not obvious - Don't Ask go to the CPAN, download the modules. I've read some books on Perl by now and I've found that it is usually used on a Unix box. Can it be used on NT platform as well ?. Yes, there are modules at the CPAN search on WIN32 cf: http://www.roth.net/perl/ cf: http://www.activestate.com/ ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
strange query.
Hi Everyone I'm having a spot of bother with a query string. The program below attempts to mimic a web form. It should post the value of 'QUERY ..' to the cgi in $location. What is actually happening is that 'QUERY ..' itself is being sent as the value. I copied the name 'QUERY ..' from the textarea name on the original web form. I have tried character escaping the space and the two dots but that didn't work (the cgi hung). Maybe I need to use CGI.pm to generate the query string? Anyone got any ideas? Thanks James -- #!/usr/bin/perl -w use strict; use LWP::UserAgent; use HTTP::Request; #This is the sequence for analysis (it is actually all on one line!!!) my Seq='MQMRVLRIQHPLDHRPRHDRKTRHEVMLPDRKTRDLVVAIRNDRRA LRIGAHIQAMPVFRRVQIERRRGVRRMHVADALLNQLRGLRMQFQRHAERGRR ALTRVVVRRGADAARGEHDVSRGERAPQRRRDALGVVADVLRPAERQPTRAEQ FDNLRQMLVDPPARQDLIAAKCHCRLFRLVSNSSVGNRRRVPHAAVLFR AHALQRAQTV'; #Send the request my $location = http://www.sbc.su.se/~miklos/DAS/tmdas.cgi;; my $agent = new LWP::UserAgent; my $req = new HTTP::Request POST = $location; $req - header('Accept' = 'text/html'); $req - header('Accept' = 'image/gif'); $req - header('Accept' = 'text/plain'); $req - header('Content-Type' = 'application/x-www-form-urlencoded'); $req - content('QUERY ..' = $seq); #Receive the response my $result = $agent-request( $req ); print $result-headers_as_string; print $result-content; James Campbell Tel:+44-(0)207-848-5111 Email: [EMAIL PROTECTED] =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 'Where shall I begin, please your Majesty?' He asked 'Begin at the beggining,' the King said gravely, 'and go on till you come to the end: then stop.' Lewis Carroll, Alice's Adventures in Wonderland. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Which one is better ??
Which one is the more preferred : perl2exe or perlapp (Active state Perl Development Kit). I have not done much with perlapp and I did run into small problem using perl2exe. Just wanted to know their merits. Thanks Shishir -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Comparison of two log files.
Script #Perl Script to Compare two backup logs and then identify # substantial differences in changed tables. use strict; use warnings; #Open the newer backup log. open FILE, C:/tmp/max_grow/max1.log or die Cann't open : $!; while(FILE){ chomp; #Input to be divided in two: #Sample of file is - # APPDOCTYPE 43 #APPLAUNCH 16 # APTRANS 1245 # ARCHIVE 0 # ASICUST 24 # ASILINK 5 # ASSETATTRIBUTE736 # ASSETCLASS 1667 #ASSIGNMENT 60648 #ATTENDANCE 103193 #Divide the input into two groups s/(.*\D)+(.*\d)/$2 $1/; If you are only interested in $1 and $2 why use a s///, just a m/// or /// would do. #Pass the two groups to variables my $value1 = $2; my $tblnam1 = $1; Assigning contents from $1, $2 ... etc. must be done inside a condition that checks for the success of the regex. These variables are not cleared, if the regex fails they will still contain the old values. #Remove all unnecessary spaces. for ($tblnam1) { s/^\s+//; s/\s*$//;} for ($value1) { s/^\s+//; s/\s*$//;} You could have avoided the chomp, regexes etc. by using split (perldoc -f split). In particular the default behaviour of split. my ($tblnam1,$value1) = split; $tblnam1 and $value1 will now contain the values you want in them. #Open the older log open FILE2, C:/tmp/max_grow/max4.log or die Cann't open : $!; while(FILE2){ chomp; s/(.*\D)+(.*\d)/$2 $1/; my $value2 = $2; my $tblnam2 = $1; for ($tblnam2) { s/^\s+//; s/\s*$//;} for ($value2) { s/^\s+//; s/\s*$//;} The same holds here too, default behaviour of split # Compare the two logfiles here. if($tblnam1 eq $tblnam2) { my $diff = $value2 - $value1; if($diff 1000){ print $tblnam1 :The difference is $diff\n; } } } } /End Script It seems like for every line in log1 you are opening log2 and doing the comparison. With m lines in log1 and n lines in log2 you are performing m*n operations. A better option would be to open log1 and form a hash. open (LOG1, $your_first_log) or die ; while (LOG1) { my ($tablnm1, $value1) = split; $comp_log{$tablnm1} = $value1; } close LOG1 or warn .; Now loop through log2 and check if a key with tblnam2 exists in the hash and if it does subtract the values for the result. open (LOG2, $your_second_log) or die ; while (LOG2) { my ($tablnm2, $value2) = split; if (defined $comp_log{$tablnm2}) { # Doing your difference check here } } close (LOG2) or warn .; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Multi-dimensional arrays and subroutines
On Jul 17, Ho, Tony said: $sth-bind_param(1, @$_-[0]); You've already fixed your problem, so that's good, but I would use $sth-bind_param(1, $_-[0]); instead of $sth-bind_param(1, @$_-[0]); Yours works by some bizarre coincidence of Perl's parsing. It should be considered a silent bug. -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for Regular Expressions in Perl published by Manning, in 2002 ** stu what does y/// stand for? tenderpuss why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Term modules
Hola, someone has used the module Term::ReadPassword with the module use Term::ANSIScreen ??? When i call the cls (clear screen) function of ANSI module before of read_password of ReadPassword module, the cls function don't work. Ex. sub read{ cls; $pass=read_password; } ##don't clean the screen sub read{ $pass=read_password; cls; } I use a Debian Linux (kernel 2.2.20) Is a bug ??? or ...?? Thanks Walter -- God hates us all -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Repeat scanning a captured value (string)
On Jul 17, Faymon, Kurt said: We are currently moving from Omnimark to PERL so I guess it's time to learn some PERL. Giving the following scenario, I am wondering if PERL can cope with the following scenario and, if so, what would the code look like: Oh wow. I'm truly astonished. Omnimark, which touted itself as the replacement for Perl. Wow. Gasp. (Perl, not PERL, please.) Someone who actually used Omnimark. I need a minute to recover. (Omnimark, which is not open-source, debuted itself at OSCON, and said it was cheaper than Perl. This is a product I have laughed at for quite a while.) pAnd it says in Documents 1,2,3 and 4 where to go/p pAnd it says in Documents A HREF=Doc11/A,A HREF=Doc22/A,A HREF=Doc33/A and A HREF=Doc44/A where to go/p Basically, I need it to find a pattern anchored by word Documents followed by an undetermined number of #'s, some separated by commas and/or the word 'and' Is this possible in PERL? Are there any better languages for predominantly text transformation? I find Perl very VERY good for text transformation. Others might use sed or awk, but Perl has more power. (More power, ar ar ar!) This is how I would approach the problem. It works on the following cases: Check Document 1 Check Documents 1 and 2 Check Documents 1, 2, and 3 Check Documents 1,2 and 3 Check Documents 1 , 2, 3, 4, and 5 Here's the code: $string =~ s{(Documents?) (\d+(?:\s*,\s*\d+)*(?:\s*,?\s*and\s+\d+)?)} { $1 . . make_links($2) }ge; # find a number, make it a link sub make_links { my $str = shift; $str =~ s{(\d+)}{a href=Doc$1$1/a}g; return $str; } -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for Regular Expressions in Perl published by Manning, in 2002 ** stu what does y/// stand for? tenderpuss why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Fixing warnings?
Hello all, Well, I have yet another question. I have started turning on warnings in my scripts, and get something like the following output when running my script. Name main::opt_C used only once: possible typo at ./cdma.pl line 42. Name main::mar_cdl_format used only once: possible typo at ./cdma.pl line 64. Name main::daily used only once: possible typo at ./cdma.pl line 46. Name CDMAConfig::PDF_FILE_PATH used only once: possible typo at ../cdma.pl line 54. Name main::date used only once: possible typo at ./cdma.pl line 46. Use of uninitialized value in numeric eq (==) at ./cdma.pl line 42. 1) How do I fix lines that say used only once or possible typo? Maybe at this point in my script I'm only going to use that variable once, and not use it until 700+ lines into my codeHow can I avoid seeing these? 2) The reason I ask question 1 is because if I am to use the warnings to fix problems and it keeps throwing up the first 50 or so warnings that Im aware of then quits because there are too many warnings, how am I to fix the ones that are really causing the problems. I know there's some trick I haven't learned to coding with warnings and use strict turned on.any help is greatly appreciated. Thanks, Kevin -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Fixing warnings?
On Jul 17, Kevin Old said: Name main::opt_C used only once: possible typo at ./cdma.pl line 42. Name main::mar_cdl_format used only once: possible typo at ./cdma.pl line 64. Name main::daily used only once: possible typo at ./cdma.pl line 46. Name CDMAConfig::PDF_FILE_PATH used only once: possible typo at ../cdma.pl line 54. Name main::date used only once: possible typo at ./cdma.pl line 46. Then declare them:: # perl 5.6 our ($opt_C, $mar_cdl_format, $daily, $date); # before perl 5.6 use vars qw( $opt_C $mar_cdl_format $daily $data ); Or, if you're using Perl 5.6, tell Perl you don't care about that warning message: no warnings 'once'; If you're using something before 5.6, here's a hack: BEGIN { $SIG{__WARN__} = sub { return if @_ =~ /used only once/; warn @_; } } Use of uninitialized value in numeric eq (==) at ./cdma.pl line 42. That's a problem you have to FIX. -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for Regular Expressions in Perl published by Manning, in 2002 ** stu what does y/// stand for? tenderpuss why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Fixing warnings?
On Wednesday, July 17, 2002, at 08:16 , Kevin Old wrote: Name main::opt_C used only once: possible typo at ./cdma.pl line 42. [..] Use of uninitialized value in numeric eq (==) at ./cdma.pl line 42. 1) How do I fix lines that say used only once or possible typo? Maybe at this point in my script I'm only going to use that variable once, and not use it until 700+ lines into my codeHow can I avoid seeing these? The simplest method to 'shut it up' is to do an 'initialization' of these variables with say our ($opt_C, $mar_cdl_format, $daily, $date) = qw/ no no no no/; The other part of the problem Could be that you have variables that you ARE only using 'once' and may want to think about WHY you are doing that to being with, my $bob = 'bob'; in itself will cause that 'used only once' error message - but if you Really do not use $bob, why have It? If you plan to use it - but have not yet written that chunk of code - you may want to adopt the 'commenting' strategy: # my $bob = 'bob'; on 'the big stack of globals' not yet in use [..] that way when you write the code that Need $bob, it will of course bark at you about needing it to be defined ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Pattern Matching
I'm working on a script that I need to use some pattern matching in. I've got a couple books that I have been reading about it and thought I knew how to seach for what I'm after but its just not working. Here is a test script I've been playing with to get this working. I want to be able to parse out of the string any one of the 'letter=values'. The way I'm trying to get this to work is by searching for the Letter of the parameter I'm searching for follow by the =. Then I add a .* which matches anything. Then I want to match to end with a ' But no matter what I've tried I will never find the ' It find the beginning of my search then go to the end of the string. I've played with escaping the ' but that didnt seem to work either. What I end up having to do to get it to work is end the seach with the Letter= of the next variable in the string and then clean it up but I really don't want to have to do it that way as its not very flexable and relies on the string being in a certain order and I don't want to count on that. If anyone has an idea about what I'm doing wrong I would be most grateful. #!/usr/bin/perl $test = 'A=test' 'P=lkjae' 'p=12' 'H=goober@localhost' 'n=crfrinch' 't=3453462'; $_ = $test; /(n=.*')/; $username = $1; print $1\n; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
XS and Shared Libraries
Hi, I am building a wrapper between some Perl code and C library. I am using XS for this. I want to compile the wrapper as a Shared Lib that is dynamically loaded by perl. Today I compile a Shared Lib statically linked to the C library (I link with the C Lib.asl) in one big Shared Lib. Perl |(load .sl) Wrapper(including C Lib) Now I want to be able to load the C library as Shared Lib: Perl |(load .sl) Wrapper |(load .sl) C Lib C Lib is not a Perl library, so it cannot be loaded by Perl using Dynaloader. So I have two possibilities: -either Wrapper loads dynamically C Lib = Wrapper includes only some XS code. Is it possible to include code to load the C Lib within my XS code ? -either Wrapper is linked statically with C Lib (As you will do for an executable) = Is it possible to link statically a Shared Lib with another one just as you will do for an exectable ? Does somebody has already face this case ? What do you advice ? Thanks, Vincent -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
formate text sequence
hi, does anyone know a function or a module which i can use to format a text which i get in a string. i would like to get out of the string lines of 40 letters which are surrounded by p and /p; the result should be stored in an string. short example with 3-letter-lines: $input = 'ABCDEFGHI'; --- $output = 'pABC/ppDEF/ppGHI/p' cu konrad -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Pattern Matching
Here is one way: /(n=[^']*)/; which says find a n= and then everything up to the next ' You probably want to wrap in if statement so if not a hit, then can do something. Wags -Original Message- From: Dan Finch [mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 17, 2002 09:09 To: [EMAIL PROTECTED] Subject: Pattern Matching I'm working on a script that I need to use some pattern matching in. I've got a couple books that I have been reading about it and thought I knew how to seach for what I'm after but its just not working. Here is a test script I've been playing with to get this working. I want to be able to parse out of the string any one of the 'letter=values'. The way I'm trying to get this to work is by searching for the Letter of the parameter I'm searching for follow by the =. Then I add a .* which matches anything. Then I want to match to end with a ' But no matter what I've tried I will never find the ' It find the beginning of my search then go to the end of the string. I've played with escaping the ' but that didnt seem to work either. What I end up having to do to get it to work is end the seach with the Letter= of the next variable in the string and then clean it up but I really don't want to have to do it that way as its not very flexable and relies on the string being in a certain order and I don't want to count on that. If anyone has an idea about what I'm doing wrong I would be most grateful. #!/usr/bin/perl $test = 'A=test' 'P=lkjae' 'p=12' 'H=goober@localhost' 'n=crfrinch' 't=3453462'; $_ = $test; /(n=.*')/; $username = $1; print $1\n; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
formate text sequence
hi, does anyone know a function or a module which i can use to format a text which i get in a string. i would like to get out of the string lines of 40 letters which are surrounded by p and /p; the result should be stored in an string. short example with 3-letter-lines: $input = 'ABCDEFGHI'; --- $output = 'pABC/ppDEF/ppGHI/p' cu konrad -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Random generator
How can I generate a whole number betwee 10 - 99? To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- This message is intended only for the personal and confidential use of the designated recipient(s) named above. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction, or as an official statement of Lehman Brothers. Email transmission cannot be guaranteed to be secure or error-free. Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such. All information is subject to change without notice. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: formate text sequence
On Jul 17, Konrad Foerstner said: does anyone know a function or a module which i can use to format a text which i get in a string. Text::Format comes to mind. short example with 3-letter-lines: $input = 'ABCDEFGHI'; --- $output = 'pABC/ppDEF/ppGHI/p' This is a very simple case: $len = 3; $string =~ s{(.{1,$len})}{p$1/p}g; -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for Regular Expressions in Perl published by Manning, in 2002 ** stu what does y/// stand for? tenderpuss why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Random generator
On Wednesday, July 17, 2002, at 09:15 , Jilani, Mohammad K wrote: How can I generate a whole number betwee 10 - 99? perldoc -f rand and then tweek it since rand runs from 0 you might try say my $rand_num = rand(90) + 10; ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: strange query.
Use double quotes ( ) for surrounding, instead of apostrophy ( ' ). Thus it will interpret it and not translate it litterally. -- Best Wishes, Yasen Petrov ICQ 163 671 835 James Campbell [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Hi Everyone I'm having a spot of bother with a query string. The program below attempts to mimic a web form. It should post the value of 'QUERY ..' to the cgi in $location. What is actually happening is that 'QUERY ..' itself is being sent as the value. I copied the name 'QUERY ..' from the textarea name on the original web form. I have tried character escaping the space and the two dots but that didn't work (the cgi hung). Maybe I need to use CGI.pm to generate the query string? Anyone got any ideas? Thanks James -- #!/usr/bin/perl -w use strict; use LWP::UserAgent; use HTTP::Request; #This is the sequence for analysis (it is actually all on one line!!!) my Seq='MQMRVLRIQHPLDHRPRHDRKTRHEVMLPDRKTRDLVVAIRNDRRA LRIGAHIQAMPVFRRVQIERRRGVRRMHVADALLNQLRGLRMQFQRHAERGRR ALTRVVVRRGADAARGEHDVSRGERAPQRRRDALGVVADVLRPAERQPTRAEQ FDNLRQMLVDPPARQDLIAAKCHCRLFRLVSNSSVGNRRRVPHAAVLFR AHALQRAQTV'; #Send the request my $location = http://www.sbc.su.se/~miklos/DAS/tmdas.cgi;; my $agent = new LWP::UserAgent; my $req = new HTTP::Request POST = $location; $req - header('Accept' = 'text/html'); $req - header('Accept' = 'image/gif'); $req - header('Accept' = 'text/plain'); $req - header('Content-Type' = 'application/x-www-form-urlencoded'); $req - content('QUERY ..' = $seq); #Receive the response my $result = $agent-request( $req ); print $result-headers_as_string; print $result-content; James Campbell Tel: +44-(0)207-848-5111 Email: [EMAIL PROTECTED] =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 'Where shall I begin, please your Majesty?' He asked 'Begin at the beggining,' the King said gravely, 'and go on till you come to the end: then stop.' Lewis Carroll, Alice's Adventures in Wonderland. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Random generator
you for got the int.. he said whole numbers my $rand_num = int(rand(90) + 10); -Original Message- From: drieux [mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 17, 2002 12:25 PM To: begin begin Subject: Re: Random generator On Wednesday, July 17, 2002, at 09:15 , Jilani, Mohammad K wrote: How can I generate a whole number betwee 10 - 99? perldoc -f rand and then tweek it since rand runs from 0 you might try say my $rand_num = rand(90) + 10; ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] The views and opinions expressed in this email message are the sender's own, and do not necessarily represent the views and opinions of Summit Systems Inc. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Random generator
On Jul 17, Jilani, Mohammad K said: How can I generate a whole number betwee 10 - 99? Well, using int(rand(10)) gives you an integer from 0 to 9. If you add 10 to it, you get an integer from 10 to 19. To get an integer from 10 to 99, you need to come up with an expression of the form X + int(rand(Y)) We know X is going to be 10 (because 10 is the lowest number to be returned. So subtracting 10 from our endpoints, we go from 10 and 99 to 0 and 89. So for int(rand(Y)) to return a number from 0 to 89, Y must be 90. $num = 10 + int rand 90; -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for Regular Expressions in Perl published by Manning, in 2002 ** stu what does y/// stand for? tenderpuss why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Field Separator
Can anyone tell me what the escape sequence for the field seprator (^]) is, or point me to where I can find it? Basically I need to do a split on it to parse some records. TIA -- Michael D. Risser Software Engineer/Linux Administrator = Machine Vision Products, Inc. www.visionpro.com [EMAIL PROTECTED] -BEGIN PGP PUBLIC KEY BLOCK- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org mQGiBDuCrxARBADE9hdFrBY4oQG8dnGZo6HV1pPXdiS1yVhDA1Hp0nTcmhsAdBtu udBPkwwrVKATJYWQsRYBwbjE9WhyeGKXW95BkeUfDQo6YJBGBaeZSnfJhugdnoEv +UB3c7McRenM6dN0oeDBWhcylTMpdUEbM9BG3pHUrKIh/TECDESWsS2PRwCgkGMy HTSPVa3xzwAyt4C5FPINSkcEALHAysCwpYou3n1BOjjIR/lc2Wg9jMDxCL5Kf5qh JIfvPu5Ew/NjkcTtoUrF8Ag4++3/D9jaHpFiUvp5xKtd/CjI+zQmWYvan3Qa5D6D ZXNAvQzDpHMQ0PNed4lD6+a2unfMI22yh57WZ51nKajSGi3kbRd+564ZdM3BC3tU 30eaA/9uwrGaTCKUpku9Q7xOXRUTQOzPKMuUkGrHK84Fea8BhRYm3P/im6+mgKPu OeAZuxTX3KD8WyTz3wPc3C9RVkcOeii90r8AbztYFa3jq7ryAxXuIAJClDyvmVxz 0i0/QsUG7Qmh3bSqSEE8j0wS1d+oCK0vys/kzPQu4BlSIZYlArQ9TWljaGFlbCBE LiBSaXNzZXIgKFNvZnR3YXJlIEVuZ2luZWVyKSA8bWljaGFlbEB2aXNpb25wcm8u Y29tPohXBBMRAgAXBQI7gq8QBQsHCgMEAxUDAgMWAgECF4AACgkQ/ikO9QMSg3cj CwCfUw/OvLdfH3J6wDkgJkgwIZdJgmgAn1PAfxKjgiFXcteIpUtN6s988k1CuQEN BDuCrxIQBADw8yDbbWdO9pvyUpdWjWxTBBFo9eQexJFFap4b9KcpWDJWawZ6S/HU Cn+7zfbFb43AZa21mlon/vr7nwvlll7P/fa9S4kvk5twM8PcwM9O9yVxhOZeInXR NUBzqjpK8FfRZgt1TaOz/CpdacNAJ9i2cShvH6wcCbHxGL9rjAu+IwADBgQA0t8p 1ivBcABEmK4o+r5+uXZoQ4jUzDDN5bZmddQOQhyyMX/JUeBX7gxQ7r2cYJHIlcN+ FCeqUHLmgQ/Ky+gze61Yr+FeEBJ4EPklkHWu3RoS4aKlEtU688nm+8Mfph6nYl+n HzmaZjf5hz/mqvs5bzBCrw+xSSjNhJBrmj8qzIqIRgQYEQIABgUCO4KvEgAKCRD+ KQ71AxKDd2/JAJ9vnTOSbmB2XceA4gBaOsZg06s5lQCfYfRtXoy/Mbw82eS19NE/ w9t+V8g= =J9H/ -END PGP PUBLIC KEY BLOCK- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Field Separator
On Jul 17, Michael D. Risser said: Can anyone tell me what the escape sequence for the field seprator (^]) is, or point me to where I can find it? Basically I need to do a split on it to parse some records. The default field separator is ^\, not ^]. Perl stores that value in the $; variable. It's chr(28). @fields = split $;, $string; -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for Regular Expressions in Perl published by Manning, in 2002 ** stu what does y/// stand for? tenderpuss why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Field Separator
On Jul 17, Michael D. Risser said: Can anyone tell me what the escape sequence for the field seprator (^]) is, or point me to where I can find it? Basically I need to do a split on it to parse some records. On the offchance that you REALLY do need ^], you can get the character in Perl via: $fs = \c]; @fields = split $fs, $string; # or, more directly @fields = split /\c]/, $string; -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for Regular Expressions in Perl published by Manning, in 2002 ** stu what does y/// stand for? tenderpuss why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Setting environment variable for process spawned with system()
Okay... maybe this is just so simple that I can't see the forest through the trees, but I've never had a need to do it before and so that inherently makes it difficult :-) I've got a script that runs gnuplot via system(). In order to use a custom path for gnuplot's fit regression function, It looks for the environment variable FIT_LOG. How can I set an environment variable in the script that will be inherited by the system() process? Thanks, -Dan --- Old programmers never die... Unless of course they refuse to accept a few extra CPU cycles over months of efficiency tuning... [Have times changed or WHAT!] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Setting environment variable for process spawned with system()
I'm not sure about in Perl, but you can usually do it on the command line (depending on shell). For example, if you use the bash shell, you can say in your perl script system( FIT_LOG=value gnuplot args ); Tanton - Original Message - From: Dan Fish [EMAIL PROTECTED] To: Perl List [EMAIL PROTECTED] Sent: Wednesday, July 17, 2002 1:27 PM Subject: Setting environment variable for process spawned with system() Okay... maybe this is just so simple that I can't see the forest through the trees, but I've never had a need to do it before and so that inherently makes it difficult :-) I've got a script that runs gnuplot via system(). In order to use a custom path for gnuplot's fit regression function, It looks for the environment variable FIT_LOG. How can I set an environment variable in the script that will be inherited by the system() process? Thanks, -Dan --- Old programmers never die... Unless of course they refuse to accept a few extra CPU cycles over months of efficiency tuning... [Have times changed or WHAT!] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Setting environment variable for process spawned with system()
kinda like this? system(qq/export FIT_LOG=check toilet; gnuplot -some options/); -Original Message- From: Dan Fish [mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 17, 2002 1:27 PM To: Perl List Subject: Setting environment variable for process spawned with system() Okay... maybe this is just so simple that I can't see the forest through the trees, but I've never had a need to do it before and so that inherently makes it difficult :-) I've got a script that runs gnuplot via system(). In order to use a custom path for gnuplot's fit regression function, It looks for the environment variable FIT_LOG. How can I set an environment variable in the script that will be inherited by the system() process? Thanks, -Dan --- Old programmers never die... Unless of course they refuse to accept a few extra CPU cycles over months of efficiency tuning... [Have times changed or WHAT!] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] The views and opinions expressed in this email message are the sender's own, and do not necessarily represent the views and opinions of Summit Systems Inc. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Setting environment variable for process spawned with system()
From: Dan Fish [EMAIL PROTECTED] Okay... maybe this is just so simple that I can't see the forest through the trees, but I've never had a need to do it before and so that inherently makes it difficult :-) I've got a script that runs gnuplot via system(). In order to use a custom path for gnuplot's fit regression function, It looks for the environment variable FIT_LOG. How can I set an environment variable in the script that will be inherited by the system() process? $ENV{FIT_LOG} = whatever; Jenda === [EMAIL PROTECTED] == http://Jenda.Krynicky.cz == There is a reason for living. There must be. I've seen it somewhere. It's just that in the mess on my table ... and in my brain I can't find it. --- me -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
exec statement
Hello, I am trying to go to a script from within a script. This is a Perl CGI script and I want to transfer to various other perl cgi scripts based on user selections. From what I read I want to use exec for this -- since I want to leave and not return to the transferring script. The trasferring program outputs a screen heading (as it should) and just sits there --I get no error message -- it doesn't matter what name I put in as the program that I am transferring to (even if I put in a garbage name) nothing seems to happen. I would have expected it to die and give me a message based on the garbage name. This is the code: # # # # # # # # # # # # # # # # # # # # # PRINT HEADING # # # # # # # # # # # # # # # # # # # # # # print Content-type: text/html\n\n; print Heading; HTMLHEADTITLECAE Solutions/TITLE/HEAD BODY BGCOLOR=teal TEXT=silver h1 align=centerCAE Solutions/h1 BR BR Heading # # # # # # # # # # # # # # # # # # # # # # # MAIN LOGIC # # # # # # # # # # # # # # # # # # # # # # if ($work_type eq 'en') { print I'm ready to leave\n\n; # exec(log_enh.cgi $validemp) exec(tslslslsestit.cgi $validemp) or die Couldni\'t go to log_enhi.cgi: $!\n; print I'm BACK \n\n; }; Thanks, Maureen -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
executing binaries
Lo all, What's the best way to execute a binary command from within perl, and read text returned by the binary, as well as write data to certain prompts that the program may have? Say, I have... #./myprogram This is my program, I will ask you a question now Please give me your name: WHATEVER Thank you. In this instance, I want to read the output from the program, wait for name:, and send it WHATEVER. Then, based on the exit code of the application, I want to execute various code (say, when the program exits successfully, of when there is a error) Does anyone have some pointers on this for me? How can I accomplish this.. To my understanding, both system() and exec() are out of bounds here... Or am I wrong? -- me -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: executing binaries
The Perl Cookbook recipie 16.8 says use the standard IPC::Open2 module: use IPC::Open2; open2(*README, *WRITEME, $program); print WRITEME Here's your input\n; $output = README; close(WRITEME); close(README); However, it warns that there could be problems if the other program buffers input or output. You should probably perldoc IPC::Open2 for all of the details. - Original Message - From: Chris Knipe [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, July 17, 2002 3:09 PM Subject: executing binaries Lo all, What's the best way to execute a binary command from within perl, and read text returned by the binary, as well as write data to certain prompts that the program may have? Say, I have... #./myprogram This is my program, I will ask you a question now Please give me your name: WHATEVER Thank you. In this instance, I want to read the output from the program, wait for name:, and send it WHATEVER. Then, based on the exit code of the application, I want to execute various code (say, when the program exits successfully, of when there is a error) Does anyone have some pointers on this for me? How can I accomplish this.. To my understanding, both system() and exec() are out of bounds here... Or am I wrong? -- me -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Perl constants with modules
Possibly time to step in here and suggest XML rather than creating some new or using some pre-existing config file standard. I am not an XML zealot, in fact I have been rather resistant to it for a while, but this sounds like opportunity knocking for it. That way coming up with parsing algorithm is not necessary and whoever maintains the code in 2 years won't have to ask about it Jeff 'japhy' Pinyan wrote: On Jul 16, Kevin Old said: Do you have any code for processing a config file and/or an example config file? There are plenty of config-file modules on CPAN. Search for config at http://search.cpan.org/. %mar_omc_and_mms = ( 'clt' = { 'omc2' = [qw(mm3 mm4)] }, 'clt1x' = { 'omc1' = [qw(mm101 mm102)], 'omc3' = [qw(mm5 mm6 mm7)] }, 'gvl' = { 'omc1' = [qw(mm1 mm2)], 'omc2' = [qw(mm3 mm4)] }, 'col' = { 'omc1' = [qw(mm1 mm2)] }, 'rdu' = { 'omc1' = [qw(mm1 mm2)] }, 'gso' = { 'omc1' = [qw(mm1 mm2)] }, 'chs' = { 'omc1' = [qw(mm1 mm2)] } ) You can create config files in any format you want. It just comes down to what's easiest for the END-USER to modify. Here's one: clt.omc2 = mm3 mm4 clt1x.omc1 = mm101 mm102 clt1x.omc3 = mm5 mm6 mm7 [etc] Here's another (a lispish fiend): (clt (omc2 mm3 mm4) ) (clt1x (omc1 mm101 mm102) (omc3 mm5 mm6 mm7) ) [etc] Here's yet another: %clt omc2 = mm3 mm4 %clt1x omc1 = mm101 mm102 omc3 = mm5 mm6 mm7 [etc] Just pick one you like, and come up with a parsing algorithm. The first and last ones are the easiest to parse in my opinion. The second one adds a layer of difficulty. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Working with hashes...
I may have missed something in the discussion as to the ultimate goal, but what about doing the sorting at the DB level, as this would seemingly make your code more readable and the DB is likely faster at this than Perl (as wonderful as it is). Or was the original intent to sort the keys of the field, which again I would think the DB should be able to handle this by realigning the field names in the initial select?? Jeff 'japhy' Pinyan wrote: On Jul 16, Shishir K. Singh said: while($db-FetchRow()){ %Data = $db-DataHash(First_Name,Last_Name); foreach $key (sort(keys %Data)) { print $key, '=', $Data{$key}, \n; } # end foreach print(\n); } Just curious. I assume that you are using DBI module. If so, I don't see the methods FetchRow and DataHash in the perldoc for DBI. I have version DBI 1.21. Am I missing something here ?? No, Ron is using the Win::ODBC module. Yes, its naming conventions and overall API suck. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: executing binaries
Thanks a million... I'll give the module a read or two or ten :p) Regards, Chris Knipe Cell: (072) 434-7582 MegaLAN Corporate Networking Services - Original Message - From: Tanton Gibbs [EMAIL PROTECTED] To: Chris Knipe [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Wednesday, July 17, 2002 9:25 PM Subject: Re: executing binaries The Perl Cookbook recipie 16.8 says use the standard IPC::Open2 module: use IPC::Open2; open2(*README, *WRITEME, $program); print WRITEME Here's your input\n; $output = README; close(WRITEME); close(README); However, it warns that there could be problems if the other program buffers input or output. You should probably perldoc IPC::Open2 for all of the details. - Original Message - From: Chris Knipe [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, July 17, 2002 3:09 PM Subject: executing binaries Lo all, What's the best way to execute a binary command from within perl, and read text returned by the binary, as well as write data to certain prompts that the program may have? Say, I have... #./myprogram This is my program, I will ask you a question now Please give me your name: WHATEVER Thank you. In this instance, I want to read the output from the program, wait for name:, and send it WHATEVER. Then, based on the exit code of the application, I want to execute various code (say, when the program exits successfully, of when there is a error) Does anyone have some pointers on this for me? How can I accomplish this.. To my understanding, both system() and exec() are out of bounds here... Or am I wrong? -- me -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: exec statement
-Original Message- From: Maureen E Fischer [mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 17, 2002 2:37 PM To: [EMAIL PROTECTED] Subject: exec statement Hello, I am trying to go to a script from within a script. This is a Perl CGI script and I want to transfer to various other perl cgi scripts based on user selections. From what I read I want to use exec for this -- since I want to leave and not return to the transferring script. The trasferring program outputs a screen heading (as it should) and just sits there --I get no error message -- it doesn't matter what name I put in as the program that I am transferring to (even if I put in a garbage name) nothing seems to happen. I would have expected it to die and give me a message based on the garbage name. This is the code: # # # # # # # # # # # # # # # # # # # # # PRINT HEADING # # # # # # # # # # # # # # # # # # # # # # print Content-type: text/html\n\n; print Heading; HTMLHEADTITLECAE Solutions/TITLE/HEAD BODY BGCOLOR=teal TEXT=silver h1 align=centerCAE Solutions/h1 BR BR Heading # # # # # # # # # # # # # # # # # # # # # # # MAIN LOGIC # # # # # # # # # # # # # # # # # # # # # # if ($work_type eq 'en') { print I'm ready to leave\n\n; # exec(log_enh.cgi $validemp) exec(tslslslsestit.cgi $validemp) or die Couldni\'t go to log_enhi.cgi: $!\n; print I'm BACK \n\n; }; Thanks, Maureen The exec will search your PATH to find the script, so you need something like: exec './myscript.pl', $validemp; die Couldn't exec: $!; In my testing, the die() would write to the error log properly. (Probably, you should specify the full path to the script and not make any assumptions about the current working directory when running under a CGI environment). Splitting the elements into a list here ensures that execvp(3) is called instead of /bin/sh. perldoc -f exec man 3 execvp -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: executing binaries
I had a look The documentation is *very* lacking. savage@netsonic:~/src# perl -MIPC::Open2 -e'open2($rd, $wr, ls -al); while ($rd) { print; } exit;' open2: wtr should not be null at -e line 1 Needless to say, I am *totally* clueless :((( - Original Message - From: Tanton Gibbs [EMAIL PROTECTED] To: Chris Knipe [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Wednesday, July 17, 2002 9:25 PM Subject: Re: executing binaries The Perl Cookbook recipie 16.8 says use the standard IPC::Open2 module: use IPC::Open2; open2(*README, *WRITEME, $program); print WRITEME Here's your input\n; $output = README; close(WRITEME); close(README); However, it warns that there could be problems if the other program buffers input or output. You should probably perldoc IPC::Open2 for all of the details. - Original Message - From: Chris Knipe [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, July 17, 2002 3:09 PM Subject: executing binaries Lo all, What's the best way to execute a binary command from within perl, and read text returned by the binary, as well as write data to certain prompts that the program may have? Say, I have... #./myprogram This is my program, I will ask you a question now Please give me your name: WHATEVER Thank you. In this instance, I want to read the output from the program, wait for name:, and send it WHATEVER. Then, based on the exit code of the application, I want to execute various code (say, when the program exits successfully, of when there is a error) Does anyone have some pointers on this for me? How can I accomplish this.. To my understanding, both system() and exec() are out of bounds here... Or am I wrong? -- me -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: strange query.
James Campbell wrote: Hi Everyone Hello, I'm having a spot of bother with a query string. The program below attempts to mimic a web form. It should post the value of 'QUERY ..' to the cgi in $location. What is actually happening is that 'QUERY ..' itself is being sent as the value. I copied the name 'QUERY ..' from the textarea name on the original web form. I have tried character escaping the space and the two dots but that didn't work (the cgi hung). Maybe I need to use CGI.pm to generate the query string? Anyone got any ideas? According to Ethereal the actual prefix sent is 'QUERY+..=' HTH John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: executing binaries
Chris Knipe wrote: savage@netsonic:~/src# perl -MIPC::Open2 -e'open2($rd, $wr, ls -al); while ($rd) { print; } exit;' open2: wtr should not be null at -e line 1 It may have to do with the fact that you can't write to ls...the following worked for me use IPC::Open2; use strict; my ($rd, $wr); open2($rd, $wr, bc); print $wr 5 + 7\n; my $x = $rd; print $x; close( $rd ); close( $wr ); Tanton -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: The True Guide to Learning Perl was Re: Thank You! :)
On 2002-07-16 12:22:45 -0700, drieux wrote: Or are you folks just DEMONS in PerlieCoderCloth, trying to lead the innocent into Perdition Perldition? };-) -- Morten Liebach [EMAIL PROTECTED], webpages at http://kallisti.dk/ PGP-key: http://kallisti.dk/ml.asc or Key-ID 0xD796A4EB on keyserver.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: executing binaries
-Original Message- From: Chris Knipe [mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 17, 2002 4:19 PM To: [EMAIL PROTECTED] Subject: Re: executing binaries I had a look The documentation is *very* lacking. savage@netsonic:~/src# perl -MIPC::Open2 -e'open2($rd, $wr, ls -al); while ($rd) { print; } exit;' open2: wtr should not be null at -e line 1 FWIW, This example worked fine for me. I did not get the error. I have zilch experience with IPC::Open2, so can't help further. I have sucessfully used Expect.pm for handling more complex interactions with applications... -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: executing binaries
I got it working on the shell now: savage@netsonic:~/src# perl -MIPC::Open2 -e'open2(*rd, *wr, /bin/ls -al); while (rd) { print; } exit;' total 32 drwxr-x--- 8 root wheel512 Jul 17 03:29 . drwxr-xr-x 8 root wheel512 Jul 16 05:38 .. -rwxr-x--- 1 root wheel 21955 Jul 17 22:36 ApacheReconfig drwxr-xr-x 5 640 15 1024 Jul 12 00:27 amavisd-snapshot-20020300 drwxr-x--- 2 root wheel512 Jul 8 01:49 ftpmail drwxr-x--- 4 root wheel512 Jul 9 07:33 mrtg-2.9.21 drwxr-x--- 9 root wheel 1024 Jul 13 21:44 nagios-1.0b4 drwxr-x--- 6 root wheel 1024 Jul 11 08:07 netsaint-plugins-1.2.9-4 drwxr-x--- 7 root wheel 2560 Jul 11 05:41 tpop3d-1.4.2 However, when I call it from my perl script: use strict; use IPC::Open2; open2(*rd, *wr, /bin/ls -al); while (rd) { print $_; } Sure, there's allot of other stuff in the perl script, mainly allot of database queries, and to open() / close() file handles, but needless to say, when I use open2() like this from the command line, it works. Inside my script it fails - Original Message - From: Tanton Gibbs [EMAIL PROTECTED] To: Chris Knipe [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Wednesday, July 17, 2002 10:27 PM Subject: Re: executing binaries Chris Knipe wrote: savage@netsonic:~/src# perl -MIPC::Open2 -e'open2($rd, $wr, ls -al); while ($rd) { print; } exit;' open2: wtr should not be null at -e line 1 It may have to do with the fact that you can't write to ls...the following worked for me use IPC::Open2; use strict; my ($rd, $wr); open2($rd, $wr, bc); print $wr 5 + 7\n; my $x = $rd; print $x; close( $rd ); close( $wr ); Tanton -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Comparison of two log files.
Denham Eva wrote: Hello listers, Hello, I would like to submit a script I have written and it does work. However I am sure that it can be: a. Shorter b. Faster As you will see it is not very well written. Certainly nothing compared to some of the listers code I have seen here. I am new at perl so here goes. Some of you might recognise the sample a part of a Oracle export log, which it is. Now I am not confident enough to use the unedited log and stripping it with perl(maybe oneday), anyway that has already been done with tools like grep and cut. Script #Perl Script to Compare two backup logs and then identify # substantial differences in changed tables. use strict; use warnings; #Open the newer backup log. open FILE, C:/tmp/max_grow/max1.log or die Cann't open : $!; while(FILE){ chomp; #Input to be divided in two: #Sample of file is - # APPDOCTYPE 43 #APPLAUNCH 16 # APTRANS 1245 # ARCHIVE 0 # ASICUST 24 # ASILINK 5 # ASSETATTRIBUTE736 # ASSETCLASS 1667 #ASSIGNMENT 60648 #ATTENDANCE 103193 #Divide the input into two groups s/(.*\D)+(.*\d)/$2 $1/; #Pass the two groups to variables my $value1 = $2; my $tblnam1 = $1; #Remove all unnecessary spaces. for ($tblnam1) { s/^\s+//; s/\s*$//;} for ($value1) { s/^\s+//; s/\s*$//;} #Open the older log open FILE2, C:/tmp/max_grow/max4.log or die Cann't open : $!; while(FILE2){ chomp; s/(.*\D)+(.*\d)/$2 $1/; my $value2 = $2; my $tblnam2 = $1; for ($tblnam2) { s/^\s+//; s/\s*$//;} for ($value2) { s/^\s+//; s/\s*$//;} # Compare the two logfiles here. if($tblnam1 eq $tblnam2) { my $diff = $value2 - $value1; if($diff 1000){ print $tblnam1 :The difference is $diff\n; } } } } I would probably do something like this: use strict; use warnings; my $log_new = 'C:/tmp/max_grow/max1.log'; my $log_old = 'C:/tmp/max_grow/max4.log'; my %data; #Open the newer backup log. open FILE, $log_new or die Cannot open $log_new: $!; while ( FILE ) { next unless my( $table, $value ) = /([A-Z]+)\s*(\d+)/; $data{$table} = $value; } close FILE; #Open the older log open FILE, $log_old or die Cannot open $log_old: $!; while ( FILE ) { next unless my( $table, $value ) = /([A-Z]+)\s*(\d+)/; # Compare the two logfiles here. if ( exists $data{$table} ) { my $diff = $value - $data{$table}; if ( $diff 1000 ) { print $table :The difference is $diff\n; } } } __END__ John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Compiling Perl Source
Hi - A quick look at perldoc perlcc shows that you must perlcc Pg.pm (or whatever .pm Pg is in) to create a shared object that can be used by your main program. (NB: the doc states that shared objects are not available for Win32). Also - perlcc is quite expermental - be careful! Aloha = Beau. -Original Message- From: Cleiton L. Siqueira [mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 17, 2002 9:58 AM To: [EMAIL PROTECTED] Subject: Compiling Perl Source Dear, I've tried to compile my code source with perlcc, but it has returned errors at the time of compilation. I've used the command line use Pg; and I think this is the problem, because if I remove this line the compilation gets success. The error returned at the time of compilation is: Compiling servicos.pl: Making C(servicos.pl.c) for servicos.pl! /usr/bin/perl -I/usr/libdata/perl/5.00503/mach -I/usr/libdata/perl/5.00503 - I/us r/local/lib/perl5/site_perl/5.005/i386-freebsd -I/usr/local/lib/perl5/site_p erl/ 5.005 -I. -MO=CC,-oservicos.pl.c servicos.pl servicos.pl syntax OK substcont: op = LOGOP (0x8277960) pp_substcont, pmop = PMOP (0x82782c0) pp_subst pmopsym = (OP*)pmop_list[3] substcont: op = LOGOP (0x8277760) pp_substcont, pmop = PMOP (0x8278040) pp_subst pmopsym = (OP*)pmop_list[4] No definition for sub Pg::PGRES_InvalidOid No definition for sub Pg::PGRES_InvalidOid (unable to autoload) No definition for sub Pg::PGRES_INV_SMGRMASK No definition for sub Pg::PGRES_INV_SMGRMASK (unable to autoload) PG_results has method DESTROY: -uPG_results assumed No definition for sub Pg::PGRES_CONNECTION_BAD No definition for sub Pg::PGRES_CONNECTION_BAD (unable to autoload) No definition for sub Pg::PGRES_FATAL_ERROR No definition for sub Pg::PGRES_FATAL_ERROR (unable to autoload) No definition for sub Pg::PGRES_EMPTY_QUERY No definition for sub Pg::PGRES_EMPTY_QUERY (unable to autoload) No definition for sub Pg::PGRES_CONNECTION_OK No definition for sub Pg::PGRES_CONNECTION_OK (unable to autoload) No definition for sub Pg::PGRES_INV_ARCHIVE No definition for sub Pg::PGRES_INV_ARCHIVE (unable to autoload) No definition for sub Pg::PGRES_COPY_OUT No definition for sub Pg::PGRES_COPY_OUT (unable to autoload) No definition for sub Pg::PGRES_BAD_RESPONSE No definition for sub Pg::PGRES_BAD_RESPONSE (unable to autoload) No definition for sub Pg::PGRES_TUPLES_OK No definition for sub Pg::PGRES_TUPLES_OK (unable to autoload) No definition for sub Pg::PGRES_INV_WRITE No definition for sub Pg::PGRES_INV_WRITE (unable to autoload) No definition for sub Pg::PGRES_COPY_IN No definition for sub Pg::PGRES_COPY_IN (unable to autoload) PG_conn has method DESTROY: -uPG_conn assumed No definition for sub Pg::PGRES_INV_READ No definition for sub Pg::PGRES_INV_READ (unable to autoload) No definition for sub Pg::PGRES_COMMAND_OK No definition for sub Pg::PGRES_COMMAND_OK (unable to autoload) No definition for sub Pg::PGRES_NONFATAL_ERROR No definition for sub Pg::PGRES_NONFATAL_ERROR (unable to autoload) Compiling C(servicos) for servicos.pl! /usr/bin/perl -I/usr/libdata/perl/5.00503/mach -I/usr/libdata/perl/5.00503 - I/us r/local/lib/perl5/site_perl/5.005/i386-freebsd -I/usr/local/lib/perl5/site_p erl/ 5.005 -I. /tmp/servicos.pl.tst cc -I/usr/libdata/perl/5.00503/mach/CORE /usr/local/lib/perl5/site_perl/5.005/ i386-freebsd/auto/Pg/Pg.so /usr/libdata/perl/5.00503/mach/auto/Fcntl/Fcntl.so -o servicos ervicos.pl.c -Wl,-E -lperl -lm -L/usr/libdata/perl/5.00503/mach/CORE -lperl -lm -lc -lcrypt /tmp/cct24774.o(.data+0x1d7c): undefined reference to `XS_Pg_PQlo_lseek' /tmp/cct24774.o(.data+0x1e60): undefined reference to `XS_Pg_PQlo_import' /tmp/cct24774.o(.data+0x1ef8): undefined reference to `XS_Pg_PQlo_export' /tmp/cct24774.o(.data+0x2028): undefined reference to `XS_Pg_PQlo_write' /tmp/cct24774.o(.data+0x21f0): undefined reference to `XS_Pg_PQlo_close' /tmp/cct24774.o(.data+0x2404): undefined reference to `XS_Pg_PQlo_read' /tmp/cct24774.o(.data+0x2dd0): undefined reference to `XS_Pg_PQlo_unlink' /tmp/cct24774.o(.data+0x2e1c): undefined reference to `XS_Pg_PQlo_tell' /tmp/cct24774.o(.data+0x2eb4): undefined reference to `XS_Pg_PQlo_open' /tmp/cct24774.o(.data+0x3160): undefined reference to `XS_Pg_PQlo_creat' ERROR: In compiling code for servicos.pl.c ! Thanks, Cleiton L. Siqueira Colégio Monjolo [EMAIL PROTECTED] (0xx45) 520-1915 Esta mensagem foi enviada pelo sistema MONJOLO WEBMAIL http://www.colegiomonjolo.com.br This e-mail was scanned by RAV AntiVirus! Esta mensagem foi verificada pelo Monjolo Antivirus. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Perl constants with modules
From: Wiggins d'Anconia [EMAIL PROTECTED] Possibly time to step in here and suggest XML rather than creating some new or using some pre-existing config file standard. I am not an XML zealot, in fact I have been rather resistant to it for a while, but this sounds like opportunity knocking for it. That way coming up with parsing algorithm is not necessary and whoever maintains the code in 2 years won't have to ask about it Rarely is the configuration complex enough to require XML. Plain old INI or config type files are usualy easier to modify by hand. There are many modules for reading/writing these types of files, search the CPAN. Jenda === [EMAIL PROTECTED] == http://Jenda.Krynicky.cz == There is a reason for living. There must be. I've seen it somewhere. It's just that in the mess on my table ... and in my brain I can't find it. --- me -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Can get script to print to command prompt no matter what I try
Ooops.. is this problem still not yet solved ?! :-( Hmmm. I don't know if this is OT of not, but seems that would be a problem for Win32 beginners need to deal with If a dosprompt is too difficult to deal with, let's return to the idea of using double click. You'll say, the screen disappear immediately, right, but you can make it not to disappear. Start - Run - dosprmpt - Enter You will see either the full black screen, or a window of dosprmpt If you see the full black screen, press Alt-Enter to make it become a window. Then there are some buttons on the top of the window, one of it is option ( A finger point to a paper ), click it. A properties panel then appear, In the program tab, uncheck the box Close ( X ), and apply it. The screen will not goes off when next time you double click on your perl files after end. Rgds, Connie I have tried numerous variations of this simple script: print (hello\n); perl -e print qq~Hello\n~ C:\ perl print Hello\n; then press 'controll Z' print hello; and press 'control C' Nothing works. I can run a pre written script, but that is it. I have the camel book and none of the sample scripts will run. HELP!!! Cory Moore Campaign Manager Pat Ahumada for Congress www.patforcongress.com www.americanvirtue.com --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.377 / Virus Database: 211 - Release Date: 7/15/2002 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: find biggest number
snip Ok, it's a slow day, I'll bite at that. Try as I might. I can't make your sort beat my map-based linear search. /snip Well, forcing the sort to copy the entire array isn't exactly fair. The proper way to write the sort based max is my $max = (sort { $a = $b } @array)[-1]; This keeps Perl from copying the entire array (it only grabs the last element). Here are my benchmark results with three added cases:a naive Perl foreach loop, a shorter Perl for loop, a version of your map based max (let me know if you have problems with my cut down version), and a version written with Inline::C. output Sample set is 10 Rate map for naive sort Inline::C map63232/s-- -1% -5% -63% -81% for63735/s1%-- -4% -63% -81% naive 66248/s5%4%-- -61% -80% sort 171775/s 172% 170% 159%-- -48% Inline::C 331567/s 424% 420% 400% 93%-- Sample set is 100 Rate map for naive sort Inline::C map 9091/s-- -18% -19% -31% -95% for11035/s 21%-- -2% -16% -93% naive 11240/s 24%2%-- -15% -93% sort 13159/s 45% 19% 17%-- -92% Inline::C 169712/s 1767% 1438% 1410% 1190%-- Sample set is 200 Rate map sort for naive Inline::C map 4787/s-- -12% -17% -20% -96% sort5444/s 14%-- -6% -9% -95% for 5781/s 21%6%-- -3% -95% naive 5985/s 25% 10%4%-- -95% Inline::C 114686/s 2296% 2006% 1884% 1816%-- Sample set is 1000 Rate sort map for naive Inline::C sort806/s-- -17% -31% -36% -97% map 976/s 21%-- -16% -22% -97% for1169/s 45% 20%-- -7% -96% naive 1252/s 55% 28%7%-- -96% Inline::C 29954/s 3614% 2968% 2462% 2292%-- Sample set is 1 Rate sort map for naive Inline::C sort 42.1/s-- -48% -62% -64% -96% map 81.2/s 93%-- -27% -30% -93% for111/s 163% 36%-- -5% -90% naive 117/s 177% 44%5%-- -90% Inline::C 1117/s 2552% 1275% 910% 858%-- Sample set is 10 Rate sort map for naive Inline::C sort 2.12/s-- -73% -80% -81% -97% map 7.77/s 266%-- -27% -31% -89% for 10.6/s 400% 37%-- -6% -86% naive 11.3/s 434% 46%7%-- -85% Inline::C 73.9/s 3385% 852% 597% 553%-- output Personally I find the results amazing. I would have sworn that the for version of max would have beaten the naive version, but it never did. As we can see from the results the best case is always the Inline::C version of max (as expected); however Inline::C is not always available, so the next best thing is the sort version of max for sample sets = 100 and the naive version of max for all other sample sets. code #!/usr/bin/perl use strict; use Benchmark; use Inline 'C'; our @array; my %sub = ( 'sort' = sub { our @array; return (sort { $a = $b } @array)[-1]; }, 'map' = sub { our @array; my $max = $array[0]; map { ($max $_)?($max = $_):undef } @array; return $max; }, 'naive' = sub { our @array; my $max = $array[0]; foreach my $current (@array) { if ($max $current) { $max = $current } } return $max; }, 'for' = sub { our @array; my $max = $array[0]; $max $_ ? $max = $_ : undef for @array; return $max; }, 'Inline::C' = sub { our @array; return Max(@array); } ); foreach my $array_size (10,100,200,1_000,10_000,100_000) { our @array = map { .5 - rand } (0..$array_size); my $max; print Sample set is $array_size\n; my $results = Benchmark::timethese(-3, \%sub, 'none'); Benchmark::cmpthese($results); print \n; } __END__ __C__ void Max (SV* first_element, ...) { Inline_Stack_Vars;
Inline::C
On Wednesday, July 17, 2002, at 03:21 , Chas Owens wrote: [..] however Inline::C is not always available, [..] http://search.cpan.org/search?dist=Inline yes from the Readme it notes: Inline saves you from the hassle of having to write and compile your own glue code using facilities like XS or SWIG. Simply type the code where you want it and run your Perl as normal. All the hairy details are handled for you. The compilation and installation of your code chunks all happen transparently; all you will notice is the delay of compilation on the first run. Hence the limiting factor is the existence of a compiler on the host where the code will run Or is there a way to get the C code to pre-compile and ship that, as one can do with the XS 'hassle' approach He said noting some of the info available in the document ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Inline::C
On Wed, 2002-07-17 at 19:02, drieux wrote: On Wednesday, July 17, 2002, at 03:21 , Chas Owens wrote: [..] however Inline::C is not always available, [..] http://search.cpan.org/search?dist=Inline yes from the Readme it notes: Inline saves you from the hassle of having to write and compile your own glue code using facilities like XS or SWIG. Simply type the code where you want it and run your Perl as normal. All the hairy details are handled for you. The compilation and installation of your code chunks all happen transparently; all you will notice is the delay of compilation on the first run. Hence the limiting factor is the existence of a compiler on the host where the code will run Or is there a way to get the C code to pre-compile and ship that, as one can do with the XS 'hassle' approach He said noting some of the info available in the document ciao drieux Well, Inline creates a directory called (by default) _Inline in the directory where the perl script resides that holds the compiled C code (and some form of checksum to keep it from recompiling unless it needs to). I would guess it is possible to copy that directory to your target platform (assuming they are have binary compatibility). I think I remember reading in the docs that it is possible to create a module using Inline that is compiled on one machine and delivered to another. jokeAll of this should be moot anyways since all machines snide voiceworth using/snide voice come with a compiler./joke -- Today is Pungenday the 52nd day of Confusion in the YOLD 3168 Grudnuk demand sustenance! Missile Address: 33:48:3.521N 84:23:34.786W -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Flat File Db
I'm use flat files to manage a list containing approx 25,000 records. For updates, I write to a temp file then unlink main and rename temp file to main. I use flock for both temp and main files during update. My main file gets blown away on occasions. What gives? I can't figure out why this happens. Thanks for any help! Jeff -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Flat File Db
Jeff wrote: I'm use flat files to manage a list containing approx 25,000 records. For updates, I write to a temp file then unlink main and rename temp file to main. I use flock for both temp and main files during update. My main file gets blown away on occasions. What gives? I can't figure out why this happens. Thanks for any help! OS? code? John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Flat File Db
John, unix, sub Update_db { $main_db = $_[0]; $tmp_db = $_[1]; $update = $_[2]; open IN, $main_db or print Can't open $main_db: $!\n; flock( IN, LOCK_EX ) or print Unable to acquire lock: $!. Aborting; open OUT, $tmp_db or print Can't open temporary file $tmp_db: $!\n; flock( OUT, LOCK_EX ) or print Unable to acquire lock: $!. Aborting; while ( IN ) { ($name, $team, $location)= split(/\|/, $_); next unless $name eq $update; $new_location = palm_bay; $_ = join( |, $name, $team, $new_location); } continue { print OUT $_ or print Error writing $tmp_db: $!\n; } close IN; close OUT; unlink $main_db; rename $tmp_db, $main_db or print Can't rename '$tmp_db' to '$main_db': $!\n; } -Original Message- From: John W. Krahn [mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 17, 2002 8:11 PM To: [EMAIL PROTECTED] Subject: Re: Flat File Db Jeff wrote: I'm use flat files to manage a list containing approx 25,000 records. For updates, I write to a temp file then unlink main and rename temp file to main. I use flock for both temp and main files during update. My main file gets blown away on occasions. What gives? I can't figure out why this happens. Thanks for any help! OS? code? John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Flat File Db
You have a race condition due to your flock being cancelled when you close the file. A open IN A flock IN A open OUT (truncates $tmp_db) A while loop B blocks A close IN B open IN A close OUT B open OUT (truncates $tmp_db) A unlinks main_db A tries to move $tmp_db to $main_bd, but $tmp_db is empty. If you're married to using flock, you can flock a semaphore file for the whole operation: sub Update_db { $main_db = $_[0]; $tmp_db = $_[1]; $update = $_[2]; $lock_file = 'somefile'; open LOCK, $lock_file; flock( LOCK, LOCK_EX ) or print Unable to acquire lock: $!. Aborting; #ps, this is a blocking call, it shouldnt fail open IN, $main_db or print Can't open $main_db: $!\n; open OUT, $tmp_db or print Can't open temporary file $tmp_db: $!\n; while ( IN ) { ($name, $team, $location)= split(/\|/, $_); next unless $name eq $update; $new_location = palm_bay; $_ = join( |, $name, $team, $new_location); } continue { print OUT $_ or print Error writing $tmp_db: $!\n; } close IN; close OUT; unlink $main_db; rename $tmp_db, $main_db or print Can't rename '$tmp_db' to '$main_db':$!\n; flock(LOCK, LOCK_UN); close(LOCK); } Otherwise you consider using a semaphore (perldoc IPC::Semaphore). On Wednesday, July 17, 2002, at 08:31 PM, Jeff wrote: John, unix, sub Update_db { $main_db = $_[0]; $tmp_db = $_[1]; $update = $_[2]; open IN, $main_db or print Can't open $main_db: $!\n; flock( IN, LOCK_EX ) or print Unable to acquire lock: $!. Aborting; open OUT, $tmp_db or print Can't open temporary file $tmp_db: $!\n; flock( OUT, LOCK_EX ) or print Unable to acquire lock: $!. Aborting; while ( IN ) { ($name, $team, $location)= split(/\|/, $_); next unless $name eq $update; $new_location = palm_bay; $_ = join( |, $name, $team, $new_location); } continue { print OUT $_ or print Error writing $tmp_db: $!\n; } close IN; close OUT; unlink $main_db; rename $tmp_db, $main_db or print Can't rename '$tmp_db' to '$main_db': $!\n; } -Original Message- From: John W. Krahn [mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 17, 2002 8:11 PM To: [EMAIL PROTECTED] Subject: Re: Flat File Db Jeff wrote: I'm use flat files to manage a list containing approx 25,000 records. For updates, I write to a temp file then unlink main and rename temp file to main. I use flock for both temp and main files during update. My main file gets blown away on occasions. What gives? I can't figure out why this happens. Thanks for any help! OS? code? John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] // George Schlossnagle // Principal Consultant // OmniTI, Inc http://www.omniti.com // (c) 240.460.5234 (e) [EMAIL PROTECTED] // 1024D/1100A5A0 1370 F70A 9365 96C9 2F5E 56C2 B2B9 262F 1100 A5A0 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Flat File Db
Jeff wrote: From: John W. Krahn [mailto:[EMAIL PROTECTED]] Jeff wrote: I'm use flat files to manage a list containing approx 25,000 records. For updates, I write to a temp file then unlink main and rename temp file to main. I use flock for both temp and main files during update. My main file gets blown away on occasions. What gives? I can't figure out why this happens. Thanks for any help! OS? code? unix, sub Update_db { $main_db = $_[0]; $tmp_db = $_[1]; $update = $_[2]; open IN, $main_db or print Can't open $main_db: $!\n; flock( IN, LOCK_EX ) or print Unable to acquire lock: $!. Aborting; open OUT, $tmp_db or print Can't open temporary file $tmp_db: $!\n; flock( OUT, LOCK_EX ) or print Unable to acquire lock: $!. Aborting; while ( IN ) { ($name, $team, $location)= split(/\|/, $_); next unless $name eq $update; $new_location = palm_bay; $_ = join( |, $name, $team, $new_location); } continue { print OUT $_ or print Error writing $tmp_db: $!\n; } close IN; close OUT; unlink $main_db; rename $tmp_db, $main_db or print Can't rename '$tmp_db' to '$main_db': $!\n; } The main problem appears to be that instead of taking a different branch if open() or flock() fails you continue on as if they had succeeded. sub Update_db { my ( $main_db, $tmp_db, $update ) = @_; local ( *IN, *OUT ); unless ( open IN, $main_db ) { print STDERR Can't open $main_db: $!; return; } unless ( flock IN, LOCK_EX ) { print STDERR Unable to acquire lock: $!. Aborting; return; } unless ( open OUT, $tmp_db ) { print STDERR Can't open temporary file $tmp_db: $!; return; } unless ( flock OUT, LOCK_EX ) { print STDERR Unable to acquire lock: $!. Aborting; return; } while ( IN ) { my ( $name, $team, $location ) = split /\|/; next unless $name eq $update; # # Why are you assigning a literal string to this variable here $new_location = palm_bay; # unless ( print OUT join '|', $name, $team, $new_location ) { print STDERR Error writing $tmp_db: $!\n; return; } } unless ( unlink $main_db ) { print STDERR Unable to unlink $main_db: $!. Aborting; return; } rename $tmp_db, $main_db or print STDERR Can't rename '$tmp_db' to '$main_db': $!; } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Flat File Db
John W. Krahn wrote: Jeff wrote: From: John W. Krahn [mailto:[EMAIL PROTECTED]] Jeff wrote: I'm use flat files to manage a list containing approx 25,000 records. For updates, I write to a temp file then unlink main and rename temp file to main. I use flock for both temp and main files during update. My main file gets blown away on occasions. What gives? I can't figure out why this happens. Thanks for any help! OS? code? unix, sub Update_db { $main_db = $_[0]; $tmp_db = $_[1]; $update = $_[2]; open IN, $main_db or print Can't open $main_db: $!\n; flock( IN, LOCK_EX ) or print Unable to acquire lock: $!. Aborting; open OUT, $tmp_db or print Can't open temporary file $tmp_db: $!\n; flock( OUT, LOCK_EX ) or print Unable to acquire lock: $!. Aborting; while ( IN ) { ($name, $team, $location)= split(/\|/, $_); next unless $name eq $update; $new_location = palm_bay; $_ = join( |, $name, $team, $new_location); } continue { print OUT $_ or print Error writing $tmp_db: $!\n; } close IN; close OUT; unlink $main_db; rename $tmp_db, $main_db or print Can't rename '$tmp_db' to '$main_db': $!\n; } The main problem appears to be that instead of taking a different branch if open() or flock() fails you continue on as if they had succeeded. sub Update_db { my ( $main_db, $tmp_db, $update ) = @_; local ( *IN, *OUT ); unless ( open IN, $main_db ) { print STDERR Can't open $main_db: $!; return; } unless ( flock IN, LOCK_EX ) { print STDERR Unable to acquire lock: $!. Aborting; return; } unless ( open OUT, $tmp_db ) { print STDERR Can't open temporary file $tmp_db: $!; return; } unless ( flock OUT, LOCK_EX ) { print STDERR Unable to acquire lock: $!. Aborting; return; } while ( IN ) { my ( $name, $team, $location ) = split /\|/; next unless $name eq $update; # # Why are you assigning a literal string to this variable here $new_location = palm_bay; # unless ( print OUT join '|', $name, $team, $new_location ) { print STDERR Error writing $tmp_db: $!\n; return; } } # sorry, forgot the close close OUT; close IN; unless ( unlink $main_db ) { print STDERR Unable to unlink $main_db: $!. Aborting; return; } rename $tmp_db, $main_db or print STDERR Can't rename '$tmp_db' to '$main_db': $!; } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Flat File Db
The main problem appears to be that instead of taking a different branch if open() or flock() fails you continue on as if they had succeeded. flock($fh,LOCK_EX ) is a blocking call, so it won't return until the lock is available. // George Schlossnagle // Principal Consultant // OmniTI, Inc http://www.omniti.com // (c) 240.460.5234 (e) [EMAIL PROTECTED] // 1024D/1100A5A0 1370 F70A 9365 96C9 2F5E 56C2 B2B9 262F 1100 A5A0 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Comparison of two log files.
Thanks to Sudarshan and John, for the suggestions. Very much appreciated! Rgds Denham DISCLAIMER This message is for the named person's use only. It may contain confidential, proprietary or legally privileged information. No confidentiality or privilege is waived or lost by any mistransmission. If you receive this message in error, please immediately delete it and all copies of it from your system, destroy any hard copies of it and notify the sender. You must not, directly or indirectly, use, disclose, distribute, print, or copy any part of this message if you are not the intended recipient. TFMC, its holding company, and any of its subsidiaries each reserve the right to monitor and manage all e-mail communications through its networks. Any views expressed in this message are those of the individual sender, except where the message states otherwise and the sender is authorized to state them to be the views of any such entity. _ This e-mail message has been scanned for Viruses and Content and cleared by MailMarshal For more information please visit www.marshalsoftware.com _