No such file or directory
Hello, I know that this is a very common problem, but I am very sure that the file exist in that directory, also its permission is -rwxrwxrwx , why does it give such an error ? What are the other potential problems that cause this ? Thanks Send instant messages to your online friends http://uk.messenger.yahoo.com
Re: No such file or directory
anthony brooke wrote: Hello, I know that this is a very common problem, but I am very sure that the file exist in that directory, also its permission is -rwxrwxrwx , why does it give such an error ? What are the other potential problems that cause this ? Thanks Send instant messages to your online friends http://uk.messenger.yahoo.com Anthony It would help if you could post a sample of you script and give the actuall error. open(RULES, 'rule.pl') || die Could not open rule file 'rule.pl'. Error $!br; Could not open rule file 'rule.pl'. Error No such file or directorybr at /var/www/modperl//ParserGenerator.pm line 368. Btw, why do I have double forward slash on that shown module ? When I put these code in /var/www/modperl//ParserGenerator.pm use Cwd; die .getcwd.; [Wed May 21 15:17:46 2008] [error] / at /var/www/modperl//ParserGenerator.pm line 44.\n I think I am confuse now. Send instant messages to your online friends http://uk.messenger.yahoo.com
Re: No such file or directory
anthony brooke wrote: Hello, I know that this is a very common problem, but I am very sure that the file exist in that directory, also its permission is -rwxrwxrwx , why does it give such an error ? What are the other potential problems that cause this ? Thanks Send instant messages to your online friends http://uk.messenger.yahoo.com Anthony It would help if you could post a sample of you script and give the actuall error. Also I am using mod_perl, is it because of that make my cwd become the top directory / ? Thanks Send instant messages to your online friends http://uk.messenger.yahoo.com
Re: No such file or directory
- Original Message From: Jeff Peng [EMAIL PROTECTED] To: Perl Beginners beginners@perl.org Sent: Wednesday, May 21, 2008 15:53:00 Subject: Re: No such file or directory open(RULES, 'rule.pl') please use full path if you don't know where you are exactly. On Wed, May 21, 2008 at 3:45 PM, anthony brooke [EMAIL PROTECTED] wrote: -- Jeff Peng - [EMAIL PROTECTED] Professional Squid supports in China http://www.ChinaSquid.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ The problem is I am using mod_perl, wherever I am it always show / as the current working directory. I got to post the problem to Send instant messages to your online friends http://uk.messenger.yahoo.com
Initialize object permanently
Hello, I am using Wordnet::QueryData which allow access to a very huge dictionary data. The initialization of object my $wn = WordNet::QueryData-new; took 2 wallclock secs ( 2.36 usr + 0.07 sys = 2.43 CPU) Then the subsequent request for the data is exetremely fast For the lines below took 0 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU) print Synset: , join(, , $wn-querySense(cat#n#7, syns)), \n; print Hyponyms: , join(, , $wn-querySense(cat#n#1, hypo)), \n; print Parts of Speech: , join(, , $wn-querySense(run)), \n; print Senses: , join(, , $wn-querySense(run#v)), \n; print Forms: , join(, , $wn-validForms(lay down#v)), \n; print Noun count: , scalar($wn-listAllWords(noun)), \n; print Antonyms: , join(, , $wn-queryWord(dark#n#1, ants)), \n; I am developing a web application, is there a way to make the initialization of object permanently in memory ? I tried to use the Storable module. But that only give me a little increase in performance. Anybody's idea is very much appreciated, Thank you. William Send instant messages to your online friends http://uk.messenger.yahoo.com
Re: Initialize object permanently
Thanks for the reply, it's a dynamic server side script that currently using CGI, but I am going for mod_perl. The interface is something like Google, so everytime the user make a request to lookup let's say the meaning of a word, the WordNet object have to be initialized. Is there a work around of this with mod_perl ? Thanks - Original Message From: Rob Dixon [EMAIL PROTECTED] To: beginner perl mailling list beginners@perl.org Cc: anthony brooke [EMAIL PROTECTED] Sent: Saturday, May 17, 2008 0:47:52 Subject: Re: Initialize object permanently anthony brooke wrote: Hello, I am using Wordnet::QueryData which allow access to a very huge dictionary data. The initialization of object my $wn = WordNet::QueryData-new; took 2 wallclock secs ( 2.36 usr + 0.07 sys = 2.43 CPU) Then the subsequent request for the data is exetremely fast For the lines below took 0 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU) print Synset: , join(, , $wn-querySense(cat#n#7, syns)), \n; print Hyponyms: , join(, , $wn-querySense(cat#n#1, hypo)), \n; print Parts of Speech: , join(, , $wn-querySense(run)), \n; print Senses: , join(, , $wn-querySense(run#v)), \n; print Forms: , join(, , $wn-validForms(lay down#v)), \n; print Noun count: , scalar($wn-listAllWords(noun)), \n; print Antonyms: , join(, , $wn-queryWord(dark#n#1, ants)), \n; I am developing a web application, is there a way to make the initialization of object permanently in memory ? I tried to use the Storable module. But that only give me a little increase in performance. Anybody's idea is very much appreciated, Thank you. When you say 'web application', do you mean a server-side CGI script or a client-side program that interrogates the Web and also needs access to the dictionary? Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ Send instant messages to your online friends http://uk.messenger.yahoo.com
initialize data permanently
Hello, I am using Wordnet::QueryData which allow access to a very huge dictionary data. The initialization of object my $wn = WordNet::QueryData-new; took 2 wallclock secs ( 2.36 usr + 0.07 sys = 2.43 CPU) Then the subsequent request for the data is exetremely fast For the lines below took 0 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU) print Synset: , join(, , $wn-querySense(cat#n#7, syns)), \n; print Hyponyms: , join(, , $wn-querySense(cat#n#1, hypo)), \n; print Parts of Speech: , join(, , $wn-querySense(run)), \n; print Senses: , join(, , $wn-querySense(run#v)), \n; print Forms: , join(, , $wn-validForms(lay down#v)), \n; print Noun count: , scalar($wn-listAllWords(noun)), \n; print Antonyms: , join(, , $wn-queryWord(dark#n#1, ants)), \n; I am developing a web application, is there a way to make the initialization of object permanently in memory ? I tried to use the Storable module. But that only give me a little increase in performance. Anybody's idea is very much appreciated, Thank you. William Send instant messages to your online friends http://uk.messenger.yahoo.com
Concatenate similar data in array
Hello, my logic is really bad, here is I want to do. my @list = qw(a b a a d e e ); I want to compact the array by concatenating the adjacent vowels and consonant together, like for the above it should become, my @list2 = qw(ab aa d ee); How do I get the @list2 ? Thanks. Send instant messages to your online friends http://uk.messenger.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Fw: Perl maximum execution time
Thanks for the reply, but sometimes I don't know where is the code that cause the infinite loop. Is there such as thing as perl configuration file, to set the execution time for any code, any where in the program just like php.ini file. Thanks. - Original Message From: Chas. Owens [EMAIL PROTECTED] To: Keenlearner [EMAIL PROTECTED] Cc: beginners@perl.org Sent: Friday, April 11, 2008 16:05:07 Subject: Re: Perl maximum execution time On Thu, Apr 10, 2008 at 9:25 PM, Keenlearner [EMAIL PROTECTED] wrote: Hello, I have had been programming in PHP for a while, new to perl. I got a perl code bug where it will go to infinite loop. So is there a maximum execution time that I could set in perl just like in PHP ? Thanks snip You can set an signal to go off after X seconds with the alarm* function: #!/usr/bin/perl use strict; use warnings; my $timeout = 5*60; #timeout after five minutes eval { local $SIG{ALRM} = sub { die timeout\n }; alarm $timeout; #stuff you want to run in under five minutes }; die unless $@ eq timeout\n if $@; * http://perldoc.perl.org/functions/alarm.html -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ Send instant messages to your online friends http://uk.messenger.yahoo.com Send instant messages to your online friends http://uk.messenger.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Fw: Perl maximum execution time
Thanks, I am using Apache 2 and Opera browser. So you mean configure through my web server ? How if I run the code through the shell ? - Original Message From: Jenda Krynicky [EMAIL PROTECTED] To: beginner perl mailling list beginners@perl.org Sent: Monday, April 14, 2008 22:31:35 Subject: Re: Fw: Perl maximum execution time From: anthony brooke [EMAIL PROTECTED] Thanks for the reply, but sometimes I don't know where is the code that cause the infinite loop. Is there such as thing as perl configuration file, to set the execution time for any code, any where in the program just like php.ini file. Thanks. Depends. Perl is not just for Web! Most likely your webserver has some settings for this, but without knowing what server do you use we can't tell you where. 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/ Send instant messages to your online friends http://uk.messenger.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Perl Serialize object as string
Hello everyone, I need to serialize an perl object to STRING TEXT, not scalar or file. The Storable module allow serialization to file and scalar variable, but this is not possible for passing between the perl and prolog program, that's why I need it to be string. I tried out the FreezeThaw module but it couldn't serialize object successfully, or have ever done it ? Thanks. Send instant messages to your online friends http://uk.messenger.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Perl Serialize object as string
Thanks for the reply, I always thought that Dumper is used for debugging purposes, I will look at it deeper. Btw, what you mean by cyclic data ? - Original Message From: Chas. Owens [EMAIL PROTECTED] To: anthony brooke [EMAIL PROTECTED] Cc: beginner perl mailling list beginners@perl.org Sent: Monday, April 7, 2008 2:09:0-1 Subject: Re: Perl Serialize object as string On Sun, Apr 6, 2008 at 1:52 PM, anthony brooke [EMAIL PROTECTED] wrote: Hello everyone, I need to serialize an perl object to STRING TEXT, not scalar or file. The Storable module allow serialization to file and scalar variable, but this is not possible for passing between the perl and prolog program, that's why I need it to be string. I tried out the FreezeThaw module but it couldn't serialize object successfully, or have ever done it ? Thanks. If you don't have cyclic data you can use Data::Dumper*, but I would suggest looking at YAML::Syck* instead. * http://perldoc.perl.org/Data/Dumper.html ** http://search.cpan.org/dist/YAML-Syck/lib/YAML/Syck.pm -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. Send instant messages to your online friends http://uk.messenger.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
locate install C code module
I had installed the Language::Prolog::Yaswi from http://search.cpan.org/~salva/Language-Prolog-Yaswi-0.14/Yaswi.pm but it is in C code implementation, normally when I install a perl module, it should be located at /usr/local/share/perl/5.8.8 but I can't see where is the Language::Prolog::Yaswi folder. Also, does anyone have the resources to understand how to link the C code with perl ? Thanks. Send instant messages to your online friends http://uk.messenger.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Install CPAN module in shared hosting
Hello, I like to install CPAN modulike like AI::Prolog, I have the Cpanel that have CPAN module installer, but my shared hosting does not allow some modules to be installed like this AI::Prolog, what can I do ? Should I install it in my computer first and then copy the PM files to my web host directory and use the use lib to include my cpan module. Is there a better way ? Thanks. Send instant messages to your online friends http://uk.messenger.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Script Required to Check a range of IP's
On 6/29/06, Mazhar [EMAIL PROTECTED] wrote: Hi Folks, I have a requirement of writing down a script to check the range of IP's in a text file and display them which all are active and not active. I have written down the below and needs your help because it is not giving me the correct ouptut. #!/usr/bin/perl use strict; use warnings; use Net::Ping; my $file_name=$ARGV[0]; my $line; my @host_array; open(FILE,$file_name) || die Not been Accessed; while (FILE) { chomp; @host_array=$_; } my $p = Net::Ping-new(); foreach my $host (@host_array) { print $host is ; print NOT unless $p-ping($host, 2); print reachable.\n; sleep(1); } $p-close(); close (FILE); ### Needs your help on the above Regards Mazhar If it helps, I wrote a script to ping a list of mirrors, from a list of fqdn's... http://perl-e.chovy.com/sample/ping-mirrors http://perl-e.chovy.com/sample/ping-mirrors.txt -- Anthony Ettinger Resume: http://chovy.dyndns.org/resume.html (I'm currently available for contract/telecommute work!) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: best way of getting a web document
On 6/24/06, Matt Johnson [EMAIL PROTECTED] wrote: Mumia W. wrote: Dan wrote: LWP or HTTP::Client? i've used both and run across..some problems. [...] i need the most reliable to fetch the feed, and pass me the body of the page so i can pass it to an xml parser of sort. unless there's something else which can already do that? [...] Hi Dan. I've played with LWP before, and it worked okay. Another option is to use the lynx web browser to fetch the page source. As far as I know, lynx cannot parse XML, so you'd have to use a separate XML parser after fetching the page with lynx. More options for fetching pages are curl (the module) and curl (the program). Foremost among the XML parsers is XML::Parser; however, CPAN has many XML parsing modules. Hi, I use WWW::Mechanize http://search.cpan.org/~petdance/WWW-Mechanize-1.18/lib/WWW/Mechanize.pm to get pages. I do some simple XML validation and manipulation in some cases. I've used HTTP::Request, curl is easy too...watch what you pass to the command line though. -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Comparing dates
Date::Calc On 6/25/06, ebony smith [EMAIL PROTECTED] wrote: I am new to perl and need to compare some dates in a file stored in dd-mm- format to find out if the dates are greater than 30, 60 or 90 days. However, I am not quite sure how to go about doing that in perl and I was wondering if anyone out there had any tips on how to do this. I extract the data required using the following to get a date and username if (-e $FILE) { unlink $FILE ;} open (CHK, $FILE) || die Cannot open $FILE; system (`awk '/Login/ {print \$1,\$7}' $FILE1 | sort -u $FILE1`); Then this gives me the current date $tm = localtime($date); $day = $tm-mday; $month = $tm-mon+1; $year = $tm-year+1900; if ( $day 10 ){ $day=0$day; } if ( $month 10 ){ $month=0$month; } $querydate = $year-$month-$day; return $querydate However I am not too sure how to go about comparing the date extracted from the data file with the current date to find out if it is greater 30, 60 or 90 days. Any help would be appreciated. _ Be the first to hear what's new at MSN - sign up to our free newsletters! http://www.msn.co.uk/newsletters -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: CPAN::Shell install into customer dir
Isn't it PERL_PREFIX? On 6/24/06, JupiterHost.Net [EMAIL PROTECTED] wrote: Howdy all :) I've a plugin installer that installs certain Perl modules: This is what it uses, CPAN::Shell-expand('Module', $module_name)-install(); which works fine as long as root is running it. What I'd like to do is install the modules as an unprivileged user into /home/$user/perl I tried setting $ENV{'PREFIX'}, $ENV{'PERL5LIB'}, to no avail. Any one have any ideas if that can be done codewise without reverting to a shell command ( a) I want to use a module not shell out a command b) I want to use CPAN so it follows dependencies instead of Makefile.PL - make etc etc Any insight into what I've missed would be absolutely excellent :) TIA! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: using (sharing) variables between perl files
On 6/19/06, Prabu [EMAIL PROTECTED] wrote: Varga Pavol wrote: Hi, may be very simple, but I don't understand well how to simple use (share) varables between perl files? I have (very) big perl script and I would like to divide it into more small scripts to make it all more transparent. Or, how to use one @array or one $array_ref for more than one file.pl? I just read book from OReilly - Learning perl and some chapters about Intermediate perl, but I am little bit confused with objects, packages and probably more ... :-( Many thanks. Hello , Hope this Small example give you some idea. $cat file1.pl #!/usr/bin/perl $name=prabu; $cat file2.pl #!/usr/bin/perl require file1.pl; print $name.\n; $ perl file2.pl prabu -- Prabu.M.A -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response read about object oriented perl. or you can always use a config file. -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: newlines on win32, old mac, and unix
# order matters $raw_text =~ s/\015\012/\n/g; $raw_text =~ s/\012/\n/g unless \n eq \012; $raw_text =~ s/\015/\n/g unless \n eq \015; Does it make any difference if I use s/\cM\cJ/cJ/ vs. s/\015\012/\n/g ? Since the newline convention is not necessarily the one in the runtime platform you cannot write a line-oriented script. If files are too big to slurp then you'd work on chunks, but need to check by hand whether a CRLF has been cut in the middle. I'm reading each line in a while loop, so it should work fine on a large file? -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: newlines on win32, old mac, and unix
On 6/19/06, John W. Krahn [EMAIL PROTECTED] wrote: Anthony Ettinger wrote: # order matters $raw_text =~ s/\015\012/\n/g; $raw_text =~ s/\012/\n/g unless \n eq \012; $raw_text =~ s/\015/\n/g unless \n eq \015; Does it make any difference if I use s/\cM\cJ/cJ/ vs. s/\015\012/\n/g ? The string cJ in your example is completely different than the string \n and even if you had used \cJ it would still not be the same some of the time and you don't have the /g option on your example. Not according to the perlport page, it reads as though they are synonymous with each other. Also, why would a newline not be at the end of a line? I don't see that /g *has* to be there except for the mac files, which is what I have. 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 -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
two process writing simultaneously
+-+ | 1 | | | |2 | | | +-+ is it possible to write to the same stdout but in two different locations on the screen ( 1 and 2)? I'd like to combine the output of a repeating pstree command with an strace at the same time. -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: About Encryption/ Decription
interesting, has anybody had any success with this on nix and win32 platforms? On 6/16/06, Prabu [EMAIL PROTECTED] wrote: kilaru rajeev wrote: Hi, Please tell me how can we encrypt or decript file. Please give me the information regarding this. Regards, Rajeev Try out with the modules available in http://search.cpan.org/~aar/Module-Crypt-0.04/Crypt.pm Module::Crypt -- Prabu -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
newlines on win32, old mac, and unix
I have to write a simple function which strips out the various newlines on text files, and replaces them with the standard unix newline \nafter reading the perlport doc, I'm even more confused now. LF eq \012 eq \x0A eq \cJ eq chr(10) eq ASCII 10 CR eq \015 eq \x0D eq \cM eq chr(13) eq ASCII 13 | Unix | DOS | Mac | --- \n | LF | LF | CR | \r | CR | CR | LF | \n * | LF | CRLF | CR | \r * | CR | CR | LF | --- * text-mode STDIO In text-mode, I open the file, and do the following: while (defined(my $line = INFILE)) { my $outline; if ($line =~ m/\cM\cJ/) { print dos\n; ($outline = $line) =~ s/\cM\cJ/\cJ/; #win32 } elsif ($line =~ m/\cM(?!\cJ)/) { print mac\n; ($outline = $line) =~ s/\cM/\cJ/g; #mac } else { print other\n; $outline = $line; #default } print OUTFILE $outline; } It works fine on unix when I run the unit tests on old mac files, win, and unix files and do a hexdump -C on themhowever, when I run it on win32 perl 5.6.1, it is not doing any replacement. Teh lines remain unchanged. My understanding is that \n is a reference (depending on which OS your perl is running on) to CR (mac), CRLF (dos), and LF (unix) in text-mode STDIO. So replacing CR (not followed by LF) with LF should work on mac, and CRLF with LF on dos, and leaving LF untouched on *nix (other)then it shouldn't be a problem...however it appears that \cJ is actually different on win32 than it is on unix. so is \cJ is actually \cM\cJ on win32? -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: subroutine?
sub ([EMAIL PROTECTED], [EMAIL PROTECTED]); collect([EMAIL PROTECTED], [EMAIL PROTECTED]); On 6/12/06, Ryan Dillinger [EMAIL PROTECTED] wrote: Hello; I have a script here, that for some reason I cannot get to print out. Can someone please point out what I may be doing wrong? I know I am going to feel like a Dummy! Thanks so much for your help!! @array1 = (a, b, c,); @array2 = (1, 2, 3,); sub collect { ($value1, $value2) = @_; print $value1; print $value2; return @value1, @value2; } sub ([EMAIL PROTECTED], [EMAIL PROTECTED]); Thanks Again! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- 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 bind values in IN value
$result-execute(@$userid); You declared an array @userid, not an arrayref, so you don't need to dereference it. $result-execute(@userid); should do the trick. -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Problem installing captcha
/first-response t/1Can't locate GD.pm in @INC (@INC install GD (requires the C library for GD as well) -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: OO Perl question
On 6/8/06, Graeme McLaren [EMAIL PROTECTED] wrote: Hi all, this class that I have written lists the contents of a log table when the $log-view method is invoked. There is some hardcoded SQL in this method and all I do is pass it a number which then looks up the relevant records. This really isn't a reusable class as far as I understand it because it assumes that anyone else using it would have a log table with various fields of a certain name defined. How can I make this completely reuseable, should it be documented saying that you need to create a log table with various fields before using it or should I code it so that the table name and fields have to be passed in and the script would then take care of it? Your thoughts and comments are as always - appreciated. Cheers, G :) Interesting. Reusable by who? Is it part of a package you're going to distribute? is there an included mypkg.sql file they have to run? Typically, package installs come with a config file where a user can specify tablename_prefix. so it would be pretty seamless if all they had to do was edit mypkg.conf and change: table_prefix = mypkg_ so then log_table would become mypkg_log_table, while columns would remain the same. You could have your module simply read the config file inside the implementation of $log-view(); The table structure(s) should stay the same, but give them a chance to override the table names incase they collide with pre-existing tables. I've found this to be the best way to ensure not dropping tables on accident, especially if you load an sql file with drop table foo if foo exists. I almost did that at work the other day on a table with 1 character diff in the name (i was lucky, and added dp_ to all my table namespaces). -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: OO Perl question
On 6/8/06, Graeme McLaren [EMAIL PROTECTED] wrote: Hi Anthony, good idea about overriding the table names. I had a feeling there would be a conf file somewhere. As I am outputting the results of the SELECT to an HTML::Template I am already using a Conf file which is another class. This leads me on to another question. If I instantiate my class and create a Conf object within $log-view then the Conf file won't be loaded till this method is invoked. I want to have all the Conf details available at the same time, I don't want to instantiate the Conf class several times and hold several copies of the Conf in memory when only one is required. So how or where should I instantiate it? If everything related to the app is encapsulated withing your Log package, put it in the constructor package Log; sub new { //create object $self-init(); } sub init { open(CONF, $conf) or die can't open config file: $!; while(CONF) { next if (m/^#/); #skip comments my ($option) = $_ =~ s/(.*?)#/; #skip inline comments my ($key, $val) = split(/\s*=\s*/, $option); $self-{$key} = $val; } close(CONF); return $self; } sub getTablePrefix { my $self = shift; return $self-{'table_prefix'}; } So now when you can print Dumper($self-{'table_prefix'}); and it should have the value from the config file. my $log = new Log; print $log-getTablePrefix(); -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: OO Perl question
my ($option) = $_ =~ s/(.*?)#/; #skip inline comments should be m//, not s// On 6/8/06, Anthony Ettinger [EMAIL PROTECTED] wrote: On 6/8/06, Graeme McLaren [EMAIL PROTECTED] wrote: Hi Anthony, good idea about overriding the table names. I had a feeling there would be a conf file somewhere. As I am outputting the results of the SELECT to an HTML::Template I am already using a Conf file which is another class. This leads me on to another question. If I instantiate my class and create a Conf object within $log-view then the Conf file won't be loaded till this method is invoked. I want to have all the Conf details available at the same time, I don't want to instantiate the Conf class several times and hold several copies of the Conf in memory when only one is required. So how or where should I instantiate it? If everything related to the app is encapsulated withing your Log package, put it in the constructor package Log; sub new { //create object $self-init(); } sub init { open(CONF, $conf) or die can't open config file: $!; while(CONF) { next if (m/^#/); #skip comments my ($option) = $_ =~ s/(.*?)#/; #skip inline comments my ($key, $val) = split(/\s*=\s*/, $option); $self-{$key} = $val; } close(CONF); return $self; } sub getTablePrefix { my $self = shift; return $self-{'table_prefix'}; } So now when you can print Dumper($self-{'table_prefix'}); and it should have the value from the config file. my $log = new Log; print $log-getTablePrefix(); -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Yet another OO question
On 6/8/06, Ricardo SIGNES [EMAIL PROTECTED] wrote: * Graeme McLaren [EMAIL PROTECTED] [2006-06-08T05:44:05] Hi all, I've just been reading a bit about accessor get/set methods. I have a method: sub even{ my $self = shift; my $even = shift; $self-{_even} = $even if defined($even); return $self-{_even}; } This basically does what a get and set method would do. So why would I need a set/get methods? This value is passed to the object like so: It's a question of style, largely. Some people prefer their code to be very clear about whether your getting or setting. Using explicit set and get methods can also help prevent bugs; you won't accidentally make a read-only value writeable, because you will avoid writing a set_ro_value method -- if you only have a get-and-set ro_value method, you might forget to special-case it to be get-only. Also, you'd probably avoid bugs like the one you introduced above. What happens if I want to clear the even value? $obj-even(undef); This does not affect the value; I can't undef even. You probably wanted: sub even { my $self = shift; return $self-{even} unless @_; return $self-{even} = shift @_; } -- rjbs -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.2 (GNU/Linux) iD8DBQFEiBrL5IEwYcR13KMRAnUiAJ9jORCdmqcxxvJSLnzfg2B0BXJdMACZAU3v H8WkVST4w7lrACbWr2hdtLY= =7rTT -END PGP SIGNATURE- i prefer the return once method: sub foo { my $self = shift; if (@_ == 1) { $self-{'foo'} = shift; } return $self-{'foo'}; } -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Yet another OO question
On 6/8/06, Mr. Shawn H. Corey [EMAIL PROTECTED] wrote: On Thu, 2006-08-06 at 10:56 -0700, Anthony Ettinger wrote: i prefer the return once method: sub foo { my $self = shift; if (@_ == 1) { $self-{'foo'} = shift; } return $self-{'foo'}; } I would prefer it to return the old value: sub foo { my $self = shift; my $old_foo = $self-{'foo'}; $self-{'foo'} = shift if @_ 0; return $old_foo; } -- __END__ Just my 0.0002 million dollars worth, --- Shawn If you set a new value, why would you want your client to still be using the old value? -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
modifying @INC permanently
Is there a way to modify @INC for the perl installation as a whole? All my scripts have logic to push the same directory to @INC. It's rather repetative. I know I can export PERL_LIB environment variable, but I need something for all system users (including win32). -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: modifying @INC permanently
You do not need logic to do that. It would seem better to use: use lib '/path/to/my/misplaced/perl-modules'; The point is to not have to specify a local path at all: use lib qw(/path); push(@inc, '/path'); Each script tests for OS: linux/sunos, and win32, and pushes the path to @INC accordingly, based on path names. I tried File::Spec, but use lib won't take a variable as it's evaluated before runtime, so that left me with push. -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: modifying @INC permanently
On 6/8/06, Chad Perrin [EMAIL PROTECTED] wrote: Yes. Recompile Perl setting the appropriate compile-time flags. More importantly, though: Why? It is just easier to install your modules in the standardly defined place for site-specific modules. By install do you mean cp myMod.pm to /my/path/ ?? -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Yet another OO question
On 6/8/06, Lawrence Statton [EMAIL PROTECTED] wrote: I would prefer it to return the old value: sub foo { I see...I i've been more or less looking at the current state $curr = $foo-bar(); $old = $curr; $curr = $foo-bar('new value'); -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- 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 to match a range of numbers?
You can simply split on whitespace. http://perl-e.chovy.com/sample/date-parse On 6/7/06, Joshua Colson [EMAIL PROTECTED] wrote: I'm trying to parse a date from a file and I would like to know how to match a range of numbers with a regex? For example, the days of the month 1..31. I understand that there are numerous modules that can do the work for me, this is as much for my own learning as anything. Thanks. --- #!/usr/bin/perl use strict; use warnings; my $date = Wed Jun 7 14:27:38 2006'; print $3 if $date =~ m{(Wed)\s(Jun)\s{1,2}([1..31])}; __END__ -- Joshua Colson [EMAIL PROTECTED] iNation, LLC -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Multiple Page Scrape
Since it's native xml format, I would use XML::Simple to parse it into a hash, then you can format however you want by looping through the hash. On 6/6/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: The script below scrapes a House of Representatives vote page which is in xml and saves it in a spreadsheet which is best opened as an xls read only. How can I: 1) scrape multiple vote pages into individual spreadsheets with a single script? 2) Only scrape columns C, F, G, H in the result here? I'd also prefer to have the spreadsheet as a csv, but that doesn't work by just changing *.xls to *.csv Thanks in advance. Ken #!/bin/perl use strict; use warnings; use WWW::Mechanize; my $output_dir = c:/training/bc; my $starting_url = http://clerk.house.gov/evs/2005/roll667.xml;; my $browser = WWW::Mechanize-new(); $browser-get( $starting_url ); foreach my $line (split(/[\n\r]+/, $browser-content)) { print $line;} open OUT, $output_dir/vote667.xls or die Can't open file:$!; foreach my $line (split(/[\n\r]+/, $browser-content)) { print OUT $line;} close OUT; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: What are the problems with my CGI script
my $name = param('name') || ''; if(defined $name) { # if its valid , HTMLescape it and print it # otherwise tell them they did bad :) } else { # ask them for theri name } definitely the better way to handle it, although you don't need the || unless you want a default value. Setting it as empty is still a value, so you potentially could have empty values in your database. if (defined($name)) would be better, but can be rather cumbersome. -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: reading Perl syntax
On 6/6/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: $self-_read_file($self-{file}) $self is an blessed reference to an object (used from inside that object) $self-_read_file() is the subroutine to call defined inside that object $self-{'file'}; is a reference to a hash defined inside the object. It's confusing, but if you ignore the $self and think of it as a standalone top-down script, it makes more sense. The syntax {} is for a hashref, it's just an un-named hashref inside that object. my $foo = new Foo; print $foo-getFooKey(); $foo-setFooKey('new value'); print $foo-getFooKey(); package Foo; sub new { my $class = shift; #new Foo where Foo is the class name $self = bless {}, $class; $self-{'fookey'} = 'some value here'; #hashref accessible only within Package Foo; return $self; } sub getFooKey { my $self = shift; return $self-{'fookey'}; } sub setFooKey { my $self = shift; if (@_== 1) { #if there's another param, set that as the value $self-{'fookey'} = shift; } return $self; } 1; -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: reading Perl syntax
just execute it with perl -wl foo or add the shebang line: #!/usr/bin/perl -w On 6/6/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Anthony Ettinger [EMAIL PROTECTED] writes: The syntax {} is for a hashref, it's just an un-named hashref inside that object. my $foo = new Foo; print $foo-getFooKey(); $foo-setFooKey('new value'); print $foo-getFooKey(); Thanks for the demo... I'm in well over my head here but the name of this group includes `beginner' so I guess this is the place for me. I didn't really understand your comments and I guess the code is supposed to run and print something so I can see what it is doing. It doesn't run here and erros out with: Can't locate object method within via package Package (perhaps you forgot to load Package?) at ./myOOP.pl line 15. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: reading Perl syntax
There's a good book PHP5 Patterns and Object Oriented Programming which I found very instrumental in my understanding of object-oriented programming, before applying it to Perl. There are of course Perl books on the subject, and the perldocs, but I found PHP's object oriented support to be less cryptic than Perl's. It was easier for me than biting off Perl syntax and OO-Perl at the same time. http://www.chovy.com/open-source/php-5-objects-patterns-and-practice-book-review/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: searching word in script
my $word = pop; #what is this for? open(FH, $file) or die $!; while (my $line = FH) { if ($line =~ m/foo/) { print matched!; next; } print unmatched :(; } close(FH); On 6/2/06, Irfan J Sayed [EMAIL PROTECTED] wrote: Hi All, I am using following code #!/usr/local/bin/perl # Main program use warnings; use strict; use File::Find; my $file = 'c:\\backup.pl'; open (FH, $file); my ($line); my $word = pop; while ($line = FH) { if ($line =~/$word/) { print match found; } else { print match not found; } } close FH; Following is the error readline() on closed filehandle FH at C:\irfan\search.pl line 13. can anybody plz help Regards Irfan Sayed -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Escaping a plus sign
should probably escape the + sign with \+ $field =~ s/\+/\\+/g; On 5/30/06, Paul Nowosielski [EMAIL PROTECTED] wrote: Dear All, I have a perl script that runs nightly. It create a data feed. The script will die if the is a + sign in the fields its parsing. Here is the snippet: while (($PKEY, $MGMTCMNT, $manager_id, $MGMTNM, $UPDATE1, $UPDATE2) = $sth-fetchrow_array) { $comment = ; if ($MGMTCMNT =~ /$MGMTNM/) { $len = length($MGMTNM); $start = index($MGMTCMNT, $MGMTNM (); $start += $len + 2; $end = index($MGMTCMNT, ), $start) - $start; $comment = substr($MGMTCMNT, $start, $end); } if ($UPDATE1 $artisttime || $UPDATE2 $artisttime ) { print (ARTMGRFILE $PKEY\t$manager_id\t$comment\n); } } Here is the error message: Quantifier follows nothing in regex; marked by -- HERE in m/+ -- HERE 1 Public Relations/ at /srv/www/htdocs/admin/utilities/aeg/manart.pl line 102. In this error the problem file had the text +1 Public Relations; Is there a way to escape this character so in the future it won't kill the script? Thank you, -- Paul Nowosielski -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: accessor problem in OO
sub foo { my $self = shift; #object if (@_ == 0) #any other arguments? { return $self-{'foo'}; #getter (no other arguments) } return $self-{'foo'} = shift; # setter (save next argument) } On 5/27/06, Peter Cornelius [EMAIL PROTECTED] wrote: This might be a little more clear if you break down the way arguments are being passed in and what they actually are. It sounds like you're aware that the arguments are passed in as a list name @_, it looks like the arguments are something like this: @_ = ( # A list { _name = 'something' }, # a hash reference (objects are hashes in perl) 'some set name string' # a string ); The first version extracts the arguments so that you can refer to them by names that might have some meaning to someone maintaining your code latter on. The second version accesses them directly. sub name{ #version 1 my $self=shift; shift is going to give you $_[0] my $set_name=shift; This sets $set_name to $_[1] $self-{_name}=$set_name if defined $set_name; So this is equivalent to $_[0]-{_name} = $_[1] if defined $_[1] the '-' is to dereference the hash reference stored in $_[0]. return $self-{_name} } Another version for the subroutine name sub name{ #verstion 2 $_[0]-{_name}=$_[1] if defined }$_[1]; {$_[0]-{_name} } I feel a little bit confuse about the verion 2 subroutine name. The way it gets the value of attribute name looks like this to me: array element-{_name} (I know that the $_[0] in the default array @_ is actually an object $self. ) Hope this helps PC -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: GnuPG again: problem with if statement evaluation
check $? or $! $gp-foo() or die $!; my $output = $gp-foo(); print return code: $?; see perldoc perlvar On 5/25/06, Jason Balicki [EMAIL PROTECTED] wrote: I'm back. This is a piece of code taken from a larger program. I'm trying to determine that the encryption succeded, but when I try to evaluate the code, it always evaluates false even though the encryption works and produces an encrypted file. Here's the specific bit I'm concerned with: if ($gpg-encrypt ( plaintext = $infile, output = $outfile, recipient = $recipient )){ $encrypt_status = success; } This always evaluates as false and never sets $encrypt_status to success even though the encryption does, in fact, succeed. And here it is in context: #!/usr/bin/perl use GnuPG; use strict; use warnings; my $recipient = [EMAIL PROTECTED]; my $infile = $ARGV[0]; my $outfile = $ARGV[1]; my $encrypt_status = failed; if ( -z $infile) { open (PLAIN, $infile) or die Can't open $infile for reading!; } open (ENCRYPT, $outfile) or die Can't open $outfile for writing!; my $gpg = new GnuPG( ); if ($gpg-encrypt ( plaintext = $infile, output = $outfile, recipient = $recipient )){ $encrypt_status = success; } close ( PLAIN ); close ( ENCRYPT ); print encrypt status: $encrypt_status\n; What am I doing wrong? Thanks, --J(K) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: GnuPG again: problem with if statement evaluation
ps...you're checking if it has a value, 256 (a typical error return code) would pass that test. On 5/25/06, Anthony Ettinger [EMAIL PROTECTED] wrote: check $? or $! $gp-foo() or die $!; my $output = $gp-foo(); print return code: $?; see perldoc perlvar On 5/25/06, Jason Balicki [EMAIL PROTECTED] wrote: I'm back. This is a piece of code taken from a larger program. I'm trying to determine that the encryption succeded, but when I try to evaluate the code, it always evaluates false even though the encryption works and produces an encrypted file. Here's the specific bit I'm concerned with: if ($gpg-encrypt ( plaintext = $infile, output = $outfile, recipient = $recipient )){ $encrypt_status = success; } This always evaluates as false and never sets $encrypt_status to success even though the encryption does, in fact, succeed. And here it is in context: #!/usr/bin/perl use GnuPG; use strict; use warnings; my $recipient = [EMAIL PROTECTED]; my $infile = $ARGV[0]; my $outfile = $ARGV[1]; my $encrypt_status = failed; if ( -z $infile) { open (PLAIN, $infile) or die Can't open $infile for reading!; } open (ENCRYPT, $outfile) or die Can't open $outfile for writing!; my $gpg = new GnuPG( ); if ($gpg-encrypt ( plaintext = $infile, output = $outfile, recipient = $recipient )){ $encrypt_status = success; } close ( PLAIN ); close ( ENCRYPT ); print encrypt status: $encrypt_status\n; What am I doing wrong? Thanks, --J(K) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: sub never called
turn warnings on /usr/bin/perl -w use strict; use diagnostics; On 5/22/06, beast [EMAIL PROTECTED] wrote: I have these following code. It seems that sub is_exist never called more than once. I've checked ldap server log, the client never request for second search. Putting $ldap object inside every sub will solve the problem, but doesn't it expensive to create ldap connection object for every search? - use strict; use warnings; use Net::LDAP; my $ldap = Net::LDAP-new($ldap_host); die Unable to connect to $ldap_host\n unless defined $ldap; my $username = 'testing'; my $email = '[EMAIL PROTECTED]'; #check if username and email already used my $unique = is_exist(uid=$username); die Username exists\n if $unique; $unique = is_exist(email=$email); die Email exists\n if $unique; sub is_exist { my $ldap_filter = shift; my ($res, $mesg); $mesg = $ldap-bind; $mesg = $ldap-search( base = $ldap_base, scope = 'one'; filter= $ldap_filter; attrs = ['uid'] ); $res = $mesg-count; $mesg = $ldap-unbind; return $res; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Running perl from perl?
On 5/23/06, siegfried [EMAIL PROTECTED] wrote: How do I run a perl program from a perl program? I could use the back quote (grave) I suppose. I could also use system. Is there a better way that does not create an additional process? I have six perl programs running once a day (via cygwin cron). I would like to have a single cron job running once an hour that checks the database for the oldest task and, if it is more than 24 hours old, run it. I could also write one monster program that combines all six programs. That is a lot of superfluous use statements if I'm only going to be running one of the six at a time. Perhaps I could have a switch statement to only require those modules that have been determined to be necessary for the oldest task. Is this the best way? if it's a standalone script you want to run, use system() or `` if you need to capture output. if it's just a bunch of routines you want to execute, you could put the main routine in the script into a sub called from within your wrapper script, including the library script with require('/path/to/script.pl'); at the top. (no need for shebang line here). require('/path/to/foo.pl'); foo(); # call main::foo sub routine defined inside foo.pl -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: What are the most successful applications of Perl? Thanks.
On 5/23/06, John W. Krahn [EMAIL PROTECTED] wrote: Japerlh wrote: What are the most successful applications of Perl? http://www.oreillynet.com/pub/a/oreilly/perl/news/success_stories.html movable type is one that I know of off hand. -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: What are the most successful applications of Perl? Thanks.
ebay.com started out as a perl, but it's been revamped as java for a few years now. -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: What are the most successful applications of Perl? Thanks.
...course everybody uses perl here and there for batch processing :) On 5/23/06, Anthony Ettinger [EMAIL PROTECTED] wrote: ebay.com started out as a perl, but it's been revamped as java for a few years now. -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Create Directories
File::Spec if you are working cross platform. then mkdir $path On 5/22/06, Toby Stuart [EMAIL PROTECTED] wrote: -Original Message- From: SkyBlueshoes [mailto:[EMAIL PROTECTED] Sent: Tuesday, 23 May 2006 12:38 PM To: beginners@perl.org Subject: Create Directories Another stupid question, search.cpan.org doesn't like me, lol: Which module is best for creating a directory and all directories in between. Ex: I want to create the directory : \dir1\dir2\dir3\targetdirectory but none of the preceding numbered directories exist... Sky Blueshoes use strict; use warnings; use File::Path; eval { mkpath(c:\\a\\test\\path) }; if ($@) { print Couldn't create: $@; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- 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..gah
On 5/7/06, Dan [EMAIL PROTECTED] wrote: i been doing perl long enough that you'd think i should know this, but one thing i've never ever ever managed to get my head around is how regex works. i'm using net::pop3 (mail::pop3client doesn't work!), and i'm trying to extract certain data from the pop3 stream (from, subject, and some of the body eventually). but the regex behind matching the line required is just baffling me. i could cheat and say if (substr($line,0,5) eq From:) { }, but i want to get past the phase of doing things the such a long way round, and learn more about regex. i wrote a program some months back which utilised a compelx regex sub $onchan{lc($data[0])} =~ s/(,|^)\Q$data[1]\E(?=,|$)//; which substitutes the exact match for $data[1] in a long string which is csv, and replace it with nothing. i'm trying to use the same routine, or the same method, to get the 'dan' out of dan [EMAIL PROTECTED] but a) the regex confuses me enough to not know how to get that out of there (i've replaced the ,'s with 's, but that's obviously not enough), and b) i don't know how to give the regex the full line of text, and assign the extracted value into a variable for use later on. i'd really like to get my head round this. if anyone's got any good guides, pointers, or places i can go to read and help me learn more, i'd much appreciate it. many thanks. dan Not to clear on what this means: to get the 'dan' out of dan [EMAIL PROTECTED] But here's a stab... my $string = '[EMAIL PROTECTED]'; $string =~ s/^(.*?)@//; This would actualy return @domain.com; If you want the username, then: my ($username) = $string =~ m/^(.*?)@/; if (substr($line,0,5) eq From:) { }, but i want to get past the phase of if ($line =~ m/^From:/i) { do something with From line; } -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
using our across blocks
I want to double-check that it is correct to use our to import globals. #!/usr/bin/perl -w use strict; BEGIN { our $foo = 'foo'; } sub something { our $foo; our $bar; ...at this point I can see 'foo' and 'bar' values. } END { our $bar = 'bar'; } If I do *not* import with our $foo; inside main::something(); I get the following errors: Variable $foo is not imported at ./script.pl line xx Variable $bar is not imported at ./script.pl line yy Global symbol $foo requires explicit package name at ./script.pl line xx. Global symbol $bar requires explicit package name at ./script.pl line yy. Is this the correct way to import globals? $perldoc vars says...: NOTE: For variables in the current package, the functionality provided by this pragma has been superseded by our declarations, available in Perl v5.6.0 or later. See our in perlfunc. -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: using our across blocks
On 5/2/06, Jay Savage [EMAIL PROTECTED] wrote: On 5/2/06, Anthony Ettinger [EMAIL PROTECTED] wrote: I want to double-check that it is correct to use our to import globals. [snip] What do you mean by import? Variables aren't imported from BEGIN blocks. They're declared in BEGIN blocks, and a variable declared in a BEGIN block should be no differnt than a variable declared at the top of your script. Except, of course, that you guarantee compile-time execution and you can put the block anywhere. But none of that effects the way the variable declaration functions. If you're having trouble, get rid of the BEGIN and END blocks and just declare your variables right after 'use strict' and 'use warnings'. You can go back and put them in the BEGIN block later. Anyway, none of us can really help you unless you send real code. If I do *not* import with our $foo; inside main::something(); I get the following errors: The you've done something wrong somewhere else. Is this the correct way to import globals? Again, what do you mean by import? You're sample pseudo-script does not exhibit the beavior you describe, nor does it import any variables . Are you actually importing the variable from somewhere else? Another file perhaps? Are there other packages in your file you haven't shown us? What errors, if any, does the following script produce in your Perl? Perhaps your installation is buggy. This should print 'foo' and exit: #!/usr/bin/perl BEGIN { use strict; use warnings; our $foo = 'foo'; our $baz = 'baz'; } sub bar {print $foo;} bar(); __END__ $perldoc vars says...: NOTE: For variables in the current package, the functionality provided by this pragma has been superseded by our declarations, available in Perl v5.6.0 or later. See our in perlfunc. And did you go see our in perlfuc? Yes, I did look, it wasn't too descriptive. What I ended up doing was reverting back to the deprecated method of use vars qw($foo); at the top of the library. using our within the sub routine to import globals seemed to work, but one of my machines is v5.6 so that won't work. #!/usr/bin/perl -w use vars qw($foo); #globals; use strict; sub foo { $foo = 'foo'; my $baz = 'baz'; } my $baz = 'pre-baz'; foo(); print $foo, \n; print $baz, \n; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: using our across blocks
On 5/2/06, Charles K. Clarkson [EMAIL PROTECTED] wrote: Anthony Ettinger wrote: : #!/usr/bin/perl -w : : use vars qw($foo); #globals; : use strict; : : sub foo { : $foo = 'foo'; : my $baz = 'baz'; : } : : my $baz = 'pre-baz'; : foo(); : : print $foo, \n; : print $baz, \n; I think the problem we are having is why use a solution which resorts to global variables when lexical variables get the job done fine? use strict; use warnings; my $baz = 'pre-baz'; my $foo = foo(); print $foo, \n; print $baz, \n; sub foo { my $foo = 'foo'; my $baz = 'baz'; return $foo; } __END__ Correct, I should've provider a better example of what I'm trying to do. I need to require(logger.pl); at the top of a bunch of scripts (ie - tool.pl), and I want to log start/end times without touching tool.pl. So I accomplish this with BEGIN/END blocks from within logger.pl, which set the start time when the tool.pl is executed, and then calls log_time(); from the END block when the tool.pl is finished. The tools are such that there is no use strict; or -w in use (and I'd rather avoid touching these beasts if I can help it at all). Here's a clearer example of logger.pl that I will be including in my tools: #!/usr/bin/perl -w use vars qw($start_time $end_time); use strict; BEGIN { $start_time = time(); } sub log_time { my $exit_code = shift; my $elapsed_time = $end_time - $start_time; print $elapsed_time, \n; } END { $end_time = time(); log_time($?); } __END__ I had originally posed the question using our inside log_time(); to import the globals defined in BEGIN/END blocks (which works by the way); however I have since discovered that one of my systems is using a version of Perl 5.6, inwhich our is not supported, so the above method, although deprecated, works across the board for my environment. (I'm not the admin, and getting Perl upgraded is not a viable option at this time). The only change I have to make to each tool-N.pl is: require(logger.pl); at the top. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: using our across blocks
. On 5/2/06, Charles K. Clarkson [EMAIL PROTECTED] wrote: Anthony Ettinger wrote: : #!/usr/bin/perl -w : : use vars qw($start_time $end_time); : use strict; : : BEGIN { : $start_time = time(); : } : : sub log_time { : my $exit_code = shift; : my $elapsed_time = $end_time - $start_time; : : print $elapsed_time, \n; : } : : END { : $end_time = time(); : log_time($?); : } : : __END__ BEGIN { my $start_time = time(); sub log_time { # my $exit_code = shift; print time() - $start_time, \n; } } END { log_time($?); } Or, if this is not a persistant perl enviroment, like modperl, just this. END { # $^T is the time at which the program began # running, in seconds since the epoch. print $^T - time(), \n; } ok, I can ditch the BEGIN block altogether and use $^T - time(); in the END block... I would have to move the call to log_time(); to the END block, since it doesn't make sense to do it at startup.
Re: What is the function of BEGIN in perl
basically, BEGIN { } is a block which gets called whenever the script begins. On 5/1/06, chen li [EMAIL PROTECTED] wrote: Dear all, Recently I read some source codes of perl modules. I find some codes look like this: BEGIN {..} What is the function of BEGIN here? Thank you, Li __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html
executing block on STDIN
I'm tracking execution time of a bunch of scripts, and want to drop in tracker.pl into each script...the problem I'm faced with is if a user walks away from their computer while the script is waiting for input from STDIN. I currently wrap any STDIN reads within the tools like: pauseTimer(); ...read from STDIN.. unpauseTimer(); This is so I can subtract out the weight time (in seconds) from the overall elapsed execution time. Is it possible to trigger these two pause/unpauseTimer() sub routines automatically from my library when STDIN is read? similar to how BEGIN/END blocks work, but with PRE-STDIN, POST-STDIN functionality? Thanks, -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: executing block on STDIN
On 5/1/06, Mr. Shawn H. Corey [EMAIL PROTECTED] wrote: On Mon, 2006-01-05 at 16:28 -0700, Anthony Ettinger wrote: I'm tracking execution time of a bunch of scripts, and want to drop in tracker.pl into each script...the problem I'm faced with is if a user walks away from their computer while the script is waiting for input from STDIN. You cannot time any script (or any part of a script) that uses IO. No, you can't. Sorry, I heard that argument before and you still can't time it. OK, IO is dependant on things outside of the computer. Yes, I know the hard disk is built-in and is inseparable while the machine is running, but it's speed is dependant on other programs that may be running at the same time. That means, they could be slowing down your program. So, now tell us what you want to achieve. Show us the code that is slow and maybe we can tell you how to speed things up. And if you can't separate the code from the IO, then what do you expect from us? -- __END__ I'm not trying to benchmark, just gather some real-world data in my tools. Basically, I set $start_time = time();, subtract out time waiting during user input, and take the difference of $end_time = time(); Whether this is a good way of gather the data is beyond the question...I'm curious if there's a way to trigger a pause/unpause routine automatically from my library when STDIN is used.
Re: executing block on STDIN
Thanks, I'll look into this...looks good so far though. I can just stick my @t = times; print join(\n, @t), \n; at the bottom of the script. On 5/1/06, John W. Krahn [EMAIL PROTECTED] wrote: Anthony Ettinger wrote: I'm not trying to benchmark, just gather some real-world data in my tools. Basically, I set $start_time = time();, subtract out time waiting during user input, and take the difference of $end_time = time(); Whether this is a good way of gather the data is beyond the question...I'm curious if there's a way to trigger a pause/unpause routine automatically from my library when STDIN is used. You may just want to use the times() function: perldoc -f times It returns the time the CPU uses so it won't include the time waiting for IO. 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 -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Perl Hash Question.
Hi there everybody, I have a question and I am pretty stumped for the answer. I have a program that does the following: A = Reads URI from URIHASH. Visits site A. Parses all URIS on site A and for each URI found adds the URI to the URIHASH. A = Reads next URI from URIHASH. Visits site A. And so on... until the MAX URIHASH size is reached. My question is, is there any way to iterate through a hash in this manner. I tried foreach(): foreach $key (keys %URIHASH){} and this does not work. What occurs is the entry that exists in the URIHASH when the foreach loop is entered, is processed. any additional entries that are added during the loop are not processed. I also tried each(): while (($key, $entry) = each %URIHASH){} When additional entries are added during the loop, this seems to produce unexpected behaviour. In my case an infinite loop. I should also mention that the URIHASH is tied to a file on the disk. Any help at all would be appreciated. Thank you very much. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Issue reading password from STDIN after STDIN was read from redirect.
I've have a program that reads input from STDIN like so: example: program file.txt and then I try to read a password from STDIN that the user types in but it skips right over that section. Do I have to do anything to STDIN before I try to get user input from it? Perhaps close and reopen it? --snip # read all of STDIN while($line = ReadLine(0)){ $STDIN .= $line; } #then ask for user password if($password){ print $user password: ; ReadMode('noecho'); # # skips over, doesn't ask for user input # $DBPASS = ReadLine(0); ReadMode('restore'); print hi $DBPASS\n; chop($DBPASS); } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Using variables to store statements/formulae in perl
Hello Perl Beginners, I'm writing a program in perl that collects data about calls into a telephone system and presents some statistics based on it. There could come a time in the future where different data needs to be used and different statistics need to be reported on so I'm trying to keep the entire thing as generic as possible. I have a conf file telling me what data represents what statistics and what formula needs to be used to get that data. Then I began to wonder if I store the formulae in variables then how do I get them out again and get perl to use them as statements? Here is some example code I wrote while trying to figure this out, any help would be appreciated. Is this even a good way to do this? -- Code Starts -- use strict; use diagnostics; # Data and Formula will eventually be read from a conf file and there may be multiple # instances of them that need to stay grouped and indexed so they're in a hash. my (%data, %formula); # Dummy Test Data $data{ext1} = 12; $data{ext2} = 9; $data{ext3} = 10; # Dummy Test Formula $formula{Addition} = ext1 + ext2; $formula{Subtraction} = ext3 - ext2; $formula{Brackets} = (ext2 + ext3) - ext1; # I can quite easily print these out and I could put the $data{extX} in with a # regular expression but how do I get it to evaluate the variable as if it # were an expression? print $formula{Addition} . \n; print $formula{Subtraction} . \n; print $formula{Brackets} . \n; -- Code Ends -- Thanks, Anthony Murphy -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Perl calling Profile
I have a perl script that I am setting up in crontab to run and when running the script under that user the script runs fun because the .profile runs and the environment variables are set up. I can I easily call the .profile within the script and keep the environment variables throughout the rest of the script? or do I need to manually call all items in the .profile. This is what is currently in the .profile # FAXCOMMANDER SETUP (BEGIN) # if test -f /usr2/faxmgr/cfg/scripts/profile; then . /usr2/faxmgr/cfg/scripts/profile fi # # FAXCOMMANDER SETUP ( END ) export ENV=$HOME/.kshrc Anthony J Segelhorst Enterprise Systems Management Team Phone: 937-495-1876 Email: [EMAIL PROTECTED] This email has been scanned for all viruses by the MessageLabs SkyScan service.___ This electronic message contains information from MeadWestvaco Corporation or subsidiary companies, which may be confidential, privileged or otherwise protected from disclosure. The information is intended to be used solely by the recipient(s) named. If you are not an intended recipient, be aware that any review, disclosure, copying, distribution or use of this transmission or its contents is prohibited. If you have received this transmission in error, please notify MeadWestvaco immediately at [EMAIL PROTECTED] ___
hour -1 routine
I am trying to set up a script that will do the do a current time -1 routine. Examples: Current Time: mmddyy:hhss 052804:1030 Output: 052804:0930 Current Time: 052704:0015 Output: 052604:23:15 I think the add_delta module is where I need to go, but I have never used modules before. Anthony J Segelhorst Enterprise Systems Management Team Phone: 937-495-1876 Email: [EMAIL PROTECTED] This email has been scanned for all viruses by the MessageLabs SkyScan service.___ This electronic message contains information from MeadWestvaco Corporation or subsidiary companies, which may be confidential, privileged or otherwise protected from disclosure. The information is intended to be used solely by the recipient(s) named. If you are not an intended recipient, be aware that any review, disclosure, copying, distribution or use of this transmission or its contents is prohibited. If you have received this transmission in error, please notify MeadWestvaco immediately at [EMAIL PROTECTED] ___
Re: hour -1 routine
Wiggins d Anconia [EMAIL PROTECTED] wrote on 05/28/2004 12:37:56 PM: I am trying to set up a script that will do the do a current time -1 routine. Examples: Current Time: mmddyy:hhss 052804:1030 Output: 052804:0930 Current Time: 052704:0015 Output: 052604:23:15 I think the add_delta module is where I need to go, but I have never used modules before. add_delta is probably a method/function in Date::Calc or Date::Manip modules. But in this case is probably overkill. You can use the built-in functions 'time' and 'localtime' to get the desired effect. perldoc -f time perldoc -f localtime 'time' will return the current time, from which you can subtract 60*60 (60 seconds in each of 60 minutes), which gives 1 hour ago. You can then use localtime to retrieve the values for the specific fields you need at the calculated time. Alternatively you could use POSIX::strftime for the formatting. perldoc POSIX HTH, http://danconia.org If I understand what you are saying about subtract 60 seconds in each of 60 minutes, how will this be able to handle: 1. When it is 00:15, because if it is 00:15 I will actually want 23:15 2. I can not just subtract 1 from the date because 010104 needs to really be 123104. If this is not what you are suggesting, let me know. You might be onto something. This is the part that is confusing me currently. I am just trying to get logical understanding of what I want to do before I start writing the code. This email has been scanned for all viruses by the MessageLabs SkyScan service.___ This electronic message contains information from MeadWestvaco Corporation or subsidiary companies, which may be confidential, privileged or otherwise protected from disclosure. The information is intended to be used solely by the recipient(s) named. If you are not an intended recipient, be aware that any review, disclosure, copying, distribution or use of this transmission or its contents is prohibited. If you have received this transmission in error, please notify MeadWestvaco immediately at [EMAIL PROTECTED] ___
HTTP
Any help for a script downloading files from a http site? Tony Esposito Oracle Developer, Enterprise Business Intelligence XO Communications Plano, TX 75074 Work Phone: 972-516-5344 Work Cell: 972-670-6144 Email: [EMAIL PROTECTED]
Pause/Hold in Perl
Is there a way in Perl to have a script wait 30 seconds before it continues processing? Like or a pause or hold? Anthony J Segelhorst Enterprise Systems Management Team Phone: 937-495-1876 Email: [EMAIL PROTECTED] This email has been scanned for all viruses by the MessageLabs SkyScan service.___ This electronic message contains information from MeadWestvaco Corporation or subsidiary companies, which may be confidential, privileged or otherwise protected from disclosure. The information is intended to be used solely by the recipient(s) named. If you are not an intended recipient, be aware that any review, disclosure, copying, distribution or use of this transmission or its contents is prohibited. If you have received this transmission in error, please notify MeadWestvaco immediately at [EMAIL PROTECTED] ___
Port Status Command in Perl
Is there a perl call to tell if a port is open or closed built into Perl? I am basically trying to build a perl script to monitor ports on Windows Servers and I am trying to stay away from system commands. Anthony J Segelhorst Enterprise Systems Management Team Phone: 937-495-1876 Email: [EMAIL PROTECTED] This email has been scanned for all viruses by the MessageLabs SkyScan service.___ Note: Please update your email address for this user to reflect MeadWestvaco Corporation. MeadWestvaco employee email addresses are in the format of [EMAIL PROTECTED] This electronic message contains information from MeadWestvaco Corporation or subsidiary companies, which may be confidential, privileged or otherwise protected from disclosure. The information is intended to be used solely by the recipient(s) named. If you are not an intended recipient, be aware that any review, disclosure, copying, distribution or use of this transmission or its contents is prohibited. If you have received this transmission in error, please notify MeadWestvaco immediately at [EMAIL PROTECTED] ___
Merging Hashes
Hi, I'm new to hashes, and I've been playing around with the following for a while... I'm just not getting it. I have two hashes, one containing data read in from a file, one with current data. I'd like to merge the two, adding any new keys and values into the hash, and for any keys that exist in both, I'd like the append the values onto the values for the same key in the original hash. An example... Hash 1 (from a file) host1=760,760,759 host2=765,760,760 host5=130,200 Hash 2 (Current) host1=758 host2=760 host4=450 host5=210 I'd like the merged hash to be: host1=760,760,759,758 host2=765,760,760,760 host5=130,200,210 host5=450 I'm using an example out of the perl cookbook, and trying to modify it to do what I want, but it isn't working out... The three hashes are: %host_list (Hash 1 in the example) %current_list (Hash 2 in the example) %final_list (The result of the merge) Here's the code I have so far for the merge (this is borrowed heavily from the Perl Cookbook): foreach $item ( \%host_list, \%current_list) { while (($key, $value) = each %$item) { if (exists $final_list{$key}) { $value .= ,$current_list{$key}; } $final_list{$key} = $value; } } Can someone point me in the right direction? - Tony -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
default value for input
Hi is it possible to give a default value to the input you're asking? I tried the code below but this didn't work. $URL = http://;; chomp ($URL = $URL.); Thx Anthony _ De winnaars zijn gekend van de fotoromanwedstrijd http://www.msn.be/valentijn/wedstrijd/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: default value for input
Thanks! But the problem is the following: the user has to enter an url and now i want to put http://; always in front (and show it on the screen) so that the user doesn't have to enter this everytime. From: Kenton Brede [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Re: default value for input Date: Tue, 24 Feb 2004 13:05:09 -0600 On Tue, Feb 24, 2004 at 07:41:46PM +0100, Anthony Vanelverdinghe ([EMAIL PROTECTED]) wrote: Hi is it possible to give a default value to the input you're asking? I tried the code below but this didn't work. $URL = http://;; chomp ($URL = $URL.); I've set up a default variable like the following but can't vouch for it being the proper way to do so. my $new_uid ||= '700'; # default to 700 if it doesn't exist. Kent -- Efficiency is intelligent laziness. -David Dunham -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response _ Ben jij klaar voor De Vuilbek? http://devuilbek.msn.be/start.php Nu op JIM en MSN -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: default value for input
It works fine! So it isn't possible to show this on the screen so that the user can see it's already there and just has to complete the url?? Thanks Anthony _ Je horoscoop al gelezen? http://www.msn.be/horoscoop -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
converting array to hash
Hi Could anyone explain why the output of the hash isn't: 1 a 2 b 3 c How can i make that the order remains the same in the hash?? Thx @count = (1,'a',2,'b',3,'c'); print @count;#output: 1a2b3c print \n; %c = @count; foreach $abc (keys %c){ print $abc.' '.$c{$abc}.\n#output: 1a ; # 3c } # 2 b _ Geschenkideeën en e-cards voor Valentijn ! http://www.msn.be/valentijn -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
tables in Perl
Hi is Java you can do the following: int[][] table=new int[4][3]; int i=table[2][2]; is there also something like this in Perl?? Thanks!! _ Online shoppen, niets zo makkelijk http://www.msn.be/shopping -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
quotes in pattern
Hi I want to save the name and the URL of a html hyperlink in an array (@bookmarks). The problem is that the quotes aren't recognized, so it doesn't save only the URL; but also the other attributes of A... How can i make sure only the URL between the quotes is saved? if (/^\s*DTA HREF=(.+).*(.+)\/A\s*$/i){ push (@bookmarks,$2,$1); } Thx! _ Online shoppen, niets zo makkelijk http://www.msn.be/shopping -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
switch statement
Hi Could anyone please tell me what's wrong with the following program? The compiler gives errors in the switch statement. Thx!! Anthony %commands=('v',0,'w',1,'t',2,'/pattern/',3,'s',4,'x',5); $end = 0; while (!end){ print bookmarks.html; $operation = ; chop $operation; $op=$commands{$operation}; switch ($op) { case 0 { add (); last;} case 1 { delete(); last;} case 2 { show(); last;} case 3 { pattern(); last;} case 4 { save(); last;} case 5 { exit (); last;} } } sub add{ print add; } sub delete{ print delete; } sub show{ print show; } sub pattern{ print pattern; } sub save{ print save; } sub exit{ $end = 1; } _ Ben jij klaar voor De Vuilbek? http://devuilbek.msn.be/start.php Nu op JIM en MSN -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: switch statement
Didn't know it wasn't in Perl, but I've just discovered it's possible with some file called Switch.pm From: Daniel Staal [EMAIL PROTECTED] Reply-To: Perl Beginners [EMAIL PROTECTED] To: Perl Beginners [EMAIL PROTECTED] Subject: Re: switch statement Date: Thu, 19 Feb 2004 16:21:22 -0500 --As of Thursday, February 19, 2004 10:14 PM +0100, Anthony Vanelverdinghe is alleged to have said: Could anyone please tell me what's wrong with the following program? The compiler gives errors in the switch statement. --As for the rest, it is mine. You mean, besides the fact that Perl doesn't have a switch statement? Daniel T. Staal --- This email copyright the author. Unless otherwise noted, you are expressly allowed to retransmit, quote, or otherwise use the contents for non-commercial purposes. This copyright will expire 5 years after the author's death, or in 30 years, whichever is longer, unless such a period is in excess of local copyright law. --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response _ Online gamen ? http://www.msn.be/games/online/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Program close
Hi When I run a very simple Perl program, it closes immediately after it has done. So that I can't even see the output. How can I solve this? Thanks in advance! _ De nieuwe Pirelli 2004 kalender al gezien? http://auto.msn.be/pirelli2004/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: upgrading perl to 5.6 from 5.005_03 question?
Instead of upgrading why not just install Perl 5.6 in a separate directory..just a thought! Tony Esposito Oracle Developer, Enterprise Business Intelligence XO Communications Plano, TX 75074 Work Phone: 972-516-5344 Work Cell: 972-670-6144 Email: [EMAIL PROTECTED] -Original Message- From: Rob Dixon [mailto:[EMAIL PROTECTED] Sent: Monday, February 02, 2004 12:50 PM To: [EMAIL PROTECTED] Subject: Re: upgrading perl to 5.6 from 5.005_03 question? Ravi Malghan wrote: I have perl 5.005_03 on solaris 2.8 which was installed with the OS. I would like to upgrade it to 5.6. Should I pkgrm the existing perl before I install the new perl ? or is there any other recommended way to upgrade. Hi Ravi. What do you mean by Should I pkgrm the existing perl If you have any Perl software that may rely on the current version of Perl, then you should be careful. OTOH, if this is a new installation without any Perl programs, then install a recognised version of Perl as soon as you can. A version 'installed with the OS' isn't a safe place to start. Rob -- 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
array push
How come when I push a variable to an array it puts one whitespace before the variables on all the lines except the first one? I would except all the lines not to have the extra white space. Is there an easier way to fill an array with a variable without using the push? $last printed out TMR2,mpd_gw,50,w32-ix86,client TMR2,mpd_gw,50,w32-ix86,client TMR2,mpd_gw,50,w32-ix86,client TMR2,mpd_gw,50,w32-ix86,client @temparray printed out TMR2,mpd_gw,50,w32-ix86,client TMR2,mpd_gw,50,w32-ix86,client TMR2,mpd_gw,50,w32-ix86,client TMR2,mpd_gw,50,w32-ix86,client Code: if (something){ $last = $tmrname,$gateway_hash{$gateway},$version,$interp,$type\n; #print $last; push(@temparray, $last); } @temparray = sort @temparray; print @temparray; Anthony J Segelhorst Enterprise Systems Management Team Phone: 937-495-1876 Email: [EMAIL PROTECTED] This email has been scanned for all viruses by the MessageLabs SkyScan service.___ Note: Please update your email address for this user to reflect the new MeadWestvaco Corporation. MeadWestvaco employee email addresses are in the format of [EMAIL PROTECTED] This electronic message contains information from MeadWestvaco Corporation or subsidiary companies, which may be confidential, privileged or otherwise protected from disclosure. The information is intended to be used solely by the recipient(s) named. If you are not an intended recipient, be aware that any review, disclosure, copying, distribution or use of this transmission or its contents is prohibited. If you have received this transmission in error, please notify MeadWestvaco immediately at [EMAIL PROTECTED] ___
Re: array push
For Quality purposes, Anthony J Segelhorst 's mail on Monday 26 January 2004 17:17 may have been monitored or recorded as: How come when I push a variable to an array it puts one whitespace before the variables on all the lines except the first one? I would except all the lines not to have the extra white space. .. print @temparray; Try print @temparay; since you have a \n at the end of your array (btw: do you really want that?) , your records are seperated by something when you print them. print puts a space in between the eleent as a convienience for people who dont have a \n at the end of their emelents. print @temparay; This worked, thanks. Anthony J Segelhorst Enterprise Systems Management Team Phone: 937-495-1876 Email: [EMAIL PROTECTED] wolf blaum [EMAIL PROTECTED] 01/26/2004 11:39 AM To: cc: Subject:Re: array push For Quality purpouses, Anthony J Segelhorst 's mail on Monday 26 January 2004 17:17 may have been monitored or recorded as: How come when I push a variable to an array it puts one whitespace before the variables on all the lines except the first one? I would except all the lines not to have the extra white space. .. print @temparray; Try print @temparay; since you have a \n at the end of your array (btw: do you really want that?) , your records are seperated by something when you print them. print puts a space in between the eleent as a convienience for people who dont have a \n at the end of their emelents. hth, wolf -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response This email has been scanned for all viruses by the MessageLabs SkyScan service.___ This email has been scanned for all viruses by the MessageLabs SkyScan service.___ Note: Please update your email address for this user to reflect the new MeadWestvaco Corporation. MeadWestvaco employee email addresses are in the format of [EMAIL PROTECTED] This electronic message contains information from MeadWestvaco Corporation or subsidiary companies, which may be confidential, privileged or otherwise protected from disclosure. The information is intended to be used solely by the recipient(s) named. If you are not an intended recipient, be aware that any review, disclosure, copying, distribution or use of this transmission or its contents is prohibited. If you have received this transmission in error, please notify MeadWestvaco immediately at [EMAIL PROTECTED] ___
counters for lines
I have the following output, and each value that is separated by comma is a variable: servera,serverb,109,aix4-r1,server servera,serverb,109,aix4-r1,server servera,serverb,109,aix4-r1,server servera,serverb,109,aix4-r1,server servera,serverb,109,aix4-r1,server servera,serverb,109,hpux10,server servera,serverb,109,solaris2,server servera,serverb,109,solaris2,server servera,serverb,109,solaris2,server servera,serverb,109,solaris2,server servera,serverb,109,solaris2,server servera,serverb,109,solaris2,server servera,serverb,109,solaris2,server servera,serverb,109,solaris2,server servera,serverb,109,solaris2,server servera,serverb,109,solaris2,server I am trying to set up a counter that would actually output the data to be: servera,serverb,109,aix4-r1,server,5 servera,serverb,109,hpux10,server,1 servera,serverb,109,solaris2,server,10 Does anyone any suggestion on how to set up a counter to count the lines until a different line shows up. I already have the list sorted, so I just need to compare the new string to old string and if they are the same increase the counter, and if they are different start a new counter. Anthony J Segelhorst Enterprise Systems Management Team Phone: 937-495-1876 Email: [EMAIL PROTECTED] This email has been scanned for all viruses by the MessageLabs SkyScan service.___ Note: Please update your email address for this user to reflect the new MeadWestvaco Corporation. MeadWestvaco employee email addresses are in the format of [EMAIL PROTECTED] This electronic message contains information from MeadWestvaco Corporation or subsidiary companies, which may be confidential, privileged or otherwise protected from disclosure. The information is intended to be used solely by the recipient(s) named. If you are not an intended recipient, be aware that any review, disclosure, copying, distribution or use of this transmission or its contents is prohibited. If you have received this transmission in error, please notify MeadWestvaco immediately at [EMAIL PROTECTED] ___
Re: counters for lines
James Edward Gray II [EMAIL PROTECTED] 01/20/2004 02:11 PM To: Anthony J Segelhorst [EMAIL PROTECTED] cc: [EMAIL PROTECTED] Subject:Re: counters for lines On Jan 20, 2004, at 12:39 PM, Anthony J Segelhorst wrote: I have the following output, and each value that is separated by comma is a variable: servera,serverb,109,aix4-r1,server servera,serverb,109,aix4-r1,server servera,serverb,109,aix4-r1,server servera,serverb,109,aix4-r1,server servera,serverb,109,aix4-r1,server servera,serverb,109,hpux10,server servera,serverb,109,solaris2,server servera,serverb,109,solaris2,server servera,serverb,109,solaris2,server servera,serverb,109,solaris2,server servera,serverb,109,solaris2,server servera,serverb,109,solaris2,server servera,serverb,109,solaris2,server servera,serverb,109,solaris2,server servera,serverb,109,solaris2,server servera,serverb,109,solaris2,server I am trying to set up a counter that would actually output the data to be: servera,serverb,109,aix4-r1,server,5 servera,serverb,109,hpux10,server,1 servera,serverb,109,solaris2,server,10 Does anyone any suggestion on how to set up a counter to count the lines until a different line shows up. I already have the list sorted, so I just need to compare the new string to old string and if they are the same increase the counter, and if they are different start a new counter. How about something like this (untested code): #!/usr/bin/perl use strict; use warnings; my($last, $counter) = (undef, 0); while () {# call with: perl script_name FILE(S) TO COUNT OUTPUT_FILE chomp; if ($last) { if ($_ eq $last) { $counter++; } else { print $last,$counter\n; undef $last; $counter = 0; } } else { $last = $_; $counter++; } } __END__ James I got this script written from James gave me: $servers = /tmp/ep_report_db_test1.log; open (SERVERFILE, $servers); my($last, $counter) = (undef, 0); while (SERVERFILE) { # call with: perl script_name FILE(S) TO COUNT OUTPUT_FILE chomp; if ($last) { if ($_ eq $last) { $counter++; } else { print $last,$counter\n; undef $last; $counter = 0; } } else { $last = $_; $counter++; } } But now I am having problems counting if there is one record of that line? Any suggestions? Example: servera,serverb,109,w32-ix86,client,1 But I am not getting a count of that line? Anthony J Segelhorst Enterprise Systems Management Team Phone: 937-495-1876 Email: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response This email has been scanned for all viruses by the MessageLabs SkyScan service.___ This email has been scanned for all viruses by the MessageLabs SkyScan service.___ Note: Please update your email address for this user to reflect the new MeadWestvaco Corporation. MeadWestvaco employee email addresses are in the format of [EMAIL PROTECTED] This electronic message contains information from MeadWestvaco Corporation or subsidiary companies, which may be confidential, privileged or otherwise protected from disclosure. The information is intended to be used solely by the recipient(s) named. If you are not an intended recipient, be aware that any review, disclosure, copying, distribution or use of this transmission or its contents is prohibited. If you have received this transmission in error, please notify MeadWestvaco immediately at [EMAIL PROTECTED] ___
Use of System
I'm attempting to use the following code on an AIX machine to monitor the error log (using the errpt command). I'm sure parts of it are very ugly, but it's (mostly) working. The part that isn't is the foreach loop. What it's supposed to do is as follows: #read in the summary error report, which is in the following format - #IDENTIFIER TIMESTAMP T C RESOURCE_NAME DESCRIPTION #AA8AB241 0120143604 T O OPERATOR OPERATOR NOTIFICATION #AA8AB241 0120143604 T O OPERATOR OPERATOR NOTIFICATION #AA8AB241 0120143604 T O OPERATOR OPERATOR NOTIFICATION #AA8AB241 0120143604 T O OPERATOR OPERATOR NOTIFICATION #AA8AB241 0120143504 T O OPERATOR OPERATOR NOTIFICATION #AA8AB241 0120143504 T O OPERATOR OPERATOR NOTIFICATION #AA8AB241 0120143504 T O OPERATOR OPERATOR NOTIFICATION #AA8AB241 0120142304 T O OPERATOR OPERATOR NOTIFICATION @errors =system(errpt |head -n $diff_t | tail -n $diff); foreach $line (@errors){ #I only care about the first field. There must be a better way! ($err_num, undef, undef, undef, undef, undef, undef) = split( , $line); #Use the errpt command to expand the message. $message = system (errpt -j $err_num -a); #add the message to a variable for all of the messages $errlogl .= $message; } Instead, when I run the command with an to put it in the background it does the first system line above (@errors=...) to standard out. Any help, or comments on the rest of the script are appreciated. -Tony #!/usr/bin/perl -w use strict; # This script will run every [interval] and check the error log # for new entries. Upon finding them, it will send an email to # administrators containing a message indicating the change # in errlog status, as well as the offending lines. my $lc = -1; #last count my $tc = -1; #This count my $interval = 30; #Interval in seconds my $me = Hardware error monitoring; my $hostname; my $os; my $mailto = root; my $diff; my $msg; my $page_msg; my $errlogl; my $line; my $err_num; my @errors; my $diff_t; my $message; open (UNAME, uname -a |) or die Couldn't fork: $!\n; ( $os, $hostname, undef, undef, undef ) = (split , UNAME); close (UNAME); system (echo \$me started.\nThis message goes to $mailto.\ | mail -s \Errlog monitoring for $hostname\ $mailto); while ( 1 ) { $tc=`errpt -dH,S,U,O | wc -l`; if ( $lc == -1 ) { $lc=$tc; } if ( $lc != $tc ) { $diff=$tc-$lc; $diff_t = $diff + 1; $msg=$diff new errors have been found on $hostname; $page_msg=$diff new errors have been found on $hostname; @errors =system(errpt |head -n $diff_t | tail -n $diff); foreach $line (@errors){ ($err_num, undef, undef, undef, undef, undef, undef) = split( , $line); $message = system (errpt -j $err_num -a); #$message = Test message\n; $errlogl .= $message; } if ( $tc eq 0 ) { $msg=$msg\n Errlog was cleared; }else{ #system (logger $msg); $msg= $msg \n Errlog details below:\n $errlogl \n; } system (echo \$msg\ | mail -s \Errlog status change on host $hostname\ $mailto); } $lc=$tc; $errlogl = ; sleep $interval; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Use of System
Sorry all, I seem to be having problems with our company's chosen mail client (Outlook). Trying this again, hopefuly it will preserve my EOL characters this time. - Tony I'm attempting to use the following code on an AIX machine to monitor the error log (using the errpt command). I'm sure parts of it are very ugly, but it's (mostly) working. The part that isn't is the foreach loop. What it's supposed to do is as follows: #read in the summary error report, which is in the following #format - #IDENTIFIER TIMESTAMP T C RESOURCE_NAME DESCRIPTION #AA8AB241 0120143604 T O OPERATOR OPERATOR NOTIFICATION #AA8AB241 0120143604 T O OPERATOR OPERATOR NOTIFICATION #AA8AB241 0120143604 T O OPERATOR OPERATOR NOTIFICATION #AA8AB241 0120143604 T O OPERATOR OPERATOR NOTIFICATION #AA8AB241 0120143504 T O OPERATOR OPERATOR NOTIFICATION #AA8AB241 0120143504 T O OPERATOR OPERATOR NOTIFICATION #AA8AB241 0120143504 T O OPERATOR OPERATOR NOTIFICATION #AA8AB241 0120142304 T O OPERATOR OPERATOR NOTIFICATION @errors =system(errpt |head -n $diff_t | tail -n $diff); foreach $line (@errors){ #I only care about the first field. There must be a better way! ($err_num, undef, undef, undef, undef, undef, undef) = split( , $line); #Use the errpt command to expand the message. $message = system (errpt -j $err_num -a); #add the message to a variable for all of the messages $errlogl .= $message; } Instead, when I run the command with an to put it in the background it does the first system line above (@errors=...) to standard out. Any help, or comments on the rest of the script are appreciated. -Tony #!/usr/bin/perl -w use strict; # This script will run every [interval] and check the error log # for new entries. Upon finding them, it will send an email to # administrators containing a message indicating the change # in errlog status, as well as the offending lines. my $lc = -1; #last count my $tc = -1; #This count my $interval = 30; #Interval in seconds my $me = Hardware error monitoring; my $hostname; my $os; my $mailto = root; my $diff; my $msg; my $page_msg; my $errlogl; my $line; my $err_num; my @errors; my $diff_t; my $message; open (UNAME, uname -a |) or die Couldn't fork: $!\n; ( $os, $hostname, undef, undef, undef ) = (split , UNAME); close (UNAME); system (echo \$me started.\nThis message goes to $mailto.\ | mail -s \Errlog monitoring for $hostname\ $mailto); while ( 1 ) { $tc=`errpt -dH,S,U,O | wc -l`; if ( $lc == -1 ) { $lc=$tc; } if ( $lc != $tc ) { $diff=$tc-$lc; $diff_t = $diff + 1; $msg=$diff new errors have been found on $hostname; $page_msg=$diff new errors have been found on $hostname; @errors =system(errpt |head -n $diff_t | tail -n $diff); foreach $line (@errors){ ($err_num, undef, undef, undef, undef, undef, undef) = split( , $line); $message = system (errpt -j $err_num -a); #$message = Test message\n; $errlogl .= $message; } if ( $tc eq 0 ) { $msg=$msg\n Errlog was cleared; }else{ #system (logger $msg); $msg= $msg \n Errlog details below:\n $errlogl \n; } system (echo \$msg\ | mail -s \Errlog status change on host $hostname\ $mailto); } $lc=$tc; $errlogl = ; sleep $interval; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Use of System
Someone kindly pointed out that perldoc is a handy thing. - Tony -Original Message- From: Akens, Anthony Sent: Tuesday, January 20, 2004 4:31 PM To: [EMAIL PROTECTED] Subject: RE: Use of System Sorry all, I seem to be having problems with our company's chosen mail client (Outlook). Trying this again, hopefuly it will preserve my EOL characters this time. - Tony I'm attempting to use the following code on an AIX machine to monitor the error log (using the errpt command). I'm sure parts of it are very ugly, but it's (mostly) working. The part that isn't is the foreach loop. What it's supposed to do is as follows: #read in the summary error report, which is in the following #format - #IDENTIFIER TIMESTAMP T C RESOURCE_NAME DESCRIPTION #AA8AB241 0120143604 T O OPERATOR OPERATOR NOTIFICATION #AA8AB241 0120143604 T O OPERATOR OPERATOR NOTIFICATION #AA8AB241 0120143604 T O OPERATOR OPERATOR NOTIFICATION #AA8AB241 0120143604 T O OPERATOR OPERATOR NOTIFICATION #AA8AB241 0120143504 T O OPERATOR OPERATOR NOTIFICATION #AA8AB241 0120143504 T O OPERATOR OPERATOR NOTIFICATION #AA8AB241 0120143504 T O OPERATOR OPERATOR NOTIFICATION #AA8AB241 0120142304 T O OPERATOR OPERATOR NOTIFICATION @errors =system(errpt |head -n $diff_t | tail -n $diff); foreach $line (@errors){ #I only care about the first field. There must be a better way! ($err_num, undef, undef, undef, undef, undef, undef) = split( , $line); #Use the errpt command to expand the message. $message = system (errpt -j $err_num -a); #add the message to a variable for all of the messages $errlogl .= $message; } Instead, when I run the command with an to put it in the background it does the first system line above (@errors=...) to standard out. Any help, or comments on the rest of the script are appreciated. -Tony #!/usr/bin/perl -w use strict; # This script will run every [interval] and check the error log # for new entries. Upon finding them, it will send an email to # administrators containing a message indicating the change # in errlog status, as well as the offending lines. my $lc = -1; #last count my $tc = -1; #This count my $interval = 30; #Interval in seconds my $me = Hardware error monitoring; my $hostname; my $os; my $mailto = root; my $diff; my $msg; my $page_msg; my $errlogl; my $line; my $err_num; my @errors; my $diff_t; my $message; open (UNAME, uname -a |) or die Couldn't fork: $!\n; ( $os, $hostname, undef, undef, undef ) = (split , UNAME); close (UNAME); system (echo \$me started.\nThis message goes to $mailto.\ | mail -s \Errlog monitoring for $hostname\ $mailto); while ( 1 ) { $tc=`errpt -dH,S,U,O | wc -l`; if ( $lc == -1 ) { $lc=$tc; } if ( $lc != $tc ) { $diff=$tc-$lc; $diff_t = $diff + 1; $msg=$diff new errors have been found on $hostname; $page_msg=$diff new errors have been found on $hostname; @errors =system(errpt |head -n $diff_t | tail -n $diff); foreach $line (@errors){ ($err_num, undef, undef, undef, undef, undef, undef) = split( , $line); $message = system (errpt -j $err_num -a); #$message = Test message\n; $errlogl .= $message; } if ( $tc eq 0 ) { $msg=$msg\n Errlog was cleared; }else{ #system (logger $msg); $msg= $msg \n Errlog details below:\n $errlogl \n; } system (echo \$msg\ | mail -s \Errlog status change on host $hostname\ $mailto); } $lc=$tc; $errlogl = ; sleep $interval; } -- 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: PERL debuggers
There is Open Perl IDE. Check out http://open-perl-ide.sourceforge.net. Unfortunately, it is for Windows only. HTH :-) Tony Esposito Oracle Developer, Enterprise Business Intelligence XO Communications Plano, TX 75074 Work Phone: 972-516-5344 Work Cell: 972-670-6144 Email: [EMAIL PROTECTED] -Original Message- From: Wiggins d Anconia [mailto:[EMAIL PROTECTED] Sent: Wednesday, January 07, 2004 2:29 PM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: Re: PERL debuggers Are there any free PERL debuggers? I once came across pvdb (a vi-aware front-end for the PERL debugger developed by Tom Christainsen), but I never got it to work. perldoc perldebtut perldoc perldebug Have you had a look at those? http://danconia.org p.s. perldoc -q 'Perl' -- 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: Microsoft Services for UNIX/LINUX
Glad you've found a solution. Just thought I'd drop a note about some of the things I've had success with. We have a few scripts (originally written as shell scripts in csh) that I've converted to perl. They reside on a box running AIX 5.1. On a win2k box I've installed the Windows services for unix 3.0 NFS gateway, which allows client machines to map to windows shares, which are just gateways to NFS exports on the AIX host. The windows clients have activestate perl installed, and are configured to map the NFS share on log in. The end result is that the users can double click on the perl apps without needing to know they're even touching a *nix box. - Tony -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Tuesday, January 06, 2004 11:17 AM To: Kevin Old Cc: [EMAIL PROTECTED] Subject: Re: Microsoft Services for UNIX/LINUX Hello, Putty has this: Plink (a command-line interface to the PuTTY back ends) http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html Thanks to all again. I just got came across a documentation for Putty, and it provides an alternative to my original solution. And it is free!!! ___ William Ampeh (x3939) Federal Reserve Board -- 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
'print' output on one line
I have a perl program ( with DBI ) which prints out a line to STDOUT after every 100 database commits. I would like the 'print' to just refresh the current line every time but - not knowing how to get around it - the program instead prints a new line every 100 commits like so: INFO 3: start deleting rows. Rows deleted: 100 Rows deleted: 200 Rows deleted: 300 Rows deleted: 400 . . . INFO 4: delete_rows.pl program ended. I would like the output to just stay on one line and just update the count as the program proceeds. So the output - when done - would just be INFO 3: start deleting rows. Rows deleted: 400 INFO 4: delete_rows.pl program ended. Is there a 'print' option/escape character the sends the file pointer ( for STDOUT in this case ) back to the beginning of the line? Here is the current code segment - the focus here is on the last 'print' statement: print INFO 3: start deleting rows.\n; while(($row_data) = $sth1-fetchrow) { if(! defined ($sth2-execute($row_data))) { # execute DELETE print ERROR 4: execute of DELETE statement failed.\n; exit(int 4); } $row_counter = $row_counter + 1; if($row_counter = 100) { $dbh-commit; $rows_deleted = $rows_deleted + $row_counter; print Rows deleted: $rows_deleted\n; $row_counter = 0; } } print INFO 4: $0 program ended.\n; Thanks for any help you can offer Tony Esposito Oracle Developer, Enterprise Business Intelligence XO Communications Plano, TX 75074 Work Phone: 972-516-5344 Work Cell: 972-670-6144 Email: [EMAIL PROTECTED]
RE: 'print' output on one line
Errata: The last print statement in the 'while' loop is the focus.. Tony Esposito Oracle Developer, Enterprise Business Intelligence XO Communications Plano, TX 75074 Work Phone: 972-516-5344 Work Cell: 972-670-6144 Email: [EMAIL PROTECTED] -Original Message- From: Esposito, Anthony Sent: Tuesday, January 06, 2004 2:54 PM To: [EMAIL PROTECTED] Subject: 'print' output on one line I have a perl program ( with DBI ) which prints out a line to STDOUT after every 100 database commits. I would like the 'print' to just refresh the current line every time but - not knowing how to get around it - the program instead prints a new line every 100 commits like so: INFO 3: start deleting rows. Rows deleted: 100 Rows deleted: 200 Rows deleted: 300 Rows deleted: 400 . . . INFO 4: delete_rows.pl program ended. I would like the output to just stay on one line and just update the count as the program proceeds. So the output - when done - would just be INFO 3: start deleting rows. Rows deleted: 400 INFO 4: delete_rows.pl program ended. Is there a 'print' option/escape character the sends the file pointer ( for STDOUT in this case ) back to the beginning of the line? Here is the current code segment - the focus here is on the last 'print' statement: print INFO 3: start deleting rows.\n; while(($row_data) = $sth1-fetchrow) { if(! defined ($sth2-execute($row_data))) { # execute DELETE print ERROR 4: execute of DELETE statement failed.\n; exit(int 4); } $row_counter = $row_counter + 1; if($row_counter = 100) { $dbh-commit; $rows_deleted = $rows_deleted + $row_counter; print Rows deleted: $rows_deleted\n; $row_counter = 0; } } print INFO 4: $0 program ended.\n; Thanks for any help you can offer Tony Esposito Oracle Developer, Enterprise Business Intelligence XO Communications Plano, TX 75074 Work Phone: 972-516-5344 Work Cell: 972-670-6144 Email: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: 'print' output on one line
I tried that already but it just gives me the final count at the end. I would like the output to change - the row count, that is - as each 100 rows is committed with the final output - when the program ends - to be: INFO 3: start deleting rows. Rows deleted: 400 INFO 4: delete_rows.pl program ended. In other words, as time goes by, you see on your screen: INFO 3: start deleting rows. Rows deleted: 100 then ( overwriting the above ) INFO 3: start deleting rows. Rows deleted: 200 and so on until the end... Tony Esposito Oracle Developer, Enterprise Business Intelligence XO Communications Plano, TX 75074 Work Phone: 972-516-5344 Work Cell: 972-670-6144 Email: [EMAIL PROTECTED] -Original Message- From: Jenda Krynicky [mailto:[EMAIL PROTECTED] Sent: Tuesday, January 06, 2004 2:59 PM To: [EMAIL PROTECTED] Subject: Re: 'print' output on one line From: Esposito, Anthony [EMAIL PROTECTED] I have a perl program ( with DBI ) which prints out a line to STDOUT after every 100 database commits. I would like the 'print' to just refresh the current line every time but - not knowing how to get around it - the program instead prints a new line every 100 commits like so: INFO 3: start deleting rows. Rows deleted: 100 Rows deleted: 200 Rows deleted: 300 Rows deleted: 400 ... print Rows deleted: $rows_deleted\n; Use \r instead of \n: print Rows deleted: $rows_deleted\r; $row_counter = 0; } } print INFO 4: $0 program ended.\n; and don't forget to add a \n in front of the INFO 4... 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] 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: 'print' output on one line (thread closed)
Alright, gents, you and I were both right...\r works, as it should. It turns out that these computers today - and Perl - are even faster than I thought. My test data set was only 300 rows so by the time the program ran - and deleted - 300 rows the Perl program had only enough time to print the output once, making it 'appear' to not work. I had a suspicion that that may be the problem so I increased my test data set to 6000 and it worked fine. Thanks all! Close this thread. :-) Tony Esposito Oracle Developer, Enterprise Business Intelligence XO Communications Plano, TX 75074 Work Phone: 972-516-5344 Work Cell: 972-670-6144 Email: [EMAIL PROTECTED] -Original Message- From: Esposito, Anthony Sent: Tuesday, January 06, 2004 3:09 PM To: Jenda Krynicky; [EMAIL PROTECTED] Subject: RE: 'print' output on one line I tried that already but it just gives me the final count at the end. I would like the output to change - the row count, that is - as each 100 rows is committed with the final output - when the program ends - to be: INFO 3: start deleting rows. Rows deleted: 400 INFO 4: delete_rows.pl program ended. In other words, as time goes by, you see on your screen: INFO 3: start deleting rows. Rows deleted: 100 then ( overwriting the above ) INFO 3: start deleting rows. Rows deleted: 200 and so on until the end... Tony Esposito Oracle Developer, Enterprise Business Intelligence XO Communications Plano, TX 75074 Work Phone: 972-516-5344 Work Cell: 972-670-6144 Email: [EMAIL PROTECTED] -Original Message- From: Jenda Krynicky [mailto:[EMAIL PROTECTED] Sent: Tuesday, January 06, 2004 2:59 PM To: [EMAIL PROTECTED] Subject: Re: 'print' output on one line From: Esposito, Anthony [EMAIL PROTECTED] I have a perl program ( with DBI ) which prints out a line to STDOUT after every 100 database commits. I would like the 'print' to just refresh the current line every time but - not knowing how to get around it - the program instead prints a new line every 100 commits like so: INFO 3: start deleting rows. Rows deleted: 100 Rows deleted: 200 Rows deleted: 300 Rows deleted: 400 ... print Rows deleted: $rows_deleted\n; Use \r instead of \n: print Rows deleted: $rows_deleted\r; $row_counter = 0; } } print INFO 4: $0 program ended.\n; and don't forget to add a \n in front of the INFO 4... 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] 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 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: case and functions
There is no 'case' statement in Perl but it is easy to mimic such a construct. Tony Esposito Oracle Developer, Enterprise Business Intelligence XO Communications Plano, TX 75074 Work Phone: 972-516-5344 Work Cell: 972-670-6144 Email: [EMAIL PROTECTED] -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Tuesday, January 06, 2004 4:08 PM To: [EMAIL PROTECTED] Subject: case and functions Yo. I read in Learning Perl that there are no such constructs like a case statement. Is there something similar or did I misread this? Also what about functions and function calls, do these exits or does the subroutines replace these? thanks Derek B. Smith OhioHealth IT UNIX / TSM / EDM Teams 614-566-4145 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: 'print' output on one line
Very helpful...thank you Tony Esposito Oracle Developer, Enterprise Business Intelligence XO Communications Plano, TX 75074 Work Phone: 972-516-5344 Work Cell: 972-670-6144 Email: [EMAIL PROTECTED] -Original Message- From: R. Joseph Newton [mailto:[EMAIL PROTECTED] Sent: Tuesday, January 06, 2004 5:07 PM To: Esposito, Anthony Cc: Jenda Krynicky; [EMAIL PROTECTED] Subject: Re: 'print' output on one line Esposito, Anthony wrote: I tried that already but it just gives me the final count at the end. I would like the output to change - the row count, that is - as each 100 rows is committed with the final output - when the program ends - to be: Try turning autoflush on: Greetings! C:\perl -w { local $| = 1; print Hello, there\r; sleep 2; print Well, bye for now\r; sleep 2; } ^Z Hello, there [two seconds later...] Greetings! C:\perl -w { local $| = 1; print Hello, there\r; sleep 2; print Well, bye for now\r; sleep 2; } ^Z Well, bye for now HTH, Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Wrapping Unix Command into Perl
Anthony J Segelhorst [EMAIL PROTECTED] wrote: I am trying to wrap the following Unix command into perl and having a few issues: find /var/spool/Tivoli/backups -name DB_* -mtime +10 -print -exec ls {} \; I have tried (and nothing to seems to work): $temp = `find /var/spool/Tivoli/backups -name DB_* -mtime +10 -print -exec ls {} \;`; system `find /var/spool/Tivoli/backups -name DB_* -mtime +10 -print -exec ls {} \;` !system `find /var/spool/Tivoli/backups -name DB_* -mtime +10 -print -exec ls {} \;`; Jeff Westman wrote: 1-- You are useing parens '( )' and should be using curley braces '{ }' in your exec. 2-- Why are you using -exec ls? -print already gives you the same output (unless you meant to write 'ls -l') 1. I am using {} and not () 2. Eventually I want to use this command to a remove rm, but I was testing with an ls. Anthony J Segelhorst Enterprise Systems Management Team Phone: 937-495-1876 Email: [EMAIL PROTECTED] Jeff Westman [EMAIL PROTECTED] 12/12/2003 03:58 PM To: perl_help [EMAIL PROTECTED] cc: Subject:Re: Wrapping Unix Command into Perl Anthony J Segelhorst [EMAIL PROTECTED] wrote: I am trying to wrap the following Unix command into perl and having a few issues: find /var/spool/Tivoli/backups -name DB_* -mtime +10 -print -exec ls {} \; I have tried (and nothing to seems to work): $temp = `find /var/spool/Tivoli/backups -name DB_* -mtime +10 -print -exec ls {} \;`; system `find /var/spool/Tivoli/backups -name DB_* -mtime +10 -print -exec ls {} \;` !system `find /var/spool/Tivoli/backups -name DB_* -mtime +10 -print -exec ls {} \;`; 1-- You are useing parens '( )' and should be using curley braces '{ }' in your exec. 2-- Why are you using -exec ls? -print already gives you the same output (unless you meant to write 'ls -l') -Jeff __ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response This email has been scanned for all viruses by the MessageLabs SkyScan service.___ This email has been scanned for all viruses by the MessageLabs SkyScan service.___ Note: Please update your email address for this user to reflect the new MeadWestvaco Corporation. MeadWestvaco employee email addresses are in the format of [EMAIL PROTECTED] This electronic message contains information from MeadWestvaco Corporation or subsidiary companies, which may be confidential, privileged or otherwise protected from disclosure. The information is intended to be used solely by the recipient(s) named. If you are not an intended recipient, be aware that any review, disclosure, copying, distribution or use of this transmission or its contents is prohibited. If you have received this transmission in error, please notify MeadWestvaco immediately at [EMAIL PROTECTED] ___
RE: Timing several processes
AIX 5.1, actually. Though eventually linux, windows, and possibly other OS's will be in the mix. I'm writing this with the idea of it being very modular in that each server will do it's own check ever 15 minutes or so, and that the webserver will only connect and grab that data when someone goes to the page (using a cgi to parse it up and display it in a heirarchical fashion). The server will access the data via NFS (the NFS exports are already in place due to another project) Writing to a file gives me a history of data should any individual box go down. (Especially the webserver in this case, since it is periodically taken offline during the course of any given week due to its role in the overall project these machines run) I also plan on the actual programs that are called to be set up in a config file. Something along the lines of: APP1_HANDLE = sar APP1_EXEC = sar 5 5 APP1_LOG = /log/monitor/delta/sar.out APP1_PARSE = /log/monitor/parse_sar.pl APP1_SUMMARY = /log/monitor/delta/sar.summary I'm planning on figuring out how to put all of those into a hash, and then using a foreach loop to exec each one, and another foreach loop to wait for each to complete, and a final foreach loop that runs the parse for each one and generates a summary. The summary files will all be in a standard format that the webserver will use to genrate its display. I had not thought of stderr from the commands, so you're right that catching it is something I need to think on. The other bit I'm working on is to make an options file for each server (generated before the summaries are parsed) that contains info like number of processors, and tuning options (set with schedtune and vmtune, etc) that can be used by the APP_PARSE scripts in calculating results. (Thrashing detection, etc). I know, it's all a little complex, but the individual pieces are fairly simple in design. And in the end it will meet the goal that management put forth, which is what keeps me paid :) -Tony -Original Message- From: drieux [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 03, 2003 7:24 PM To: Perl Perl Subject: Re: Timing several processes On Dec 3, 2003, at 10:49 AM, Akens, Anthony wrote: [..] print Running vmstat\n; defined(my $vmstat_pid = fork) or die Cannot fork: $!; unless ($vmstat_pid) { exec vmstat 5 5 /log/monitor/delta/vmstat.out; die cannot exec vmstat: $!; } print Running sar\n; defined(my $sar_pid = fork) or die Cannot fork: $!; unless ($sar_pid) { exec sar 5 5 /log/monitor/delta/sar.out; die cannot exec date: $!; } print Waiting...\n; waitpid($vmstat_pid, 0); waitpid($sar_pid, 0); print done!\n; [..] I presume you are working on a solaris box? have you thought about timex sar 5 5 timex vmstat 5 5 and you will notice that the sar command will take about 25 seconds and the vmstat about 20. but then there is that minor nit about exec vmstat 5 5 /log/monitor/delta/vmstat.out or die cannot exec vmstat: $!; since in theory exec WILL not return, so if it failed why not keep it in the proper context... Then there is that Minor Nit about not controlling 'stderr' which can lead to things like: vladimir: 60:] ./st*.plx Running vmstat Running sar sh: /log/monitor/delta/vmstat.out: cannot create sh: /log/monitor/delta/sar.out: cannot create Waiting... done! vladimir: 61:] So while you are in the process of learning fork() and exec() why not think a bit more agressively and go with say a pipe to pass back the information so as not to buy the IO overhead of writing to files? While the following was written for a command line 'let us get interactive' type of solution, it might be a framework you could rip off and use: http://www.wetware.com/drieux/pbl/Sys/gen_sym_big_dog.txt ciao drieux --- -- 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]
Timing several processes
Hi all! I'm wanting to write a simple web-based tool to see the status of several servers at a glance. I know there are many solutions existing, but I can't learn as much about perl by just using one of those as I can by writing my own. The first step I want to do is call a script from cron that runs several basic monitoring tools (sar, vmstat, df, iostat, etc) and saves the output of each to a file. Then I'd parse those files up, and write a summary file. Easy enough. And I could certainly do it with by calling the tools one at a time. However, I'd like to get roughly 1 minute of vmstat, iostat, and sar output Simultaneously. So I'm supposing I'd want to fork off each process, and then when those are all done come back and run a script that then parses those results out for the individual statistics I'm looking for. I've never used fork before, and while it looks fairly straight forward what I am not sure of is how to make sure all of those forked processes have completed before moving on and parsing the files. Any pointers? Thanks in advance -Tony -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]