SEARCH YOUR SOLUTION HERE  

Noob Q: Ways for module to find config file?

What are the techniques for a module to find its config file It's a chicken/egg problem, since the location of the config file is itself a parameter that may (or must) be configured. One technique I can think of is ...

Posted On: Monday 26th of November 2012 08:13:51 PM Total Views:  371
View Complete with Replies




Related Messages:

Absolute noobie question regarding opening files on Windows platform   (147 Views)
Hi all I wrote this code to read a file (in the same directory as the script) on Win XP *************************************************************************************************** #!/usr/local/bin/perl use strict; use warnings; open(READFILE1,"
FAQ 4.60 How can I always keep my hash sorted?   (264 Views)
This is an excerpt from the latest version perlfaq4.pod, which comes with the standard Perl distribution. These postings aim to reduce the number of repeated questions as well as allow the community to review and update the answers. The latest version of the complete perlfaq is at http://faq.perl.org . -------------------------------------------------------------------- 4.60: How can I always keep my hash sorted You can look into using the "DB_File" module and "tie()" using the $DB_BTREE hash bindings as documented in "In Memory Databases" in DB_File. The "Tie::IxHash" module from CPAN might also be instructive. Although this does keep your hash sorted, you might not like the slow down you suffer from the tie interface. Are you sure you need to do this -------------------------------------------------------------------- The perlfaq-workers, a group of volunteers, maintain the perlfaq. They are not necessarily experts in every domain where Perl might show up, so please include as much information as possible and relevant in any corrections. The perlfaq-workers also don't have access to every operating system or platform, so please include relevant details for corrections to examples that do not work on particular platforms. Working code is greatly appreciated. If you'd like to help maintain the perlfaq, see the details in perlfaq.pod. -- Posted via a free Usenet account from http://www.teranews.com
FAQ 4.37 What's wrong with always quoting "$vars"?   (91 Views)
This is an excerpt from the latest version perlfaq4.pod, which comes with the standard Perl distribution. These postings aim to reduce the number of repeated questions as well as allow the community to review and update the answers. The latest version of the complete perlfaq is at http://faq.perl.org . -------------------------------------------------------------------- 4.37: What's wrong with always quoting "$vars" The problem is that those double-quotes force stringification--coercing numbers and references into strings--even when you don't want them to be strings. Think of it this way: double-quote expansion is used to produce new strings. If you already have a string, why do you need more If you get used to writing odd things like these: print "$var"; # BAD $new = "$old"; # BAD somefunc("$var"); # BAD You'll be in trouble. Those should (in 99.8% of the cases) be the simpler and more direct: print $var; $new = $old; somefunc($var); Otherwise, besides slowing you down, you're going to break code when the thing in the scalar is actually neither a string nor a number, but a reference: func(\@array); sub func { my $aref = shift; my $oref = "$aref"; # WRONG } You can also get into subtle problems on those few operations in Perl that actually do care about the difference between a string and a number, such as the magical "++" autoincrement operator or the syscall() function. Stringification also destroys arrays. @lines = `command`; print "@lines"; # WRONG - extra blanks print @lines; # right -------------------------------------------------------------------- The perlfaq-workers, a group of volunteers, maintain the perlfaq. They are not necessarily experts in every domain where Perl might show up, so please include as much information as possible and relevant in any corrections. The perlfaq-workers also don't have access to every operating system or platform, so please include relevant details for corrections to examples that do not work on particular platforms. Working code is greatly appreciated. If you'd like to help maintain the perlfaq, see the details in perlfaq.pod. -- Posted via a free Usenet account from http://www.teranews.com
tk - running always   (123 Views)
I'm new to tk - so mercy. I've got the widget thing down, have a window, buttons, frames ...... Question is about my 'monitor'. I press a button to start a program that writes information to a text area. It runs continuously. How start and stop this monitor program and return from the button push
Help wth Net::FTP in script sometimes fails but wsftp always works   (125 Views)
I have a script that transfers files from a Solaris server to target unix servers. The script uses Net::FTP->put to write the files, which can be any number of files, not always the same. This script works flawlessly to many servers. Sometimes the 'puts' fail, not always on the same file. What is odd is I can transfer that file, and many others with ws-ftp from my PC. Any idea why that would be First I tried to set the buffer size in the ftp->new to the 4096 like wsftp, from the default 10240, but that didn't work. I see in the doc about Net::FTP, there is a dataconn class. Can I use those commands without specifying any other class in the perl program There is a "write ( BUFFER, SIZE [, TIMEOUT ] )" statement. I cannot find any more information about that, like what is the default BUFFER. Can I use it instead of 'put
FAQ 4.37 What's wrong with always quoting "$vars"?   (83 Views)
This is an excerpt from the latest version perlfaq4.pod, which comes with the standard Perl distribution. These postings aim to reduce the number of repeated questions as well as allow the community to review and update the answers. The latest version of the complete perlfaq is at http://faq.perl.org . -------------------------------------------------------------------- 4.37: What's wrong with always quoting "$vars" The problem is that those double-quotes force stringification--coercing numbers and references into strings--even when you don't want them to be strings. Think of it this way: double-quote expansion is used to produce new strings. If you already have a string, why do you need more If you get used to writing odd things like these: print "$var"; # BAD $new = "$old"; # BAD somefunc("$var"); # BAD You'll be in trouble. Those should (in 99.8% of the cases) be the simpler and more direct: print $var; $new = $old; somefunc($var); Otherwise, besides slowing you down, you're going to break code when the thing in the scalar is actually neither a string nor a number, but a reference: func(\@array); sub func { my $aref = shift; my $oref = "$aref"; # WRONG } You can also get into subtle problems on those few operations in Perl that actually do care about the difference between a string and a number, such as the magical "++" autoincrement operator or the syscall() function. Stringification also destroys arrays. @lines = `command`; print "@lines"; # WRONG - extra blanks print @lines; # right -------------------------------------------------------------------- The perlfaq-workers, a group of volunteers, maintain the perlfaq. They are not necessarily experts in every domain where Perl might show up, so please include as much information as possible and relevant in any corrections. The perlfaq-workers also don't have access to every operating system or platform, so please include relevant details for corrections to examples that do not work on particular platforms. Working code is greatly appreciated. If you'd like to help maintain the perlfaq, see the details in perlfaq.pod.
XML::Parser Q: The Char handler always returns '1'   (118 Views)
Here is the code fragments: ============================================================== # Parser command my $parser = new XML::Parser (ErrorContext => 2); $parser->setHandlers(Start => \&start_handler , Char => \&char_handler , End => \&end_handler , Default => \&default_handler ); $retVal = $parser->parsefile($file); .... sub char_handler { my ($p, $data) = @_; print "char_handler: data = *$data*\n"; ============================================================== The last print statement always prints '1' with the following input (even for NAME or VALUE fields). Subroutines for Start or End seem to work just fine. ============================================================== T1_TXT MY_NAME 1 .... ==============================================================
FAQ 4.37 What's wrong with always quoting "$vars"?   (93 Views)
This is an excerpt from the latest version perlfaq4.pod, which comes with the standard Perl distribution. These postings aim to reduce the number of repeated questions as well as allow the community to review and update the answers. The latest version of the complete perlfaq is at http://faq.perl.org . -------------------------------------------------------------------- 4.37: What's wrong with always quoting "$vars" The problem is that those double-quotes force stringification--coercing numbers and references into strings--even when you don't want them to be strings. Think of it this way: double-quote expansion is used to produce new strings. If you already have a string, why do you need more If you get used to writing odd things like these: print "$var"; # BAD $new = "$old"; # BAD somefunc("$var"); # BAD You'll be in trouble. Those should (in 99.8% of the cases) be the simpler and more direct: print $var; $new = $old; somefunc($var); Otherwise, besides slowing you down, you're going to break code when the thing in the scalar is actually neither a string nor a number, but a reference: func(\@array); sub func { my $aref = shift; my $oref = "$aref"; # WRONG } You can also get into subtle problems on those few operations in Perl that actually do care about the difference between a string and a number, such as the magical "++" autoincrement operator or the syscall() function. Stringification also destroys arrays. @lines = `command`; print "@lines"; # WRONG - extra blanks print @lines; # right -------------------------------------------------------------------- The perlfaq-workers, a group of volunteers, maintain the perlfaq. They are not necessarily experts in every domain where Perl might show up, so please include as much information as possible and relevant in any corrections. The perlfaq-workers also don't have access to every operating system or platform, so please include relevant details for corrections to examples that do not work on particular platforms. Working code is greatly appreciated. If you'd like to help maintain the perlfaq, see the details in perlfaq.pod.
FAQ 7.3 Do I always/never have to quote my strings or use semicolons and commas?   (163 Views)
This is an excerpt from the latest version perlfaq7.pod, which comes with the standard Perl distribution. These postings aim to reduce the number of repeated questions as well as allow the community to review and update the answers. The latest version of the complete perlfaq is at http://faq.perl.org . -------------------------------------------------------------------- 7.3: Do I always/never have to quote my strings or use semicolons and commas Normally, a bareword doesn't need to be quoted, but in most cases probably should be (and must be under "use strict"). But a hash key consisting of a simple word (that isn't the name of a defined subroutine) and the left-hand operand to the "=>" operator both count as though they were quoted: This is like this ------------ --------------- $foo{line} $foo{'line'} bar => stuff 'bar' => stuff The final semicolon in a block is optional, as is the final comma in a list. Good style (see perlstyle) says to put them in except for one-liners: if ($whoops) { exit 1 } @nums = (1, 2, 3); if ($whoops) { exit 1; } @lines = ( "There Beren came from mountains cold", "And lost he wandered under leaves", ); -------------------------------------------------------------------- The perlfaq-workers, a group of volunteers, maintain the perlfaq. They are not necessarily experts in every domain where Perl might show up, so please include as much information as possible and relevant in any corrections. The perlfaq-workers also don't have access to every operating system or platform, so please include relevant details for corrections to examples that do not work on particular platforms. Working code is greatly appreciated. If you'd like to help maintain the perlfaq, see the details in perlfaq.pod.
FAQ 7.3 Do I always/never have to quote my strings or use semicolons and commas?   (138 Views)
This is an excerpt from the latest version perlfaq7.pod, which comes with the standard Perl distribution. These postings aim to reduce the number of repeated questions as well as allow the community to review and update the answers. The latest version of the complete perlfaq is at http://faq.perl.org . -------------------------------------------------------------------- 7.3: Do I always/never have to quote my strings or use semicolons and commas Normally, a bareword doesn't need to be quoted, but in most cases probably should be (and must be under "use strict"). But a hash key consisting of a simple word (that isn't the name of a defined subroutine) and the left-hand operand to the "=>" operator both count as though they were quoted: This is like this ------------ --------------- $foo{line} $foo{'line'} bar => stuff 'bar' => stuff The final semicolon in a block is optional, as is the final comma in a list. Good style (see perlstyle) says to put them in except for one-liners: if ($whoops) { exit 1 } @nums = (1, 2, 3); if ($whoops) { exit 1; } @lines = ( "There Beren came from mountains cold", "And lost he wandered under leaves", ); -------------------------------------------------------------------- The perlfaq-workers, a group of volunteers, maintain the perlfaq. They are not necessarily experts in every domain where Perl might show up, so please include as much information as possible and relevant in any corrections. The perlfaq-workers also don't have access to every operating system or platform, so please include relevant details for corrections to examples that do not work on particular platforms. Working code is greatly appreciated. If you'd like to help maintain the perlfaq, see the details in perlfaq.pod.
A noob playing with: Divert sockets, Linux and Perl.   (141 Views)
I use Debian Etch. Since Divert sockets is not available on the 2.6.18-5-686 kernel, i compiled a 2.6.12.3 kernel and iptables 1.3.1, with the required divert socket patches and installed it. I then used the C code from here (scroll to the bottom): http://sourceforge.net/docman/displa...group_id=63197 with the following iptables rule: iptables -A INPUT -p ICMP -j DIVERT --div-port xxx to test and see if divert sockets was working. It worked great. My problem is that the Perl Net:ivert module refused to work with the sample code in perldoc Net:ivert. I'm sure it's not the iptables rule modified for -p tcp that's causing the problem because I tested with the C code. The error i got in perl was: Can't call method "autoflush" on an undefined value at /usr/local/ share/perl/5.8.8/Net/Divert.pm line 115. So i checked the Divert.pm module and commented line 115 because perldoc IO::Socket::INET says: "As of VERSION 1.18 all IO::Socket objects have autoflush turned on by default. This was not the case with earlier releases." After the commenting out, my script runs without any errors but it does absolutely nothing. It just sits... Could someone suggest what I could do to resolve this problem Seems to me that the 'divert' parameter being passed in IO::Socket::INET is being ignored
Can someone 'splain why this regex won't work both ways?   (119 Views)
I'm trying to find a repeated number in a string, like 122345 finds 22. This works: /(\d)\1/ This doesn't: /\1(\d)/ I guess LLR parsing is to blame, but shouldn't the second example first try to FIND a $1 then check to see if there is a \1, and repeat that process moving L to R I though Perl sort of went to and fro trying to do matching. To me, there IS a /\1(\d)/ in the string since $1 is 2, and there is a \1 = 2 preceeding it. I was a little surprized this didn't work although I can sort of see why in a way too. In some ways it seems to me that regexes should be *disconnected* from parsing - just answer the question does this match , spydox@gmail.com wrote in news:e6278092-e663-4ea6-8f07-40d65faeb551 @f63g2000hsf.googlegroups.co m: [ please do not snip attributions ] >> > I guess LLR parsing is to blame, >> >> I don't look at this as a parsing issue. Rather, it is a "the >> universe must make sense" kind of issue: The first match does not >> exist before the first match. That makes sense to me. It may not >> make sense to you. >> > > To me, like conventional pattern-recognition, of say two tanks > next to each other, the system should accept it whether the match > is described either way: > > find a tank with another identical tank to it's left > > *or* > > find a tank with another identical tank to it's right > > > The system should have no *context-sensitivity* where only one of > the two matches. Sure, internally an algorithm may be scanning L > to R or R to L or whatever, but the user should not even be > concerned with that, at least in this case. I still think it gave > up too soon- it should have tried R to L (backtracking) when L to > R failed. What you seem to want is a "match two identical characters" operator. For this particular case, you can achieve that by using: =for example my @strings = qw( 1222345 1233345 ); s/00|11|22|33|44|55|66|77|88|99// for @strings; print "$_\n" for @strings; =cut When you use a character class, every element of that class is considered equivalent to every other one. So, for example, when you write /\d{2}/ that does find two characters that are in the same equivalence class. The tank ****ogy works perftectly here because there are no two identical tanks in the world. Instead, there are equivalence classes of tanks. Tanks that are the same model, tanks in the same unit etc. If what you want is to say, find a tank, then find another tank that is the same model as the one you just found well, that is equivalent to /(\d)\1/ J. D. Baldwin gives perfect examples of why /\1(\d)/ does not make sense: Finding another tank in the same equivalence class as the one you first found comes after first finding a tank. > Just IMHO, thank-you for your thoughts. This area seems just a bit > gray to me I'd be very interested in Damain or Mark's thoughts. s/Damain/Damian/ My feeble mind looks at the following: #!/usr/bin/perl use strict; use warnings; use 5.010; for ( my @a = qw( 1222345 1233345 ) ) { s/(\d)\K\k// and print "$_\n"; } for ( my @a = qw( 1222345 1233345 ) ) { s/(\d)\K\k+// and print "$_\n"; } for ( my @a = qw( 1222345 1233345 ) ) { s/(\d)\k// and print "$_\n"; } __END__ thinks that the third one is the most natural (that is, find a tank, then find another tank in the same equivalence class) to the other ones. Sinan -- A. Sinan Unur (remove .invalid and reverse each component for email address) comp.lang.perl.misc guidelines on the WWW: http://www.rehabitation.com/clpmisc/
why is return always 0?   (98 Views)
How do I make tftp fail if the host is bad my $rc = system( "/usr/bin/tftp bad$host < $tempFile 2>&1 >/ dev/null" ); if ( $rc != 0 ) { print "unable to tftp to '$host'\n"; exit 1; } else { print "success: $rc\n"; } , jammer wrote: > On Mar 16, 9:10 pm, sandy_sayda...@yahoo.com wrote: > > On 16 Mar, 17:45, jammer wrote: > > > > > How do I make tftp fail if the host is bad It seems that that is a question for the authors of tftp, not a Perl question. But there may be a Perl work-a-round. > > > > > my $rc = system( "/usr/bin/tftp bad$host < $tempFile 2>&1 > > > >/dev/null" ); if ( $rc != 0 ) { > > > print "unable to tftp to '$host'\n"; > > > exit 1; > > > } else { > > > print "success: $rc\n"; > > > } > > > > Make sure the binary returns non-zero on failure. Try that command on > > the command line and do "echo $" right after. > > > > -sandyhttp://myperlquiz.com/ > > It prints an error when run interactively. Does it do that when run noninteractively You could try capturing and parsing its stderr. IPC::Run might be a good way. (I think it might also help you trick tftp into thinking it is running interactively, if that is necessary.) > tftp does run, it just can't find the host. > It returns 0 because it ran, didn't work but it ran. :-( Well, that was probably a poor design decision. By that criterion, nothing should ever exit with anything but 0. If it ran, it ran. If it didn't run, it can't exit with anything at all. Xho -- -------------------- http://NewsReader.Com/ -------------------- The costs of publication of this article were defrayed in part by the payment of page charges. This article must therefore be hereby marked advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate this fact.
FAQ 4.60 How can I always keep my hash sorted?   (145 Views)
This is an excerpt from the latest version perlfaq4.pod, which comes with the standard Perl distribution. These postings aim to reduce the number of repeated questions as well as allow the community to review and update the answers. The latest ...
FAQ 4.60 How can I always keep my hash sorted?   (121 Views)
This is an excerpt from the latest version perlfaq4.pod, which comes with the standard Perl distribution. These postings aim to reduce the number of repeated questions as well as allow the community to review and update the answers. The latest ...
FAQ 4.60 How can I always keep my hash sorted?   (116 Views)
This is an excerpt from the latest version perlfaq4.pod, which comes with the standard Perl distribution. These postings aim to reduce the number of repeated questions as well as allow the community to review and update the answers. The latest ...
FAQ 7.3 Do I always/never have to quote my strings or use semicolons and commas?   (119 Views)
This is an excerpt from the latest version perlfaq7.pod, which comes with the standard Perl distribution. These postings aim to reduce the number of repeated questions as well as allow the community to review and update the answers. The latest ...
WWW::Mechanize doesn't always follow_link(text   (136 Views)
I'm using WWW::Mechanize 1.34 and have a problem. This doesn't work: $agent->follow_link(text => 'Edit&nbsp;Librarians', n => 1); It doesn't work in the sense that the link isn't followed and the $agent is still on the same page. Is there a ...
FAQ 4.60 How can I always keep my hash sorted?   (120 Views)
This is an excerpt from the latest version perlfaq4.pod, which comes with the standard Perl distribution. These postings aim to reduce the number of repeated questions as well as allow the community to review and update the answers. The latest ...
FAQ 4.60 How can I always keep my hash sorted?   (134 Views)
This is an excerpt from the latest version perlfaq4.pod, which comes with the standard Perl distribution. These postings aim to reduce the number of repeated questions as well as allow the community to review and update the answers. The latest ...