Printing html document
I need to print a html page using a button(but not the mozilla or explorer button). So I need I button in a web page that will print that page to a printer that is not attached to the local computer, but to the web server where the page is hosted. The problem is that when I send a html page it prints all the tags: table, ... I belive I need function that can give me the right string to send to the printer. Thank you. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Background info
After recent web host problems, we decided to host our own website. My hosting server is running Win XP with Apache 2.3.1 on it. My site is working but now I am trying to work out the kinks. We use a simple formmail.cgi script to allow visitors to submit a questionaire. What do I need to set up to allow that form to work again. Will Apache be able to send mail or does sendmail need to communicate with a different mail server. Just trying to grasp the concept of how it works. Thanks -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Printing html document
On Fri, Sep 24, 2004 at 12:12:33PM +0300, victor wrote: So I need I button in a web page that will print that page to a printer that is not attached to the local computer, but to the web server where the page is hosted. The problem is that when I send a html page it prints all the tags: table, ... So you need some sort of filter to convert an HTML document to a format that your printer can understand. Are you trying to get plain text output? HTML::Striper might be your friend. Want it formatted? HTML::Latext might do as a first stage (then you'll need to convert the LaTeX to something your printer can understand (maybe postscript)). -- David Dorward http://dorward.me.uk -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Background info
On Thu, 23 Sep 2004, Sander wrote: After recent web host problems, we decided to host our own website. My hosting server is running Win XP with Apache 2.3.1 on it. Are you sure about this? The current version of Apache2 is 2.0.51. My site is working but now I am trying to work out the kinks. We use a simple formmail.cgi script to allow visitors to submit a questionaire. What do I need to set up to allow that form to work again. Will Apache be able to send mail or does sendmail need to communicate with a different mail server. Just trying to grasp the concept of how it works. Thanks Where did you get your copy of formmail.cgi ? There is an older program for this that is unreliable and insecure -- do not use it. There is a more recent version from a project called NMS that provides a much better version. It can be downloaded from: http://nms-cgi.sourceforge.net/scripts.shtml If the formmail you are using is not this one, it probably should be. Download that one and read over the documentation it provides, then try to install it and let us know -- in some detail -- if anything breaks. -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Background info
Sander wrote: Will Apache be able to send mail No. or does sendmail need to communicate with a different mail server. You need a mail server, a mail transfer agent (MTA) to be precise, to send mail. If you don't have one installed locally, such as sendmail or Postfix, it's possible to use a remote MTA instead. It should be noted that many scripts include a simple pipe to the local mail program, and a remote MTA precludes that technique. -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
ordered hash
Hello, I was hoping to get a little advice creating a cgi form. I want to create a popup menu to list all the states in the US( and then later countries), I want to store all the values in variables to pass to the subroutines later on. The below code works, I just have the values for the states stored in a hash which is unorderd and diplayed as such on the form. I would like the popup menu display to keep the order from below. Also adding modules like Hash::Ordered and Tie::IxHash isn't an option. Is there a better way of doing this or am I just making it overly complicated? Thanks for any help you can give. #!/usr/bin/perl use warnings; use strict; use CGI qw(:standard escapeHTML); use CGI::Carp qw(fatalsToBrowser); BEGIN {open(STDERR,error.log);} my (@address, @state, $choice); @address = ({name = last_name, label = Last name:, size = 20, req = 1}, {name = first_name,label = First name:, size = 20, req = 1}, {name = business_name, label = Business name:, size = 40}, {name = address1, label = Street address:, size = 40, req = 1}, {name = addreess2, label = ,size = 40}, {name = city, label = City:, size = 20, req = 1} ); @state = ({name = state/prov, label = State/Prov:, values = {AK = Alaska, AL = Alabama, AR = Arkansas, AZ = Arizona = CA = California, CO = Colorado, MT = Montana, NC = North Carolina, ND = North Dakota, NE = Nebraska, NH = New Hampshire, NJ = New Jersey, NM = New Mexico, NV = Nevada, NY = New York, OH = Ohio, OK = Oklahoma, OR = Oregon, PA = Pennsylvania, PR = Puerto Rico, RI = Rhode Island, SC = South Carolina, SD = South Dakota, TN = Tennessee, TX = Texas, UT = Utah, VA = Virginia, VI = Virgin Islands, WA = Washington, WI = Wisconsin, WV = West Virginia, WY = Wyoming, OTHER = OTHER (Outside USA)}} ); # foreach $f (@{$address}) { $label = $f-{label}; $label .= * if $f-{req}; # add asterick for required fields push(@row, Tr(td(escapeHTML($label)), td(textfield(-name = $f-{name}, -size = $f-{size})) )); } print table(@row); foreach $f (@{$state}) { $label = $f-{label}; push (@row, Tr ( td (escapeHTML ($label)), td (popup_menu (-name = $f-{name}, -value = $f-{values})) )); } print table(@row), submit(-name = choice, -value = Submit), -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: ordered hash
On Fri, 24 Sep 2004, brian larochelle wrote: ordered hash Hashes are, almost by definition, unordered lists of key/value pairs. If you want to work with one in order, add a sort command to accesses: my @sorted_keys = sort keys %hash; foreach $key @sorted_keys { my $value = $hash{$key}; } etc. Or just foreach $key ( sort keys %hash ) { my $value = $hash{$key}; } to skip the temp variable. Make sense ? -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: ordered hash
Thank you for your quick response Chris. That makes perfect sense. Except for the last value of 'other' which I would want at the end of the list and a choice for the person filling out the form is they did not live in the US. Chris Devers wrote: On Fri, 24 Sep 2004, brian larochelle wrote: ordered hash Hashes are, almost by definition, unordered lists of key/value pairs. If you want to work with one in order, add a sort command to accesses: my @sorted_keys = sort keys %hash; foreach $key @sorted_keys { my $value = $hash{$key}; } etc. Or just foreach $key ( sort keys %hash ) { my $value = $hash{$key}; } to skip the temp variable. Make sense ? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: ordered hash
On Fri, 24 Sep 2004, brian larochelle wrote: That makes perfect sense. Except for the last value of 'other' which I would want at the end of the list and a choice for the person filling out the form is they did not live in the US. A common way around this is to leave other out of the hash: do_stuff( other ); foreach $key ( sort keys %hash ) { do_stuff( $hash{$key} ); } do_stuff( final thing ); sub do_stuff { my $thingy = shift; ... print qq[ p $thingy /p ]; } This general approach can be applied to lots of situations, including the one that you're describing. -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: regex help
Hi! what's problem in these regular expressions.. every thing correct! do you need to convert one or more than one match into single replacement then regexp should be $safeString =~ s/\s+/_/g; -Original Message- From: Johnstone, Colin [mailto:[EMAIL PROTECTED] Sent: Friday, September 24, 2004 11:02 AM To: [EMAIL PROTECTED] Subject: regex help Gidday all, Im trying to write a regex to convert spaces to underscores and ampersands to 'and' can someone help. $safeString = News Events; $safeString =~ s//and/g; $safeString =~ s/\s/_/g; Regards Colin This E-Mail is intended only for the addressee. Its use is limited to that intended by the author at the time and it is not to be distributed without the author's consent. Unless otherwise stated, the State of Queensland accepts no liability for the contents of this E-Mail except where subsequently confirmed in writing. The opinions expressed in this E-Mail are those of the author and do not necessarily represent the views of the State of Queensland. This E-Mail is confidential and may be subject to a claim of legal privilege. If you have received this E-Mail in error, please notify the author and delete this message immediately. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: regex help
Thank you I musthave just coded something wrong, your right they do work. Sorry! -Original Message- From: Raymond Raj [mailto:[EMAIL PROTECTED] Sent: Friday, September 24, 2004 3:55 PM To: Johnstone, Colin; [EMAIL PROTECTED] Subject: RE: regex help Hi! what's problem in these regular expressions.. every thing correct! do you need to convert one or more than one match into single replacement then regexp should be $safeString =~ s/\s+/_/g; -Original Message- From: Johnstone, Colin [mailto:[EMAIL PROTECTED] Sent: Friday, September 24, 2004 11:02 AM To: [EMAIL PROTECTED] Subject: regex help Gidday all, Im trying to write a regex to convert spaces to underscores and ampersands to 'and' can someone help. $safeString = News Events; $safeString =~ s//and/g; $safeString =~ s/\s/_/g; Regards Colin This E-Mail is intended only for the addressee. Its use is limited to that intended by the author at the time and it is not to be distributed without the author's consent. Unless otherwise stated, the State of Queensland accepts no liability for the contents of this E-Mail except where subsequently confirmed in writing. The opinions expressed in this E-Mail are those of the author and do not necessarily represent the views of the State of Queensland. This E-Mail is confidential and may be subject to a claim of legal privilege. If you have received this E-Mail in error, please notify the author and delete this message immediately. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: LM an NT hashes
I has my self, I found Crypt-Smb moduloe por perl, for those that use MDK I buid the SRPM at http://www.linuxchange.com/download/Mandrake%20Official%2010/samba/Perl-Crypt-Smb-0.02-1mdk.src.rpm CU LD Le jeudi 23 Septembre 2004 20:15, Luis Daniel Lucio Quiroz a écrit : I wonder if someone has perl functions to make LM and NT hashes that samba uses. Best regards, LD -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
extern varibales
Hello together, I have this problem of global variables again. But in my case I need a varibale, a string, which should be known in all my modules. I put some of my functions out in modules which I call when I use them but all these functions also need some directory-pathes as strings. At the time I tell this functions this pathes with parameters but this is very long windet. Does anybody know another solution. Do we have in perl something like a scope EXTERN linke in C ? Gruss Christian -- Christian Stalp Institut für Medizinische Biometrie, Epidemiologie und Informatik (IMBEI) Obere Zahlbacher Straße 69 55131 Mainz Tel.: 06131/ 17-6852 E-Mail: [EMAIL PROTECTED] Internet: www.imbei.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: speed up string matching
Gunnar Hjalmarsson [EMAIL PROTECTED] wrote: C R wrote: Gunnar Hjalmarsson wrote: C R wrote: Are you certain that using the module makes the simultaneous matching faster than a sequential and to what degree (roughly)? Certain? Certainly not. :) It depends, among other things, on your systems ability to run parallel processes and on the size of the string you want to parse. I have an average personal computer. At the moment the size of the string can get up to about 600.000 characters, but in the future it will get much larger than 100 MB. I still can't tell. Maybe somebody else is able to give you guidance, but why don't you simply try it if you want to explore that option? OK, thanks! -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Calling Perl From Java?
I have had to do this. Did a fair bit of research and the best that I could come up with (and what we have implemented) is to call mod_perl url from java. That way we don't have to recompile each time, and get some database persistance with Apache::DBI. Works out quite well. On Sep 23, 2004 04:24 PM, Siegfried Heintze [EMAIL PROTECTED] wrote: I did a google search on calling Perl from Java. I found one site (http://ebb.org/perljvm/) that suggested the most promising project tackling this problem had been abandoned. The traditional approach is apparently very cumbersome: Have Java call C and C all Perl. This sounds very tedious. Does this sum up the situation? Thanks, Siegfried -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Moving between hashes 2.
Gunnar, Thanks so much for the help and the links! They help quit a bit. I decided to use the if statement you posted: if ( $aa eq '-' ) { $hash3{$_} .= '---'; } else { $hash3{$_} .= substr $dna,0,3,''; } instead of: $hash3{$_} .= $aa eq '-' ? '---' : substr $dna,0,3,''; only because I had to add a $count++ function within the else statement (shown below) to accomplish another task within my larger script: if ( $aa eq '-' ) { $hash3{$_} .= '---'; } else { $hash3{$_} .= substr $dna,0,3,''; $count++ } I couldn't figure out if it was possible to add $count++ within the ?: statement above. I tried but could not get it to work. However, everything works well at this point. Again, I really appreciate the help! -Mike On Sep 20, 2004, at 6:55 PM, [EMAIL PROTECTED] wrote: From: Gunnar Hjalmarsson [EMAIL PROTECTED] Date: September 19, 2004 9:12:32 PM MDT To: [EMAIL PROTECTED] Subject: Re: Moving between hashes 2. Michael S. Robeson II wrote: Ok, well I think I can see the forest but I have little idea as to what is actually going on here. I spent a few hours looking things up and I have a general sense of what is actually occurring but I am getting lost in the details that were posted in the last digest. Well, before an attempt to explain and/or point you to the applicable docs, I'd like to change my mind once again. :) This is my latest idea: my %hash3; for ( keys %hash1 ) { my $dna = $hash2{$_}; for my $aa ( split //, $hash1{$_} ) { $hash3{$_} .= $aa eq '-' ? '---' : substr $dna,0,3,''; } } I'll assume that you don't have a problem with the outer loop, that simply iterates over the hash keys. As a first step in each iteration I copy the DNA sequence to the $dna variable, so as to not destroying %hash2. Over to the 'tricky' part. The inner loop iterates over each character in the amino-acid sequence data, and respective character is assigned to $aa. For that I use the split() function: http://www.perldoc.com/perl5.8.4/pod/func/split.html $hash3{$_} .= $aa eq '-' ? '---' : substr $hash2{$_},0,3,''; This is something new to me. I think I follow your use of the ?: pattern feature. However, none of the perl books I have discuss it's use in this fashion. That sounds strange to me, because that's how it should be used... Read about the conditional operator in http://www.perldoc.com/perl5.8.4/pod/perlop.html OTOH, that notation is basically the same as: if ( $aa eq '-' ) { $hash3{$_} .= '---'; } else { $hash3{$_} .= substr $dna,0,3,''; } which is a little more intuitive (at least I think it is). So, as far as I can tell, you are saying: hey, if you find '-' in $aa then append a '---' in $hash3, otherwise append the next three DNA letters. Precisely. However, I do not understand the syntax of how perl is actually doing this. Hopefully the if/else statement makes it easier to grasp, and the '.=' operator is used just for appending something to a string. Finally we have my use of the substr() function. http://www.perldoc.com/perl5.8.4/pod/func/substr.html It returns the first three characters in $dna, and since I also pass the null string as the fourth argument, it changes the content of $dna at the same time, i.e. it replaces the first three characters with nothing. HTH. If you need further explanations, you'll have to ask specific questions. -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Help with putting a subroutine into a variable?
Hi all, I have this: - #!/usr/bin/perl use warnings; use strict; my @pics = *.jpg; my $website = 'http://www.website.com/uploads'; sub links { foreach (@pics) { print a href=\$website/$_\$website/$_/a\n; } } - I would normally call the subroutine like links; but I want to put the result into a variable in order to stick it into an e-mail. I have been trying all day reading all my perl books and it's time to ask for help. Thanks. -- Just getting into the best language ever... Fancy a [EMAIL PROTECTED] Just ask!!! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
SIGZERO
Hi Perlers, I'm trying to check on the status of a process by sending a SIGZERO to it with kill(). This SHOULD (according to the docs I've been reading) return false if the process died. But mine is not. It always returns true. if( kill 0 = $pid ) { print the process is OK\n; } else { print Something happened to the process: $!\n; } And for me, the above ALWAYS returns true. I'm wondering if this is something to do with Solaris, and not Perl. Maybe this signal doesn't behave the same way under Solaris? Ok, In the middle of writing this email I decided to write up a quick and dirty test: #!/usr/bin/perl use warnings; use strict; my $pid = shift; if( kill 0 = $pid ) { print Everything's ok\n; } else { print $pid is not ok: $!\n; } When I run this code against a made up PID (I grep for it first to be sure it's not really there), It works as expected, and: 17455 is not ok: No such process is returned! That's good! that's what I want. but when I throw it in my larger, longer Daemon script, it doesn't do it right. Just to give some more explaination, My script daemonizes itself: sub daemonize { chdir '/' or die Can't chdir to /: $!; open STDIN, '/dev/null' or die Can't read /dev/null: $!; open STDOUT, '/dev/null' or die Can't write to /dev/null: $!; defined( my $pid = fork ) or die Can't fork the monitor: $!; exit if $pid; setsid or die Can't start a new session: $!; open STDERR, 'STDOUT' or die Can't dup STDOUT: $!; } then, It starts a bunch of children, capturing all of their process ID in a hash: sub start_servers { my $cmdName = shift; defined( my $pid = fork ) or die Can't fork the server $cmdName: $!; if( $pid == 0 ) { # Child chdir '/' or die Can't chdir to /: $!; open STDIN, '/dev/null' or die Can't read /dev/null: $!; open STDOUT, '/dev/null' or die Can't write to /dev/null: $!; setsid or die Can't start a new session: $!; open STDERR, 'STDOUT' or die Can't dup STDOUT: $!; exec( $cmdName ); } else { # Parent $children{$pid} = $cmdName; } } Then, the original goes into a loop, checking the children and (for debug purposes at the moment) just prints some status: do { foreach( keys %children ) { if( kill 0 = $_ ) { print - $_: $children{$_} is still ok.\n; } else { print * $_: $children{$_} is not responding: $!\n; } } sleep 5; } while( 1 ); But ... I always get back the TRUE response, - 17455: ./dummy_script is still ok.. Did I miss something? --Errin -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: SIGZERO
On Fri, 24 Sep 2004 09:17:58 -0500, Errin Larsen [EMAIL PROTECTED] wrote: Hi Perlers, I'm trying to check on the status of a process by sending a SIGZERO to it with kill(). This SHOULD (according to the docs I've been reading) return false if the process died. But mine is not. It always returns true. SNIP But ... I always get back the TRUE response, - 17455: ./dummy_script is still ok.. Did I miss something? --Errin I guess I should have pointed out that, at the OS prompt, I'm 'kill -9' ing one of those dummy_script processes so I can test what happens when it dies. --Errin -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Help with putting a subroutine into a variable?
Hi all, I have this: - #!/usr/bin/perl use warnings; use strict; Good start. my @pics = *.jpg; my $website = 'http://www.website.com/uploads'; sub links { foreach (@pics) { print a href=\$website/$_\$website/$_/a\n; } } Your sub breaks encapsulation because it relies on the fact that @pics and $website are available in the sub but have not been passed into it. Generally we want our subs to take arguments and return values. If you were to move this sub to the top of the file or to another file (such as a library/module) it would break. So the first thing you should correct is the encapsulation by making your sub accept its arguments and return a value. sub links { my ($base_url, @list) = @_; foreach my $element (@list) { print . } return; } - I would normally call the subroutine like links; but I want to put the result into a variable in order to stick it into an e-mail. I have been trying all day reading all my perl books and it's time to ask for help. Note that we don't want to call Clinks that is better written as Clinks(). What is the result? In your case you are printing the links, so there is no real result. You need to decide what the return value of the sub will be, maybe the list of urls? a bool? undef for positive or an exception for failure? In the case of the list you should be Cpushing the values to list and then returning the list. In this last case we can call the sub such as, my @ahrefs = links($website, @pics); foreach my $link (@ahrefs) { print $linkbr /\n; } For instance. Thanks. Give it a shot, see if this helps, if not come back and ask more. http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: SIGZERO
Errin Larsen wrote: Hi Perlers, snip if( kill 0 = $pid ) { snip Forgive me if I presume too much, but shouldn't the above be: if( kill 0, $pid ) { perldoc -f kill -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Moving between hashes 2.
Michael Robeson wrote: I decided to use the if statement you posted: snip only because I had to add a $count++ function within the else statement (shown below) to accomplish another task within my larger script: if ( $aa eq '-' ) { $hash3{$_} .= '---'; } else { $hash3{$_} .= substr $dna,0,3,''; $count++ } I couldn't figure out if it was possible to add $count++ within the ?: statement above. I tried but could not get it to work. Right, the conditional operator is merely designed for assignment. OTOH, you don't need a loop to count a certain type of characters in a string: my $string = 'mfg--f'; my $count = $string =~ tr/a-z//; -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: SIGZERO
From: Ed Christian [EMAIL PROTECTED] Errin Larsen wrote: Hi Perlers, snip if( kill 0 = $pid ) { snip Forgive me if I presume too much, but shouldn't the above be: if( kill 0, $pid ) { Those two are equivalent. perl -MO=Deparse -e kill 0 = $pid prints kill 0, $pid; -e syntax OK just like perl -MO=Deparse -e kill 0, $pid Jenda = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: SIGZERO
On Fri, 24 Sep 2004 10:31:36 -0400, Ed Christian [EMAIL PROTECTED] wrote: Errin Larsen wrote: Hi Perlers, snip if( kill 0 = $pid ) { snip Forgive me if I presume too much, but shouldn't the above be: if( kill 0, $pid ) { perldoc -f kill Jenda is correct. I like to think of '=' as The FANCY comma!!. It's just a pretty way of typing a comma for just such an occasion when you want you code to reflect what you're doing. So, in the above, I'm sending a signal to $pid, so the big arrow shows that the signal (0) is being sent to that process ($pid)! Perl is Fun!!! This works great (and is seen most often) in hash declarations: my %demo_hash = ( Key_One = 1, Key_Two = 2, Key_Three = 3 ); -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: SIGZERO
Errin Larsen wrote: On Fri, 24 Sep 2004 10:31:36 -0400, Ed Christian [EMAIL PROTECTED] wrote: Errin Larsen wrote: Hi Perlers, snip if( kill 0 = $pid ) { snip Forgive me if I presume too much, but shouldn't the above be: if( kill 0, $pid ) { perldoc -f kill Jenda is correct. I like to think of '=' as The FANCY comma!!. It's just a pretty way of typing a comma for just such an occasion when you want you code to reflect what you're doing. So, in the above, I'm sending a signal to $pid, so the big arrow shows that the signal (0) is being sent to that process ($pid)! Perl is Fun!!! This works great (and is seen most often) in hash declarations: my %demo_hash = ( Key_One = 1, Key_Two = 2, Key_Three = 3 ); I stand corrected. Sorry it wasn't an easy solution. :) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Help with putting a subroutine into a variable?
Your sub breaks encapsulation because it relies on the fact that @pics and $website are available in the sub but have not been passed into it. Generally we want our subs to take arguments and return values. If you were to move this sub to the top of the file or to another file (such as a library/module) it would break. So the first thing you should correct is the encapsulation by making your sub accept its arguments and return a value. sub links { my ($base_url, @list) = @_; foreach my $element (@list) { print . } return; } I have the Perl V3.0 CD Bookshelf (Much better than V4.0 IMHO) and this makes sense now. Found this bit: 4.6. Private Variables in Subroutines But if Perl can give us a new @_ for every invocation, can't it give us variables for our own use as well? Of course it can. By default, all variables in Perl are global variables; that is, they are accessable from every part of the program. But you can create private variables called lexical variables at any time with the my operator: sub max { my($a, $b); # new, private variables for this block ($a, $b) = @_;# give names to the parameters if ($a $b) { $a } else { $b } } These variables are private (or scoped) to the enclosing block; any other $a or $b is totally unaffected by these two. And that goes the other way, too -- no other code can access or modify these private variables, by accident or design.[108] So, we could drop this subroutine into any Perl program in the world and know that we wouldn't mess up that program's $a and $b (if any).[109] - -- Just getting into the best language ever... Fancy a [EMAIL PROTECTED] Just ask!!! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Help with putting a subroutine into a variable?
Wiggins d Anconia said: Hi all, I have this: - #!/usr/bin/perl use warnings; use strict; Good start. Courtesy of the Lama :-) my @pics = *.jpg; my $website = 'http://www.website.com/uploads'; sub links { foreach (@pics) { print a href=\$website/$_\$website/$_/a\n; } } Your sub breaks encapsulation because it relies on the fact that @pics and $website are available in the sub but have not been passed into it. Generally we want our subs to take arguments and return values. If you were to move this sub to the top of the file or to another file (such as a library/module) it would break. So the first thing you should correct is the encapsulation by making your sub accept its arguments and return a value. sub links { my ($base_url, @list) = @_; foreach my $element (@list) { print . } return; } Doesn't this still get the scalar and array from what I defined at the top? Also, why do you assign them to @_, can't we use that when iterating @list? Why wouldn't it accept it's arguments? - I would normally call the subroutine like links; but I want to put the result into a variable in order to stick it into an e-mail. I have been trying all day reading all my perl books and it's time to ask for help. Note that we don't want to call Clinks that is better written as Clinks(). What is the result? In your case you are printing the links, so there is no real result. That is what I want, but I can't figure how to but the list into the e-mail message. You need to decide what the return value of the sub will be, maybe the list of urls? A list of urls. a bool? undef for positive or an exception for failure? In the case of the list you should be Cpushing the values to list and then returning the list. In this last case we can call the sub such as, my @ahrefs = links($website, @pics); I get this part. foreach my $link (@ahrefs) { print $linkbr /\n; } Isn't the above the same as my subroutine? For instance. Thanks. Give it a shot, see if this helps, if not come back and ask more. Much appreciated. I will be re-reading Ch2-4 of the Lama tonight. -- Just getting into the best language ever... Fancy a [EMAIL PROTECTED] Just ask!!! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: SIGZERO
Ok, I learned something else ... When I type: kill -9 SOME_PROCESS_ID on the command line, It's not actually killing the process. Let me explain. My script starts 3 others and then stays around watching them. So, when I run it, I get this: # ps -ef | grep dummy user1 18000 1 0 10:04:22 ?0:00 dummy_monitor user1 18001 18000 0 10:04:22 ? 0:00 dummy1 user1 18002 18000 0 10:04:22 ? 0:00 dummy2 user1 18003 18000 0 10:04:22 ? 0:00 dummy3 (the names have been changed to protect the innocent!) Now ... After I run a kill: # kill -9 18002 # ps -ef | grep dummy user1 18000 1 0 10:04:22 ?0:00 dummy_monitor user1 18001 18000 0 10:04:22 ? 0:00 dummy1 user1 18003 18000 0 10:04:22 ? 0:00 dummy3 However, I just discovered that if I check the PID instead: # ps -ef | grep 18002 user1 180002 18000 0 0:00 defunct See that defunct?! How did my process get a defunct status? Is that a Solaris-fancy way of saying zombie-child? The above explains why my (kill 0 = $pid) isn't working the way I expect, but How can I kill the kid. The defunct child process finally dies if I kill the parent (original dummy_monitor) script. Does this mean that my setsid line in my original script is not working correctly? I'm confused here. --Errin -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: SIGZERO
From: Errin Larsen [EMAIL PROTECTED] See that defunct?! How did my process get a defunct status? Is that a Solaris-fancy way of saying zombie-child? I believe so. The above explains why my (kill 0 = $pid) isn't working the way I expect, but How can I kill the kid. The defunct child process finally dies if I kill the parent (original dummy_monitor) script. Does this mean that my setsid line in my original script is not working correctly? I'm confused here. I believe you are supposed to wait()/waitpid() on your children. Or install a $SIG{SIGCHLD} handler that reaps the children. I haven't used Perl under any Unix for years so I can't give you the details. perldoc perlipc should help. Jenda = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Help with putting a subroutine into a variable?
Wiggins d Anconia said: snip sub links { my ($base_url, @list) = @_; foreach my $element (@list) { print . } return; } Doesn't this still get the scalar and array from what I defined at the top? No, note that I have changed the names (on purpose) so that they are defined specifically to the sub (as your other email mentioned). Since I have given them new names they are essentially copies of the original data, but since the variables are within the scope of the sub I can now take the sub and drop it into a library and it will still work, though the calling syntax has to be different (see summary below). Also, why do you assign them to @_, can't we use that when iterating @list? I am not assigning them *to* @_, but *from* @_. In other words, when the subroutine is called it automatically stuffs the arguments given to it in @_. Then within the subroutine I want to pull those arguments back out of @_ and use them to do something (you don't really have to give them new names, but accessing into @_ as $_[0], $_[1], etc. gets annoying). Of course that is where hashes come into play :-)... Why wouldn't it accept it's arguments? In your case you were not using the @_ values so it was not expecting (or using) the arguments, and your calling syntax of Clinks() indicates that no arguments are being passed. - I would normally call the subroutine like links; but I want to put the result into a variable in order to stick it into an e-mail. I have been trying all day reading all my perl books and it's time to ask for help. Note that we don't want to call Clinks that is better written as Clinks(). What is the result? In your case you are printing the links, so there is no real result. That is what I want, but I can't figure how to but the list into the e-mail message. See summary below... You need to decide what the return value of the sub will be, maybe the list of urls? A list of urls. Ok. a bool? undef for positive or an exception for failure? In the case of the list you should be Cpushing the values to list and then returning the list. In this last case we can call the sub such as, my @ahrefs = links($website, @pics); I get this part. foreach my $link (@ahrefs) { print $linkbr /\n; } Isn't the above the same as my subroutine? Sort of, except I have broken the different functional components apart and can now reuse Clinks() as a sub to build a list rather than to *print* a list. But in some cases I want to print a list, so I just print it afterwards. For instance. Thanks. Give it a shot, see if this helps, if not come back and ask more. Much appreciated. I will be re-reading Ch2-4 of the Lama tonight. The llama is excellent. Ok so for the summary, Starting over with your sub that breaks encapsulation by not accepting arguments, and not returning a value, and has the less portable benefit of always printing the values (despite the fact that sometimes we might want them returned to us). my @pics = (list); my $website = 'url'; links(); sub links { foreach (@pics) { print a href=\$website/$_\$website/$_/a\n; } } So in the above your sub *assumes* @pics and $website exist. We want to switch it so that the sub assumes nothing and accepts all of the info it needs as arguments. So we get, my @pics = (list); my $website = 'url'; links($website, @pics); sub links { my ($url, @list) = @_; foreach my $element (@list) { print a href=\$url/$_\$url/$_/a\n; } } Notice that the call to the sub changed, and that it now doesn't use either of @pics, or $website, which means that it could be a list of anything and the $website is really just a base url. But we are still stuck with it just printing to STDOUT, so lets make it return a value instead making it more useful for other things... my @pics = (list); my $website = 'url'; my @piclinks = links($website, @pics); # now @piclinks is just a list that we could put in an email instead print for @piclinks; sub links { my ($url, @list) = @_; my @return; foreach my $element (@list) { push @return, a href=\$url/$_\$url/$_/a\n; } return @return; } So again I changed the call to now catch what the sub returns, and stopped the sub from printing the links. Inside of the sub I built a temporary list and returned it so that the caller could catch it and use it. (I have specifically left out the syntactic sugar of editing the elements in place, etc. for clarity since we are discussing subs not shortening of code.) So why is this better, still does the same thing? Mostly because it is reusable now. For instance, my @piclist1 = (list); my @piclist2 = (a different list); my $website = 'url'; my @email_list = links($website, @piclist1); my @db_list = links($website, @piclist2); # send an email with @email_list #
Re: SIGZERO
On Fri, 24 Sep 2004 17:20:44 +0200, Jenda Krynicky [EMAIL PROTECTED] wrote: From: Errin Larsen [EMAIL PROTECTED] See that defunct?! How did my process get a defunct status? Is that a Solaris-fancy way of saying zombie-child? I believe so. The above explains why my (kill 0 = $pid) isn't working the way I expect, but How can I kill the kid. The defunct child process finally dies if I kill the parent (original dummy_monitor) script. Does this mean that my setsid line in my original script is not working correctly? I'm confused here. I believe you are supposed to wait()/waitpid() on your children. Or install a $SIG{SIGCHLD} handler that reaps the children. I haven't used Perl under any Unix for years so I can't give you the details. perldoc perlipc should help. Jenda Yup. I tried putting: $SIG{CHLD}='IGNORE'; in my parent and that prevents the zombie child. So, next question! how do I wait() or waitpid() on more than one process? don't both of those make the wait()ing process sit still and do nothing else until it gets a return? I'll read perlipc again (man that's a hard one to grok) and see what it says. --Errin -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: SIGZERO
From: Errin Larsen [EMAIL PROTECTED] See that defunct?! How did my process get a defunct status? Is that a Solaris-fancy way of saying zombie-child? I believe so. I do as well. The above explains why my (kill 0 = $pid) isn't working the way I expect, but How can I kill the kid. The defunct child process finally dies if I kill the parent (original dummy_monitor) script. Does this mean that my setsid line in my original script is not working correctly? I'm confused here. I believe you are supposed to wait()/waitpid() on your children. Or install a $SIG{SIGCHLD} handler that reaps the children. That is what i was thinking. Essentially a process that has children wants to hear from them (and will stop sending money if it doesn't). Generally this is done by having the parent wait for the child until it notifies the parent that it is gone, generally the parent knows that when it doesn't have any more children it is done (or is to spawn more, etc.). I haven't used Perl under any Unix for years so I can't give you the details. perldoc perlipc should help. Yes, as well as, perldoc -f wait perldoc -f waitpid Jenda http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: SIGZERO
On Fri, 24 Sep 2004 10:34:50 -0500, Errin Larsen [EMAIL PROTECTED] wrote: On Fri, 24 Sep 2004 17:20:44 +0200, Jenda Krynicky [EMAIL PROTECTED] wrote: From: Errin Larsen [EMAIL PROTECTED] SNIP how do I wait() or waitpid() on more than one process? don't both of those make the wait()ing process sit still and do nothing else until it gets a return? I'll read perlipc again (man that's a hard one to grok) and see what it says. --Errin Well, I found the following code snippet in perlipc: sub REAPER { my $child; while( ( $child = waitpid( -1, WNOHANG ) ) 0 ) { $Kid_Status{$child} = $?; } $SIG{CHLD} = \REAPER; } $SIG{CHLD} = \REAPER; This seems to do something similar to what I want, but I'm confused about exactly what it's doing. what does the '-1' argument to waitpid() do? What is the 'WNOHANG' flag? Why are we reassigning '$SIG{CHLD}' to 'REAPER' inside of REAPER (this seems redundant to me!) I realize this is getting away from the beginner focus of this mailing list, but I don't currently belong to any other mailing lists. Thanks for any help you can throw at me. --Errin -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: SIGZERO
I am a beginner, but I love to see all the knowledge transfer so keep the moderate to difficult questions coming! thanks, Derek B. Smith OhioHealth IT UNIX / TSM / EDM Teams 614-566-4145 Errin Larsen [EMAIL PROTECTED] 09/24/2004 11:44 AM Please respond to Errin Larsen To: Jenda Krynicky [EMAIL PROTECTED] cc: [EMAIL PROTECTED] Subject:Re: SIGZERO On Fri, 24 Sep 2004 10:34:50 -0500, Errin Larsen [EMAIL PROTECTED] wrote: On Fri, 24 Sep 2004 17:20:44 +0200, Jenda Krynicky [EMAIL PROTECTED] wrote: From: Errin Larsen [EMAIL PROTECTED] SNIP how do I wait() or waitpid() on more than one process? don't both of those make the wait()ing process sit still and do nothing else until it gets a return? I'll read perlipc again (man that's a hard one to grok) and see what it says. --Errin Well, I found the following code snippet in perlipc: sub REAPER { my $child; while( ( $child = waitpid( -1, WNOHANG ) ) 0 ) { $Kid_Status{$child} = $?; } $SIG{CHLD} = \REAPER; } $SIG{CHLD} = \REAPER; This seems to do something similar to what I want, but I'm confused about exactly what it's doing. what does the '-1' argument to waitpid() do? What is the 'WNOHANG' flag? Why are we reassigning '$SIG{CHLD}' to 'REAPER' inside of REAPER (this seems redundant to me!) I realize this is getting away from the beginner focus of this mailing list, but I don't currently belong to any other mailing lists. Thanks for any help you can throw at me. --Errin -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: SIGZERO
On Fri, 24 Sep 2004 10:34:50 -0500, Errin Larsen [EMAIL PROTECTED] wrote: On Fri, 24 Sep 2004 17:20:44 +0200, Jenda Krynicky [EMAIL PROTECTED] wrote: From: Errin Larsen [EMAIL PROTECTED] SNIP how do I wait() or waitpid() on more than one process? don't both of those make the wait()ing process sit still and do nothing else until it gets a return? I'll read perlipc again (man that's a hard one to grok) and see what it says. --Errin Well, I found the following code snippet in perlipc: sub REAPER { my $child; while( ( $child = waitpid( -1, WNOHANG ) ) 0 ) { $Kid_Status{$child} = $?; } $SIG{CHLD} = \REAPER; } $SIG{CHLD} = \REAPER; This seems to do something similar to what I want, but I'm confused about exactly what it's doing. what does the '-1' argument to waitpid() do? What is the 'WNOHANG' flag? Why are we reassigning '$SIG{CHLD}' to 'REAPER' inside of REAPER (this seems redundant to me!) The -1 argument is to tell Cwaitpid that it should wait for any processes in the session, aka all of your children as opposed to a particular PID. The CWNOHANG flag tells waitpid not to block if no processes are available to reap, aka allow the parent to continue processing something else. The reassignment appears to be to avoid a bug in older systems that use a SysV fork model, perldoc perlipc includes a comment about this. Because Perl's signal mechanism is currently based on the signal(3) function from the C library, you may sometimes be so misfortunate as to run on systems where that function is broken, that is, it behaves in the old unreliable SysV way rather than the newer, more reasonable BSD and POSIX fashion. Followed by an example of a defensive signal handler. I realize this is getting away from the beginner focus of this mailing list, but I don't currently belong to any other mailing lists. Thanks for any help you can throw at me. --Errin I still suggest checking out the POE framework, specifically the POE::Wheel::Run to handle all of this nonsense. At least once you are satisfied that you understand the underpinnings. http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: SIGZERO
On Fri, 24 Sep 2004 11:52:19 -0400, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I am a beginner, but I love to see all the knowledge transfer so keep the moderate to difficult questions coming! SNIP I'm like you, Derek! I love just reading this stuff. Satisfies some inner-geek need I have! On Fri, 24 Sep 2004 10:34:50 -0500, Errin Larsen [EMAIL PROTECTED] wrote: On Fri, 24 Sep 2004 17:20:44 +0200, Jenda Krynicky [EMAIL PROTECTED] wrote: From: Errin Larsen [EMAIL PROTECTED] SNIP SNIP This seems to do something similar to what I want, but I'm confused about exactly what it's doing. what does the '-1' argument to waitpid() do? What is the 'WNOHANG' flag? Why are we reassigning '$SIG{CHLD}' to 'REAPER' inside of REAPER (this seems redundant to me!) SNIP Ok, I found this is the Perl Cookbook. Below is a quote: To avoid accumulating dead children, simply tell the system that you're not interested in them by setting $SIG{CHLD} to IGNORE. If you want to know which children die and when, you'll need to use waitpid. The waitpid function reaps a single process. Its first argument is the process to wait for - use -1 to mean any process - and its second argument is a set of flags. We use the WNOHANG flag to make waitpid immediately return 0 if there are no dead children. A flag value of 0 is supported everywhere, indicating a blocking wait. Call waitpid from a SIGCHLD handler, as we do in the Solution, to reap the children as soon as they die. The wait function also reaps children, but it does not have a non-blocking option. If you inadvertently call it when there are running child processes but none have exited, your program will pause until there is a dead child. Now, why can't the {perldoc -f waitpid} tell me use -1 to mean any process ?!? That would have been helpful!! --Errin -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
How do I get rid of
Hi All, This is in a text file that I am working with. I am trying to remove it, but it seems to be a different character in different places throughout the text, even though to me, when viewed in Textpad text editor, it looks the same. Is there a special hex code or something that I can use to strip all of these from the text file? Thanks Will -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
How to check the FILE HANDLE STATUS ???
hi, I want to check the status of File handle before reading/writing to file ? How to do this ? like following open(FH_IN_FILE, file.txt); # This statement is executed by some other function close(FH_IN_FILE); print FH_IN_FILE SOME DATA; here before writing to file, i want to check the status of FH_IN_FILE..(whether file is opened or closed ) Thanks __ Do you Yahoo!? Yahoo! Mail is new and improved - Check it out! http://promotions.yahoo.com/new_mail -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: How do I get rid of
if you open the file in vi,say :%s/ctrl-v ctrl-p//g You can check $line =~ s/ctrl-v ctrl-p//g; Mainly ^ = ctrl-v P = ctrl-p regards -Ajey On Thu, 23 Sep 2004, William Martell wrote: Hi All, This is in a text file that I am working with. I am trying to remove it, but it seems to be a different character in different places throughout the text, even though to me, when viewed in Textpad text editor, it looks the same. Is there a special hex code or something that I can use to strip all of these from the text file? Thanks Will -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: XMLin() not finding XML::SAX or XML::Parser modules Problem
I installed the expat libs,but the cpan shell is now asking for EXPATLIBPATH and EXPATINCPATH. It says perl Makefile.PL path_to_libraries Now,how do i specify these paths for XML::Module installation?? Where is this Makefile.PL file? Regards again -Ajey On Thu, 23 Sep 2004, Chris Devers wrote: Please send all replies to the list, not me directly. Thanks. On Thu, 23 Sep 2004, Ajey Kulkarni wrote: Thanks a bunch Chris. I FORCED the pms to be copied. I'll try to install this and get it running. It usually isn't a good idea to force an install unless you understand what the error you're getting means and are confident that in a given case it can be safely ignored. In this case, the README file is clear that you need to have one of the two modules you noted in order for things to work. If you skip that step, then, well, things won't work. On the bright side, you probably don't have to reinstall XML::Simple; once the support module[s] is/are in place, XMLin(...) should work. Or at least that's what it seems like will happen... -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: How to check the FILE HANDLE STATUS ???
hi, I want to check the status of File handle before reading/writing to file ? How to do this ? like following open(FH_IN_FILE, file.txt); Which itself is a bad idea, always check that the open succeeded in the first place, open FH_IN_FILE, file.txt or die Can't open file for writing: $!; # This statement is executed by some other function close(FH_IN_FILE); Iffy, but ok. print FH_IN_FILE SOME DATA; here before writing to file, i want to check the status of FH_IN_FILE..(whether file is opened or closed ) perldoc -f fileno Is about the only way to check (IIRC). The only way to know whether a file can really be written to is to try and catch any errors that occur. Thanks http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: XMLin() not finding XML::SAX or XML::Parser modules Problem
On Fri, 24 Sep 2004, Ajey Kulkarni wrote: I installed the expat libs,but the cpan shell is now asking for EXPATLIBPATH and EXPATINCPATH. Oh. That. Yeah, that's a pain. The first thing is to get Expat installed, which I forgot about before. Instructions for this will vary depending what OS you're running on. The docs for whichever of XML::SAX or XML::Parser you're going with may have more notes to go by here. Once Expat is installed, you need to set those variables for Perl to use while building. The two ways I can think of doing this are: * set them before launching the CPAN shell with one of these methods: $ sudo perl -MCPAN -e shell EXPATLIBPATH=... EXPATINCPATH=... or $ export EXPATLIBPATH=... $ export EXPATINCPATH=... $ sudo perl -MCPAN -e shell (Note that if you use csh/tcsh, it's `setenv FOO bar` instead.) * or, run the CPAN shel to download, then open a subshell to build: $ sudo perl -MCPAN -e shell cpan get XML::Parser cpan look XML::Parser # perl Makefile.PL EXPATLIBPATH=... EXPATINCPATH=... # make make test make install I can be more specific if I know what operating system you're running and which Unix shell (bash, tcsh, etc) you're using, but in general the approach will be along these lines. -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: XMLin() not finding XML::SAX or XML::Parser modules Problem
On Fri, 24 Sep 2004, Ajey Kulkarni wrote: I installed the expat libs,but the cpan shell is now asking for EXPATLIBPATH and EXPATINCPATH. Oh. That. Yeah, that's a pain. The first thing is to get Expat installed, which I forgot about before. Instructions for this will vary depending what OS you're running on. The docs for whichever of XML::SAX or XML::Parser you're going with may have more notes to go by here. Once Expat is installed, you need to set those variables for Perl to use while building. The two ways I can think of doing this are: * set them before launching the CPAN shell with one of these methods: $ sudo perl -MCPAN -e shell EXPATLIBPATH=... EXPATINCPATH=... or $ export EXPATLIBPATH=... $ export EXPATINCPATH=... $ sudo perl -MCPAN -e shell (Note that if you use csh/tcsh, it's `setenv FOO bar` instead.) * or, run the CPAN shel to download, then open a subshell to build: $ sudo perl -MCPAN -e shell cpan get XML::Parser cpan look XML::Parser # perl Makefile.PL EXPATLIBPATH=... EXPATINCPATH=... # make make test make install In the case of using CPAN you can temporarily (or permanantly) set these options using: o conf makepl_arg EXPATINCPATH=... EXPATLIBPATH=... If you have other arguments to Makefile.PL you don't want to clobber them so they will have to be set in the above too. To see what is already configured just issue, o conf By itself. You can reset makepl_arg back to empty once the module is installed, though I would be surprised if it mattered. If you want to keep them as permanant settings, issue, o conf commit Before closing your session. I can be more specific if I know what operating system you're running and which Unix shell (bash, tcsh, etc) you're using, but in general the approach will be along these lines. -- Chris Devers http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: How to check the FILE HANDLE STATUS ???
open(FH_IN_FILE, file.txt); # This statement is executed by some other function close(FH_IN_FILE); print FH_IN_FILE SOME DATA; here before writing to file, i want to check the status of FH_IN_FILE..(whether file is opened or closed ) You could do something like the following: - #!/usr/local/bin/perl -w use strict; my %fhs; # open the filehandle, store in hash open $fhs{one}, ' test1.txt' or die couldn't write file: $!\n; # function takes hashref and name of which filehandle to use sub blah { my ($fh, $which) = @_; close $fh-{$which}; # delete the filehandle when you close it delete $fh-{$which}; } blah(\%fhs, 'one'); # it's closed if it's gone from the hash close $fhs{one} if exists $fhs{one}; - There might be a better way to do whatever you're trying to do, though. What's the bigger problem you're trying to solve? Dave -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Daemon that starts other Daemons
Errin Larsen wrote: Ok ... so with some research and playi^H^H^H^H^Htesting I've found the answer to what's really been bothering me. If you *really* want to understand the nuts and bolts of all this, Stevens' _Advanced Programming in the UNIX Environment_ is a must. http://www.amazon.com/exec/obidos/ASIN/0201563177 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: How to check the FILE HANDLE STATUS ???
Madhu Reddy wrote: hi, Hello, I want to check the status of File handle before reading/writing to file ? How to do this ? like following open(FH_IN_FILE, file.txt); # This statement is executed by some other function close(FH_IN_FILE); print FH_IN_FILE SOME DATA; here before writing to file, i want to check the status of FH_IN_FILE..(whether file is opened or closed ) if ( defined fileno FH_IN_FILE ) { print FH_IN_FILE SOME DATA; } else { warn Error: FH_IN_FILE is closed!\n; } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: How do I get rid of
William Martell wrote: Hi All, Hello, This is in a text file that I am working with. I am trying to remove it, but it seems to be a different character in different places throughout the text, even though to me, when viewed in Textpad text editor, it looks the same. Is there a special hex code or something that I can use to strip all of these from the text file? tr/\10-\15\40-\176//cd John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Daemon that starts other Daemons
Bob Showalter wrote: Errin Larsen wrote: Ok ... so with some research and playi^H^H^H^H^Htesting I've found the answer to what's really been bothering me. If you *really* want to understand the nuts and bolts of all this, Stevens' _Advanced Programming in the UNIX Environment_ is a must. http://www.amazon.com/exec/obidos/ASIN/0201563177 Since the OP mentioned that he is using Solaris he may want to get this book instead: http://www.rite-group.com/rich/ssp/index.html John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
How to return 'k'-cliques in a graph
Dear all, I have a following code that find a k-clique within a graph. k-Clique is a complete subgraph of size 'k'. (Please see the attached picture). Currently running this code gives: $ perl graph.pl 3 5 6 9 $ perl graph.pl 4 1 2 3 4 As you can see the code below only return the last k-clique found. My question is how can I modify my code below so it can store and then returns all the k-clique found? That is: $ perl graph.pl 3 would give: 1 2 3 1 2 4 1 3 4 2 3 4 5 6 9 Thanks so much for your time. Regards, Edward WIJAYA SINGAPORE __BEGIN__ #! /usr/local/bin/perl use warnings; @V = (1, 2, 3, 4, 5, 6, 7, 8, 9); #vertices @E = ([1,2], [1,3],[1,4], [2,3], [2,4], [3,4],[1,5],[5,6], [5,9] ,[5,7],[7,8],[8,9],[6,9]); #Edges [EMAIL PROTECTED] = ([1,2], [1,3],[1,4], [1,5], [5,4]); $k = shift || 3; #Construct a string as follows: $string = (join ',' = @V) . ';' . (join ',' = map $_-[0]-$_-[1], @E); #Then construct a regular expression as follows: $regex = '^ .*\b ' . join(' , .*\b ' = ('(\d+)') x $k) . '\b .* ;' . \n; for ($i = 1; $i $k; $i++) { for ($j = $i+1; $j = $k; $j++) { $regex .= '(?= .* \b ' . \\$i-\\$j . ' \b)' . \n; } } #graph contains a k-clique if and only if if ($string =~ /$regex/x) { print join( , map $$_, 1..$k), \n; } __END__attachment: graph.jpg-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response