Re: Flushing output buffer under mod_perl
Since mod_perl wraps my entire code into a handler subroutine behind the scenes, I figured out how to access the apache API from a normal cgi script. Hence, the following example appears to be working under mod_perl2: #!/usr/bin/perl my $r = shift; use CGI; my $cgi = new CGI; print $cgi-header(); print $cgi-start_html(); $r-rflush; print $cgi-h2(test1); sleep 1; $r-rflush; print $cgi-h2(test2); sleep 1; $r-rflush; print $cgi-h2(test3); sleep 1; $r-rflush; print $cgi-end_html(); With my more complicated example (listed below), I get mixed results. Sometimes it works, sometimes I get segmentation faults, and sometimes I get the following error in my Apache error_log which I don't understand: $r-rflush can't be called before the response phase at /html/perl/test.pl line 107 The complete code is as follows: #!/usr/bin/perl my $r = shift; use CGI; local our $cgi = new CGI; our $action = ; $action = $cgi-param(action) || 'test_code'; if ( $action eq test_code ) { test_code (); } elsif ( $action eq run ) { test_prog ($cgi); } sub test_code { # my ($cgi_sub) = @_; my $cgi_sub = new CGI; print $cgi_sub-header(); print $cgi_sub-start_html( -title = 'Javascript calls from Perl' ); print $cgi_sub-h2(test code); print $cgi_sub-div($cgi_sub-font({-face='Arial'},Status: )); print $cgi_sub-start_form(); print $cgi_sub-submit(-name='action',-value='run'); print $cgi_sub-end_form(); print $cgi_sub-end_html(); } sub test_prog { my ($cgi_sub) = @_; print $cgi_sub-header(); print $cgi_sub-start_html( -title = 'Javascript calls from mod_perl' ); print $cgi_sub-h2(test code); print EOT ; script language=JavaScript1.2!-- if (document.getElementById || document.all || document.layers) document.write(div id=statusboxfont face=ArialStatus: /font/div); function newstatus(s) { var e; if (document.getElementById) { e = document.getElementById(statusbox); } else if (document.all) { e = document.all[statusbox]; } else if (document.layers) { e = document.layers[statusbox]; } e.innerHTML = font face=arialStatus: /fontfont face=arial color=blueb + s + /b/font; } //--/script EOT for (my $i = 1; $i = 6; $i++){ if ($i == 6){ newstatus(Aggregating Data...); sleep (2); newstatus(Analyzing Data...); sleep (2); newstatus(Finished \(this text is from the server\)); } else { newstatus(Querying . $i . out of 5 suppliers); sleep (1); } } print $cgi_sub-start_form(); print $cgi_sub-submit(-name='action',-value='run'); print $cgi_sub-end_form(); print $cgi_sub-end_html(); } sub newstatus { my ($s) = @_; print EOT ; script language=JavaScript1.2!-- newstatus($s); //--/script EOT $r-rflush; } On 7/11/06, zentara [EMAIL PROTECTED] wrote: On Mon, 10 Jul 2006 19:11:08 +0200, [EMAIL PROTECTED] (Ibrahim Dawud) wrote: The following code works great using normal perl but does not work under mod_perl: #!/usr/bin/perl use CGI; my $cgi = new CGI; print $cgi-header(); print $cgi-start_html(); $| = 1; print $cgi-h2(test1); sleep 1; $| = 1; print $cgi-h2(test2); sleep 1; $| = 1; print $cgi-h2(test3); print $cgi-end_html(); The purpose of the code is print periodic messages to the browser during long processing. Can someone please explain or show an example of how I can flush the output buffer when running the same code under mod_perl. According to my understanding, I have to do this at the level of the Apache API using rflush. The problem is that I don't know how to write such a handler and even if i did, i don't know how to call it into my existing CGI code in place of $|=1. Suggestions are highly appreciated. Try asking this at http://perlmonks.org where a few mod_perl experts hang out. -- I'm not really a human, but I play one on earth. http://zentara.net/japh.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
calling a perl script on windows
Hi all, I am working on porting some scripts from unix to windows, and I noticed that perl ignores the first line of the script, and it seems I have to run the script like this: D:\Perl\bin\perl.exe myscript.pl if I run it like we do on unix: ./myscript.pl it will search the path and it uses the perl found in the path env variable. How can I make it to run exactly like Unix, meaning, just use the first line in the script? Thanks, Mahdi. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: calling a perl script on windows
Mahdi A Sbeih wrote: Hi all, I am working on porting some scripts from unix to windows, and I noticed that perl ignores the first line of the script, and it seems I have to run the script like this: D:\Perl\bin\perl.exe myscript.pl if I run it like we do on unix: ./myscript.pl it will search the path and it uses the perl found in the path env variable. How can I make it to run exactly like Unix, meaning, just use the first line in the script? Thanks, Mahdi. Hi Mahdi The Sha-Bang line (path to the perl interpreter) is supported in windows also.You need tell the exact path to the perl interpreter. For example if you installed in c:\perl\ #!/perl/bin/perl Windows will search only C: drive for this. -- Thanks Regards Chandru -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: pattern match
Ryan Dillinger wrote: Hello, Hi Ryan I had two scripts that were identical, well almost. I ran the two together, but straghtened them out. Anyway I have one here, that when ran say's: Use of uninitialized value in pattern match (m//) at headline.pl line 7 and 10. I have changed differernt things within, nothing worked. It is back to it's original state now. Can someone point out the problem I have with this script please? Thanks For your help! #!/usr/bin/perl use warnings; use strict; open LYNX, lynx -source http://www.perl.com/ | or die Can't open lynx: $!; $_ = ; There is no need for this assignment as you change the value again straight away. $_ = LYNX until /standard\.def/; As Mumia pointed out, this line will not complete if there is no 'standard.def' in the page. Better to: while (LYNX) { last if /standard\.def/; } die Unable to find 'standard.def' in Web page unless defined; my $head = LYNX; $head =~ m|^A HERF=[^]+(.*?)/a|i; print Today's www.perl.com headline: $!\n; Using HREF instead of HERF and $1 instead of $! should make this work. This whole thing would be better done using something like LWP::Simple and HTML::TokeParser (or, as Shawn suggested, HTML::TreeBuilder) like this: use LWP::Simple; use HTML::TokeParser; my $page = get('http://www.perl.com/'); my $p = HTML::TokeParser-new(\$page) or die Unable to parse page; while (my $anchor = $p-get_tag('a')) { my $text = $p-get_trimmed_text('/a'); print $text, \n; } which will print the text contents of all the a elements in the page. *However*, looking at the current contents of the page there is no 'standard.def' string and I can't see anything that would be called a headline, so I can't guess any further how to distinguish the particular element you want to see. Anyway, HTH. Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: calling a perl script on windows
Hi all, Hello Mahdi. I am working on porting some scripts from unix to windows, and I noticed that perl ignores the first line of the script, and it seems I have to run the script like this: D:\Perl\bin\perl.exe myscript.pl if I run it like we do on unix: ./myscript.pl it will search the path and it uses the perl found in the path env variable. How can I make it to run exactly like Unix, meaning, just use the first line in the script? You can't, essentially. Unlike Unix shells, Windows doesn't open and read the file to decide what to do with it, and the only way to identify it as a Perl file is to add the .pl filename extension. Perl will, however, honour the switches in the #! line to control how it runs the program, so #!perl -w will enable warnings, for instance. If you want to chnage the instance of Perl used to run your program, then you must either mention it explicitly on the command line or change the file associations for .pl files. You might also want to take a look at 'pl2bat' which will create a myscript.bat for you so you can say just 'myscript' on the command line. The resulting batch file can be edited to select a specific perl.exe rather than the first one in the path. HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: calling a perl script on windows
Hi Chandru, Do I need to go to windows_explorer-Tools-Folder Options-File Types and associating the extension .pl with the perl executable? What if the perl is in the D: drive not C:, also do I need to specify .exe Thanks, Mahdi. Chandru wrote: Mahdi A Sbeih wrote: Hi all, I am working on porting some scripts from unix to windows, and I noticed that perl ignores the first line of the script, and it seems I have to run the script like this: D:\Perl\bin\perl.exe myscript.pl if I run it like we do on unix: ./myscript.pl it will search the path and it uses the perl found in the path env variable. How can I make it to run exactly like Unix, meaning, just use the first line in the script? Thanks, Mahdi. Hi Mahdi The Sha-Bang line (path to the perl interpreter) is supported in windows also.You need tell the exact path to the perl interpreter. For example if you installed in c:\perl\ #!/perl/bin/perl Windows will search only C: drive for this. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: calling a perl script on windows
On 12 Jul 2006 at 0:32, Mahdi A Sbeih wrote: Hi Chandru, Do I need to go to windows_explorer-Tools-Folder Options-File Types and associating the extension .pl with the perl executable? Yes. However if you've installed activestate's Perl it would have asked if you wanted to do this. Is that the perl your using? What if the perl is in the D: drive not C:, also do I need to specify .exe Good luck. Dp. Dermot Paikkos Network Administrator @ Science Photo Library Phone: 0207 432 1100 Fax: 0207 286 8668 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Linux to Windows portability problem
Hello, I have a quite common problem : portability :( I wrote a Perl script that works perfectly under Linux with Perl 5.8.8. Very confident, I try to run it under Windows with the lastest release of ActivePerl, and all required modules. But annoyances come quickly :( Perl returns me an error message : cannot use initialized value in null operation. My first idea about the problem was the utilisation of the fork() primitive : I know it presents some limitations under Windows. But after reading the fork() information page of ActivePerl, it seems I'm not concerned by these limitations. I learned, by reading the previous documentation, that ActivePerl uses threads to emulate posix fork(). I use DBI for my script, and it seems DBI is not really thread-safe, or at least, it may bring problems. But this is only an hypothetical reason. If somebody has skill about such problems, help would be greatly appreciated. Thanks. Mickael -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Specify download file name
Hi Anish The following example works and I have tested it. use CGI; $cgiObject=new CGI; $filename=SRQ.zip; print $cgiObject-header(-charset='', -Expires='-1d' , -'Cache-Control'='private, max-age=0', -attachment= $filename, -type='application/octet-stream' ); open ZIPFILE, $filename || die Can't open $filename for reading; binmode (ZIPFILE); @file=ZIPFILE; print @file; close ZIPFILE; Thanks Prasanna -Original Message- From: Anish Kumar K. [mailto:[EMAIL PROTECTED] Sent: Tuesday, July 11, 2006 7:04 PM To: Nagasamudram, Prasanna Kumar Cc: beginners@perl.org Subject: Re: Specify download file name Hi Prasanna Thanks for the reply. But that is not helping me in the situation Thanks Anish Nagasamudram, Prasanna Kumar wrote: Hi Anish Can you try adding the following to your $cgiObject-header ? -attachment='$filename.zip', And changing -type='application/zip' to -type='application/octet-stream' [PS : The above is not tested] Thanks Prasanna -Original Message- From: Anish Kumar K. [mailto:[EMAIL PROTECTED] Sent: Tuesday, July 11, 2006 3:43 PM To: beginners@perl.org Subject: Specify download file name Hi This is somewhat easy question I feel but for some reason I am not getting this The issue is I am using CGI to download a file, I am setting the header as this print $cgiObject-header(-type='application/zip',-charset='',-Expires='-1d' ,-'Cache-Control'='private, max-age=0'); the download works fine. But the issue is the file name it is coming as the filename...say when I download I am geting downloadwav.pl. which is the file name of the perl file. Is there a way I can specify a file name, It is a zip file. I tried this $file_name=attachment.zip; print Content-Disposition: attachment; filename = $file_name\n\n; Not working...any help Thanks Anish -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: calling a perl script on windows
-Original Message- From: Mahdi A Sbeih [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 12, 2006 2:41 AM To: beginners@perl.org Subject: calling a perl script on windows Hi all, I am working on porting some scripts from unix to windows, and I noticed that perl ignores the first line of the script, and it seems I have to run the script like this: D:\Perl\bin\perl.exe myscript.pl if I run it like we do on unix: ./myscript.pl it will search the path and it uses the perl found in the path env variable. How can I make it to run exactly like Unix, meaning, just use the first line in the script? Thanks, Mahdi. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response For windows make sure you have the path to the perl executable in the path (environment variable) For example, if you perl.exe executable resides in c:\perl\bin Make sure you put c:\perl\bin in the PATH Also, make sure you associate the .pl extension with the perl.exe executable. You can do this within Windows Explorer\Tools\Folder Options\File Types Doing that will enable you to run any perl script from the command line without calling perl firstie. you can just type foo.pl and it will run. And likewise if you clicked on the file within windows.it will automatically run the perl interpreter to run the script. Hope that helps. Regards, Sam -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Linux to Windows portability problem
On 7/12/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hello, I have a quite common problem : portability :( I wrote a Perl script that works perfectly under Linux with Perl 5.8.8. Very confident, I try to run it under Windows with the lastest release of ActivePerl, and all required modules. But annoyances come quickly :( Perl returns me an error message : cannot use initialized value in null operation. My first idea about the problem was the utilisation of the fork() primitive : I know it presents some limitations under Windows. But after reading the fork() information page of ActivePerl, it seems I'm not concerned by these limitations. I learned, by reading the previous documentation, that ActivePerl uses threads to emulate posix fork(). I use DBI for my script, and it seems DBI is not really thread-safe, or at least, it may bring problems. But this is only an hypothetical reason. If somebody has skill about such problems, help would be greatly appreciated. Thanks. Mickeal, We'll be happy to help, but you need to give us more to go on. Show us your code--enough that we can see what's going on in your program--and tell us which line is causing the error. Then we can help you fix it. The number of things that might possibly cause a particular error message are almost infinite; we need to see why your code is causing it. Best, -- jay -- This email and attachment(s): [ ] blogable; [ x ] ask first; [ ] private and confidential daggerquill [at] gmail [dot] com http://www.tuaw.com http://www.dpguru.com http://www.engatiki.org values of β will give rise to dom!
Script Optimization file parsing script
Hi, I am working on optimization of one of the file parsing script. There are around 4,50,000 lines present in the input file. This file size is bound to increase in coming days. New entries would be added every 2 minutes. Current script is taking around 60 seconds (average) and 150 seconds (max) time for parsing the input file and writing into the output file. Since this script is executed every two minutes (have to :( and very important script), times in seconds itself is costing me. The flow in the script is something like this: 1. Open the input file handle using the open function 2. In while loop parse the entries (using the file handle directly in while), parse the input entries. Do the sanity check required (sanity check involved is a combination of specific line format and a few regular expression check). If sanity check is successful, load the required entries into the hash. Close the input file handle. 3. Open the output file handle 4. Sorting of the hash in the required order. 5. Print hash into the file 6. Close output file handle. Any help/suggestion would be appreciated. Thanks, Ajay -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Script Optimization file parsing script
Nagrale, Ajay wrote: The flow in the script is something like this: 1. Open the input file handle using the open function 2. In while loop parse the entries (using the file handle directly in while), parse the input entries. Do the sanity check required (sanity check involved is a combination of specific line format and a few regular expression check). If sanity check is successful, load the required entries into the hash. Close the input file handle. 3. Open the output file handle 4. Sorting of the hash in the required order. 5. Print hash into the file 6. Close output file handle. Any help/suggestion would be appreciated. * Keep track of the last item in the file via tell() and seek() that location at the next run. * Keep the previous sorted output in a file with the format: sort_key (delimiter) output_line * Merge sort the new entries with the old output to produce the output and a new sorted file. -- __END__ Just my 0.0002 million dollars worth, --- Shawn For the things we have to learn before we can do them, we learn by doing them. Aristotle * Perl tutorials at http://perlmonks.org/?node=Tutorials * A searchable perldoc is at http://perldoc.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Copying files in windows from one directory to the other
Hi, I got some files in $BNY_DOWNLOAD which is a directory in windows. Now i have to identify most recent one in that file and have to move it $BNY_DATA directory it is also a directory. To identify the most recent file I used sort command and sorted it by using -M and and space ship operators. It is returning list of files in that directory that are sorted by the last modification order. I'm getting that most recently modified as the first element in the sorted list. Now I want to move this file from this $BNY_DOWNLOAD to $BNY_DATA directory. I'm not familiar with the windows environment that's why please help elaborately. Waiting for your earlier responce. Please note I'm have to use the $BNY_DATA and $BNY_DOWNLOAD while copying. Regards, Rajeev
Re: Script Optimization file parsing script
Nagrale, Ajay schreef: I am working on optimization of one of the file parsing script. There are around 4,50,000 lines present in the input file. This file size is bound to increase in coming days. New entries would be added every 2 minutes. Current script is taking around 60 seconds (average) and 150 seconds (max) time for parsing the input file and writing into the output file. Since this script is executed every two minutes (have to :( and very important script), times in seconds itself is costing me. The flow in the script is something like this: 1. Open the input file handle using the open function 2. In while loop parse the entries (using the file handle directly in while), parse the input entries. Do the sanity check required (sanity check involved is a combination of specific line format and a few regular expression check). If sanity check is successful, load the required entries into the hash. Close the input file handle. 3. Open the output file handle 4. Sorting of the hash in the required order. 5. Print hash into the file 6. Close output file handle. Any help/suggestion would be appreciated. Does the file have (mostly) totally new data, evey 2 minutes? If so, go to (2). (1) You re-process old lines over and over again. For what? Cache the old lines in a database, only insert (or append) the new data, create the output. (2) I would use a yacc/lex solution, because that normally does it in a few seconds. -- Affijn, Ruud Gewoon is een tijger. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Copying files in windows from one directory to the other
On 7/12/06, kilaru rajeev [EMAIL PROTECTED] wrote: Now I want to move this file from this $BNY_DOWNLOAD to $BNY_DATA directory. You may be able to simply use rename() to do what you want, but it sounds as if you might want to use the File::Copy module, and its move() function. Hope this helps! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Copying files in windows from one directory to the other
Probably the simplest way to do this would be to use the File::Copy module. It's about as straightforward as you can get. move($BNY_DOWNLOAD.\\.$filename,$BNY_DATA.\\.$filename) or die(Couldn't copy $filename to $BNY_DATA! $!\n); -Original Message- From: kilaru rajeev [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 12, 2006 10:44 AM To: beginners@perl.org Subject: Copying files in windows from one directory to the other Hi, I got some files in $BNY_DOWNLOAD which is a directory in windows. Now i have to identify most recent one in that file and have to move it $BNY_DATA directory it is also a directory. To identify the most recent file I used sort command and sorted it by using -M and and space ship operators. It is returning list of files in that directory that are sorted by the last modification order. I'm getting that most recently modified as the first element in the sorted list. Now I want to move this file from this $BNY_DOWNLOAD to $BNY_DATA directory. I'm not familiar with the windows environment that's why please help elaborately. Waiting for your earlier responce. Please note I'm have to use the $BNY_DATA and $BNY_DOWNLOAD while copying. Regards, Rajeev -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Copying files in windows from one directory to the other
kilaru rajeev wrote: Hi, Hello, I got some files in $BNY_DOWNLOAD which is a directory in windows. Now i have to identify most recent one in that file and have to move it $BNY_DATA directory it is also a directory. To identify the most recent file I used sort command and sorted it by using -M and and space ship operators. It is returning list of files in that directory that are sorted by the last modification order. I'm getting that most recently modified as the first element in the sorted list. Now I want to move this file from this $BNY_DOWNLOAD to $BNY_DATA directory. I'm not familiar with the windows environment that's why please help elaborately. Waiting for your earlier responce. Please note I'm have to use the $BNY_DATA and $BNY_DOWNLOAD while copying. To move the file, something like: rename $BNY_DOWNLOAD/$file, $BNY_DATA/$file or die Cannot move '$BNY_DOWNLOAD/$file' $!; If you want to *copy* the file like the Subject line says: perldoc File::Copy John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: calling a perl script on windows
In addition to the suggestions that have already been given about associating the .pl file extension with perl.exe, I would heartily recommend that you install ActivePerl from http://www.activestate.com. It's free, and is the de facto standard for Windows Perl. There are other ones that work (Cygwin's version, for example), but this one is the most widely used and takes care of these kinds of things for you in addition to giving you the very useful PPM utility for installing precompiled modules, which can get you up and running quicker. -Original Message- From: Mahdi A Sbeih [mailto:[EMAIL PROTECTED] Sent: Tuesday, July 11, 2006 11:41 PM To: beginners@perl.org Subject: calling a perl script on windows I am working on porting some scripts from unix to windows, and I noticed that perl ignores the first line of the script, and it seems I have to run the script like this: D:\Perl\bin\perl.exe myscript.pl if I run it like we do on unix: ./myscript.pl it will search the path and it uses the perl found in the path env variable. snip -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Date Time
Hi, I got a file with this line: 200607081000@@01510 It means Datetime@@Values I'm trying to insert this in Mysql with fields terminated by `@@`'; It's works fine but i got the wrong Datetime. How kann i change 200607081000 mailto:200607081000@@01510 into 2006-07-08 10:00 mailto:200607081000@@01510 Please Help Thanks
RE: question on redirecting output of Perl debugger commands
WC: Thanks for your response! I think what you suggested works fine for normal shell commands, but it doesn't appear to work for the Perl debugger. Here's a sample session, running on a Linux machine: bash-2.05b$ cat test.pl #!/usr/bin/perl $x = 1; print x:$x\n; bash-2.05b$ perl -d test.pl | tee xxx 21 yyy Loading DB routines from perl5db.pl version 1.28 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(test.pl:3): $x = 1; DB1 s main::(test.pl:4): print x:$x\n; DB1 p $x 1 DB2 q bash-2.05b$ ls -ralt total 10116 ... -rw-rw-r--1 gbowlby isp 0 Jul 12 11:21 yyy -rw-rw-r--1 gbowlby isp 0 Jul 12 11:21 xxx drwxrwxr-x3 gbowlby isp 4096 Jul 12 11:21 . bash-2.05b$ cat xxx bash-2.05b$ cat yyy bash-2.05b$ So no output was sent to either the file xxx or yyy. I would like to see the results of the Perl debugging session in a file. Gavin -Original Message- From: Chasecreek Systemhouse [mailto:[EMAIL PROTECTED] Sent: Sunday, July 09, 2006 3:21 PM To: beginners perl Subject: Re: question on redirecting output of Perl debugger commands On 7/7/06, Gavin Bowlby [EMAIL PROTECTED] wrote: Is there a way to redirect the output of a debugger command to a file? What I use is Linux specific, sort of varies by bash and distro for example, but you are welcome to try it out (I asked in irc #bash before posting here) - ls -ial |tee captured_output 21 | less You will need to play with arrangement to get the desired effect. -- WC (Bill) Jones -- http://youve-reached-the.endoftheinternet.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Date Time
Semiyi.Abiola wrote: Hi, Hello, I got a file with this line: 200607081000@@01510 It means Datetime@@Values I'm trying to insert this in Mysql with fields terminated by `@@`'; It's works fine but i got the wrong Datetime. How kann i change 200607081000 mailto:200607081000@@01510 into 2006-07-08 10:00 mailto:200607081000@@01510 $ perl -le' $_ = 200607081000; print; s/(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)/$1-$2-$3 $4:$5/; print; ' 200607081000 2006-07-08 10:00 John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: question on redirecting output of Perl debugger commands
On 7/12/06, Gavin Bowlby [EMAIL PROTECTED] wrote: bash-2.05b$ cat test.pl #!/usr/bin/perl $x = 1; print x:$x\n; bash-2.05b$ perl -d test.pl | tee xxx 21 yyy Hmmm. You know, when posted previously I guess I should have stated that I had not yet gotten it to work myself but posted anyways kind of hoping you might be able to. Also I looked at the PerlDebug man page a few times while thinking about this and I keep returning to this statement: PerlDebugThe DB::OUT filehandle is opened to /dev/tty, regardless of where STDOUT may be redirected to./PerlDebug To me this implies it should be possible to capture it using something like Expect (expect.nist.gov) -- but I simply have not had time to delve that deeply into it. Besides, and maybe I'm making a leap here, I have to think that it isn't possible -- considering none of the Unix gurus have chimed in about it. Sorry. -- WC (Bill) Jones -- http://youve-reached-the.endoftheinternet.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Date Time
It looks like part of your message got munged by one of our mail clients, but here's a code snippet that should give you an idea of how you can proceed: ## use strict; use warnings; $| = 1; my $string = '200607081000@@01510'; #Check to make sure the regex matched, then proceed. if($string =~ /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})[EMAIL PROTECTED]@(\d+)$/){ $string = $1-$2-$3 $4:$5 = $6; print $string; }else{ print Invalid String!\n; } # -Original Message- From: Semiyi.Abiola [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 12, 2006 1:10 AM To: beginners@perl.org Subject: Date Time Hi, I got a file with this line: 200607081000@@01510 It means Datetime@@Values I'm trying to insert this in Mysql with fields terminated by `@@`'; It's works fine but i got the wrong Datetime. How kann i change 200607081000 mailto:200607081000@@01510 into 2006-07-08 10:00 mailto:200607081000@@01510 Please Help Thanks -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: calling a perl script on windows
Mahdi A Sbeih schreef: How can I make it to run exactly like Unix, meaning, just use the first line in the script? Also check ASSOC and FTYPE. -- Affijn, Ruud Gewoon is een tijger. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: question on redirecting output of Perl debugger commands
On 7/12/06, Gavin Bowlby [EMAIL PROTECTED] wrote: I would like to see the results of the Perl debugging session in a file. The debugger wasn't made with that in mind, but you could work around it. At least, this works for me. open $DB::OUT, | tee dbug.txt or die if $DB::OUT; You may find some escape sequences in the output. Some would call that a feature. If using that line early in your code (or as a debugger command) isn't soon enough to catch what you need, you could wrap it in a BEGIN block. If the BEGIN block doesn't make it execute soon enough, you can hack a copy of perl5db.pl to start the tee as the debugger starts up; see the perldebug manpage. Hope this helps! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
regex repetition
I need to write some code to allow users to specify which of a whole bunch of elements(e.g.512/1024) that they want to view. My idea for how to do this was to have them input a semicolon delimited list, for example: 1-10;25;33;100-250 i tried using this to check to make sure they input a valid list that i can process: ### foreach ($temp2 = ) { $list1 = $temp2; if ($list1 =~ /(\s*\d+;)+/g || $list1 =~ /(\s*\d+;)+/g ) { print yay\n; }else {print boo\n;}; #print ...,$list1, ...\n; } ### which doesn't work, because as soon as it matches the first time, anything goes. How do i get it check for repetition, even though i don't know how many repetitions there will be. there could be 1,2,3,5, even 10 groupings. so the pattern isns't hard, there has to be a number, then either a '-' or s ';', then repeat or not. the only special case is the first one which could just be a single number, or a number '-'number. I just don't know how to implement it. (#(-||;))(#(-||;))(#(-||;)) thanks, ryan -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: regex repetition
Ryan Moszynski wrote: I need to write some code to allow users to specify which of a whole bunch of elements(e.g.512/1024) that they want to view. My idea for how to do this was to have them input a semicolon delimited list, for example: 1-10;25;33;100-250 You will need more than a regex: my $lower; my upper; for my $part ( split /;/, $list ){ if( $part =~ /(\d+)-(\d+)/ ){ $lower = $1; $upper = $2; }elsif( $part =~ /(\d+)/ ){ $upper = $lower = $1; }else{ warn invalid format of part: '$part'\n; next; } # process $lower and $upper } -- __END__ Just my 0.0002 million dollars worth, --- Shawn For the things we have to learn before we can do them, we learn by doing them. Aristotle * Perl tutorials at http://perlmonks.org/?node=Tutorials * A searchable perldoc is at http://perldoc.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: question on redirecting output of Perl debugger commands
Tom, WC: Thanks! This works (almost) perfectly. I issued the open $DB::OUT, | tee dbug.txt as a Perl Debugger command. The output is a little funky when displaying Perl debugger keyboard commands entered by the user, but the output produced by the Perl debugger is captured faithfully in the output file. It is really nice to have the brainpower of this reflector to answer questions like this! thanks again, Gavin sample keyboard session output follows: bash-2.05b$ perl -d test.pl Loading DB routines from perl5db.pl version 1.28 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(test.pl:3): $x = 1; DB1 open $DB::OUT, | tee dbug.txt DB2 s main::(test.pl:4): print x:$x\n; DB2 p $x 1 DB3 q bash-2.05b$ ls -ralt ... total 8272 -rw-rw-r--1 gbowlby isp 113 Jul 12 15:28 dbug.txt bash-2.05b$ cat dbug.txt DB2 main::(test.pl:4): print x:$x\n; DB2 1 = This is the output of the debugger p $x command. bash-2.05b$ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Tom Phoenix Sent: Wednesday, July 12, 2006 12:11 PM To: Gavin Bowlby Cc: perl beginners Subject: Re: question on redirecting output of Perl debugger commands On 7/12/06, Gavin Bowlby [EMAIL PROTECTED] wrote: I would like to see the results of the Perl debugging session in a file. The debugger wasn't made with that in mind, but you could work around it. At least, this works for me. open $DB::OUT, | tee dbug.txt or die if $DB::OUT; You may find some escape sequences in the output. Some would call that a feature. If using that line early in your code (or as a debugger command) isn't soon enough to catch what you need, you could wrap it in a BEGIN block. If the BEGIN block doesn't make it execute soon enough, you can hack a copy of perl5db.pl to start the tee as the debugger starts up; see the perldebug manpage. Hope this helps! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: regex repetition
Why not just use split()? Then you can do a simple regex on each element: ### use strict; use warnings; my $string = '1-10;25;33;1-00-250'; my @array = split(/;/,$string); foreach my $element(@array){ if($element =~ /^\d+-?\d*?$/){ print $element = valid\n; }else{ print $element = bad input\n; } } Of course you could also skip the intermediary array and just do foreach my $element(split(/;/,$string)){ I just added it for clarity. -Original Message- From: Ryan Moszynski [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 12, 2006 3:09 PM To: beginners Subject: regex repetition I need to write some code to allow users to specify which of a whole bunch of elements(e.g.512/1024) that they want to view. My idea for how to do this was to have them input a semicolon delimited list, for example: 1-10;25;33;100-250 Snip if ($list1 =~ /(\s*\d+;)+/g || $list1 =~ /(\s*\d+;)+/g ) { snip -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: write out filenames of files existing on a filesystem into afile
Hi: Sorry to start this thread again, but it would not have been wise to ask my related question in a different thread. I tried to run the program on a windows machine, apparently the regex in question only lists directories within directories and not the files within the directories. I tried Rob's regex as well as Randal's. In addition how can I modify the code, so that the buildlist.txt only lists the files within the directories and not the directories? TIA! --- use strict; use warnings; my $path = $ARGV[0]; opendir DIR, $path or die Can't open $path: $!; my @new = grep /[^.]/, readdir DIR; #tried this #my @new = grep { $_ ne . and $_ ne .. } readdir DIR; #tried this too. closedir DIR; open FILE,c:/buildlist.txt; print FILE $_\n foreach @new; #this only lists directories within directories and not the files within the directories close FILE; open(FILE2,c:/final.txt); foreach my $file (@new) { my $record = qq(SL/$file %ORACLE_HOME%/server/bin/$file $file NA\n); print $record; print FILE2 $record; } close FILE2; On 7/11/06, Rob Dixon [EMAIL PROTECTED] wrote: Randal I'm in two minds as to whether to just let this go as it had gone on for too long, but I will try just once more to explain my true stance, which you seem keen to obfuscate. (Randal L. Schwartz) wrote: Rob == Rob Dixon [EMAIL PROTECTED] writes: Rob Not much chance of that I'm afraid Shawn. I can do without the apology, I Rob just wish he'd confirm that his original critique was wrong instead of Rob banging on about filenames with three dots. I think leaving people with Rob that misinformation uncorrected is a lot more important. My original critique was wrong. I mistook /^[.]/ for /[^.]/. So your post was wrong, but I said it was wrong for the wrong reasons. You also claimed the rest of my post was incorrect, wouldn't work and hadn't been tested. You were wrong on all counts, and clearly didn't choose to test the code yourself. That still doesn't solve the problems I addressed about your post elsewhere, nor that you had to go three rounds with me in private email repeatedly looking for some way to save your original post from being labeled wrong. The quotes are yours: I was indeed trying to save it from the allegations of your incorrect response. My original post was not wrong as you described it, but only insofar as it discarded three-dot files. In context even that can only be considered a problem with portability as the OP used a Windows system where such files cannot exist. And I didn't 'go three rounds' with you - I didn't consider it a fight and am surprised if you did. I'm here for the group. I want people to walk away from this list knowing how to code *better* Perl. Your post distracted from that. I have nothing against you personally, but your behaviors distract from my goal, and will be called for what they are. Randal, there are ways to correct people without being abusive and creating this monstrous storm of debate. Had your initial response been to correct just the incorrect filename filtering I doubt you would have seen an opportunity to be so vehement, and I think it is clear that defamatory posts also serve to distract from teaching people better Perl. Please try to be civil with your criticism and make this list a better place to learn and to impart what we know. Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: regex repetition
Ryan Moszynski wrote: I need to write some code to allow users to specify which of a whole bunch of elements(e.g.512/1024) that they want to view. My idea for how to do this was to have them input a semicolon delimited list, for example: 1-10;25;33;100-250 i tried using this to check to make sure they input a valid list that i can process: ### foreach ($temp2 = ) { $list1 = $temp2; if ($list1 =~ /(\s*\d+;)+/g || $list1 =~ /(\s*\d+;)+/g ) { print yay\n; }else {print boo\n;}; #print ...,$list1, ...\n; } ### which doesn't work, because as soon as it matches the first time, anything goes. How do i get it check for repetition, even though i don't know how many repetitions there will be. there could be 1,2,3,5, even 10 groupings. so the pattern isns't hard, there has to be a number, then either a '-' or s ';', then repeat or not. the only special case is the first one which could just be a single number, or a number '-'number. I just don't know how to implement it. (#(-||;))(#(-||;))(#(-||;)) Hi Ryan Stuff like this is easier if you build regex expressions to match individual elements of the pattern and then use those to build up the expression for the whole string. each item separated by teh semicolons is a string of digits, optionally followed by a hyphen and another string of digits. So we ccan write this: my $element = qr/\d+(-\d+)?/; and the whole string must match any number of such elements followed by a semicolon, ending with an element on its own: my $pattern = qr/^($element;)*$element$/; so we can write the whole program: use strict; use warnings; my $string = '1-10;25;33;100-250'; my $element = qr/\d+(-\d+)?/; my $pattern = qr/^($element;)*$element$/; if ($string =~ $pattern) { print OK\n; } else { print NOT OK\n; } HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: regex repetition
Ryan Moszynski wrote: I need to write some code to allow users to specify which of a whole bunch of elements(e.g.512/1024) that they want to view. My idea for how to do this was to have them input a semicolon delimited list, for example: 1-10;25;33;100-250 i tried using this to check to make sure they input a valid list that i can process: ### foreach ($temp2 = ) { $list1 = $temp2; You are assigning a scalar from to $temp2 and then foreach is assigning that same value to $_ and then you are assigning that same value to $list1. How many variables do you need to hold the same value? Perhaps you should use: while ( my $list1 = ) { if ($list1 =~ /(\s*\d+;)+/g || $list1 =~ /(\s*\d+;)+/g ) { From your example above the pattern matches the three substrings: 1-10;25;33;100-250 ^^^+++^^^ And after the match $1 contains '33;' print yay\n; }else {print boo\n;}; #print ...,$list1, ...\n; } ### which doesn't work, because as soon as it matches the first time, anything goes. How do i get it check for repetition, even though i don't know how many repetitions there will be. there could be 1,2,3,5, even 10 groupings. so the pattern isns't hard, there has to be a number, then either a '-' or s ';', then repeat or not. the only special case is the first one which could just be a single number, or a number '-'number. I just don't know how to implement it. (#(-||;))(#(-||;))(#(-||;)) You probably want: while ( my $list1 = ) { chomp $list1; if ( $list1 =~ /^(?:\d[\d;-]*\d|\d)$/; print yay\n; } else { print boo\n; } #print ...$list1...\n; } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: write out filenames of files existing on a filesystem into afile
Nishi Bhonsle wrote: Hi: Sorry to start this thread again, but it would not have been wise to ask my related question in a different thread. I tried to run the program on a windows machine, apparently the regex in question only lists directories within directories and not the files within the directories. I tried Rob's regex as well as Randal's. In addition how can I modify the code, so that the buildlist.txt only lists the files within the directories and not the directories? TIA! --- use strict; use warnings; my $path = $ARGV[0]; opendir DIR, $path or die Can't open $path: $!; my @new = grep /[^.]/, readdir DIR; #tried this #my @new = grep { $_ ne . and $_ ne .. } readdir DIR; #tried this too. closedir DIR; open FILE,c:/buildlist.txt; print FILE $_\n foreach @new; #this only lists directories within directories and not the files within the directories close FILE; open(FILE2,c:/final.txt); foreach my $file (@new) { my $record = qq(SL/$file %ORACLE_HOME%/server/bin/$file $file NA\n); print $record; print FILE2 $record; } close FILE2; Hi again Nishi. I think somebody mentioned it before, but what you need is File::Find. This code will put into @new the names of all the files in and below $path. use strict; use warnings; use File::Find; my @new; find(sub {push @new, $File::Find::name}, $path); print $_\n foreach @new; Now beware that all files and directories are included. I've never been sure whether you were interested in the directory names, and if you want to filter out the directories and leave just the files, change the call to find() like this: find(sub {push @new, $File::Find::name if -f}, 'E:/Games/Darwinia/'); This solution has the advantage that File::Find doesn't return the pseudo- directories '.' and '..' so we have nothing to worry about on that score :) HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: write out filenames of files existing on a filesystem into afile
Rob Dixon wrote: I think somebody mentioned it before, but what you need is File::Find. This code will put into @new the names of all the files in and below $path. use strict; use warnings; use File::Find; my @new; find(sub {push @new, $File::Find::name}, $path); print $_\n foreach @new; Now beware that all files and directories are included. I've never been sure whether you were interested in the directory names, and if you want to filter out the directories and leave just the files, change the call to find() like this: find(sub {push @new, $File::Find::name if -f}, $path); This solution has the advantage that File::Find doesn't return the pseudo- directories '.' and '..' so we have nothing to worry about on that score :) I just looked at your original post again, and it may well be that you're not interested in the directory path to the file at all, in which case change the line again to: find(sub {push @new, $_ if -f}, $path); which will leave just the bare filenames in the array. Remember to take off the 'if -f' if you want directories in the list too. Cheers, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: regex repetition
Ryan Moszynski schreef: 1-10;25;33;100-250 echo '1-10;25;33;100-250' | perl -nle ' /\A\d+(?:-\d+)?(?:;\d+(?:-\d+)?)*\z/ and print $_ =OK ' But that also matches '12-3'. -- Affijn, Ruud Gewoon is een tijger. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: regex repetition
Check out the module Set::IntSpan and see if it does what you want. http://search.cpan.org/dist/Set-IntSpan/IntSpan.pm On Jul 12, 2006, at 3:08 PM, Ryan Moszynski wrote: I need to write some code to allow users to specify which of a whole bunch of elements(e.g.512/1024) that they want to view. My idea for how to do this was to have them input a semicolon delimited list, for example: 1-10;25;33;100-250 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: write out filenames of files existing on a filesystem into afile
On 7/12/06, Nishi Bhonsle [EMAIL PROTECTED] wrote: Hi: Sorry to start this thread again, but it would not have been wise to ask my related question in a different thread. I tried to run the program on a windows machine, apparently the regex in question only lists directories within directories and not the files within the directories. I tried Rob's regex as well as Randal's. In addition how can I modify the code, so that the buildlist.txt only lists the files within the directories and not the directories? TIA! Nishi, Several people have suggested File::Find. You should really look it up on cpan. But since you asked about readdir... readdir() lists everything in the directory; files, directories, everything. If you're not seeing any files, you're reading a directory that only contains other directories. If you wan't to get only the files in a directory that contains files and directories, you need to test whether the handles are files or something else with a file test; readdir() just returns names. Something like this should get you started: opendir(DIR, $somedir) or die $!\n; my @files = grep { $_ !~ /^\.{1,2}$/ -f $somedir/$_ } readdir(DIR); closedir(DIR); While we're on the subject, the regex doesn't list anything. readdir() lists. grep() uses the rexes to take what you don't want out of the list. The only files the regex is removing are files with names that are entirely strings of periods. If you're not seeing what you think you should be seeing, make sure your script is running from the correct directory. HTH, -- jay -- This email and attachment(s): [ ] blogable; [ x ] ask first; [ ] private and confidential daggerquill [at] gmail [dot] com http://www.tuaw.com http://www.dpguru.com http://www.engatiki.org values of β will give rise to dom!
Re: write out filenames of files existing on a filesystem into afile
Jay Savage wrote: opendir(DIR, $somedir) or die $!\n; my @files = grep { $_ !~ /^\.{1,2}$/ -f $somedir/$_ } readdir(DIR); closedir(DIR); my @files = grep { -f } glob( $somedir/* ); If you're not interested in subdirectories, you only need glob(). And yes, it doesn't list hidden files; that's because it shouldn't. Hidden files are HIDDEN! -- __END__ Just my 0.0002 million dollars worth, --- Shawn For the things we have to learn before we can do them, we learn by doing them. Aristotle * Perl tutorials at http://perlmonks.org/?node=Tutorials * A searchable perldoc is at http://perldoc.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Check whether a string exists
Hi: I would like to check whether the string [server_bin.files] exists in a particular file and if it does, then do not add it again. How can I check for this string using perl regex? Thanks!
Re: Check whether a string exists
On 7/12/06, Nishi Bhonsle [EMAIL PROTECTED] wrote: Hi: I would like to check whether the string [server_bin.files] exists in a particular file and if it does, then do not add it again. How can I check for this string using perl regex? Perl Faq 4 print seen server_bin.files if /server_bin\.files/; -- WC (Bill) Jones -- http://youve-reached-the.endoftheinternet.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Check whether a string exists
Hi: I tried the following -- open(FILE2,c:/writeto.txt); my @text = FILE2; foreach my $a(@text) { print(@text); if ($a !~ /server_lib\.files/) { print not seen server_lib.files; my $header = [server_lib.files]; print FILE2 \n; print FILE2 $header; print FILE2 \n; } else { print seen server_lib.files; } } apparently, i think because the file is open in append mode, i am not able to read the file whether it contains the string or not. I also noticed that the print(@text) does not print any contents to the console. How i can correct this? Thanks. On 7/12/06, Chasecreek Systemhouse [EMAIL PROTECTED] wrote: On 7/12/06, Nishi Bhonsle [EMAIL PROTECTED] wrote: Hi: I would like to check whether the string [server_bin.files] exists in a particular file and if it does, then do not add it again. How can I check for this string using perl regex? Perl Faq 4 print seen server_bin.files if /server_bin\.files/; -- WC (Bill) Jones -- http://youve-reached-the.endoftheinternet.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Printing after expression match
I can't believe I didn't find this through searching. While looping through a file,array,hash etc.. how can I start printing only after a certain expression matches. in other words how can I skip the lines in the data until an expression match. Thanks -- # want to print lines from apple on down while ($line = DATA) { next until $line =~ /^banan/; print $line; } __DATA__ orange peach banana apple pear mango -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Printing after expression match
# want to print lines from apple on down while ($line = DATA) { next until $line =~ /^banan/; print $line; } Hello,how about this? my $ok; while (DATA){ $ok = 1 if /^banan/; print if $ok; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Printing after expression match
Jim wrote: I can't believe I didn't find this through searching. While looping through a file,array,hash etc.. how can I start printing only after a certain expression matches. in other words how can I skip the lines in the data until an expression match. Thanks -- # want to print lines from apple on down while ($line = DATA) { next until $line =~ /^banan/; $line never changes, so this is an infinite loop. print $line; } __DATA__ orange peach banana apple pear mango Try: #!/usr/bin/perl use strict; use warnings; my $print_line = 0; while( DATA ){ if( /banana/ ){ $print_line = 1; }elsif( $print_line ){ print; } } __DATA__ orange peach banana apple pear mango -- __END__ Just my 0.0002 million dollars worth, --- Shawn For the things we have to learn before we can do them, we learn by doing them. Aristotle * Perl tutorials at http://perlmonks.org/?node=Tutorials * A searchable perldoc is at http://perldoc.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Printing after expression match
# want to print lines from apple on down while ($line = DATA) { next until $line =~ /^banan/; print $line; } Hello,how about this? my $ok; while (DATA){ $ok = 1 if /^banan/; print if $ok; } yes that works, thanks. Are there other ways using control structures? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Printing after expression match
Try: #!/usr/bin/perl use strict; use warnings; my $print_line = 0; while( DATA ){ if( /banana/ ){ $print_line = 1; }elsif( $print_line ){ print; } } __DATA__ orange peach banana apple pear mango -- Thanks, this is similar to Jeff's response, sets a flag to start printing thanks all for the help -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: regex repetition
On 07/12/2006 05:08 PM, Ryan Moszynski wrote: I need to write some code to allow users to specify which of a whole bunch of elements(e.g.512/1024) that they want to view. My idea for how to do this was to have them input a semicolon delimited list, for example: 1-10;25;33;100-250 i tried using this to check to make sure they input a valid list that i can process: [...] $str =~ m/^((\d+-\d+|\d+);?)+$/g; However, this does not consider 250-100 to be invalid. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Printing after expression match
Jim wrote: I can't believe I didn't find this through searching. While looping through a file,array,hash etc.. how can I start printing only after a certain expression matches. in other words how can I skip the lines in the data until an expression match. Thanks -- # want to print lines from apple on down while ($line = DATA) { next until $line =~ /^banan/; print $line; } __DATA__ orange peach banana apple pear mango while ( DATA ) { print if /^apple/ .. eof; } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Check whether a string exists
Hello , Hope this helps you. open(FILE2,+c:/writeto.txt); my @text = FILE2; @found = grep(/server_lib\.files/,@text); $arsize=$#found+1; if($arsize0) { print seen server_lib.files; } else { print not seen server_lib.files; my $header = [server_lib.files]; print FILE2 \n; print FILE2 $header; print FILE2 \n; } On 7/13/06, Nishi Bhonsle [EMAIL PROTECTED] wrote: Hi: I tried the following -- open(FILE2,c:/writeto.txt); my @text = FILE2; foreach my $a(@text) { print(@text); if ($a !~ /server_lib\.files/) { print not seen server_lib.files; my $header = [server_lib.files]; print FILE2 \n; print FILE2 $header; print FILE2 \n; } else { print seen server_lib.files; } } apparently, i think because the file is open in append mode, i am not able to read the file whether it contains the string or not. I also noticed that the print(@text) does not print any contents to the console. How i can correct this? Thanks. On 7/12/06, Chasecreek Systemhouse [EMAIL PROTECTED] wrote: On 7/12/06, Nishi Bhonsle [EMAIL PROTECTED] wrote: Hi: I would like to check whether the string [server_bin.files] exists in a particular file and if it does, then do not add it again. How can I check for this string using perl regex? Perl Faq 4 print seen server_bin.files if /server_bin\.files/; -- WC (Bill) Jones -- http://youve-reached-the.endoftheinternet.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- Regards Prabu M A
Re: Randla L. Schwartz is Wrong (WAS:write out filenames of files existing on a filesystem into afile)
I thought about this; then I thought about this; and then I thought about this. Randal L. Schwartz wrote: Shawn == Mr Shawn H Corey [EMAIL PROTECTED] writes: Shawn Not everyone who reads this mailing list posts to it. What impression Shawn would his comments leave on them? How can we encourage people to use Shawn Perl if they think they will receive harsh criticism? The fact that the Shawn criticism was to a response and not an original post is unimportant; the Shawn fact that is was done is. I never criticize a question here (unless it's homework), so this shouldn't be construed by onlookers as a discouragement to ask questions. First, you should never criticize a homework problem. Everybody has to learn how to do it right. Like you, I am astonish by those who try to pull a fast one. I mean I have been programming in Perl for more years than they have been alive. Do they really think they can pull a fast one on me? Well, maybe yes, but there are others to set me right. The proper way to ask a homework question is: I have this homework question that I don't understand. Please help me get started. Second, even if it's a homework question, what right do we have to treat it any different? Every question gets an answer; the more details you give, the more specific the answer. I *do* criticize broken *answers* though, so hopefully anyone looking on will *test* their answers before posting. Then the original questioner gets *good* code, I can skip answering that, and we *all win*. It's not the criticism, it's the tone. Everybody makes mistakes; even the great Randal L. Shwartz (I have a list). If you think somebody else has made a mistake, point it out. DO NOT SAY EVERYTHING THEY POST IS WRONG! This is what I'm aiming for. Ask all you want, but when you answer, be DAMN WELL sure that it's a good answer. And if you're not sure or you don't have time to test, MOVE ON, because someone else will probably answer better, faster, cheaper. There's enough experts in this group already: we don't need to be distracted by threads like this where we've had to point out the flaws in an answer. Thank you. Ask all you want, but do not angry the great god Randal L. Schwartz? Yeah, we who have busted our balls have answers. And we don't care what you think. All we are trying to do is answer the questions to the best of our abilities. You may have a better idea. BUT DO NOT THINK WE ARE INFERIOR BECAUSE WE DO NOT ANSWER THE SAME WAY YOU DO! You are wrong; not because your answers are wrong; it's because your attitude is wrong. People ask questions to support their egos; not to support yours. -- __END__ Just my 0.0002 million dollars worth, --- Shawn For the things we have to learn before we can do them, we learn by doing them. Aristotle * Perl tutorials at http://perlmonks.org/?node=Tutorials * A searchable perldoc is at http://perldoc.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Randla L. Schwartz is Wrong (WAS:write out filenames of files existing on a filesystem into afile)
Randla L. Schwartz is great on Perl field,I think everyone here has read some of his books.Those books bring us into Perl world and let us know what's the essence of Perl.I think he just want to let every answer here know the basic rules for asking/answering the questions.Follow the suggestions by him,this mailing lists should be more regular.Everyone newbie coming here,asking the questions and getting the right answers with good style,he would get more harvest rather than the problem itself.For me,I do agree here should have the basic potential rules for asking and answering,though this is a free lists. Shawn is always kind to reply all kinds of questions here with high-level skills.I think both you are great to people in the perl world.So don't be angry for something that's not so important please.This's a technology lists,too much topics about personal feeling shoud get things not good. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Randla L. Schwartz is Wrong (WAS:write out filenames of files existing on a filesystem into afile)
On 7/13/06, Mr. Shawn H. Corey [EMAIL PROTECTED] wrote: I thought about this; then I thought about this; and then I thought about this. Randal L. Schwartz wrote: Shawn == Mr Shawn H Corey [EMAIL PROTECTED] writes: Shawn Not everyone who reads this mailing list posts to it. What impression Shawn would his comments leave on them? How can we encourage people to use Shawn Perl if they think they will receive harsh criticism? The fact that the Shawn criticism was to a response and not an original post is unimportant; the Shawn fact that is was done is. I never criticize a question here (unless it's homework), so this shouldn't be construed by onlookers as a discouragement to ask questions. First, you should never criticize a homework problem. Everybody has to learn how to do it right. Like you, I am astonish by those who try to pull a fast one. I mean I have been programming in Perl for more years than they have been alive. Do they really think they can pull a fast one on me? Well, maybe yes, but there are others to set me right. The proper way to ask a homework question is: I have this homework question that I don't understand. Please help me get started. Second, even if it's a homework question, what right do we have to treat it any different? Every question gets an answer; the more details you give, the more specific the answer. I *do* criticize broken *answers* though, so hopefully anyone looking on will *test* their answers before posting. Then the original questioner gets *good* code, I can skip answering that, and we *all win*. It's not the criticism, it's the tone. Everybody makes mistakes; even the great Randal L. Shwartz (I have a list). If you think somebody else has made a mistake, point it out. DO NOT SAY EVERYTHING THEY POST IS WRONG! This is what I'm aiming for. Ask all you want, but when you answer, be DAMN WELL sure that it's a good answer. And if you're not sure or you don't have time to test, MOVE ON, because someone else will probably answer better, faster, cheaper. There's enough experts in this group already: we don't need to be distracted by threads like this where we've had to point out the flaws in an answer. Thank you. Ask all you want, but do not angry the great god Randal L. Schwartz? Yeah, we who have busted our balls have answers. And we don't care what you think. All we are trying to do is answer the questions to the best of our abilities. You may have a better idea. BUT DO NOT THINK WE ARE INFERIOR BECAUSE WE DO NOT ANSWER THE SAME WAY YOU DO! You are wrong; not because your answers are wrong; it's because your attitude is wrong. People ask questions to support their egos; not to support yours. -- __END__ Just my 0.0002 million dollars worth, --- Shawn For the things we have to learn before we can do them, we learn by doing them. Aristotle * Perl tutorials at http://perlmonks.org/?node=Tutorials * A searchable perldoc is at http://perldoc.perl.org/ Am I allowed to give a view point from the perspective of a newbie NOT to Perl, but to some of the styles I have been introduced to (Remember TIMTOWTDI ???) What has taken place here is a War of the Gods that reminds me of so many listservs, forums, and magazine rebuttals (letters to the editor). Eventually, with this type of war, this list will eventually cause the good ones to stop posting/answering and the newbies fearful of asking a question. Not gonna lie about it. My style of code would probably remind most of you of the 90's... BUT IT WORKS and I UNDERSTAND IT! For the most part, I learned that in Perl, there is more than one way to do it, BUT from this list, it appears that there is ONLY ONE way... So I ask, can someone up front stop the car, stop the arguing, simply pull over, ask for some directions and lead us to where ever it is we are supposedly going...As I forgot the map, starting to feel car-sick, and I gotta peee... All fun aside, I have a Perl question, but I have learned not to top post and NOT to hijack a thread... Thanks to all that have taught me such. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Randal L. Schwartz is Wrong (WAS:write out filenames of files existing on a filesystem into afile)
Jeff Peng wrote: Shawn is always kind to reply all kinds of questions here with high-level skills.I think both you are great to people in the perl world.So don't be angry for something that's not so important please.This's a technology lists,too much topics about personal feeling shoud get things not good. First, I would like to say: I am sorry I got your name wrong in the Subject, it should be Randal L. Schwartz. I apologize for my error. Second, there is technology; and then there are people. I do not disagree with his answers about technology; I disagree with his attitude. Learning to program is a difficult task. Learning to program when somebody is given harsh criticism is even more difficult. It's not because he gave harsh criticism to one person; it's because these things spill over to all. I have put up with Mr. Schwartz' comments. I have put up with Mr. Schwartz calling me wrong, even though I was right (and the bad words he called me). BUT I WILL NOT TOLERATE HIM SAYING SOMEBODY SHOULD NOT POST TO THIS MAILING LIST BECAUSE OF AN ERROR. We all make mistakes. I make mistakes. Randal makes mistakes (I told you I have a list). Mistakes are not as important as attitude. It comes down to this, either he will post an apology for stating a third party should not post his comments, or I'll leave this list, never to return. I DON'T PUT UP WITH BULLIES IN ANY FORM, FOR ANY REASON! -- __END__ Just my 0.0002 million dollars worth, --- Shawn For the things we have to learn before we can do them, we learn by doing them. Aristotle * Perl tutorials at http://perlmonks.org/?node=Tutorials * A searchable perldoc is at http://perldoc.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: regex repetition
Mumia W. schreef: Ryan Moszynski: I need to write some code to allow users to specify which of a whole bunch of elements(e.g.512/1024) that they want to view. My idea for how to do this was to have them input a semicolon delimited list, for example: 1-10;25;33;100-250 i tried using this to check to make sure they input a valid list that i can process: [...] $str =~ m/^((\d+-\d+|\d+);?)+$/g; However, this does not consider 250-100 to be invalid. Nor 10-30-20. What's the g-modifier for? The structure is 'a;b;c;d', the smallest is 'a', so treat the ';' as the start of a trailer. -- Affijn, Ruud Gewoon is een tijger. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
MOVE ON ALREADY!!!
Please. This thread has gone on long enough. What started out as a question with mixed responses (admittedly, I think mine may have been off the mark), has turned into a waste of my drive space. So with respect to those of us that have seen enough MOVE ON ALREADY!!! Mathew Snyder Mr. Shawn H. Corey wrote: Jeff Peng wrote: Shawn is always kind to reply all kinds of questions here with high-level skills.I think both you are great to people in the perl world.So don't be angry for something that's not so important please.This's a technology lists,too much topics about personal feeling shoud get things not good. First, I would like to say: I am sorry I got your name wrong in the Subject, it should be Randal L. Schwartz. I apologize for my error. Second, there is technology; and then there are people. I do not disagree with his answers about technology; I disagree with his attitude. Learning to program is a difficult task. Learning to program when somebody is given harsh criticism is even more difficult. It's not because he gave harsh criticism to one person; it's because these things spill over to all. I have put up with Mr. Schwartz' comments. I have put up with Mr. Schwartz calling me wrong, even though I was right (and the bad words he called me). BUT I WILL NOT TOLERATE HIM SAYING SOMEBODY SHOULD NOT POST TO THIS MAILING LIST BECAUSE OF AN ERROR. We all make mistakes. I make mistakes. Randal makes mistakes (I told you I have a list). Mistakes are not as important as attitude. It comes down to this, either he will post an apology for stating a third party should not post his comments, or I'll leave this list, never to return. I DON'T PUT UP WITH BULLIES IN ANY FORM, FOR ANY REASON! -- If we don't protect freedom of speech, how will we know who the assholes are? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response