Re: Flock and Sleep
Sara wrote: (sub get_number { open(NUMBER,data.txt); flock (NUMBER, 2); Use the constants from the Fcntl module. Do blah blah blah close (NUMBER); closing a file automatically removes the lock?? Yes. or should I have to unlock it by placing flock (NUMBER, 8); close (NUMBER); No, you don't need to do that. In fact, it used to be dangerous, because of buffering. If you unlocked the file, buffered data could be written after the lock was released. Perl now automatically flushes the file before unlocking to avoid this. Bottom line: if you're going to close the file, don't worry about explicitly unlocking. You only need to unlock if you want to allow another process to gain the lock while you still hold the file open (i.e. coordinating changes to the file among multiple processes). My second question is how I can delay the execution of a script (If two users trying to execute the same script) for 30 sec by using sleep function? and If I implement sleep function in my script . Do I really need to use 'flock' in my script or there is no need then. If you want to make sure the two programs aren't changing the file simultaneously, you should use flock. If you dont' want to block forever if another process has the file locked, you need to use the LOCK_NB parameter and then sleep() or whatever until you want to retry the lock. Note that if multiple processes need to append to the file and each writes its data with individual calls to syswrite(), you don't need to use locking (although it doesn't really hurt anything). The kernel will perform individual writes atomically. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Perl line breaks
This code is working fine under Windows, but maybe you have made some mistakes in your subroutine that prints the header... You don't need to print so many separate lines using the print ...; function. You can use: print EOF; html /html EOF Teddy, Teddy's Center: http://teddy.fcc.ro/ Email: [EMAIL PROTECTED] - Original Message - From: Mike Harrison [EMAIL PROTECTED] To: 'Octavian Rasnita' [EMAIL PROTECTED]; Jon Hogue [EMAIL PROTECTED] Cc: 'Andrew Brosnan' [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Wednesday, August 06, 2003 2:24 AM Subject: RE: Perl line breaks I was trying to find a log file to look at. I guess half the problem is I am using a hosting service, and it is on a Microsoft IIS server (Windows NT-based I think, but definitely not UNIX). I will have to ask the hosting admin where I might find a log file... Here is the part of the perl script that I start printing things to the browser (see previous message for the html.pm script that contains the HTML_header and HTML_ender subroutines): my $header = 'Successful update'; my $msg = h2Your preferences have been updated successfully.../h2hrbrbrbr; # Finally, put up a HTML document announcing that the update was successful. HTML_header($header); print body\n; print center\n; print $msg\n; print pReturn to the a href=\amtest.pl?uname=$uname\ onMouseover=\window.status='Back to account management'; return true\ onMouseout=\window.status=''; return true\Account Management/a page/p\n; print /center\n; HTML_ender; Note that I have also tried using print qq| ... | code as well. I am now getting a CGI error message along the lines of Cannot find a string terminator '' in ... line ... (the line above starting with print p... . I can't find a problem with that line??? Thanks for your help so far guys! I am losing a bit of sleep on this one :( Regards, Mike. -Original Message- From: Octavian Rasnita [mailto:[EMAIL PROTECTED] Sent: Wednesday, 06 August, 2003 2:30 AM To: Jon Hogue Cc: Mike Harrison; 'Andrew Brosnan'; [EMAIL PROTECTED] Subject: Re: Perl line breaks For troubleshooting a script you can take a look in the server's log file and you will find there any error. Teddy, Teddy's Center: http://teddy.fcc.ro/ Email: [EMAIL PROTECTED] - Original Message - From: Jon Hogue [EMAIL PROTECTED] To: Octavian Rasnita [EMAIL PROTECTED] Cc: Mike Harrison [EMAIL PROTECTED]; 'Andrew Brosnan' [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Tuesday, August 05, 2003 4:19 PM Subject: Re: Perl line breaks ...and you don't need to print the HTML header in the BEGIN {} block. You can just print it at the top of the perl program or in the middle of the program but before anything else is printed. if something is dieing in a module you are loading, you will never know about it because it will never get to the Content-Type and therefore never send anything good to your browser. if you use a BEGIN block, you might catch things that happen in modules you load. i wouldn't recommend doing that for your normal script, but it is a useful troubleshooting tool. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: obtain web page contents with perl through a proxy server
Hi, look at LWP; module at perldoc.com, search.cpan.org or on yahoo. I forgot how to use it. Since it has been long time ago. awards -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Escaping
Hi everybody, I've written a script that retrieves data from a database and uses this data to built a list of links. snippet-- print(a href='nextscript.pl?subchpt=$result-{subchapter}'More.../a); snippet-- Unfortunatly one Subchapter is named 'MA'. So when I try to retrieve the param subchpt my $subchpt = $q-param('subchpt'); I get $subchpt = 'M' So my question is: Is there a possibility to escape the ? Greetings Marcus Marcus Willemsen Online Redaktion Juve Verlag GmbH Sachsenring. 6 50677 Köln ++49 (0)221 91 38 80 16 www.juve.de Geschäftsführer: Dr. Astrid Gerber, Dr. Aled W. Griffiths Sitz der Gesellschaft: Köln Amtsgericht Köln HRB 29593, Gerichtsstand: Köln Bankverbindung: Stadtsparkasse Köln, BLZ 37050198, Kto-Nr. 4772281
obtain web page contents with perl through a proxy server
Hi, I am a new perl user. I have a question of obtaining web page contents with perl. Hope you can help me. Here is my question: how can I use perl to access a webpage, fill in some search parameters, pull out parts of the search results returned that I really need and save them in a file? For example, a web site has some information about a bunch of companies for various years. After one puts in the company name and the relevant years, one would be directed to another page that has the text contents needed. I have the file containing the company names and the years I want. Since the number of companies I have is large, it would be really nice to have perl pull out the contents for me. Could it do this? How? What if I need to access the web page through a proxy server? Once again, I am new to the perl community and I am sorry if the question is too simple. But I do need you help. Thanks a lot. Wendy __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: obtain web page contents with perl through a proxy server
Here is a simple example from one of my scripts. You can use the method of mirror, getstore, use LWP::Simple; if(is_success(getstore(http://$sitename/wsp/scripts/$cgiscript/data.txt,/$pkg::cgiroot/$pkg::cgidir/admin/scripts/$cgiscript/data.txt;))){ print STDERR \n Transfered http://$hostprog/wsp/scripts/$cgiscript/data.txt;; }else{print STDERR \n Couldn't transfer file $!; print STDERR \n Couldn't transfered http://$hostprog/wsp/scripts/$cgiscript/data.txt;} } #this is from this page at cpan: http://search.cpan.org/author/GAAS/libwww-perl-5.69/lib/LWP/Simple.pm perl -MLWP::Simple -e 'getprint http://www.sn.no;' use LWP::Simple; $content = get(http://www.sn.no/;); die Couldn't get it! unless defined $content; if (mirror(http://www.sn.no/;, foo) == RC_NOT_MODIFIED) { ... } if (is_success(getprint(http://www.sn.no/;))) { ... } --- wendy soros [EMAIL PROTECTED] wrote: Hi, I am a new perl user. I have a question of obtaining web page contents with perl. Hope you can help me. Here is my question: how can I use perl to access a webpage, fill in some search parameters, pull out parts of the search results returned that I really need and save them in a file? For example, a web site has some information about a bunch of companies for various years. After one puts in the company name and the relevant years, one would be directed to another page that has the text contents needed. I have the file containing the company names and the years I want. Since the number of companies I have is large, it would be really nice to have perl pull out the contents for me. Could it do this? How? What if I need to access the web page through a proxy server? Once again, I am new to the perl community and I am sorry if the question is too simple. But I do need you help. Thanks a lot. Wendy __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: how do i list the methods connected to a object?
Jenda Krynicky wrote: Guess what methods does this object support ;-) package Len; sub new { my $self; bless \$self, 'Len'; } sub AUTOLOAD { $AUTOLOAD =~ s/^.*:://; return length($AUTOLOAD); } Nice one Jenda! But I couldn't find it on CPAN :-/ Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Help with Unlink please
On Wed, Aug 06, 2003 at 11:49:20PM -0400, perlwannabe wrote: I have made the script as simple as possible and cannot get unlink to work. unlink (c:\testdir\*030977*.*) || die unlink failed: $!; You'd need to expand the wildcards yourself: my $pat = 'c:\testdir\*030977*.*'; foreach (glob($pat)) { unlink or warn Couldn't unlink '$_': $!; } And be careful with double-quotes and backslashes. I have even simplified further using a file test.txt and using unlink (test.txt); this also failed. What was the error this time? (Maybe you're in the wrong directory.) -- Steve -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: While loop on a file handle
--On Wednesday, August 06, 2003 2:50 PM +0200 Jenda Krynicky [EMAIL PROTECTED] wrote: From: Morrison, Trevor (Trevor) [EMAIL PROTECTED] What I am trying to do is to process a file that has say 1000 orders in it all pretty much of the same format. I want to open up the file, and then using a while loop go down through all of the order one-at-a-time and once I have all the fields populated and I have reached a certain line at the end of each order write the data to the database. Then have it all reset, and process the next order; and do this until the EOF. That is the goal. Seems you want something like this (untested of course): use Switch; my %order; while (IN) { chomp; switch ($_) { case /^(\w+)\s*: *(.*)/ {$order{lc($1)} = $2} case /^ORDER END MARKER/ { save_the_order(\%order); undef %order; } else {print Incorrectly formated line $.: $_\n} } } This assumes that the order file looks somewhat like this: Name: John Doe Amount: 10 Goods: gun XYZ-12345 Sum: 10100 ORDER END MARKER Name: John Doe Amount: 1 Goods: machinegun ABC-987 Sum: 2000 ORDER END MARKER If it's the case that the end-of-order marker is a constant string, it can be a little shorter: $/=ORDER END MARKER\n; while (DATA) { chomp; my %order = split /\n|:\s*/; save_order( \%order ); } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to replace a text in a file
Vinay Thombre wrote at Tue, 05 Aug 2003 17:31:32 +0530: I am novice to Perl and learning very basic things. I want to replace a text in a file with new text. I want to do it programatically. How can I do that? What have you learned so far yet? What is your tutorial? What does it say about replacting texts in a file? What have you tried so far? What are your exact problems? I'm asking as it is simpler to write a good answer if we know more about your knowledge and the problems you are running. Especially as it is hard to believe that no example of a file changing is shown in any tutorial. I do not want to use Perl command line argumanets. Can anyone help? Well, you could e.g. do something like use strict; use warnings; open FILE, 'filename' or die Can't open file: $!; open TEMP, 'filename.bak' or die Can't open temporary file: $!; while (FILE) { s/windows/linux/; # Upgrade your system print TEMP; } close FILE; close TEMP; rename 'filename.bak', 'filename' or die Could not rename temporary to actually file: $!; Another way would be perhaps to use the module Tie::File. But why won't you use command line arguments? The whole above script could be rewritten as perl -pi -e 's/windows/linux' filename what is much easier. Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Net::FTP question
On Wed, 6 Aug 2003 12:38:04 -0700, Michael Adrian [EMAIL PROTECTED] wrote: I have a question re Net::FTP. I would like to change the record size when I 'put' the file I'm ftp'ing. What argument would I use, if any to do this? Though I don't know how universal it is (as I am a unix guy not a mainframe one), we use a 'SITE' command with specific paramaters to set the record type/record length. Something along the lines of: LRECL=1331 RECFM=FB There is a 'site' method that will allow you to send such commands It this what you meant by record size? my $site = 'LRECL=1331 RECFM=FB'; my $site_result = $ftp-site($site); unless ($site_result) { die Can't set 'site': . $ftp-message; } print SITE command successful\n; I'm not sure if this is what you want or not but... You might need to do a step by step version of put() instead of using put(): my $write = $ftp-stor($file); $write-write($t, $sizeyouwanttosenditin); $write-close(); HTH DMuey -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
How to read a bitMap file with Perl ?
Hello all, Incase of reading a bitmap file into an array variable , if I have to get the hex value do I have to convert the bitmap file into Hex before sending it into an array variable or after reading the bitmap file into an array what should I do if I want the bitmap file data to be output as hexvalue into an another file.I hope I did not confuse anyone with my question. Cheers, Hari - Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software
RE: http paths in @INC
Yep, the require doc says that clearly. I should have read it first before posting. Just got things working ;) -Sharad -Original Message- From: Bob Showalter [mailto:[EMAIL PROTECTED] Sent: Wednesday, August 06, 2003 6:00 PM To: Gupta, Sharad; [EMAIL PROTECTED] Subject: Re: http paths in @INC Gupta, Sharad wrote: Hi All, Can i have something like http:://Somepath in @INC. No. It is possible to write code allowing simple modules to be fetched via HTTP and compiled.
RE: how to do paging of records
oracle doesnt accept a limit clause, so i have to work around that, any ideas! i been stuck on this issue over a few days... -Original Message- From: Gary Stainburn [mailto:[EMAIL PROTECTED] Sent: Wednesday, August 06, 2003 8:57 AM To: Coello, David; [EMAIL PROTECTED] Subject: Re: how to do paging of records On Wednesday 06 Aug 2003 1:40 pm, Coello, David wrote: can anyone help me on how to do paging of records i want a few records per page, im using oracle 8i.!!! and cgi. david I personally would look at LIMIT and OFFSET clauses for your select statement to enable you to choose the chunk of records retrieved -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Eval for module
That's because eval BLOCK still compiles the block at compile-time. You want to use eval EXPR. eval 'use Module ...; 1'; if ($@) { uh oh } You can also use q{} instead of single quotes for more code-like appearance. Excellent Jeff! Thanks for that tid bit I missed it somewhere along the way. Works perfect! Thanks Dan -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
CGI text process question
Hello all, this is my first post to this group, and I hope it isn¹t inappropriate. Anyway I have the following code in a CGI I¹m working on, it¹s supposed to translate the ugly %(hexhex) markers for non-alphanumeric characters back into normal text and assign the results to elements of an array. In the following script $in has a sample line of form input to give you a better idea of what¹s going on: $in = protocol=nserver=www.a.this%2Fis%2F%7Esilly.htmlregex=babo%5Bd%7Ce%5D; @in = split(//,$in); foreach $inp (@in) { $inp =~ s/^.*=//; (@hxcodes) = ($inp =~ /\%(\w\w)/g); $nummatches = $#hxcodes + 1; if ($nummatches == 0) { print($inp,\n); next; } elsif ($nummatches 0) { for ($i=0;$i = $nummatches;$i++) { $trans{$hxcodes[$i]} = pack(C,hex($hxcodes[$i])); $inp =~ tr/%//d; $inp =~ s/$hxcodes[$i]/$trans{$hxcodes[$i]}/; } } print($inp,\n); } When I try this at home (on MacPerl) and at school (using standard Unix Perl in OSX) the script works perfectly; however when I try to run it as a CGI on the server (which is running Perl 5.006001) I get a blank page: presumably the script is not generating any errors (at least according to the error log), but it isn¹t giving me any results either. Does anyone have any idea why that might be? Also I¹m a total novice at Perl, so please no rude comments about my awkward coding (instructive comments about my awkward coding would be more than welcome). Thanks in advance! Ben [EMAIL PROTECTED]
Fw: Can Perl dealing with PID ?
Is there any module in Perl can dealing with Procession ID on Win32? And does Perll able to stop or start a services / application? Any pointers where I can start from ? Thank you very much...
Re: Simple question
You method does work ! However, you can write as : $line[1] /= 1000; # which is the same as $line[1] = $line[1] / 1000; HTH - Original Message - From: Sommer, Henrik [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, August 05, 2003 11:05 PM Subject: Simple question Hi, How do I divide a variable in an array ? Lets say element one need to be divided by 1000? $line[1] = $line[1]/1000; Thanks, Henrik -- 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: get http through a proxy authentication
For more info check this: http://search.cpan.org/author/GAAS/libwww-perl-5.69/lwpcook.pod#PROXIES José. -Original Message- From: Darbesio Eugenio [mailto:[EMAIL PROTECTED] Sent: Thursday, August 07, 2003 5:02 PM To: [EMAIL PROTECTED] Subject: get http through a proxy authentication Hi In this code I do http request through the env proxy: my $user_agent = new LWP::UserAgent; $user_agent-agent(Mozilla/4.0); $user_agent-timeout($timeOut); $user_agent-env_proxy(); $page = ($user_agent-request(HTTP::Request-new(GET=$url)))-as_string; but my proxy requests an authetication (username/password). How can I introduce authetication in my code? Thanks! E. LOQUENDO S.p.A. Vocal Technology and Services www.loquendo.it [EMAIL PROTECTED] CONFIDENTIALITY NOTICE This message and its attachments are addressed solely to the persons above and may contain confidential information. If you have received the message in error, be informed that any use of the content hereof is prohibited. Please return it immediately to the sender and delete the message. Should you have any questions, please contact us by replying to [EMAIL PROTECTED] Thank you -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] DISCLAIMER This e-mail and any attachment thereto may contain information which is confidential and/or protected by intellectual property rights and are intended for the sole use of the recipient(s) named above. Any use of the information contained herein (including, but not limited to, total or partial reproduction, communication or distribution in any form) by other persons than the designated recipient(s) is prohibited. If you have received this e-mail in error, please notify the sender either by telephone or by e-mail and delete the material from any computer. Thank you for your cooperation. For further information about Proximus mobile phone services please see our website at http://www.proximus.be or refer to any Proximus agent. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Look Ahead
Hi All, I have a path like: $s = http::/foo/bar:http::/foo1/bar1:http/foo1/bar1; I am trying to get all the http paths which are seperated by : like this: @x = ($s =~ /(http::.*?):(?=http::.*?)/g) The problem is i get all the elements in @x except the last one. Where is that??. -Sharad -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
ERRNO ... What am I missing
Can someone explain the interaction of POSIX ERRNO and PERL scripts? When does ERRNO get set and is it set with each PERL call? I cant seem to track when '$!' is set. Sometimes it will be set to 0, and others 2. I am having difficultly nailing its behavior down. If there is good reading I am missing, please let me know. Thanks, Jason
Re: List::Util / arrays
On Aug 5, Jakob Kofoed said: 1 5001 2 5002 3 5003 [snip] Are those line numbers actually in the file too? If so, that might cause problems for you. open IN, , num2.txt; my @in = IN; At this point, @in holds all the lines of the file... push @col1, $in[0]; ... but here, you only store the FIRST line (the first element of @in) in the @col1 array. Other people have suggested better approaches; I'm just pointing out the flaw in your program. -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ 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: :FTP question
I have a question re Net::FTP. I would like to change the record size when I 'put' the file I'm ftp'ing. What argument would I use, if any to do this? Change the record size? What do you mean by record? Do you mean only ftp xx amount of bytes of a file to the ftp site or -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Help with Unlink please
On Thu, Aug 07, 2003 at 11:00:07PM -0400, perlwannabe wrote: Steve Grazzini wrote at Wed, 06 Aug 2003 23:38:00 -0400: my $pat = 'c:\testdir\*030977*.*'; ^ That looks like trouble. Using forward slashes, as Janek has done below, would have been smarter. foreach (glob($pat)) { unlink or warn Couldn't unlink '$_': $!; } Or if you want to write it as a one liner, you can exploit that unlink also takes a list as its arguments: unlink glob c:/testdir/*030977*.* or die No files unlinked: $!; That's not very good error-reporting. Maybe unlink failed ninety-nine times and succeeded once... Neither of these worked. Did they give any error messages? my $test = (c:\\testdir\\testfile.txt); unlink glob ($test) || die unlink failed: $!; ^^ And that's the wrong or. If you use the alphabetical or, you'll at least get an error message. unlink $test or die unlink: $test: $!; -- Steve -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
[New Question] Large file line by line
Hi! Reading all these message about reading a 'big' file (I know that 180MB its not a big file), but what's the difference from reading like this: @file = FILE; foreach (@file) { print $_; } and with a While? Thanks!! -- Pablo Fischer Sandoval ([EMAIL PROTECTED]) http://www.pablo.com.mx http://www.debianmexico.org GPG FingerTip: 3D49 4CB8 8951 F2CA 8131 AF7C D1B9 1FB9 6B11 810C Firma URL: http://www.pablo.com.mx/firmagpg.txt -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]