Re: Running a process in background?
Hi, Can I run more processes in background? A process runs fine but I want to run more processes. I have a search script and I am wondering if it will work faster if I will use more processes to query more database text files in the same time. Do I need to use the fork function for more times, or how could I run more processes? Thank you again. On Sun, 29 Sep 2002 16:40:07 +0200, [EMAIL PROTECTED] (Octavian Rasnita) wrote: I want to make a script that is activated from a browser but it might take a long time to send all the messages using the Net::SMTP. So I think that it could be a good idea to make a background process to run it. Can you give me some hints about how I should use the fork, to run the process in background? Your biggest problem is to close the pipes to apache from the forked children, else your clients will see their browser's hang. Merlyn has a good column on this at www.stonehenge.com column 20. Here is a simple example to demonstrate the problem. Make up some long process to test this with, like while(1){sleep(1)} Then try running it as a cgi script with and without the line which closes STDOUT, STDIN, and STDERR. With it commented out, your browser will hang. ## #!/usr/bin/perl use warnings; use strict; $| = 1; # need either this or to explicitly flush stdout, etc. # before forking print Content-type: text/plain\n\n; print Going to start the fork now\n; fork exit; #try running with the following line commented out close STDOUT;close STDIN;close STDERR; exec('./fork-long-process-test-process') || warn funniness $!; #if you use system here, instead of exec, the parent process #hangs around for child to exit, even though the cgi exits. # Teddy's Center for the blind: http://teddy.fcc.ro/ Email: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Running a process in background?
On Tue, 15 Oct 2002 08:01:43 +0200, [EMAIL PROTECTED] (Octavian Rasnita) wrote: Can I run more processes in background? A process runs fine but I want to run more processes. Maybe the Parallel::ForkManager module? If you want to do it manually, here is a sub which will fork a bunch of children and hand different data to each of them. ## #!/usr/bin/perl #For afork, the first argument is an array - a child will be #forked for each array element. The second argument indicates the maximum #number of children that may be alive at one time. The third argument is a #code reference; this is the code that will be executed by the child. One #argument will be given to this code fragment. For afork, the array element is #passed. Note that this code will assume no other children will be spawned, #and that $SIG {CHLD} hasn't been set to IGNORE. #by Abigail if ($#ARGV 0){@ARGV = qw( 1 2 3 4 5)} afork (\@ARGV,10,\hello); print Main says: All done now\n; sub hello{ my $data = $_[0]; print hello world from $data\n;} ## sub afork (\@$) { my ($data, $max, $code) = @_; my $c = 0; foreach my $data (@$data) { wait unless ++ $c = $max; die Fork failed: $!\n unless defined (my $pid = fork); exit $code - ($data) unless $pid; } 1 until -1 == wait; } # ### -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
hr; ##syntax error
Hello all, I am getting a syntax error when trying to run the following with CGI (:standard). It is at line 24 which is marked below. This is coming directly from the CGI.PM documentation, worse yet I am running PERL 5.6.1. Am I missing something obvious? # # Code Example # # #!/usr/local/bin/perl use CGI qw(:standard); print header; print start_html('A Simple Example'), h1('A Simple Example'), start_form, What's your name? ,textfield('name'), p, What's the combination?, p, checkbox_group(-name='words', -values=['eenie','meanie','minie','moe'], -defaults=['eenie','minie']), p, What's your favorite color?, popup_menu(-name='color', -values=['red','green','blue','chartreuse'], p, submit, end_form, hr; ==Line 24 if (param()) { print Your name is,em(param('name')), p, The keywords are: ,em(join(, ,param('words'))), p, Your favorite color is ,em(param('color')), hr; } print end_html; # #End_of_code example# # I developed on WIN32 in Primal Script which saw the error, I then saved the program and moved it to LINUX, with PERL 5.6.1 and the problem showed up there as well. I have done a search on Google, with no help. I have even reread through O'Rielly's book. I appreciate any help -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: hr; ##syntax error
Robert, You're missing a closing paren on the popup_menu function. William -- Lead Developer Knowmad Services Inc. || Internet Applications Database Integration http://www.knowmad.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
FW: replacing numbers around a decimal
Never mind. I figured it out using substr(). Thanks, Andrew -Original Message- From: Hughes, Andrew Sent: Wednesday, October 16, 2002 4:04 PM To: [EMAIL PROTECTED] Subject: replacing numbers around a decimal I am creating a little calculator that is going to need to take a user entered number that will always have 2 decimal places (using sprintf). It could be 89562321.29 or it could be 101.00) and take the last 4 digits (with the period included, so five places) and do two things: 1)Store the number in a variable. For the two examples above that would be 21.29 and 01.00 respectively would be stored in their own variable x=21.29 or it could be x=01.00; and 2) replace the last 4 numbers (5 places) with 00.00 -- always. For the two examples above they would become 89562300.00 and 100.00. Can anyone point me in the right direction? Thanks, Andrew -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Newbie Question.
I've been looking through the manual perlboot. This is a beginners tutorial on Perl OOP. One of the practice programs in this manual had the following line: my $class = shift; This was located in the subroutine: sub Sheep::speak {...} From what I've gathered so far, my makes the variable $class local to the subroutine only? Is this correct? shift takes the leftmost value out of a list and places it in the variable $class? Is this correct? If I got all of this correct, where is the array that shift is working on and why use shift instead of pop? Also what are the contents of this array and how can I see them? I know that that line of code places the value Sheep into $class, I was just wondering how this works in plain English? I'm guessing, and please correct me if I'm wrong here, the array is @_? And this array contains the current class name Sheep as it's only item? And this is why shift and pop produce the same results? Thanks in advance. SA I can do everything on my Mac that I used to do on my PC, plus alot more ... --Me -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
More Newbie OOP Questions ...
Take the following example from the perlboot manual: { package Horse; @ISA = qw(Animal); sub sound { neigh } sub name { my $self = shift; $$self; } sub named { my $class = shift; my $name = shift; bless \$name, $class; } } my $talking = Horse-named(Mr. Ed); print $talking-name, says , $talking-sound, \n; When we create the instance, what values go into @_ so that $talking-name returns the de-referenced scalar Mr. Ed, $class receives the value Horse, and $name receives the reference $talking? Or am I wrong on how this works? Thanks. SA P.S. (Please use plain English, for I am not the most proficient Perl programmer yet.) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
converting to CSV
I need some much needed help to do some data munging. I come from a C++ background (3+ years) and have little experience with PERL (about 2 months). At work today I was given a task to convert 1300+ logs to a new format, and the program is due tomorrow (i know.. how nice?)!!! Currently a log is defined in this format [http://us.f1.yahoofs.com/users/593a164/bc/sample/current_format.txt?bcecNr9AYfCpF3LW] and needs to be converted to a CSV file in this format [http://us.f1.yahoofs.com/users/593a164/bc/sample/csv.htm?bcecNr9A7uS5stoy] As of right now, I'm stuck of how to extract each token from the old format and convert it to the new format such as the values of author, number , version number. I've tried to find some sample code on the NET including this site but was unable. Please bless me with some PERL wisdom to get me started on this. I will greatly apprecitiate any help that I get. Thanks ahead. -- http://fastmail.fm/ - IMAP accessible web-mail -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: converting to CSV
Yahoo! is acting funny. http://www.geocities.com/pelpme/current_format.txt (original file) http://www.geocities.com/pelpme/csv.htm (new format) On Wed, 16 Oct 2002 03:10:12 UT, pelp [EMAIL PROTECTED] said: This is the correct link to the CSV file, http://us.f1.yahoofs.com/users/593a164/bc/sample/csv.htm?bchPOr9A0FpGqXUN On Wed, 16 Oct 2002 02:55:34 UT, pelp [EMAIL PROTECTED] said: I need some much needed help to do some data munging. I come from a C++ background (3+ years) and have little experience with PERL (about 2 months). At work today I was given a task to convert 1300+ logs to a new format, and the program is due tomorrow (i know.. how nice?)!!! Currently a log is defined in this format [http://us.f1.yahoofs.com/users/593a164/bc/sample/current_format.txt?bcecNr9AYfCpF3LW] and needs to be converted to a CSV file in this format [http://us.f1.yahoofs.com/users/593a164/bc/sample/csv.htm?bcecNr9A7uS5stoy] As of right now, I'm stuck of how to extract each token from the old format and convert it to the new format such as the values of author, number , version number. I've tried to find some sample code on the NET including this site but was unable. Please bless me with some PERL wisdom to get me started on this. I will greatly apprecitiate any help that I get. Thanks ahead. -- http://fastmail.fm/ - IMAP accessible web-mail -- http://fastmail.fm/ - IMAP accessible web-mail -- http://fastmail.fm - Email service worth paying for. Try it for free -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Backup Program?
hi and how do this in unix? cio Hi - Just curious - why not use xcopy? Do you want a GUI? Aloha = Beau. -Original Message- From: Steve Gross [mailto:[EMAIL PROTECTED]] Sent: Tuesday, October 15, 2002 7:33 PM To: [EMAIL PROTECTED] Subject: Backup Program? Does anyone out there have a program that will back up windows files from one drive to another? I would like it to work like DOS xcopy, which can copy files or directories, plus it wouldn't bother if the source file hadn't changed since the last backup. I've looked on CPAN with no results. Thanks. __ Stephan Gross 732-548-3494 [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Couple of qustions...
How would I go about going to a previous line? I would also like to do several regexp's against a scalar value...something like this (hopefully you know a way for me to make this shorter!) $next_music_file =~ s/[.]/ /; $next_music_file =~ s/^[0]//; $next_music_file =~ s/.flac//; $next_music_file =~ s/[_]/ /g; Thanks for any help. shawn -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Trying to strip HTML tags
Hi all, I have a CGI script that tries to remove the tags from a string that represents the content of an HTML file. There are a number of tags that I would like to keep intact, and I represent them in the following array: @INCLUDE_TAGS = ( I, BR, SUP, FONT, P ); However, some of these tags take arguments (FONT and P, for example) and I cannot seem to get the script to leave these tags intact. Below is the regular expression that I am using to perform the search and replace operation: $html =~ s/[^]*[^(@INCLUDE_TAGS.*)]/ /gi; I don't know if I've missed something obvious, but if anyone can help me out that would be wonderful. Thanks in advance, Graig -- 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: file to file copy
hi again, i've got some problems using your script: best is if i give you the three files so here they are file1 should be merged in file2 but file2 should have the same layout as befor merging christophe folschette Rob wrote: Christophe I think using Tie::File is overkill here. Try this: # Merge the two files into a single hash # for $file ( 'file2.dat', 'file1.dat' ) { open FILE, $file; while ( FILE ) { chomp; ($key, $val) = split /:\s+/; $data{$key} = $val; } close FILE; } # and splat it out again # open FILE, file3.dat; printf FILE %s: %s\n, $_, $data{$_} for (sort keys %data); close FILE; I'm not sure about your 'some text'. If you're allowing comment lines starting with a hash then next if /^#/; at the start of the inner loop will do. Now if you want the comments retaining, that's another matter :)) I never like posting just a solution on the beginners' group, but I don't think I'm doing anything obscure here that needs explaining. Tell me if I'm wrong. HTH. Cheers, Rob - Original Message - From: folschette [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, October 15, 2002 10:56 AM Subject: file to file copy hello, i have to write a perl script which copies text from one file to another but only if the text is not exisiting yet. For example: in file1: word: moon word2: sky ... the same syntax for every line in file2: #some text word: honey word3: lol word4: mu ... as well the same syntax for every line so now i want to merge file1 into file2, so that word: honey will be replaced by word: moon and word2: sky will be appended to file2. i have written the following script but i've got little problem with it, can someone help me? or test it? thanx, christophe folschette -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] start_url: http://www.google.com common_dir: /search/common database_dir: /search/db config_dir: /search/conf limit_urls_to: ${start_url} exclude_urls: /cgi-bin/ .cgi bad_extensions: .wav .gz .z .sit .au .zip .tar .hqx .exe .com .gif \ .jpg .jpeg .aiff .class .map .ram .tgz .bin .rpm .mpg .mov .avi # The excerpts that are displayed in long results rely on stored information # in the index databases. The compiled default only stores 512 characters of # text from each document (this excludes any HTML markup...) If you plan on # using the excerpts you probably want to make this larger. The only concern # here is that more disk space is going to be needed to store the additional # information. Since disk space is cheap (! :-)) you might want to set this # to a value so that a large percentage of the documents that you are going # to be indexing are stored completely in the database. At SDSU we found # that by setting this value to about 50k the index would get 97% of all # documents completely and only 3% was cut off at 50k. You probably want to # experiment with this value. # Note that if you want to set this value low, you probably want to set the # excerpt_show_top attribute to false so that the top excerpt_length characters # of the document are always shown. # max_head_length:75000 # The following are used to change the text for the page index. # The defaults are just boring text numbers. These images spice # up the result pages quite a bit. (Feel free to do whatever, though) # next_page_text: prochaine page no_next_page_text: prev_page_text: page précédente no_prev_page_text: page_number_text: 1 \ 2 \ 3 \ 4 \ 5 \ 6 \ 7 \ 8 \ 9 \ 10 # # To make the current page stand out, we will put a border arround the # image for that page. # no_page_number_text:b1/b \ b2/b \ b3/b \ b4/b \ b5/b \ b6/b \ b7/b \ b8/b \ b9/b \ b10/b #LENGTH OF THE EXCERPT excerpt_length: 500 #if the searched word isn't found in the document itself, the beginning of the document is shown if excerpt_show_top: yes excerpt_show_top: no #wann dat gesichtent wuert net fonnt get dann get keen excerpt ugewisen #no_excerpt_text: Le mot que vous aviez recherché ne peut pas être trouvé en tant que tel dans ce document mais par exemple si vous aviez recherché le mot #'tabac', il se peut que le mot 'tabacs' a été trouvé dans le document en
RE: Backup Program? [OT]
-Original Message- From: folschette [mailto:[EMAIL PROTECTED]] Sent: 16 October 2002 08:19 To: [EMAIL PROTECTED] Subject: RE: Backup Program? hi and how do this in unix? cio OT as this is not Perl A nice easy option is rsync http://www.google.com/search?sourceid=navclientq=rsync An alternative approach is find /dir/to/backup | cpio -pm /var/backup/ do a man find to see all the find options you can use - for example you can tell find to only report files modified within the last day with: find /dir/to/backup -mtime 1 | cpio -pm /var/backup/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: excluding @@
On Fri, 11 Oct 2002, david wrote: Sudarshan Raghavan wrote: $ perl -Mstrict -wle'@+ = qw/b c d/;(my $name = q/a b c d efg/) =~ s/@+//; print $name' a b c d efg When I run this on 5.8.0 it gives out a 'Modification of a read only attempted...' Same with 5.6.1 as well, but not the case with 5.6.0 which distribution of Perl you have? ActiveState? the Mac side? be specific. your statement is far reaching. did you try what you just said? do you mean you have to use s/\@+/xxx/ instead of just s/@+/xxx/ in 5.6.1? No, you don't have to escape '@' in 5.6.1. try it before you post: I did try it out before I posted. In the example you have given below, you are not trying to modify @+. Try that and you will get the fatal message on 5.6.1 too. sraghav@nt1488 ~$ /usr/bin/perl -v This is perl, v5.6.1 built for i386-linux #!/usr/bin/perl -w use strict; use 5.6.1; my $i = 'abcd1234'; $i =~ s/@+/__hahaha__/; print $i\n; #-- guess what that prints __END__ prints: abcd__hahaha___1234 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
CGI for ftp?
Hello, I am searching for an Perl/CGI for up/downloading and editing files on an ftp-server via http-interface. Has somebody made such a programm? I made a programm for editing files on the server via http. Thanks. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Backup Program?
In which Unix? ex. rcopy rsync a GUI solution using the File Manager and mounting the disks using NFS/Samba etc Pablo.- -Original Message- From: folschette [mailto:[EMAIL PROTECTED]] Sent: 16 October 2002 08:19 To: [EMAIL PROTECTED] Subject: RE: Backup Program? hi and how do this in unix? cio Hi - Just curious - why not use xcopy? Do you want a GUI? Aloha = Beau. -Original Message- From: Steve Gross [mailto:[EMAIL PROTECTED]] Sent: Tuesday, October 15, 2002 7:33 PM To: [EMAIL PROTECTED] Subject: Backup Program? Does anyone out there have a program that will back up windows files from one drive to another? I would like it to work like DOS xcopy, which can copy files or directories, plus it wouldn't bother if the source file hadn't changed since the last backup. I've looked on CPAN with no results. Thanks. __ Stephan Gross 732-548-3494 [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: creating a string on the fly
Sorry Vincent I'm not sure what you're meaning. You've written GetColumns ($table). Does it return an array of column names as it should? - Original Message - From: Vincent Lee [EMAIL PROTECTED] To: Rob [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Tuesday, October 15, 2002 11:05 PM Subject: RE: creating a string on the fly Rob, I've written a subroutine do the getColumns($table). The problem is that it's passing the entire column set back and appending each one. 'Passing the entire column set back' is surely what you want? 'Appending each one' what to what? I just do a select of the columns based on the table that is sent to the subroutine. The code you sent me does the entire thing...any ideas? Sounds like you just need to package the inner loop inside a subroutine: sub CreateView { $table = shift; print CREATE VIEW_$table AS\n; print SELECT (; $n = 0; foreach $column ( GetColumns ($table) ) { print , if $n++; print $column; } print ) FROM $table;\n; } Am I reading you right? R -Original Message- From: Rob [mailto:[EMAIL PROTECTED]] Sent: Tuesday, October 15, 2002 11:38 AM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re: creating a string on the fly Two problems here. 1/ Getting the tables' names and columns from the database. 2/ Constructing the SQL from that information. The second part is easy: foreach $table ( GetTables() ) { print CREATE VIEW_$table AS\n; print SELECT (; $n = 0; foreach $column ( GetColumns ($table) ) { print , if $n++; print $column; } print ) FROM $table;\n; } Which may be enough for you. GetTables() and GetColumns() are the first part, and I can't say any more about what these might do without knowing more about what interface you have with the database. HTH Rob - Original Message - From: Vincent Lee [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Tuesday, October 15, 2002 3:37 PM Subject: Re: creating a string on the fly -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Newbie Question.
Yes, shift operates on @_ by default, which is also the array that contains all arguments passed to the subroutine. You are probably right that Sheep is the only item in the list, due to the shift/pop behavior you mentioned. -Original Message- From: montana [mailto:[EMAIL PROTECTED]] Sent: Tuesday, October 15, 2002 2:41 PM To: [EMAIL PROTECTED] Subject: Newbie Question. I've been looking through the manual perlboot. This is a beginners tutorial on Perl OOP. One of the practice programs in this manual had the following line: my $class = shift; This was located in the subroutine: sub Sheep::speak {...} From what I've gathered so far, my makes the variable $class local to the subroutine only? Is this correct? shift takes the leftmost value out of a list and places it in the variable $class? Is this correct? If I got all of this correct, where is the array that shift is working on and why use shift instead of pop? Also what are the contents of this array and how can I see them? I know that that line of code places the value Sheep into $class, I was just wondering how this works in plain English? I'm guessing, and please correct me if I'm wrong here, the array is @_? And this array contains the current class name Sheep as it's only item? And this is why shift and pop produce the same results? Thanks in advance. SA I can do everything on my Mac that I used to do on my PC, plus alot more --Me -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Mailing from Windows 98
Emailing using Perl on a Windows system is pretty much the same as emailing on any system, provided that you have access to an SMTP server. If you know the DNS name or address of your SMTP server, then check out the following modules: Mail::SendMail; Mail::Sender; Net::SMTP; (I might have the case wrong, so double-check them before using them) -Original Message- From: Rajendra Babu, Praveen [mailto:[EMAIL PROTECTED]] Sent: Tuesday, October 15, 2002 11:27 PM To: '[EMAIL PROTECTED]' Subject: Mailing from Windows 98 Hello All, I am to write a program which also mails the result of the execution. I am doing this in Windows 98. Can someone please guide me from where could I start knowing more about e-mailing using Perl in Windows system. Thanks in advance, Praveen IMPORTANT- (1) The contents of this email and its attachments are confidential and intended only for the individual or entity named above. Any unauthorised use of the contents is expressly prohibited. If you receive this email in error, please contact us, then delete the email. (2) ACNielsen collects personal information to provide and market our services. For more information about use, disclosure and access see our privacy policy at www.acnielsen.com.au or contact us on [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: file to file copy
hi again, and which i forgot to say: while merging file1 into file2 , no key should be double, the right key is the one in file1!! so in fact it is a replacement of some lines in file2 by some lines in file1, and the lines that don't exist yet in file2 are appended. thanx, christophe folschette Folschette wrote: hi again, i've got some problems using your script: best is if i give you the three files so here they are file1 should be merged in file2 but file2 should have the same layout as befor merging christophe folschette Rob wrote: Christophe I think using Tie::File is overkill here. Try this: # Merge the two files into a single hash # for $file ( 'file2.dat', 'file1.dat' ) { open FILE, $file; while ( FILE ) { chomp; ($key, $val) = split /:\s+/; $data{$key} = $val; } close FILE; } # and splat it out again # open FILE, file3.dat; printf FILE %s: %s\n, $_, $data{$_} for (sort keys %data); close FILE; I'm not sure about your 'some text'. If you're allowing comment lines starting with a hash then next if /^#/; at the start of the inner loop will do. Now if you want the comments retaining, that's another matter :)) I never like posting just a solution on the beginners' group, but I don't think I'm doing anything obscure here that needs explaining. Tell me if I'm wrong. HTH. Cheers, Rob - Original Message - From: folschette [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, October 15, 2002 10:56 AM Subject: file to file copy hello, i have to write a perl script which copies text from one file to another but only if the text is not exisiting yet. For example: in file1: word: moon word2: sky ... the same syntax for every line in file2: #some text word: honey word3: lol word4: mu ... as well the same syntax for every line so now i want to merge file1 into file2, so that word: honey will be replaced by word: moon and word2: sky will be appended to file2. i have written the following script but i've got little problem with it, can someone help me? or test it? thanx, christophe folschette -- 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: Couple of qustions...
Fogle Cpl Shawn B wrote: How would I go about going to a previous line? Save the previous line in a variable or use tell() and seek() to reposition the file pointer. I would also like to do several regexp's against a scalar value...something like this (hopefully you know a way for me to make this shorter!) $next_music_file =~ s/[.]/ /; $next_music_file =~ s/^[0]//; $next_music_file =~ s/.flac//; $next_music_file =~ s/[_]/ /g; Can you describe what you want to do in english? The substitutions you show can't be made much shorter. John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Newbie Question.
Hi, don't know much about oo in perl, but a regular sub: From man perlsub: [...] All functions aree passead as parameters one single flat list os scalars. [...] Any arguments passed in show up in the array '@_'.Therefor, if you called a function with two arguments, those would be stored in '$_[0] and $_[1]. Hope it helps, Duarte -Original Message- From: montana [mailto:[EMAIL PROTECTED]] Sent: Tuesday, October 15, 2002 10:41 PM To: [EMAIL PROTECTED] Subject: Newbie Question. I've been looking through the manual perlboot. This is a beginners tutorial on Perl OOP. One of the practice programs in this manual had the following line: my $class = shift; This was located in the subroutine: sub Sheep::speak {...} From what I've gathered so far, my makes the variable $class local to the subroutine only? Is this correct? shift takes the leftmost value out of a list and places it in the variable $class? Is this correct? If I got all of this correct, where is the array that shift is working on and why use shift instead of pop? Also what are the contents of this array and how can I see them? I know that that line of code places the value Sheep into $class, I was just wondering how this works in plain English? I'm guessing, and please correct me if I'm wrong here, the array is @_? And this array contains the current class name Sheep as it's only item? And this is why shift and pop produce the same results? Thanks in advance. SA I can do everything on my Mac that I used to do on my PC, plus alot more ... --Me -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] For your protection, this e-mail message has been scanned for viruses. Visit us at http://www.neoris.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Backup Program?
In linux you can use: cp -a In almost any other unix (including linux): Cp -dpR -- Duarte Manuel Cordeiro -Original Message- From: folschette [mailto:[EMAIL PROTECTED]] Sent: Wednesday, October 16, 2002 8:19 AM To: [EMAIL PROTECTED] Subject: RE: Backup Program? hi and how do this in unix? cio Hi - Just curious - why not use xcopy? Do you want a GUI? Aloha = Beau. -Original Message- From: Steve Gross [mailto:[EMAIL PROTECTED]] Sent: Tuesday, October 15, 2002 7:33 PM To: [EMAIL PROTECTED] Subject: Backup Program? Does anyone out there have a program that will back up windows files from one drive to another? I would like it to work like DOS xcopy, which can copy files or directories, plus it wouldn't bother if the source file hadn't changed since the last backup. I've looked on CPAN with no results. Thanks. __ Stephan Gross 732-548-3494 [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] For your protection, this e-mail message has been scanned for viruses. Visit us at http://www.neoris.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Newbie Question.
[1] pop takes out the elements from the right end of the array while shift does that from the left end. [2]When there is one element then the above mentioned functions will give you the same result :) [3] Yes, your notion about my is correct but for more information go through the man pages on www.perldoc.com or your system. [4] Here @_ is the array (you are right about that also). In this case you don't have to mention the name of the array. Regards Dharmender Rai --- montana [EMAIL PROTECTED] wrote: I've been looking through the manual perlboot. This is a beginners tutorial on Perl OOP. One of the practice programs in this manual had the following line: my $class = shift; This was located in the subroutine: sub Sheep::speak {...} From what I've gathered so far, my makes the variable $class local to the subroutine only? Is this correct? shift takes the leftmost value out of a list and places it in the variable $class? Is this correct? If I got all of this correct, where is the array that shift is working on and why use shift instead of pop? Also what are the contents of this array and how can I see them? I know that that line of code places the value Sheep into $class, I was just wondering how this works in plain English? I'm guessing, and please correct me if I'm wrong here, the array is @_? And this array contains the current class name Sheep as it's only item? And this is why shift and pop produce the same results? Thanks in advance. SA I can do everything on my Mac that I used to do on my PC, plus alot more ... --Me -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ Do You Yahoo!? Everything you'll ever need on one web page from News and Sport to Email and Music Charts http://uk.my.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: file to file copy
Hi, Christophe I suggest the following (see attached file: modcfg) Hope this helps. folschette a écrit : hi again, and which i forgot to say: while merging file1 into file2 , no key should be double, the right key is the one in file1!! so in fact it is a replacement of some lines in file2 by some lines in file1, and the lines that don't exist yet in file2 are appended. thanx, christophe folschette Folschette wrote: hi again, i've got some problems using your script: best is if i give you the three files so here they are file1 should be merged in file2 but file2 should have the same layout as befor merging christophe folschette Rob wrote: Christophe I think using Tie::File is overkill here. Try this: # Merge the two files into a single hash # for $file ( 'file2.dat', 'file1.dat' ) { open FILE, $file; while ( FILE ) { chomp; ($key, $val) = split /:\s+/; $data{$key} = $val; } close FILE; } # and splat it out again # open FILE, file3.dat; printf FILE %s: %s\n, $_, $data{$_} for (sort keys %data); close FILE; I'm not sure about your 'some text'. If you're allowing comment lines starting with a hash then next if /^#/; at the start of the inner loop will do. Now if you want the comments retaining, that's another matter :)) I never like posting just a solution on the beginners' group, but I don't think I'm doing anything obscure here that needs explaining. Tell me if I'm wrong. HTH. Cheers, Rob - Original Message - From: folschette [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, October 15, 2002 10:56 AM Subject: file to file copy hello, i have to write a perl script which copies text from one file to another but only if the text is not exisiting yet. For example: in file1: word: moon word2: sky ... the same syntax for every line in file2: #some text word: honey word3: lol word4: mu ... as well the same syntax for every line so now i want to merge file1 into file2, so that word: honey will be replaced by word: moon and word2: sky will be appended to file2. i have written the following script but i've got little problem with it, can someone help me? or test it? thanx, christophe folschette -- 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] #!/usr/local/bin/perl -w use strict; my %modif; my ($key, $val); # first store modifs from file1 to a hash # assuming the format is: keyword:whitespacevalue # keywords and values are only one word each ! open(F1, ./file1.txt) or die Can't open file1.txt for reading.\n; while(F1) { chomp; ($key, $val) = split(); $modif{$key} = $val; } close(F1); # now copy file2 to file3, modifying lines as needed open(F2, ./file2.txt) or die Can't open file2.txt for reading.\n; open(F3, ./file3.txt) or die Can't open file3.txt for writing.\n; while(F2) { chomp; # assume 'interesting' lines always contain some_word: some_text # if that key already exists in the hash (in file1) # - prepare line in $_ for further printing in F3 # - delete that (precessed) key in the hash # always print the line in F3 (modified or unchanged) if(/:/) { ($key, $val) = split(); if (defined($modif{$key})) { $_ = $key $modif{$key}; delete $modif{$key}; } } print F3 $_\n;; } # last, print a line to file3 for each key remaining in the hash while (($key, $val) = each(%modif)) { print F3 $key $val\r\n\n; } close(F2); close(F3); -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Trying to strip HTML tags
From: Graig Warner [EMAIL PROTECTED] I have a CGI script that tries to remove the tags from a string that represents the content of an HTML file. There are a number of tags that I would like to keep intact, and I represent them in the following array: @INCLUDE_TAGS = ( I, BR, SUP, FONT, P ); However, some of these tags take arguments (FONT and P, for example) and I cannot seem to get the script to leave these tags intact. Below is the regular expression that I am using to perform the search and replace operation: $html =~ s/[^]*[^(@INCLUDE_TAGS.*)]/ /gi; I don't know if I've missed something obvious, but if anyone can help me out that would be wonderful. It's not that easy to parse HTML properly. Therefore it's best to use a tested module. Like HTML::Parser. You don't have to use it directly though. See http://Jenda.Krynicky.cz/#HTML::JFilter use HTML::JFilter; $filter = new HTML::JFilter '*END*' b i code pre br a: href name font: color size style *END* $filteredHTML = $filter-doSTRING($enteredHTML); If you are using ActivePerl you may install HTML::JFilter from my repository by ppm install --location=http://Jenda.Krynicky.cz/perl HTML-JFilter HTH, Jenda === [EMAIL PROTECTED] == http://Jenda.Krynicky.cz == When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Backup Program?
Take a look at File::Copy -Original Message- From: Steve Gross [mailto:[EMAIL PROTECTED]] Sent: Wednesday, October 16, 2002 1:33 AM To: [EMAIL PROTECTED] Subject: Backup Program? Does anyone out there have a program that will back up windows files from one drive to another? I would like it to work like DOS xcopy, which can copy files or directories, plus it wouldn't bother if the source file hadn't changed since the last backup. I've looked on CPAN with no results. Thanks. __ Stephan Gross 732-548-3494 [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
comparing two hashes
Hi, can any one point me at how to compare two hases. ie hash1 1 abc 2 def 3 ghi hash2 1 abc 2 defzzz 3 ghi I want to take the values for matching keys and see if they are the same if not write out the value so in the above the values in 1 and 1 are ok, the values in 3 and 3 are ok but in key 2 they do not match Thanks very much, Regards, Gary The information contained in or attached to this email is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, or a person responsible for delivering it to the intended recipient, you are not authorised to and must not disclose, copy, distribute, or retain this message or any part of it. It may contain information which is confidential and/or covered by legal professional or other privilege (or other rules or laws with similar effect in jurisdictions outside England and Wales). The views expressed in this email are not necessarily the views of Centrica plc, and the company, its directors, officers or employees make no representation or accept any liability for its accuracy or completeness unless expressly stated to the contrary. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: converting to CSV
Well, I don't know if this is exactly what you were looking for, but hopefully it's at least enough to get you started. You can run it with: perl convert.pl IN_FILE OUT_FILE I couldn't see how the Feature, Modification Date, and Last Modified fields were being used in the new format, so this version doesn't use them. They would be trivial to add, if you did want them though (add to %columns for the first two and/or modify the last split for the other). This script doesn't quote CSV fields that need it. None of your example fields did, but if others might, you'll have to add it. Good luck with your conversion. James #!/usr/bin/perl use 5.6.0; use strict; use warnings; my %columns = ( 'Author'= 1, 'Number'= 5, 'Version Number'= 4, 'File Name' = 0 ); my $header = 1; my @row = ('', '', '', '', '', '', '', '', ''); while () { if ($header) { my($name, $value) = split /:/, $_; if ($value) { $name =~ s/\s*$//; $value =~ s/^\s*(.+?)\s*$/$1/; $row[ $columns{$name} ] = $value if exists $columns{$name}; } else { $header = 0; print File Name,Author,Date (MM/DD/Year),, Time (H:M:S),Version No.,Number,, Feature Name,Paragraph Number,Requirement Number\n; } } else { (@row[7, 8], undef) = split; print join(',', @row) . \n; } } On Wednesday, October 16, 2002, at 03:50 AM, pelp wrote: Yahoo! is acting funny. http://www.geocities.com/pelpme/current_format.txt (original file) http://www.geocities.com/pelpme/csv.htm (new format) On Wed, 16 Oct 2002 03:10:12 UT, pelp [EMAIL PROTECTED] said: This is the correct link to the CSV file, http://us.f1.yahoofs.com/users/593a164/bc/sample/ csv.htm?bchPOr9A0FpGqXUN On Wed, 16 Oct 2002 02:55:34 UT, pelp [EMAIL PROTECTED] said: I need some much needed help to do some data munging. I come from a C++ background (3+ years) and have little experience with PERL (about 2 months). At work today I was given a task to convert 1300+ logs to a new format, and the program is due tomorrow (i know.. how nice?)!!! Currently a log is defined in this format [http://us.f1.yahoofs.com/users/593a164/bc/sample/ current_format.txt?bcecNr9AYfCpF3LW] and needs to be converted to a CSV file in this format [http://us.f1.yahoofs.com/users/593a164/bc/sample/ csv.htm?bcecNr9A7uS5stoy] As of right now, I'm stuck of how to extract each token from the old format and convert it to the new format such as the values of author, number , version number. I've tried to find some sample code on the NET including this site but was unable. Please bless me with some PERL wisdom to get me started on this. I will greatly apprecitiate any help that I get. Thanks ahead. -- http://fastmail.fm/ - IMAP accessible web-mail -- http://fastmail.fm/ - IMAP accessible web-mail -- http://fastmail.fm - Email service worth paying for. Try it for free -- 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: comparing two hashes
Something like: foreach (keys %hash1) { next if $hash1{$_} eq $hash2{$_}; print $hash1{$_} $hash2{$_}\n; } On Wednesday, October 16, 2002, at 08:54 AM, Egleton, Gary wrote: Hi, can any one point me at how to compare two hases. ie hash1 1 abc 2 def 3 ghi hash2 1 abc 2 defzzz 3 ghi I want to take the values for matching keys and see if they are the same if not write out the value so in the above the values in 1 and 1 are ok, the values in 3 and 3 are ok but in key 2 they do not match Thanks very much, Regards, Gary The information contained in or attached to this email is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, or a person responsible for delivering it to the intended recipient, you are not authorised to and must not disclose, copy, distribute, or retain this message or any part of it. It may contain information which is confidential and/or covered by legal professional or other privilege (or other rules or laws with similar effect in jurisdictions outside England and Wales). The views expressed in this email are not necessarily the views of Centrica plc, and the company, its directors, officers or employees make no representation or accept any liability for its accuracy or completeness unless expressly stated to the contrary. -- 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: comparing two hashes
.--[ Egleton, Gary wrote (2002/10/16 at 14:54:57) ]-- | | Hi, | | can any one point me at how to compare two hases. | | ie | | hash1 | 1 abc | 2 def | 3 ghi | | hash2 | 1 abc | 2 defzzz | 3 ghi | | I want to take the values for matching keys and see if they are the same if | not write out the value | | so in the above the values in 1 and 1 are ok, the values in 3 and 3 are ok | but in key 2 they do not match | `- This should do it: foreach my $key ( keys(%hash1) ) { if( $hash1{$key} ne $hash2{$key} ) { print hash1: $hash1{$key} hash2: $hash2{$key}\n; } } - Frank Wiles [EMAIL PROTECTED] http://frank.wiles.org - -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: comparing two hashes
How would you write to those 2 hashes??? -Original Message- From: Frank Wiles [mailto:[EMAIL PROTECTED]] Sent: Wednesday, October 16, 2002 11:25 AM To: Egleton, Gary Cc: [EMAIL PROTECTED] Subject:Re: comparing two hashes .--[ Egleton, Gary wrote (2002/10/16 at 14:54:57) ]-- | | Hi, | | can any one point me at how to compare two hases. | | ie | | hash1 | 1 abc | 2 def | 3 ghi | | hash2 | 1 abc | 2 defzzz | 3 ghi | | I want to take the values for matching keys and see if they are the same if | not write out the value | | so in the above the values in 1 and 1 are ok, the values in 3 and 3 are ok | but in key 2 they do not match | `- This should do it: foreach my $key ( keys(%hash1) ) { if( $hash1{$key} ne $hash2{$key} ) { print hash1: $hash1{$key} hash2: $hash2{$key}\n; } } - Frank Wiles [EMAIL PROTECTED] http://frank.wiles.org - -- 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]
How to use a module located relative to the current script
Hi, From some perl script, say some_path/lib/sos.pl, I would like to make use of a perl module, which is located at some_path/modules. I don't know what some_path is inside sos.pl, but I know that I can reach the module using a relative path ../modules. The problem is, writing use lib '../modules' treats the path as a relative path to the current directory, and not to the directory of sos.pl (if I understood correctly). Is there a way that I can say in sos.pl that I want to use the module located in ../modules relative to it? Thanks, Shlomo -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Newbie Question
So looking at the following package: { package Horse; @ISA = qw(Animal); sub sound { neigh } sub name { my $self = shift; $$self; } sub named { my $class = shift; my $name = shift; bless \$name, $class; } } followed by the following instantiation lines: my $talking = Horse-named(Mr. Ed); print $talking-name, says , $talking-sound, \n; The only variable I see passed to the package is the name Mr. Ed which is in fact passed to the constructor named located in the package Horse. Is this correct? So the constructor named takes the following list: @_ = {Horse, Mr. Ed} Is this correct? If so then Horse would be put into the scalar $class, and Mr. Ed would be put into the scalar $name. Is this correct? Ok so is $talking now an instance? And how does the $talking-sound produce neigh? Is the @ISA line and the sub name function needed in this package for Horse to still work, or is that there for inheritance purposes only? Thanks. SA P.S. I kind of try to work my questions out as I go along so sorry for the details if it is too much. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: comparing two hashes
but this only works if each hash has the same keys. if one hash might have more/less keys than the other use this: my %seen; foreach ( grep !$seen{$_}++, (keys %hash1, keys %hash2) ) { next if $hash1{$_} eq $hash2{$_}; print key: $_ - hash1: $hash1{$_} - hash2: $hash2{$_}\n; # now prints extra keys not in both hashes } -Original Message- From: James Edward Gray II [mailto:[EMAIL PROTECTED]] Sent: Wednesday, October 16, 2002 11:25 AM To: Egleton, Gary Cc: [EMAIL PROTECTED] Subject: Re: comparing two hashes Something like: foreach (keys %hash1) { next if $hash1{$_} eq $hash2{$_}; print $hash1{$_} $hash2{$_}\n; } The views and opinions expressed in this email message are the sender's own, and do not necessarily represent the views and opinions of Summit Systems Inc. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: comparing two hashes
.--[ Ned Cunningham wrote (2002/10/16 at 11:38:07) ]-- | | How would you write to those 2 hashes??? | I'm not quite sure what you mean by this. You can update the value at a certain key at anytime by simply assigning something to it like $hash1{2} = 'foobar'; This sets hash1's value at key '2' to 'foobar'. Or am I misunderstanding your question? - Frank Wiles [EMAIL PROTECTED] http://frank.wiles.org - | Subject:Re: comparing two hashes | | .--[ Egleton, Gary wrote (2002/10/16 at 14:54:57) | | | | Hi, | | | | can any one point me at how to compare two hases. | | | | ie | | | | hash1 | | 1 abc | | 2 def | | 3 ghi | | | | hash2 | | 1 abc | | 2 defzzz | | 3 ghi | | | | I want to take the values for matching keys and see if | they are the same if | | not write out the value | | | | so in the above the values in 1 and 1 are ok, the values | in 3 and 3 are ok | | but in key 2 they do not match | | | `- | | This should do it: | | foreach my $key ( keys(%hash1) ) { | | if( $hash1{$key} ne $hash2{$key} ) { | print hash1: $hash1{$key} hash2: $hash2{$key}\n; | } | | } | `- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to use a module located relative to the current script
use Path::To::Module; On Wednesday, October 16, 2002, at 10:05 AM, Reinstein, Shlomo wrote: Hi, From some perl script, say some_path/lib/sos.pl, I would like to make use of a perl module, which is located at some_path/modules. I don't know what some_path is inside sos.pl, but I know that I can reach the module using a relative path ../modules. The problem is, writing use lib '../modules' treats the path as a relative path to the current directory, and not to the directory of sos.pl (if I understood correctly). Is there a way that I can say in sos.pl that I want to use the module located in ../modules relative to it? Thanks, Shlomo -- 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: comparing two hashes
On Wed, 2002-10-16 at 09:54, Egleton, Gary wrote: Hi, can any one point me at how to compare two hases. ie hash1 1 abc 2 def 3 ghi hash2 1 abc 2 defzzz 3 ghi I want to take the values for matching keys and see if they are the same if not write out the value so in the above the values in 1 and 1 are ok, the values in 3 and 3 are ok but in key 2 they do not match Thanks very much, Regards, Gary snip / You could always use grep to get the keys that don't match: code #!/usr/bin/perl use warnings; use strict; my %hash1 = ( 1 = 'abc', 2 = 'def', 3 = 'ghi', ); my %hash2 = ( 1 = 'abc', 2 = 'defzzz', 3 = 'ghi', ); for my $k (grep { $hash1{$_} ne $hash2{$_} } keys %hash1) { print at key [$k]: [$hash1{$k}] doesn't equal [$hash2{$k}]\n; } /code -- Today is Prickle-Prickle the 70th day of Bureaucracy in the YOLD 3168 Or not. Missile Address: 33:48:3.521N 84:23:34.786W -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: How to use a module located relative to the current script
Use FindBin module. The advantage is that FindBin module belongs to standard distribution Your some_path/lib/sos.pl script will look like: #!/usr/bin/perl -w use strict; use FindBin qw($Bin) # so $Bin contains your some_path/lib #from here TMTWOTDI, one way is to pick up some_path from $Bin my ($some_path)=$Bin=~/(\S+)\/lib/; #then use lib use lib ($some_path/modules); HTH, José. -Original Message- From: Reinstein, Shlomo [mailto:[EMAIL PROTECTED]] Sent: Wednesday, October 16, 2002 5:05 PM To: '[EMAIL PROTECTED]' Subject: How to use a module located relative to the current script Hi, From some perl script, say some_path/lib/sos.pl, I would like to make use of a perl module, which is located at some_path/modules. I don't know what some_path is inside sos.pl, but I know that I can reach the module using a relative path ../modules. The problem is, writing use lib '../modules' treats the path as a relative path to the current directory, and not to the directory of sos.pl (if I understood correctly). Is there a way that I can say in sos.pl that I want to use the module located in ../modules relative to it? Thanks, Shlomo -- 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]
File::Find::find problem.
Script purpose: I am trying to search an extremely large mounted dir on NT and find the location of any file or dir that starts with a certain string that is given on command line. Problem: File::Find::find({wanted = \wanted}, 'e:\\'); There is something about this line that is just not working. I can enter a specific directory, such as 'e:\\foobar' and get the results that I desire. However if I leave it as it is in the script, the file does not display. I also get an opendir() error entering a certain dir that does not allow the script to complete. Questions: 1) Why will the script work if the next level dir is specified, but will not work off the root of the mounted dir? 2) If I specify no_chdir, will the find still search the entire dir tree or just the next dir level? Thanks to all that help. FILE1: #! C:\Perl\bin\perl.exe -w eval 'exec C:\Perl\bin\perl.exe -S $0 ${1+$}' if 0; #$running_under_some_shell use strict; use File::Find (); #open(OUT, output.txt) || die can't open output.txt: $!; # Set the variable $File::Find::dont_use_nlink if you're using AFS, # since AFS cheats. # for the convenience of wanted calls, including -eval statements: use vars qw/*name *dir *prune/; *name = *File::Find::name; *dir= *File::Find::dir; *prune = *File::Find::prune; # Traverse desired filesystems File::Find::find({wanted = \wanted}, 'e:\\'); #close(OUT); print \nfinished\n; exit; sub wanted { print *; /^$ARGV[0].*\z/s print($name\n); } EOF Thanks.
Re: How to use a module located relative to the current script
From: James Edward Gray II [EMAIL PROTECTED] use Path::To::Module; Beg::Your::Pardon? 1) this will not help him. This'll cause perl to search for Module.pm in all Path/To subdirectories of directories in @INC. But he needs to add something to @INC. 2) If you do this the module will most probably not initialize properly. In this case perl would assume there will be package Path::To::Module; in the Module.pm. And it will try to call the import() function in that package. On Wednesday, October 16, 2002, at 10:05 AM, Reinstein, Shlomo wrote: Hi, From some perl script, say some_path/lib/sos.pl, I would like to make use of a perl module, which is located at some_path/modules. I don't know what some_path is inside sos.pl, but I know that I can reach the module using a relative path ../modules. The problem is, writing use lib '../modules' treats the path as a relative path to the current directory, and not to the directory of sos.pl (if I understood correctly). Is there a way that I can say in sos.pl that I want to use the module located in ../modules relative to it? Thanks, Shlomo use FindBin qw($Bin); # this wil store the directory containing the script into $Bin use lib $Bin.'/../modules'; # this will add the directory you need to # @INC (list of library directories) Jenda === [EMAIL PROTECTED] == http://Jenda.Krynicky.cz == When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: How to use a module located relative to the current script
Use FindBin module. The advantage is that FindBin module belongs to standard distribution Your some_path/lib/sos.pl script will look like: #!/usr/bin/perl -w use strict; use FindBin qw($Bin) # so $Bin contains your some_path/lib #from here TMTWOTDI, one way is to pick up some_path from $Bin my ($some_path)=$Bin=~/(\S+)\/lib/; #then use lib use lib ($some_path/modules); HTH, José. -Original Message- From: Reinstein, Shlomo [mailto:[EMAIL PROTECTED]] Sent: Wednesday, October 16, 2002 5:05 PM To: '[EMAIL PROTECTED]' Subject: How to use a module located relative to the current script Hi, From some perl script, say some_path/lib/sos.pl, I would like to make use of a perl module, which is located at some_path/modules. I don't know what some_path is inside sos.pl, but I know that I can reach the module using a relative path ../modules. The problem is, writing use lib '../modules' treats the path as a relative path to the current directory, and not to the directory of sos.pl (if I understood correctly). Is there a way that I can say in sos.pl that I want to use the module located in ../modules relative to it? Thanks, Shlomo -- 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]
Re: File::Find::find problem.
Script purpose: I am trying to search an extremely large mounted dir on NT and find the location of any file or dir that starts with a certain string that is given on command line. Problem: File::Find::find({wanted = \wanted}, 'e:\\'); There is something about this line that is just not working. I can enter a specific directory, such as 'e:\\foobar' and get the results that I desire. However if I leave it as it is in the script, the file does not display. I also get an opendir() error entering a certain dir that does not allow the script to complete. I'd try File::Find::find({wanted = \wanted}, 'e:\\.'); Jenda === [EMAIL PROTECTED] == http://Jenda.Krynicky.cz == When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Help me on concurant comiunication
yes my server forks once the server starts it connects to a socket and starts to listen. then create processes as much as possible (about 50) but when one process reach the line while($client=$sockHandle-accept()){ #lines to handle the client } all the other processes blocks so the problem is when the fist client connected while this process start to handle tat request one of the other process react to the line $client=$sockHandle-accept() then all the other processes get blocked so the so the process which have a request to handle cant do it I use Windows2000 problem in sort is even when I use fork() when I call the accept() method program stops all the works and waits for a incoming request - Original Message - From: James Edward Gray II [EMAIL PROTECTED] To: Rakhitha Malinda Karunarathne [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Tuesday, October 15, 2002 11:29 PM Subject: Re: Help me on concurant comiunication This is a pretty involved issue, so I would need more information to help. By multiple processes, do you mean your server forks? As for more information, Network Programming with Perl by Lincoln D. Stein, covers this issue in detail and is quite good, I think. James On Tuesday, October 15, 2002, at 12:30 PM, Rakhitha Malinda Karunarathne wrote: I wrote a program (a server ) to listen for clients requests using multiple processes but while a one process waits to incoming client requests all the other processes blocks how can i over come this problem I used IO::Socket::INET for comiunication is there a better way and where can i find good documentation to learn about them ? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to use a module located relative to the current script
I stand corrected. My apologies. James On Wednesday, October 16, 2002, at 11:10 AM, Jenda Krynicky wrote: From: James Edward Gray II [EMAIL PROTECTED] use Path::To::Module; Beg::Your::Pardon? 1) this will not help him. This'll cause perl to search for Module.pm in all Path/To subdirectories of directories in @INC. But he needs to add something to @INC. 2) If you do this the module will most probably not initialize properly. In this case perl would assume there will be package Path::To::Module; in the Module.pm. And it will try to call the import() function in that package. On Wednesday, October 16, 2002, at 10:05 AM, Reinstein, Shlomo wrote: Hi, From some perl script, say some_path/lib/sos.pl, I would like to make use of a perl module, which is located at some_path/modules. I don't know what some_path is inside sos.pl, but I know that I can reach the module using a relative path ../modules. The problem is, writing use lib '../modules' treats the path as a relative path to the current directory, and not to the directory of sos.pl (if I understood correctly). Is there a way that I can say in sos.pl that I want to use the module located in ../modules relative to it? Thanks, Shlomo use FindBin qw($Bin); # this wil store the directory containing the script into $Bin use lib $Bin.'/../modules'; # this will add the directory you need to # @INC (list of library directories) Jenda === [EMAIL PROTECTED] == http://Jenda.Krynicky.cz == When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: How to use a module located relative to the current script
Thanks. However, I think this module won't help me. You see, some_path/lib/sos.pl is not the original (bin) script, but rather it's a library of routines used by many original scripts. That is to say, users don't run perl some_path/lib/sos.pl, but rather they run some other script which knows how to locate and require sos.pl. Shlomo -Original Message- From: NYIMI Jose (BMB) [mailto:[EMAIL PROTECTED]] Sent: Wednesday, October 16, 2002 6:10 PM To: Reinstein, Shlomo; [EMAIL PROTECTED] Subject: RE: How to use a module located relative to the current script Use FindBin module. The advantage is that FindBin module belongs to standard distribution Your some_path/lib/sos.pl script will look like: #!/usr/bin/perl -w use strict; use FindBin qw($Bin) # so $Bin contains your some_path/lib #from here TMTWOTDI, one way is to pick up some_path from $Bin my ($some_path)=$Bin=~/(\S+)\/lib/; #then use lib use lib ($some_path/modules); HTH, José. -Original Message- From: Reinstein, Shlomo [mailto:[EMAIL PROTECTED]] Sent: Wednesday, October 16, 2002 5:05 PM To: '[EMAIL PROTECTED]' Subject: How to use a module located relative to the current script Hi, From some perl script, say some_path/lib/sos.pl, I would like to make use of a perl module, which is located at some_path/modules. I don't know what some_path is inside sos.pl, but I know that I can reach the module using a relative path ../modules. The problem is, writing use lib '../modules' treats the path as a relative path to the current directory, and not to the directory of sos.pl (if I understood correctly). Is there a way that I can say in sos.pl that I want to use the module located in ../modules relative to it? Thanks, Shlomo -- 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]
Converting IO::Handle to filehandle
Hi, I have something like this my $child = new IO::Handle; When I try to redirect this handle to a filehandle using open(MY_DESCRIPTOR, $child); it gives me an error. What is it that I am doing wrong ?? Thanks -V __ Do you Yahoo!? Faith Hill - Exclusive Performances, Videos More http://faith.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
getting file on STDIN, howto process GLOB
Hi, I'm looking at a script that takes a file on STDIN. ### #!/usr/bin/perl my $input = \*STDIN; print $input\n; ## If I run it script somefile the result is GLOB(0x123ab458) What can you do with that GLOB? For instance to use the input file as a string or array? I've seen it used as input to new objects. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Help me on concurant comiunication
Again, this is very complicated, so I can really only give basic theory. The usual strategy of forking servers is to fork just after they receive a connection. The main loop usually looks close to: while (my $c = $socket-accept) { my $child = fork; die unless defined $child; if ($child == 0) { # in child process close $socket; # not needed, but safest handle_connection($c); exit 0; } close $c; # in parent process } The other main strategy is preforking, which is better under heavy loads. I believe this is a little closer to what you're describing. It typically looks like this: foreach (1..PREFORK_CHILDREN) { next if fork; # parent process do_child($socket); # child process exit 0; # child never loops } sub do_child { my $socket = shift; while (my $c = $socket-accept) { handle_connection($c); close $c; } } Of course, all of this is VERY basic. There are plenty of gotchas both ways. I'm not sure why your child processes would hang when the parent calls accept. This shouldn't happen. You mention that you're on Windows, but not your version of Perl. Forking on Windows didn't come until version 5.6.0, so you might check that. Also, try closing the listening socket in the children, as I did above, just to be safe. Again, I highly recommend Network Programming with Perl. It covers all of this very well. The code above is straight out of it. Good luck with your server. James On Wednesday, October 16, 2002, at 11:27 AM, Rakhitha Malinda Karunarathne wrote: yes my server forks once the server starts it connects to a socket and starts to listen. then create processes as much as possible (about 50) but when one process reach the line while($client=$sockHandle-accept()){ #lines to handle the client } all the other processes blocks so the problem is when the fist client connected while this process start to handle tat request one of the other process react to the line $client=$sockHandle-accept() then all the other processes get blocked so the so the process which have a request to handle cant do it I use Windows2000 problem in sort is even when I use fork() when I call the accept() method program stops all the works and waits for a incoming request - Original Message - From: James Edward Gray II [EMAIL PROTECTED] To: Rakhitha Malinda Karunarathne [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Tuesday, October 15, 2002 11:29 PM Subject: Re: Help me on concurant comiunication This is a pretty involved issue, so I would need more information to help. By multiple processes, do you mean your server forks? As for more information, Network Programming with Perl by Lincoln D. Stein, covers this issue in detail and is quite good, I think. James On Tuesday, October 15, 2002, at 12:30 PM, Rakhitha Malinda Karunarathne wrote: I wrote a program (a server ) to listen for clients requests using multiple processes but while a one process waits to incoming client requests all the other processes blocks how can i over come this problem I used IO::Socket::INET for comiunication is there a better way and where can i find good documentation to learn about them ? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: How to use a module located relative to the current script
From: Reinstein, Shlomo [EMAIL PROTECTED] Thanks. However, I think this module won't help me. You see, some_path/lib/sos.pl is not the original (bin) script, but rather it's a library of routines used by many original scripts. That is to say, users don't run perl some_path/lib/sos.pl, but rather they run some other script which knows how to locate and require sos.pl. Shlomo I see. Could you try to print $INC{'sos.pl'} or (if that doesn't print anything) use foreach (keys %INC) { print \t$_ = $INC{$_}\n; } This should tell you where was the sos.pl loaded from. You may then strip the 'sos.pl' from the path with a regexp and append '../modules'. Jenda === [EMAIL PROTECTED] == http://Jenda.Krynicky.cz == When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Help me on concurant comiunication
i tried it too but after creating the child process the main process comes back and start to listne in line $client=$sockHandle-accept()){ then all the child processes blocks i have atached my code with this please tel me if there is an error in line - Original Message - From: James Edward Gray II [EMAIL PROTECTED] To: Rakhitha Malinda Karunarathne [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Wednesday, October 16, 2002 11:43 PM Subject: Re: Help me on concurant comiunication Again, this is very complicated, so I can really only give basic theory. The usual strategy of forking servers is to fork just after they receive a connection. The main loop usually looks close to: while (my $c = $socket-accept) { my $child = fork; die unless defined $child; if ($child == 0) { # in child process close $socket; # not needed, but safest handle_connection($c); exit 0; } close $c; # in parent process } The other main strategy is preforking, which is better under heavy loads. I believe this is a little closer to what you're describing. It typically looks like this: foreach (1..PREFORK_CHILDREN) { next if fork; # parent process do_child($socket); # child process exit 0; # child never loops } sub do_child { my $socket = shift; while (my $c = $socket-accept) { handle_connection($c); close $c; } } Of course, all of this is VERY basic. There are plenty of gotchas both ways. I'm not sure why your child processes would hang when the parent calls accept. This shouldn't happen. You mention that you're on Windows, but not your version of Perl. Forking on Windows didn't come until version 5.6.0, so you might check that. Also, try closing the listening socket in the children, as I did above, just to be safe. Again, I highly recommend Network Programming with Perl. It covers all of this very well. The code above is straight out of it. Good luck with your server. James On Wednesday, October 16, 2002, at 11:27 AM, Rakhitha Malinda Karunarathne wrote: yes my server forks once the server starts it connects to a socket and starts to listen. then create processes as much as possible (about 50) but when one process reach the line while($client=$sockHandle-accept()){ #lines to handle the client } all the other processes blocks so the problem is when the fist client connected while this process start to handle tat request one of the other process react to the line $client=$sockHandle-accept() then all the other processes get blocked so the so the process which have a request to handle cant do it I use Windows2000 problem in sort is even when I use fork() when I call the accept() method program stops all the works and waits for a incoming request - Original Message - From: James Edward Gray II [EMAIL PROTECTED] To: Rakhitha Malinda Karunarathne [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Tuesday, October 15, 2002 11:29 PM Subject: Re: Help me on concurant comiunication This is a pretty involved issue, so I would need more information to help. By multiple processes, do you mean your server forks? As for more information, Network Programming with Perl by Lincoln D. Stein, covers this issue in detail and is quite good, I think. James On Tuesday, October 15, 2002, at 12:30 PM, Rakhitha Malinda Karunarathne wrote: I wrote a program (a server ) to listen for clients requests using multiple processes but while a one process waits to incoming client requests all the other processes blocks how can i over come this problem I used IO::Socket::INET for comiunication is there a better way and where can i find good documentation to learn about them ? server temp.pl Description: Perl program -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
a newbies attempt at cleverness are failing
Hi everyone, I know there must be a easy way to do this but I just can't figure it out. I issue a command from a remote server and get a variable like so: my $out = 14G; # actually it's 14G\n I am trying to get just a numeric out oif it: I just want the 14: I have been tried a lot of things, but I just can't gget the G outta there. Here is what I have now: my $Size = ( split /G/, chomp $out )[0]; I am grasping at straws. I tried chop, chomp and the like (substr) but just can't get it to drop both the new line character and the G. Any help? Thanks, Chad signature.asc Description: This is a digitally signed message part
Re: How to use a module located relative to the current script
check in the paths in each cells @INC array for the file u want in the array cell assending order fist maching file is the loaded one like this if any body have a better way to check existents of a file please send $file_to_search='sos.pl'; # Your file to find for($c=$#INC; $c-1; $c--){ # Search In all the paths in the list reverse order is very important bocouse it is the priority assending oder $err=10; open(T,$INC[$c]/$file_to_search)or $err=1; # $err will be 1 if file is not there if ($err==10){ #** if file egxist close(T);#** close it $filepath= $INC[$c]/$file_to_search; #*** Add the file $find_file=1;#** set as file is found } } if ($find_file){ # if find print print $filepath; }else{print cant locate file $file_to_search; } - Original Message - From: Jenda Krynicky [EMAIL PROTECTED] To: Reinstein, Shlomo [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Thursday, October 17, 2002 12:06 AM Subject: RE: How to use a module located relative to the current script From: Reinstein, Shlomo [EMAIL PROTECTED] Thanks. However, I think this module won't help me. You see, some_path/lib/sos.pl is not the original (bin) script, but rather it's a library of routines used by many original scripts. That is to say, users don't run perl some_path/lib/sos.pl, but rather they run some other script which knows how to locate and require sos.pl. Shlomo I see. Could you try to print $INC{'sos.pl'} or (if that doesn't print anything) use foreach (keys %INC) { print \t$_ = $INC{$_}\n; } This should tell you where was the sos.pl loaded from. You may then strip the 'sos.pl' from the path with a regexp and append '../modules'. Jenda === [EMAIL PROTECTED] == http://Jenda.Krynicky.cz == When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: a newbies attempt at cleverness are failing
my $size; $out =~ /(\d+)/ $size = $1; Regular expressions are good for this sort of task. chad kellerman wrote: Hi everyone, I know there must be a easy way to do this but I just can't figure it out. I issue a command from a remote server and get a variable like so: my $out = 14G; # actually it's 14G\n I am trying to get just a numeric out oif it: I just want the 14: I have been tried a lot of things, but I just can't gget the G outta there. Here is what I have now: my $Size = ( split /G/, chomp $out )[0]; I am grasping at straws. I tried chop, chomp and the like (substr) but just can't get it to drop both the new line character and the G. Any help? Thanks, Chad -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Help me on concurant comiunication
Your code pretty much works, on my system. It issues a warning about the $pid variable, but that's because you aren't using it. It services connections just fine, but you forgot to exit the child so it doesn't loop back to that accept() call on it's closed listen socket. One small change fixes that: #!/usr/bin/perl -w use IO::Socket; use Net::hostent; # for OO version of gethostbyaddr $PORT = 9000; # pick something not in use $server = IO::Socket::INET-new( Proto = 'tcp', LocalPort = $PORT, Listen= SOMAXCONN, ); $EOL = \015\012; $|=1; die can't setup server unless $server; while ($client=$server-accept()){ if (fork()){# $pid not used close $client; #** Nothing in parent go back and waite } else{ close $server; print $client Welcome To my server $EOL ; while ($inp=$client){ print $inp; print $client got your Massage $EOL; } $client-close(); exit 0; # close child before it loops } } On Wednesday, October 16, 2002, at 01:14 PM, Rakhitha Malinda Karunarathne wrote: i tried it too but after creating the child process the main process comes back and start to listne in line $client=$sockHandle-accept()){ then all the child processes blocks i have atached my code with this please tel me if there is an error in line - Original Message - From: James Edward Gray II [EMAIL PROTECTED] To: Rakhitha Malinda Karunarathne [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Wednesday, October 16, 2002 11:43 PM Subject: Re: Help me on concurant comiunication Again, this is very complicated, so I can really only give basic theory. The usual strategy of forking servers is to fork just after they receive a connection. The main loop usually looks close to: while (my $c = $socket-accept) { my $child = fork; die unless defined $child; if ($child == 0) { # in child process close $socket; # not needed, but safest handle_connection($c); exit 0; } close $c; # in parent process } The other main strategy is preforking, which is better under heavy loads. I believe this is a little closer to what you're describing. It typically looks like this: foreach (1..PREFORK_CHILDREN) { next if fork; # parent process do_child($socket); # child process exit 0; # child never loops } sub do_child { my $socket = shift; while (my $c = $socket-accept) { handle_connection($c); close $c; } } Of course, all of this is VERY basic. There are plenty of gotchas both ways. I'm not sure why your child processes would hang when the parent calls accept. This shouldn't happen. You mention that you're on Windows, but not your version of Perl. Forking on Windows didn't come until version 5.6.0, so you might check that. Also, try closing the listening socket in the children, as I did above, just to be safe. Again, I highly recommend Network Programming with Perl. It covers all of this very well. The code above is straight out of it. Good luck with your server. James On Wednesday, October 16, 2002, at 11:27 AM, Rakhitha Malinda Karunarathne wrote: yes my server forks once the server starts it connects to a socket and starts to listen. then create processes as much as possible (about 50) but when one process reach the line while($client=$sockHandle-accept()){ #lines to handle the client } all the other processes blocks so the problem is when the fist client connected while this process start to handle tat request one of the other process react to the line $client=$sockHandle-accept() then all the other processes get blocked so the so the process which have a request to handle cant do it I use Windows2000 problem in sort is even when I use fork() when I call the accept() method program stops all the works and waits for a incoming request - Original Message - From: James Edward Gray II [EMAIL PROTECTED] To: Rakhitha Malinda Karunarathne [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Tuesday, October 15, 2002 11:29 PM Subject: Re: Help me on concurant comiunication This is a pretty involved issue, so I would need more information to help. By multiple processes, do you mean your server forks? As for more information, Network Programming with Perl by Lincoln D. Stein, covers this issue in detail and is quite good, I think. James On Tuesday, October 15, 2002, at 12:30 PM, Rakhitha Malinda Karunarathne wrote: I wrote a program (a server ) to listen for clients requests using multiple processes but while a one process waits to incoming client requests all the other processes blocks how can i over come this problem I used IO::Socket::INET for comiunication is there a better
Re: file to file copy
Ah, now that's a different kettle of fish. (English fish kettles are a bit like American ball parks. Je ne sais pas la métaphore Française. ;) File1 is a list of key/value pairs which should be used to modify File2 such that 1/ Every line in File2 which has a key matching one of those in File1 takes its value from File1 2/ Any line in File1 with a key not previously mentioned in File2 should be appended to File2 3/ All other lines in File2 should remain in sequence and unchanged Is that right? Your example has what must be continued lines, terminated by a backslash. It's not too bad as long as we can assume the following: 1/ We can ignore anything in File1 that insn't a key/value pair (no comments or blank lines) 2/ We don't have to support continued lines for File1 3/ We don't need to preserve the number of spaces between the colon and the value field 4/ We don't have to expand stuff like ${start_url} My first crack at this gives: =perl # Pull all the key/value pairs from file1 into a hash # whose values are array references [ value string, usage count ] # open FILE, file1.txt; while ( FILE ) { next if /^#/ or /^\s*$/;# Ignore blank lines and comments die Can't accept continued lines if /\\$/; chomp; ($key, $val) = /([^:]+):\s*(.+?)\s*$/; $merge{$key} = [$val, 0]; } close FILE; # Open the merged output file # open MERGE, file3.txt; # Translate all the lines in file2 to the output file # according to the revisions in %merge # open FILE, file2.txt; while ( FILE ) { chomp; if ( /^[^\s#].*:/ ) { ($key) = /^([^:]+)/; if ( exists $merge{$key} ) { $_ = $key: $merge{$key}[0]; ++$merge{$key}[1]; } } print MERGE $_\n; } close FILE; # Append all the key/value pairs in the hash that still # have a zero usage count # for $key ( keys %merge ) { next if $merge{$key}[1]; print MERGE $key: $merge{$key}[0]\n; } close MERGE =cut Which works with your given data. Finishing the comments is left as an exercise for the reader. The PerlFAST and PerlBRIEF speakers in the group can refine it and demonstrate TMTOWTDI once more. Cheers all, and bonne chance R - Original Message - From: folschette [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, October 16, 2002 9:24 AM Subject: Re: file to file copy hi again, i've got some problems using your script: best is if i give you the three files so here they are file1 should be merged in file2 but file2 should have the same layout as befor merging christophe folschette Rob wrote: Christophe I think using Tie::File is overkill here. Try this: # Merge the two files into a single hash # for $file ( 'file2.dat', 'file1.dat' ) { open FILE, $file; while ( FILE ) { chomp; ($key, $val) = split /:\s+/; $data{$key} = $val; } close FILE; } # and splat it out again # open FILE, file3.dat; printf FILE %s: %s\n, $_, $data{$_} for (sort keys %data); close FILE; I'm not sure about your 'some text'. If you're allowing comment lines starting with a hash then next if /^#/; at the start of the inner loop will do. Now if you want the comments retaining, that's another matter :)) I never like posting just a solution on the beginners' group, but I don't think I'm doing anything obscure here that needs explaining. Tell me if I'm wrong. HTH. Cheers, Rob - Original Message - From: folschette [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, October 15, 2002 10:56 AM Subject: file to file copy hello, i have to write a perl script which copies text from one file to another but only if the text is not exisiting yet. For example: in file1: word: moon word2: sky ... the same syntax for every line in file2: #some text word: honey word3: lol word4: mu ... as well the same syntax for every line so now i want to merge file1 into file2, so that word: honey will be replaced by word: moon and word2: sky will be appended to file2. i have written the following script but i've got little problem with it, can someone help me? or test it? thanx, christophe folschette -- -- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Off topic
Hi, Sorry to ask this OT question. But i am sure I can get help here. I was looking for a good Linux admin mailing list. Thanks in advance
RE: Off topic
Google groups: http://groups.google.com/groups?sourceid=navclientie=UTF-8oe=UTF-8q=linux +admin that should have been your first guess. -Original Message- From: Anidil Rajendran-Raj [mailto:[EMAIL PROTECTED]] Sent: Wednesday, October 16, 2002 4:08 PM To: [EMAIL PROTECTED] Subject: Off topic Hi, Sorry to ask this OT question. But i am sure I can get help here. I was looking for a good Linux admin mailing list. Thanks in advance The views and opinions expressed in this email message are the sender's own, and do not necessarily represent the views and opinions of Summit Systems Inc. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Stupid newbie question.
Can some one please explain $i to me? It is my understanding that this is one of those special little variables. Sorry, and thanks. __ Do you Yahoo!? Faith Hill - Exclusive Performances, Videos More http://faith.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: comparing two hashes
Gary Egleton wrote: Hi, Hello, can any one point me at how to compare two hases. ie hash1 1 abc 2 def 3 ghi hash2 1 abc 2 defzzz 3 ghi I want to take the values for matching keys and see if they are the same if not write out the value so in the above the values in 1 and 1 are ok, the values in 3 and 3 are ok but in key 2 they do not match Probably something like this should work: for my $key ( keys %hash1 ) { if ( exists $hash2{$key} and $hash1{$key} ne $hash2{$key} ) { print %hash1: $hash1{$key}\n; print %hash2: $hash2{$key}\n; } } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Stupid newbie question.
Hi, Coe, :) On Wed, 16 Oct 2002, coe smythe wrote: Can some one please explain $i to me? It is my understanding that this is one of those special little variables. Sorry, and thanks. This isn't a stupid question... however, if you provided a little more context, perhaps we might be of more help. If you run perldoc perlvar You'll get more information than you ever wanted on Perl's magical built-in variables. When I did this, though, I didn't find anything special about a $i variable, so I'm not sure what you're asking. Hence the more context stuff. (Also, John Vromans' excellent Perl 5 Pocket Reference is handy for these kinds of questions, too.) As far as I know, $i is just a user-specified scalar variable. Is there a specific problem you're having? ---Jason Sonos Handbell Ensemble http://www.sonos.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: a newbies attempt at cleverness are failing
Chad Kellerman wrote: Hi everyone, Hello, I know there must be a easy way to do this but I just can't figure it out. I issue a command from a remote server and get a variable like so: my $out = 14G; # actually it's 14G\n I am trying to get just a numeric out oif it: I just want the 14: I have been tried a lot of things, but I just can't gget the G outta there. Here is what I have now: my $Size = ( split /G/, chomp $out )[0]; I am grasping at straws. I tried chop, chomp and the like (substr) but just can't get it to drop both the new line character and the G. # perl -e' my $out = 14G\n; print $out; my $Size = $out + 0; print $Size, \n; ' 14G 14 John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: creating a string on the fly
--- Rob [EMAIL PROTECTED] wrote: Sorry Vincent I'm not sure what you're meaning. You've written GetColumns ($table). Does it return an array of column names as it should? - Original Message - From: Vincent Lee [EMAIL PROTECTED] To: Rob [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Tuesday, October 15, 2002 11:05 PM Subject: RE: creating a string on the fly Rob, I've written a subroutine do the getColumns($table). The problem is that it's passing the entire column set back and appending each one. 'Passing the entire column set back' is surely what you want? 'Appending each one' what to what? I just do a select of the columns based on the table that is sent to the subroutine. The code you sent me does the entire thing...any ideas? Sounds like you just need to package the inner loop inside a subroutine: sub CreateView { $table = shift; print CREATE VIEW_$table AS\n; print SELECT (; $n = 0; foreach $column ( GetColumns ($table) ) { print , if $n++; print $column; } print ) FROM $table;\n; } Am I reading you right? R -Original Message- From: Rob [mailto:[EMAIL PROTECTED]] Sent: Tuesday, October 15, 2002 11:38 AM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re: creating a string on the fly Two problems here. 1/ Getting the tables' names and columns from the database. 2/ Constructing the SQL from that information. The second part is easy: foreach $table ( GetTables() ) { print CREATE VIEW_$table AS\n; print SELECT (; $n = 0; foreach $column ( GetColumns ($table) ) { print , if $n++; print $column; } print ) FROM $table;\n; } Which may be enough for you. GetTables() and GetColumns() are the first part, and I can't say any more about what these might do without knowing more about what interface you have with the database. HTH Rob - Original Message - From: Vincent Lee [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Tuesday, October 15, 2002 3:37 PM Subject: Re: creating a string on the fly -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] = Regards, Vincent __ Do you Yahoo!? Faith Hill - Exclusive Performances, Videos More http://faith.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: creating a string on the fly
Here's the code: sub GetColumns{ my @columns=; $statement=uc(SELECT colname from syscat.columns where tabname='$_[0]' and tabschema='$sch' ORDER BY colno); $s=$dbHandle-prepare($statement) or die Select error. Check the syntax\n; $s- execute() or die error here.; $s-bind_columns(\$colname); while ($s-fetch()){ push (@columns, $colname); } return @columns; } --- Rob [EMAIL PROTECTED] wrote: Sorry Vincent I'm not sure what you're meaning. You've written GetColumns ($table). Does it return an array of column names as it should? - Original Message - From: Vincent Lee [EMAIL PROTECTED] To: Rob [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Tuesday, October 15, 2002 11:05 PM Subject: RE: creating a string on the fly Rob, I've written a subroutine do the getColumns($table). The problem is that it's passing the entire column set back and appending each one. 'Passing the entire column set back' is surely what you want? 'Appending each one' what to what? I just do a select of the columns based on the table that is sent to the subroutine. The code you sent me does the entire thing...any ideas? Sounds like you just need to package the inner loop inside a subroutine: sub CreateView { $table = shift; print CREATE VIEW_$table AS\n; print SELECT (; $n = 0; foreach $column ( GetColumns ($table) ) { print , if $n++; print $column; } print ) FROM $table;\n; } Am I reading you right? R -Original Message- From: Rob [mailto:[EMAIL PROTECTED]] Sent: Tuesday, October 15, 2002 11:38 AM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re: creating a string on the fly Two problems here. 1/ Getting the tables' names and columns from the database. 2/ Constructing the SQL from that information. The second part is easy: foreach $table ( GetTables() ) { print CREATE VIEW_$table AS\n; print SELECT (; $n = 0; foreach $column ( GetColumns ($table) ) { print , if $n++; print $column; } print ) FROM $table;\n; } Which may be enough for you. GetTables() and GetColumns() are the first part, and I can't say any more about what these might do without knowing more about what interface you have with the database. HTH Rob - Original Message - From: Vincent Lee [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Tuesday, October 15, 2002 3:37 PM Subject: Re: creating a string on the fly -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] = Regards, Vincent __ Do you Yahoo!? Faith Hill - Exclusive Performances, Videos More http://faith.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Converting IO::Handle to filehandle
Vishal Mittal wrote: Hi, Hello, I have something like this my $child = new IO::Handle; When I try to redirect this handle to a filehandle using open(MY_DESCRIPTOR, $child); means to duplicate an existing file handle. it gives me an error. What is it that I am doing wrong What is the error message? The entry for the open function in perlfunc and the perlopentut documents have plenty of examples. John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: getting file on STDIN, howto process GLOB
Zentara wrote: Hi, Hello, I'm looking at a script that takes a file on STDIN. perldoc -q How can I read in an entire file all at once Found in /usr/lib/perl5/5.6.0/pod/perlfaq5.pod How can I read in an entire file all at once? ### #!/usr/bin/perl my $input = \*STDIN; print $input\n; ## If I run it script somefile the result is GLOB(0x123ab458) What can you do with that GLOB? For instance to use the input file as a string or array? I've seen it used as input to new objects. Read the I/O Operators section in perlop perldoc perlop John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Microsoft Access Question
Dear, I need to retrieve data from Microsoft Access database and put them in a PostgreSQL database. I got to access PostgreSQL normally, but I can't open a Microsoft Access database using perl. Someone knows how can I do it? Thanks! Cleiton L. Siqueira Colégio Monjolo [EMAIL PROTECTED] (0xx45) 520-1915 Esta mensagem foi enviada pelo sistema MONJOLO WEBMAIL http://www.colegiomonjolo.com.br -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
SIMPLE regex expression comparison !! - What am I doing wrong?
Hello I'm trying to write a simple script to test if a port is up or down. It all depends on being able to parse for the word Connected in an array. Try as I might, I can't figure out why the following regex comparison won't work. if $reply[1] =~ /Connected/ { The code snippet is as follows: #!/bin/perl $host = ARGV[0]; $port = ARGV[1]; reply = `echo | telnet $host $port`; if $reply[1] =~ /Connected/ { print Port is up\n; else print Port is down\n; } If I comment out the if statement, and just print out the variables, I see what I'm expecting, e.g.: ... print $reply[1] Connected to ldsslcu151.chq.slc.ut.usa.wh.lds. My preference would be to parse the whole array for Connected and not just presume placement in any element. I tried storing the response to just a scaler (e.g., $reply = `echo | telnet $host $port`;), but I'm not sure how a scalar handles cr or lf characters. Anyway, the solution is probably obvious to someone, and I'd be really grateful if they'd share it. Lance -- This message may contain confidential information, and is intended only for the use of the individual(s) to whom it is addressed. ==
RE: Stupid newbie question.
$i is generally used as a counter or increment variable. It isn't a special variable. Most of the time you'd see it in something like this: Until ($i == 100) { # do this 100 times ...do something $i++;# increment $i by 1 } HTH Bryan J. Casto bryan . casto (a) marshall . edu -Original Message- From: coe smythe [mailto:[EMAIL PROTECTED]] Sent: Wednesday, October 16, 2002 4:18 PM To: [EMAIL PROTECTED] Subject: Stupid newbie question. Can some one please explain $i to me? It is my understanding that this is one of those special little variables. Sorry, and thanks. __ Do you Yahoo!? Faith Hill - Exclusive Performances, Videos More http://faith.yahoo.com -- 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: SIMPLE regex expression comparison !! - What am I doing wrong?
On Oct 16, Lance Murray said: #!/bin/perl You should get used to using 'strict' and warnings #!/bin/perl -w use strict; $host = @ARGV[0]; That should be $ARGV[0]. $port = @ARGV[1]; Why not: my ($host, $port) = @ARGV; @reply = `echo | telnet $host $port`; if $reply[1] =~ /Connected/ { You're missing the ()'s around the conditional: if ($reply[1] =~ /Connected/) { ... } print Port is up\n; else print Port is down\n; } Why not tell us the error message, by the way? -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for Regular Expressions in Perl published by Manning, in 2002 ** stu what does y/// stand for? tenderpuss why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Microsoft Access Question
From: Cleiton L. Siqueira [EMAIL PROTECTED] I need to retrieve data from Microsoft Access database and put them in a PostgreSQL database. I got to access PostgreSQL normally, but I can't open a Microsoft Access database using perl. Someone knows how can I do it? What do you mean got to access PostgreSQL normally? DBI+DBD::Something? You can do pretty much the same for Access. Just use DBD::ODBC. If that doesn't work please tell us what did you try and what did it do. Jenda = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Getting Columns
All, I recently was reading a posting regarding getting table names and then retrieving colmn names from another post. I have been trying to make a perl program that I have written (with DBI) to be more object oriented. To be able to get column names would be a great help. I have the Perl DBI book from OReilly, but it only makes a small mention of something that seems to do this: $sth = $dbh-table_info; it also says that the method is experimental and may change. Does anybody know how one would go about doing this? Any help would be appreciated. Here is some more detailed information: 1- DB: Postgres SQL 2- Perl: 5.6.1 on one server and on the other 5.8.0 3- DBI: 1.28 currently using a sub-routine (method): sub setDataColumns { my ($class, $columns) = _; if ($columns) { dRows = split (/|/, $columns); } return dRows; } at least the method is similar to that. The problem here is that I have to pass to the module (class) the list of columns in a string. If I can get this same info without have to code it or pass this information, it would sure make everything more secure and cleaner. Thanks again! Brady
RE: SIMPLE regex expression comparison !! - What am I doing wrong?
Hi - 1) try: if ($reply[1] =~ /Connected/) { ... I _think_ w/o parens, Perl says: if $reply[1] = true true =~ /Connected/ = false (you also may have to have the m in m/Connected/ 2) whole array: for (@reply) { if (/Connected/) { ... OK ... last; } } 3) after having read into a scalar: if ($reply =~ m/Connected/s) { ... 's' says search thru new lines. Aloha = Beau. -Original Message- From: Lance Murray [mailto:[EMAIL PROTECTED]] Sent: Wednesday, October 16, 2002 10:59 AM To: [EMAIL PROTECTED] Subject: SIMPLE regex expression comparison !! - What am I doing wrong? Hello I'm trying to write a simple script to test if a port is up or down. It all depends on being able to parse for the word Connected in an array. Try as I might, I can't figure out why the following regex comparison won't work. if $reply[1] =~ /Connected/ { The code snippet is as follows: #!/bin/perl $host = @ARGV[0]; $port = @ARGV[1]; @reply = `echo | telnet $host $port`; if $reply[1] =~ /Connected/ { print Port is up\n; else print Port is down\n; } If I comment out the if statement, and just print out the variables, I see what I'm expecting, e.g.: ... print $reply[1] Connected to ldsslcu151.chq.slc.ut.usa.wh.lds. My preference would be to parse the whole array for Connected and not just presume placement in any element. I tried storing the response to just a scaler (e.g., $reply = `echo | telnet $host $port`;), but I'm not sure how a scalar handles cr or lf characters. Anyway, the solution is probably obvious to someone, and I'd be really grateful if they'd share it. Lance -- This message may contain confidential information, and is intended only for the use of the individual(s) to whom it is addressed. == -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Microsoft Access Question
Cleiton - Have you tried ODBC? There is a perl DBD for it. Check CPAN Aloha = Beau. -Original Message- From: Cleiton L. Siqueira [mailto:[EMAIL PROTECTED]] Sent: None To: [EMAIL PROTECTED] Subject: Microsoft Access Question Dear, I need to retrieve data from Microsoft Access database and put them in a PostgreSQL database. I got to access PostgreSQL normally, but I can't open a Microsoft Access database using perl. Someone knows how can I do it? Thanks! Cleiton L. Siqueira Colégio Monjolo [EMAIL PROTECTED] (0xx45) 520-1915 Esta mensagem foi enviada pelo sistema MONJOLO WEBMAIL http://www.colegiomonjolo.com.br -- 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: More Newbie OOP Questions ...
On Tue, Oct 15, 2002 at 09:26:33PM -0500, montana wrote: Take the following example from the perlboot manual: { package Horse; @ISA = qw(Animal); sub sound { neigh } sub name { my $self = shift; $$self; } sub named { my $class = shift; my $name = shift; bless \$name, $class; } } my $talking = Horse-named(Mr. Ed); print $talking-name, says , $talking-sound, \n; When we create the instance, what values go into @_ so that $talking-name returns the de-referenced scalar Mr. Ed, $class receives the value Horse, and $name receives the reference $talking? Or am I wrong on how this works? You're close. You are correct that $class is set to Horse. This is because the constructor (named) was called as Horse-named(...). However, $name is set to Mr. Ed. When you call a method, the only difference to calling a normal sub is that the first element of @_ will be the name of the class, or the instance of the class upon which you called the method. Then the rest of the parameters are added to @_. So in this case, @_ = (Horse, Mr. Ed). You can check this for yourself by printing @_ as the first line in the method. The constructor, then blesses $name into the class Horse, or more accurately, blesses a reference to $name. The bless function also returns that blessed reference, and so this value is returned from the constructor. This value is then assigned to $talking. $talking is then an instance of the class Horse, which happens to be a reference to a scalar holding the value Mr. Ed. The other methods work correctly because $talking knows to which class it belongs, and it can also be dereferenced to find out the name of the horse. Later Randal introduces blessed hashes, which are a more usual container for objects. In fact, it is rare to see blessed scalars outside of XS code, so I am a little surprised at the order in which Randal introduces these concepts, but as he has taught this a lot more than I have, I suspect that he has found this order to be most helpful in general. Thanks. SA P.S. (Please use plain English, for I am not the most proficient Perl programmer yet.) Hmmm. Perl OO in plain English. How'd I do? -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: SIMPLE regex expression comparison !! - What am I doing wrong?
Lance Murray wrote: Hello Hello, I'm trying to write a simple script to test if a port is up or down. It all depends on being able to parse for the word Connected in an array. Try as I might, I can't figure out why the following regex comparison won't work. Perhaps you need the Net::Telnet module? http://search.cpan.org/author/JROGERS/Net-Telnet-3.03/ John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Getting Columns
All, I recently was reading a posting regarding getting table names and then retrieving colmn names from another post. I have been trying to make a perl program that I have written (with DBI) to be more object oriented. To be able to get column names would be a great help. I have the Perl DBI book from OReilly, but it only makes a small mention of something that seems to do this: $sth = $dbh-table_info; it also says that the method is experimental and may change. Does anybody know how one would go about doing this? Any help would be appreciated. Here is some more detailed information: 1- DB: Postgres SQL 2- Perl: 5.6.1 on one server and on the other 5.8.0 3- DBI: 1.28 currently using a sub-routine (method): sub setDataColumns { my ($class, $columns) = _; if ($columns) { dRows = split (/|/, $columns); } return dRows; } at least the method is similar to that. The problem here is that I have to pass to the module (class) the list of columns in a string. If I can get this same info without have to code it or pass this information, it would sure make everything more secure and cleaner. Thanks again! Brady
Re: Microsoft Access Question
Take the following steps: # 1) Install Modules DBI and ODBC: screen snapshot Microsoft Windows 2000 [Versão 5.00.2195] (C) Copyright 1985-2000 Microsoft Corp. D:\Perlppm PPM install DBI Install package 'DBI?' (y/N): y Installing package 'DBI'... Bytes transferred: 368671 Installing D:\Perl\site\lib\auto\DBI\dbd_xsh.h Installing D:\Perl\site\lib\auto\DBI\DBI.bs etc... Installing D:\Perl\bin\dbish Installing D:\Perl\bin\dbish.bat Writing D:\Perl\site\lib\auto\DBI\.packlist PPM install DBD-ODBC Install package 'DBD-ODBC?' (y/N): Y Installing package 'DBD-ODBC'... Bytes transferred: 35966 Installing D:\Perl\site\lib\auto\DBD\ODBC\ODBC.bs Installing D:\Perl\site\lib\auto\DBD\ODBC\ODBC.dll Installing D:\Perl\site\lib\auto\DBD\ODBC\ODBC.exp Installing D:\Perl\site\lib\auto\DBD\ODBC\ODBC.lib Installing D:\Perl\html\site\lib\DBD\ODBC.html Installing D:\Perl\site\lib\DBD\ODBC.pm Writing D:\Perl\site\lib\auto\DBD\ODBC\.packlist PPM QUIT Quit! D:\Perl /screen snapshot 2) Configure a System DSN for the file to be accessed via ODBC DataSource (Control Panel / Administrative Tools), like this: name = Agenda drive = MS Access (*.mdb) file = C:\Agenda.mdb (drive:\fullpath\filename.mdb) # 3) Try this code example: code use DBI; $dbh = DBI-connect( dbi:ODBC:Agenda, , , {RaiseError = 1, PrintError = 1, AutoCommit = 1} ) or die Unable to connect: . $DBI::errstr . \n; $sel = $dbh-prepare( select name, phone, city, country from phonebook where city = ? and country = ? order by name ); @col = ( 'Sao Paulo', 'Brazil' ); $sel-execute( @col ); while( @col = $sel-fetchrow_array ){ $name = $col[0]; $phone = $col[1]; $city = $col[2]; $country = $col[3]; printf \n\n\rName___: \t%s \n\rPhone__: \t%s \n\rCity___: \t%s \n\rCountry: \t%s, $name, $phone, $city, $country; } $sel-finish; $dbh-disconnect; /code The SQL statement applied in $dbh-prepare( ... ) may be a select, insert, update, delete. I hope it helps you. Josimar Nunes de Oliveira [EMAIL PROTECTED] - Original Message - From: Cleiton L. Siqueira [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, October 16, 2002 6:02 PM Subject: Microsoft Access Question Dear, I need to retrieve data from Microsoft Access database and put them in a PostgreSQL database. I got to access PostgreSQL normally, but I can't open a Microsoft Access database using perl. Someone knows how can I do it? Thanks! Cleiton L. Siqueira Colégio Monjolo [EMAIL PROTECTED] (0xx45) 520-1915 Esta mensagem foi enviada pelo sistema MONJOLO WEBMAIL http://www.colegiomonjolo.com.br -- 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]
Who sees what?
I am surprise that a private variable is accessible by a sub. Consider this my $private = new $class; sub1 ($private); sub1{ (my $private) = @_; sub2; } sub2{ $private-dothis; #??? } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Who sees what?
On Oct 16, chris said: my $private = new $class; sub1 ($private); sub1{ (my $private) = @_; sub2; } sub2{ $private-dothis; #??? THIS is the $private you declared OUTSIDE of sub1(). Both $privates happen to point to the same referent. -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for Regular Expressions in Perl published by Manning, in 2002 ** stu what does y/// stand for? tenderpuss why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Who sees what?
http://perl.plover.com/FAQs/Namespaces.html The first my holds for the whole block (the whole file in this case). The second instance of private is only available inside sub1 and not deeper than sub1, aka not in sub2. Read the article, it explains it much better than I can. http://danconia.org chris wrote: I am surprise that a private variable is accessible by a sub. Consider this my $private = new $class; sub1 ($private); sub1{ (my $private) = @_; sub2; } sub2{ $private-dothis; #??? } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: comparing two hashes
Gary Egleton wrote: can any one point me at how to compare two hases. You can also use a CPAN module, e.g. use Data::Compare; if (Compare(\%hash1, \%hash2)) { # hashes are equal } else { # they arent } Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Perl and IIS 5.0
Hello, Does anybody know how to configure Microsoft IIS 5.0 (W2KProf) to run perl scripts? Thanks, Josimar
Re: Problem with redirection
Vishal Mittal [EMAIL PROTECTED] wrote: I am encountering a problem with this piece of code that I have written for forking multiple processes and making all the child processed communicating with the parent process... ** my($child_fh, $parent_fh) = (new IO::Handle, new IO::Handle); ... open(STDOUT, $parent_fh) or die Cant redirect STDOUT $!\n; open(STDIN, $parent_fh) or die Cant redirect STDIN $!\n; Here you need to do: open STDOUT, . $parent_fh-fileno But you'd be *much* better off with IPC::Open{2,3}. -- Steve perldoc -qa.j | perl -lpe '($_)=m((.*))' -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Problem with redirection
Steve Grazzini [EMAIL PROTECTED] wrote: Vishal Mittal [EMAIL PROTECTED] wrote: I am encountering a problem with this piece of code that I have written for forking multiple processes and making all the child processed communicating with the parent process... ** my($child_fh, $parent_fh) = (new IO::Handle, new IO::Handle); ... open(STDOUT, $parent_fh) or die Cant redirect STDOUT $!\n; open(STDIN, $parent_fh) or die Cant redirect STDIN $!\n; Here you need to do: open STDOUT, . $parent_fh-fileno Well the angle is backward, but you know what I meant. -- Steve perldoc -qa.j | perl -lpe '($_)=m((.*))' -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Perl and IIS 5.0
You may find this link to be useful http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q245225LN=EN-USSD=gnFR=0qry=perlrnk=19src=DHCS_MSPSS_gn_SRCHSPR=IIS On Wed, 16 Oct 2002 21:26:05 -0300, [EMAIL PROTECTED] (Josimar Nunes De Oliveira) wrote: Hello, Does anybody know how to configure Microsoft IIS 5.0 (W2KProf) to run perl scripts? Thanks, Josimar -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Getting A File Name
Hi, I have a directory in which there are files such as: fred.1 fred.2 fred.3 The suffix increases and older files get deleted so there are always 3 fred.* files in the directory at any one time. I need to get the name of the file with the highest suffix so I can go and do some other stuff with it. I have tried lots of different things but to no significant outcome. Any suggestions? Thanks Ken -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Getting A File Name
I think this script will help u. Assume that u r in the directory where u have these three files.(If not use chdir and move to that directory). @file_List = fred.* On executing the above statement @file_List will have all the three files fred.*. map {$_ =~ s/fred.//} @file_List The above statement removes the fred. from each file name and the @file_List array will only have the extension part of each file. My $ext = 0; foreach $val (@extension) { $ext = $val if($val $ext); } Now the variable $ext will have the highest suffix value. We can generate the file name with the below statement. $file_Name = fred.$ext; The full code is below @file_List = fred.*; map ($_ =~ s/fred.//gi, @file_List); my $ext = 0; foreach $val (@file_List) { $ext = $val if($val $ext); } $file_Name = fred.$ext; print $file_Name\n; Rgds, vinai -Original Message- From: Ken Cole [mailto:[EMAIL PROTECTED]] Sent: Wednesday, October 16, 2002 7:44 AM To: [EMAIL PROTECTED] Subject: Getting A File Name Hi, I have a directory in which there are files such as: fred.1 fred.2 fred.3 The suffix increases and older files get deleted so there are always 3 fred.* files in the directory at any one time. I need to get the name of the file with the highest suffix so I can go and do some other stuff with it. I have tried lots of different things but to no significant outcome. Any suggestions? Thanks Ken -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] **Disclaimer** Information contained in this E-MAIL being proprietary to Wipro Limited is 'privileged' and 'confidential' and intended for use only by the individual or entity to which it is addressed. You are notified that any use, copying or dissemination of the information contained in the E-MAIL in any manner whatsoever is strictly prohibited. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
generating a new web page
Hello All, This is my first web perl program. I want the user to select an option from a drop down menu, then click submit. The program should then go to a new web page to display the results. The below code displays all the info on the one page, how do I move to new web pages. I want to build the program up so that each new web page gathers more and more info from the user, then culminates in a final page that emulates the users selections. Any suggestions or pointers would be great. shane. #!perl.exe require DBI; use CGI; use strict; my $dbh = DBI-connect(DBI:mysql:database=golf;host=localhost); my $current_time = localtime; my $query = new CGI; select_tournament(); show_result(); sub select_tournament { print $query-header; print HTML\nHEAD\nTITLEGOLF Inc/TITLE\n/HEAD\nBODY\n; print H1 COLOR=BLUE-Golfer Score Board/H1\n; print FORM\n; print Current Tournaments\n; my $sth = $dbh-prepare('SELECT cname, id FROM tournament'); $sth-execute(); my $row; print SELECT NAME='tourn' SIZE=1\n; while ($row = $sth-fetchrow_arrayref()) { print option value='$$row[0]'$$row[0]/option\n; } print /select; print P\n; print INPUT TYPE='submit'\n; print /P\n; print /FORM\n; print /BODY\n/HTML\n; # Disconnect from the database. $dbh-disconnect(); } sub show_result { my $query = new CGI; print HTML\nHEAD\nTITLEGOLF Inc 2/TITLE\n/HEAD\nBODY\n; print FORM\n; print HR\n; print H1 COLOR=BLUE-Golf Tournament:/H1\n; print bSelection:/b . $query-param('tourn') . br\n; print /FORM\n; print /BODY\n/HTML\n; print HR\n; } Thanks, shane.. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Getting A File Name
Thanks Vinai, For the code and the explanations. Ken -Original Message- From: vinai AR [mailto:[EMAIL PROTECTED]] Sent: Thursday, October 17, 2002 1:54 PM To: Ken Cole; [EMAIL PROTECTED] Subject: RE: Getting A File Name I think this script will help u. Assume that u r in the directory where u have these three files.(If not use chdir and move to that directory). @file_List = fred.* On executing the above statement @file_List will have all the three files fred.*. map {$_ =~ s/fred.//} @file_List The above statement removes the fred. from each file name and the @file_List array will only have the extension part of each file. My $ext = 0; foreach $val (@extension) { $ext = $val if($val $ext); } Now the variable $ext will have the highest suffix value. We can generate the file name with the below statement. $file_Name = fred.$ext; The full code is below @file_List = fred.*; map ($_ =~ s/fred.//gi, @file_List); my $ext = 0; foreach $val (@file_List) { $ext = $val if($val $ext); } $file_Name = fred.$ext; print $file_Name\n; Rgds, vinai -Original Message- From: Ken Cole [mailto:[EMAIL PROTECTED]] Sent: Wednesday, October 16, 2002 7:44 AM To: [EMAIL PROTECTED] Subject: Getting A File Name Hi, I have a directory in which there are files such as: fred.1 fred.2 fred.3 The suffix increases and older files get deleted so there are always 3 fred.* files in the directory at any one time. I need to get the name of the file with the highest suffix so I can go and do some other stuff with it. I have tried lots of different things but to no significant outcome. Any suggestions? Thanks Ken -- 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: generating a new web page
Hi, Shane, You should write a first html page with a form that use an action to a script, like this: html head titlePágina Teste/title body form action=../scripts/test.pl action=post input input ... input type=submit value=Process name=process input type=submit value=Final name=final /form body /html The script ../scripts/test.pl may have a content like this: print HTTP/1.0 200 OK\n; print Content-Type: text/html\n\n; print 'HTML'; print 'HEAD'; print 'TITLEProcessed/TITLE'; print '/HEAD'; print 'BODY'; your business logic must be coded here, with some output if the user click on final button, the output should be produced by the final fase that you have planned use the following piece of code to separate the input fields sent by the form @my_query_string = split(//,$ENV{'QUERY_STRING'}); foreach $index (0..$my_query_string){ @col = split /=/, $my_query_string[$index]; print 'Field: ', $col[0], ' Value=', $col[1], 'br'; } print '/BODY'; print '/HTML'; I hope it helps you. Josimar - Original Message - From: Shane Laffin [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, October 17, 2002 1:01 AM Subject: generating a new web page Hello All, This is my first web perl program. I want the user to select an option from a drop down menu, then click submit. The program should then go to a new web page to display the results. The below code displays all the info on the one page, how do I move to new web pages. I want to build the program up so that each new web page gathers more and more info from the user, then culminates in a final page that emulates the users selections. Any suggestions or pointers would be great. shane. #!perl.exe require DBI; use CGI; use strict; my $dbh = DBI-connect(DBI:mysql:database=golf;host=localhost); my $current_time = localtime; my $query = new CGI; select_tournament(); show_result(); sub select_tournament { print $query-header; print HTML\nHEAD\nTITLEGOLF Inc/TITLE\n/HEAD\nBODY\n; print H1 COLOR=BLUE-Golfer Score Board/H1\n; print FORM\n; print Current Tournaments\n; my $sth = $dbh-prepare('SELECT cname, id FROM tournament'); $sth-execute(); my $row; print SELECT NAME='tourn' SIZE=1\n; while ($row = $sth-fetchrow_arrayref()) { print option value='$$row[0]'$$row[0]/option\n; } print /select; print P\n; print INPUT TYPE='submit'\n; print /P\n; print /FORM\n; print /BODY\n/HTML\n; # Disconnect from the database. $dbh-disconnect(); } sub show_result { my $query = new CGI; print HTML\nHEAD\nTITLEGOLF Inc 2/TITLE\n/HEAD\nBODY\n; print FORM\n; print HR\n; print H1 COLOR=BLUE-Golf Tournament:/H1\n; print bSelection:/b . $query-param('tourn') . br\n; print /FORM\n; print /BODY\n/HTML\n; print HR\n; } Thanks, shane.. -- 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: Newbie Question
Montana , Read the ## part in ur attached mail below: --- montana [EMAIL PROTECTED] wrote: So looking at the following package: { package Horse; @ISA = qw(Animal); sub sound { neigh } sub name { my $self = shift; $$self; } sub named { my $class = shift; my $name = shift; bless \$name, $class; } } followed by the following instantiation lines: my $talking = Horse-named(Mr. Ed); print $talking-name, says , $talking-sound, \n; The only variable I see passed to the package is the name Mr. Ed which is in fact passed to the constructor named located in the package Horse. Is this correct? ### yeah So the constructor named takes the following list: @_ = {Horse, Mr. Ed} Is this correct? ## Yeah If so then Horse would be put into the scalar $class, and Mr. Ed would be put into the scalar $name. Is this correct? Ok so is $talking now an instance? And how does the $talking-sound produce neigh? Is the @ISA line and the sub name function needed in this package for Horse to still work, or is that there for inheritance purposes only? ## So you have finally read the perlboot :) Thanks. SA P.S. I kind of try to work my questions out as I go along so sorry for the details if it is too much. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ Do You Yahoo!? Everything you'll ever need on one web page from News and Sport to Email and Music Charts http://uk.my.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Get Script to run same time each day automatically
Gidday from Downunder, Is it possible to write a script that runs automatically at the same time each day. Why you might ask? You see we want to send out a newsletter notifying journalists of our latest press releases. The newsletters are generated automatically by our CMS (Interwoven Teamsite). They will be deployed manually by the content contributor to the production server. The way I see it working is that each day the script runs and builds a list of files in a particular directory, it compares this new list to the previous stored list. Any new files must be new press releases so therefore we have to send out a newsletter. Or we could just check the date of each file and send out those files that matched that days date. I've generated the newsletter, and got all the sendmail routines, just need to get this working. Any help appreciated. Colin Johnstone Website Project Officer Corporate Website Unit Public Affairs Directorate NSW Department of Education and Training ph 9561 8643 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]