Re: MySQL time
Hi, Yes I know that I can benchmark the perl script using (times)[0] but I am wondering if there is a method of getting the time returned by the MySQL server. Or that time shown by mysql client is not returned by MySQL server but by that client in the same way I can do it using (times)[0]? Thanks. T - Original Message - From: Chris Devers [EMAIL PROTECTED] To: Octavian Rasnita [EMAIL PROTECTED] Cc: Perl Beginners List beginners@perl.org Sent: Monday, March 14, 2005 8:41 PM Subject: Re: MySQL time On Mon, 14 Mar 2005, Octavian Rasnita wrote: Please tell me how can I find the time needed to pass for a perl program execute an SQL query using MySQL, DBI and DBD::mysql. You find the time required by benchmarking the procedure. If this isn't what you mean, maybe you could clarify what you mean by time (if you have some MySQL-specific concept of the term), and what it is exactly that you need (elapsed time to execute a query? elapsed time for a Perl/DBI script to connect to a MySQL server and issue a query? elapsed time for the whole Perl script to run? something else?). As always, posting the code you have so far is very helpful. -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
DBI query
Anyone got any any idea what is happening here $dbh=DBI-connect(dbi:Pg:dbname=data_cc,$user,$pw); $dump_dir='/home/data_cc/dump'; @names=$dbh-tables(); #$dbh-execute; #print @names; foreach $names(@names){ if (substr($names,0,9) eq public.tb) { $file1= $dump_dir\/$names; $dbh-prepare(COPY $names TO ? WITH DELIMITER AS #); $dbh-bind_param(1,$file1); $dbh-execute(); } } results in output [Mon Mar 14 17:30:10 2005] [error] [client 127.0.0.1] Can't locate object method bind_param via package DBI::db at /home/www/cgi- bin/dump_all.pl line 25. confused - it seems to be losing the connection to the db -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
DBI query
Anyone got any any idea what is happening here $dbh=DBI-connect(dbi:Pg:dbname=data_cc,$user,$pw); $dump_dir='/home/data_cc/dump'; @names=$dbh-tables(); #$dbh-execute; #print @names; foreach $names(@names){ if (substr($names,0,9) eq public.tb) { $file1= $dump_dir\/$names; $dbh-prepare(COPY $names TO ? WITH DELIMITER AS #); $dbh-bind_param(1,$file1); $dbh-execute(); } } results in output [Mon Mar 14 17:30:10 2005] [error] [client 127.0.0.1] Can't locate object method bind_param via package DBI::db at /home/www/cgi- bin/dump_all.pl line 25. confused - it seems to be losing the connection to the db -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: DBI query
Hi mike Am Montag, 14. März 2005 18.38 schrieb mike: Anyone got any any idea what is happening here Apart from your actual problem, it happens that the coding below will give big chances to have undetected or hard to find errors. - use use strict; use warnings; at the top of the code - declare your variables (as local to the first usage as possible) - check the results of methods/functions I did not run your (and my) code; just some annotations: $dbh=DBI-connect(dbi:Pg:dbname=data_cc,$user,$pw); my $dbh=DBI-connect(dbi:Pg:dbname=data_cc,$user,$pw) or die $DBI::errstr; (an example for declaring $dbh and checking the result of connect()) $dump_dir='/home/data_cc/dump'; @names=$dbh-tables(); #$dbh-execute; #print @names; foreach $names(@names){ sidenote: since $names contains a scalar, $name would be a better name for this variable. if (substr($names,0,9) eq public.tb) { $file1= $dump_dir\/$names; $dbh-prepare(COPY $names TO ? WITH DELIMITER AS #); The prepare method returns a statement handle for further usage, check the manual of DBI. my $sth=$dbh-prepare(COPY $names TO ? WITH DELIMITER AS #) or die $DBI::errstr $dbh-bind_param(1,$file1); $dbh-execute(); and the statement handle has the bind_param and execute methods: $sth-bind_param(1,$file1) or die $DBI::errstr; $sth-execute() or die $DBI::errstr; There are several methods to retrieve the results from the statement handle (see man DBI) - at this place in the code, not outside of the foreach loop. } } results in output [Mon Mar 14 17:30:10 2005] [error] [client 127.0.0.1] Can't locate object method bind_param via package DBI::db at /home/www/cgi- bin/dump_all.pl line 25. This is correct, since the database handle has no such methods. confused - it seems to be losing the connection to the db No, this would not result in an object dropping a method. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Directory fastscan
Hallo all! How should I fast check up if in the current directory ever one directory exists? I think this way is incorrect: sub is_node { my $cur_dir = shift; opendir(DIR, $cur_dir) || return 0; my @dirs = readdir(DIR); closedir(DIR); while(@dirs){ //Looking up directory until any [sub]directory found return 1 if (lstat)[1] 004 $_ !~ /^\.+/; } return 0; //No subdirs found. } And for example: chdir(/path/to/dir/); print /path/to/dir has .(is_node(./) ? : not). directory(s)\n; -- Vladimir D Belousov -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
System o/p to a varaible
Hi This program I use to get the last line from the log file cipe.log. and then write the line onto a text file a.txt system(tail -1 cipe.log a.txt); open INPUT,a.txt; my $line=INPUT; then I open the text file and read the value from the file handle. This invloves cumbersome process. I need to avoid writing to a file the o/p of the system command. Is there a way to assign to some variable... Thanks Anish
Re: Directory fastscan
Sorry, I mean sub is_node { my $cur_dir = shift; opendir(DIR, $cur_dir) || return 0; my @dirs = readdir(DIR); closedir(DIR); for(@dirs){ //Looking up directory until any [sub]directory found return 1 if (lstat)[2] 004 $_ !~ /^\.+/; } return 0; //No subdirs found. } Vladimir D Belousov wrote: Hallo all! How should I fast check up if in the current directory ever one directory exists? I think this way is incorrect: sub is_node { my $cur_dir = shift; opendir(DIR, $cur_dir) || return 0; my @dirs = readdir(DIR); closedir(DIR); while(@dirs){ //Looking up directory until any [sub]directory found return 1 if (lstat)[1] 004 $_ !~ /^\.+/; } return 0; //No subdirs found. } And for example: chdir(/path/to/dir/); print /path/to/dir has .(is_node(./) ? : not). directory(s)\n; -- Vladimir D Belousov HiTech solutions for business http://businessreklama.ru -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Directory fastscan
Hi, Vladimir D Belousov [EMAIL PROTECTED] wrote; Sorry, I mean sub is_node { my $cur_dir = shift; opendir(DIR, $cur_dir) || return 0; my @dirs = readdir(DIR); closedir(DIR); for(@dirs){ //Looking up directory until any [sub]directory found return 1 if (lstat)[2] 004 $_ !~ /^\.+/; } return 0; //No subdirs found. } sub is_node { my $cur_dir = shift; my $have_dir = 0; opendir( DIR, $cur_dir ) || return undef; while( my $entry = readdir(DIR) ){ next if $entry =~ m/^\.\.?$/; last if -d $cur_dir/$entry ++ $have_dir; } closedir( DIR ); return $have_dir; } HTH, Thomas -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: DBI query
mike wrote: Anyone got any any idea what is happening here $dbh=DBI-connect(dbi:Pg:dbname=data_cc,$user,$pw); $dump_dir='/home/data_cc/dump'; @names=$dbh-tables(); #$dbh-execute; #print @names; foreach $names(@names){ if (substr($names,0,9) eq public.tb) { $file1= $dump_dir\/$names; $dbh-prepare(COPY $names TO ? WITH DELIMITER AS #); $dbh-bind_param(1,$file1); $dbh-execute(); } } results in output [Mon Mar 14 17:30:10 2005] [error] [client 127.0.0.1] Can't locate object method bind_param via package DBI::db at /home/www/cgi- bin/dump_all.pl line 25. bind_param and execute are *statement* handle method, and you're applying them to a *database* handle. You need to save the return value from prepare() and call bind_param() and execute() on that. Or, you can combine the prepare/bind/execute all into one call to do(): $dbh-do(COPY $names TO ? WITH DELIMITER AS #, undef, $file); confused - it seems to be losing the connection to the db No, the error message is a Perl error telling you that the package that $dbh belongs to (DBI::db) doesn't have or inherit a method called bind_param. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: System o/p to a varaible
Am Dienstag, 15. März 2005 01.33 schrieb Anish Kumar K.: Hi This program I use to get the last line from the log file cipe.log. and then write the line onto a text file a.txt system(tail -1 cipe.log a.txt); open INPUT,a.txt; my $line=INPUT; then I open the text file and read the value from the file handle. This invloves cumbersome process. I need to avoid writing to a file the o/p of the system command. Is there a way to assign to some variable... Here an easy way: use strict; use warnings; my $line; open FILE, , 'cipe.log' or die error opening file: $!; $line=$_ while FILE; # copies each line to $line :-( close FILE or warn error closing file: $!; print $line; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: System o/p to a varaible
On Tue, 15 Mar 2005, Anish Kumar K. wrote: This program I use to get the last line from the log file cipe.log. and then write the line onto a text file a.txt system(tail -1 cipe.log a.txt); open INPUT,a.txt; my $line=INPUT; then I open the text file and read the value from the file handle. You're very brave to not check that these commands work. Every one of them should have an or die ... (or or croak ...) at the end to make sure that things are okay. More broadly, any time your program interacts with a system resource, you *must* check to be sure that the resource is actually available. Therefore: my $commmand = tail -1 cipe.log a.txt; system($command) or die Couldn't run command '$command': $!; my $cipetail = a.txt; open CIPETAIL, , $cipetail or die Couldn't read from $cipetail: $!; my $slurp_in_whole_file = CIPETAIL or die Couldn't read from $cipetail: $!; And then when you close it, that needs to be handled as well: close CIPETAIL or die Couldn't close $cipetail: $!; This invloves cumbersome process. I need to avoid writing to a file the [output] of the system command. Is there a way to assign to some variable... That's an excellent thing to want to avoid. For that matter, you shouldn't be using a system command in the first place -- Perl is perfectly capable of opening the file and reading in the last line. The _Perl Cookbook_ has a recipie that does almost what you want -- it truncates the last line, but we can amend that: open (FH, + $file) or die can't update $file: $!; while ( FH ) { $addr = tell(FH) unless eof(FH); } truncate(FH, $addr) or die can't truncate $file: $!; # ^ From http://www.oreilly.com/catalog/cookbook/chapter/ch08.html So, if you omit the call to truncate, this does what you want. A version like this should be about right: my $cipelog = cipe.log; open CIPELOG, , $cipelog or die Can't read from $cipelog: $!; while CIPELOG { my $line = tell CIPELOG unless eof CIPELOG; } close CIPELOG or doe Couldn't close $cipelog: $!; At this point, $line has the data you want. -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: System o/p to a varaible
Anish Kumar K. wrote: Hi This program I use to get the last line from the log file cipe.log. and then write the line onto a text file a.txt system(tail -1 cipe.log a.txt); open INPUT,a.txt; my $line=INPUT; then I open the text file and read the value from the file handle. This invloves cumbersome process. I need to avoid writing to a file the o/p of the system command. Is there a way to assign to some variable... Backticks capture output: my $line = `tail -1 cipe.log`; Tie::File is also easy, and portable to systems without tail(1): use Tie::File; tie @arr, 'Tie::File', 'cipe.log' or die $!; my $line = @arr[-1]; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
How to read and delete mail from a cron job
Can someone please give me some suggestions (or pointers) as to how to read and delete emails from a cron job. I will be receiving conformation email and need to process it once then delete it - not process it again. Thank you in advance, John Moon -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: System o/p to a varaible
[EMAIL PROTECTED] (Anish Kumar K.) wrote in news:[EMAIL PROTECTED]: system(tail -1 cipe.log a.txt); open INPUT,a.txt; my $line=INPUT; my $line = qx(tail -1 cipe.log); -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
configuring cpan
Hi all, I have a problem using the cpan command line for installing modules because I don't know for what reasons, some FTP sites are not accessible, but cpan doesn't give a short enough timeout, and I need to wait very much until those servers give a timeout and the 404 error. Is there a way to change these settings in order to specify that if a server doesn't answer in... let's say 15 seconds, break the connection and try with the second CPAN mirror? Thank you. Teddy -- 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 read and delete mail from a cron job
On Tue, 15 Mar 2005, Moon, John wrote: Can someone please give me some suggestions (or pointers) as to how to read and delete emails from a cron job. I will be receiving conformation email and need to process it once then delete it - not process it again. Is procmail not an option? This is exactly the sort of thing it's good at. Procmail sits watching your incoming mail, then handles it in some way. This usually means transferring the message to a specific folder, but it could also mean running a program that transforms the contents of the message (adding or modifying headers, etc), or doing something else -- as, in this case, you're trying to do. For example, my Procmail rule to run SpamAssassin on incoming mail is: :0fw: spamassassin.lock | /usr/local/bin/spamc If I just wanted to filter certain messages, I might do this: :0fw: spamassassin.lock * ^Subject:.*confirmation | /usr/local/bin/spamc You should be able to adapt this to your needs, and it should be much more flexible than using a cron job. (Note though that setting up Procmail, if it isn't there already, requires some overhead. A lot of [Unix] mail servers are already set up for it, and all you have to do is enable it for your account, but you'll have to sort out what to do if you're starting from scratch. There's a lot of good tutorials out there that a Google search will uncover.) -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Perl and quickbooks?
Chris wrote: Greetings, Has anybody done anything with perl and quickbooks? I simply need to export some data into quickbooks format where the user can take that exported quickbooks data and import it into quickbooks as a check. I have been looking around, but haven't found anything worthwhile. Any tips are appreciated. Thanks! CPAN didn't indicate anything directly for Quickbooks but I suspect it can use QIF format, so you might try that. http://search.cpan.org/~nmcfarl/Finance-QIF-1.03/ HTH, http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: configuring cpan
On Tue, 15 Mar 2005 15:54:54 +0200, Octavian Rasnita wrote: Hi all, I have a problem using the cpan command line for installing modules because I don't know for what reasons, some FTP sites are not accessible, but cpan doesn't give a short enough timeout, and I need to wait very much until those servers give a timeout and the 404 error. Is there a way to change these settings in order to specify that if a server doesn't answer in... let's say 15 seconds, break the connection and try with the second CPAN mirror? perl -MCPAN -e shell o conf inactivity_timeout 15 o conf commit q -- Peter Scott http://www.perlmedic.com/ http://www.perldebugged.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: z/OS unicode error.
Are you running with strict and warnings turned on? Because I'm getting Malformed UTF-8 character messages running this: #!/usr/bin/perl use strict; use warnings; my $u = unpackU0U, \x8a\x73; print \$u: $u\n; my $p = pack(U0U, $u); print \$p: $p\n; And I can get rid of those errors by changing the pack/unpack template to UU or U*... What are you trying to accomplish with U0U? I figured that the malformed character error that you mentioned, doesnt show up on z/OS while using 'U0U'. This is even if I run the same with 'use strict' and 'use warnings'. Also, the U0U indicates that the string of bytes passed to unpack has to be strictly in utf-8 unicode. Try U0U*, that seems to work better for me. Are you running the same on z/OS unix ? I am running this on z/OS v1R4. No, I'm running RH9... don't have access to a z/OS box. -- 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 and quickbooks?
Chris, What are you trying to do? I would like to automate the creation of invoices with Quickbooks. Let me know how your project goes. Do you know how to apply QIF files? I know that Quick Books has an extensive COM interface which should be quite compatible with windows (ActiveState) perl. I seem to remember that I could not program quick books (using COM) without buy a special pricey version of quick books. Do you know if this is true? Siegfried -Original Message- From: Wiggins d'Anconia [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 15, 2005 7:28 AM To: Chris Cc: beginners@perl.org Subject: Re: Perl and quickbooks? Chris wrote: Greetings, Has anybody done anything with perl and quickbooks? I simply need to export some data into quickbooks format where the user can take that exported quickbooks data and import it into quickbooks as a check. I have been looking around, but haven't found anything worthwhile. Any tips are appreciated. Thanks! CPAN didn't indicate anything directly for Quickbooks but I suspect it can use QIF format, so you might try that. http://search.cpan.org/~nmcfarl/Finance-QIF-1.03/ HTH, http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
array of numbers with padded zeroes
I'm having trouble with this, and I'm sure someone out there has a really clever solution-- I have a hash, %data, with, say, 32 elements. From that, I need an array going from 01 to 32, i.e. 01, 02, 03, 04, etc. But if my hash had 750 elements, I'd want it to go from 001 to 750. I thought this should be easy, but I'm really struggling with it-- This is the best I've come up with: @allkeys = ('0' x (length(keys(%data)) - 1) . '1' .. keys(%data)); ... but it doesn't work. Any ideas? TIA. - Bryan -- 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 and quickbooks?
On Tuesday 15 March 2005 11:52 am, Siegfried Heintze wrote: Chris, What are you trying to do? I would like to automate the creation of invoices with Quickbooks. Let me know how your project goes. Do you know how to apply QIF files? I know that Quick Books has an extensive COM interface which should be quite compatible with windows (ActiveState) perl. I seem to remember that I could not program quick books (using COM) without buy a special pricey version of quick books. Do you know if this is true? Siegfried Just trying to export some data so quickbooks can import it as a check. I can't use Windows for this, i just need to take my data and generate the appropriate file type for quickbooks. -c -- 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 read and delete mail from a cron job
Chris, Thank you for the suggestion but when I say process I mean that I need to read the reply, grep for user id and a confirmation number, update my database to say that the email I send was replied to as requested, and that the email address I was given was correct... I am registering users for access to web ap. and need(require) a good email address (initially!). Plus I am not an admin but a developer and procmail is not a product I believe I can use... (at least I can't find it on this UNIX box) Anyone else? jwm -Original Message- From: Chris Devers [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 15, 2005 9:03 AM To: Moon, John Cc: Perl Beginners Subject: Re: How to read and delete mail from a cron job On Tue, 15 Mar 2005, Moon, John wrote: Can someone please give me some suggestions (or pointers) as to how to read and delete emails from a cron job. I will be receiving conformation email and need to process it once then delete it - not process it again. Is procmail not an option? This is exactly the sort of thing it's good at. Procmail sits watching your incoming mail, then handles it in some way. This usually means transferring the message to a specific folder, but it could also mean running a program that transforms the contents of the message (adding or modifying headers, etc), or doing something else -- as, in this case, you're trying to do. For example, my Procmail rule to run SpamAssassin on incoming mail is: :0fw: spamassassin.lock | /usr/local/bin/spamc If I just wanted to filter certain messages, I might do this: :0fw: spamassassin.lock * ^Subject:.*confirmation | /usr/local/bin/spamc You should be able to adapt this to your needs, and it should be much more flexible than using a cron job. (Note though that setting up Procmail, if it isn't there already, requires some overhead. A lot of [Unix] mail servers are already set up for it, and all you have to do is enable it for your account, but you'll have to sort out what to do if you're starting from scratch. There's a lot of good tutorials out there that a Google search will uncover.) -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: array of numbers with padded zeroes
Bryan R Harris wrote: I'm having trouble with this, and I'm sure someone out there has a really clever solution-- I have a hash, %data, with, say, 32 elements. From that, I need an array going from 01 to 32, i.e. 01, 02, 03, 04, etc. The real question is what are you attempting to do? With the hash, you can have totals and any other info, pulse you have the key as part of what is going. Wags ;) But if my hash had 750 elements, I'd want it to go from 001 to 750. I thought this should be easy, but I'm really struggling with it-- This is the best I've come up with: @alleys = ('0' x (length(keys(%data)) - 1) . '1' .. keys(%data)); ... but it doesn't work. Any ideas? TIA. - Bryan *** This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. *** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: array of numbers with padded zeroes
Bryan R Harris wrote: I'm having trouble with this, and I'm sure someone out there has a really clever solution-- I have a hash, %data, with, say, 32 elements. From that, I need an array going from 01 to 32, i.e. 01, 02, 03, 04, etc. But if my hash had 750 elements, I'd want it to go from 001 to 750. I thought this should be easy, but I'm really struggling with it-- This is the best I've come up with: @allkeys = ('0' x (length(keys(%data)) - 1) . '1' .. keys(%data)); To generate a list from 1 to n, where the values are padded with zeroes to the length of the longest value, you can do something like: my $n = keys %data; my $l = length $n; my @arr = map sprintf(%0*d, $l, $_), 1 .. $n; But @arr is just a list of numbers. It has no particular correspondence to the actual keys in %data, so what are you trying to do? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: array of numbers with padded zeroes
I'm having trouble with this, and I'm sure someone out there has a really clever solution-- I have a hash, %data, with, say, 32 elements. From that, I need an array going from 01 to 32, i.e. 01, 02, 03, 04, etc. The real question is what are you attempting to do? With the hash, you can have totals and any other info, pulse you have the key as part of what is going. I'm building a script that will split a file into a bunch of little pieces, based on very specific and custom criteria. The hash holds the data, e.g. $data{32.52,53.21} would hold all the data pertaining to that key (10 20 30\n40 50 60\n), and I want to write these little files out. I want to number the output files based on the number of hash elements, but I want them to be zero-padded so they line up in file lists. The rest of it works, I'm just having trouble coming up with the zero-padded numbers! - B -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: array of numbers with padded zeroes
Thanks to everyone who replied! Your suggestions cleaned out a block in my mind, and I got it figured out. Here's what works, for those interested: @allkeys = ('0' x (length(keys(%data)) - 1) . '1' .. (keys(%data)) . ); - B ps. Is there an easy way to test this versus the solution below, to see which one is faster? I know it won't make much difference, but I was just curious... Bryan R Harris wrote: I'm having trouble with this, and I'm sure someone out there has a really clever solution-- I have a hash, %data, with, say, 32 elements. From that, I need an array going from 01 to 32, i.e. 01, 02, 03, 04, etc. But if my hash had 750 elements, I'd want it to go from 001 to 750. I thought this should be easy, but I'm really struggling with it-- This is the best I've come up with: @allkeys = ('0' x (length(keys(%data)) - 1) . '1' .. keys(%data)); To generate a list from 1 to n, where the values are padded with zeroes to the length of the longest value, you can do something like: my $n = keys %data; my $l = length $n; my @arr = map sprintf(%0*d, $l, $_), 1 .. $n; But @arr is just a list of numbers. It has no particular correspondence to the actual keys in %data, so what are you trying to do? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: array of numbers with padded zeroes
Bryan R Harris wrote: I'm having trouble with this, and I'm sure someone out there has a really clever solution-- I have a hash, %data, with, say, 32 elements. From that, I need an array going from 01 to 32, i.e. 01, 02, 03, 04, etc. The real question is what are you attempting to do? With the hash, you can have totals and any other info, pulse you have the key as part of what is going. I'm building a script that will split a file into a bunch of little pieces, based on very specific and custom criteria. The hash holds the data, e.g. $data{32.52,53.21} would hold all the data pertaining to that key (10 20 30\n40 50 60\n), and I want to write these little files out. I want to number the output files based on the number of hash elements, but I want them to be zero-padded so they line up in file lists. The rest of it works, I'm just having trouble coming up with the zero-padded numbers! - B Then use sprintf and what you believe to be the largest number you would process in a day. If less than a thousand, then a sprintf %03d would zero pad and allow up to 999 entries per day. If over a 1000, then change to %04d to get almost 10,000 elements in a day. You could use the hash and the array element to hold what you want to do: $data{key}[0] = file number $data{key}[1] = data for file. Now you can sort the key or not and then do something like: my $MyFileOut = sprintf %03d, $data{key}[0]; # now $MyFileOut is say 001 and you can open and write the data using [1] for the data. Just a thought. Wags ;) Wags ;) *** This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. *** -- 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 read and delete mail from a cron job
on di, 15 mrt 2005 17:07:10 GMT, John Moon wrote: Plus I am not an admin but a developer and procmail is not a product I believe I can use... (at least I can't find it on this UNIX box) Anyone else? http://search.cpan.org/~simon/Mail-Audit-2.1/ and a line in .forward perhaps? -- felix -- 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 read and delete mail from a cron job
Because it's up-side down. Why is that? It makes replies harder to read. Why not? Please don't top-post. - Sherm Pendley, Mac OS X list Moon, John wrote: Chris, Thank you for the suggestion but when I say process I mean that I need to read the reply, grep for user id and a confirmation number, update my database to say that the email I send was replied to as requested, and that the email address I was given was correct... I am registering users for access to web ap. and need(require) a good email address (initially!). Plus I am not an admin but a developer and procmail is not a product I believe I can use... (at least I can't find it on this UNIX box) Anyone else? jwm Chris' point was that you can intercept the message as it is delivered and process it in real time as opposed to having it sit in a queue (read mailbox). So rather than checking periodically (via cron) that a message has arrived, your process is kicked off when the message arrives and gets fed its contents on STDIN. A very good way to handle incoming mail. procmail and sendmail both handle this type of process, so if procmail isn't available and sendmail is it will still work. The only setup requirement is that you can point an address at a pipe but regardless the address setup is virtually the same, and you will have to have an address unless If you really just want to verify that the user can receive mail, then rather than have them reply, why not just provide a link that they can click on that will go to a specific URL with the confirmation information in it. This tends to be easier than dealing with incoming mail, as you will have to parse the message, etc. And you are really testing their ability to receive e-mail and use your web site, rather than their ability to send messages to your mailing lists, etc. (unless that *is* what you are doing). I have used the latter on several sites and other than the occasional user who absolutely refuses to actually read the mail they get (in which cases replying ain't going to help) it works very well. http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: System o/p to a varaible
On Mar 15, Chris Devers said: system($command) or die Couldn't run command '$command': $!; That needs to be system($command) == 0 or die ...; -- Jeff japhy Pinyan % How can we ever be the sold short or RPI Acacia Brother #734 % the cheated, we who for every service http://japhy.perlmonk.org/ % have long ago been overpaid? http://www.perlmonks.org/ %-- Meister Eckhart -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: System o/p to a varaible
On Tue, 15 Mar 2005, Jeff 'japhy' Pinyan wrote: On Mar 15, Chris Devers said: system($command) or die Couldn't run command '$command': $!; That needs to be system($command) == 0 or die ...; ...which is all the more reason to avoid the system command :-) There's no reason to solve this problem that way. Just open the file, read to the last line, and close it. Perl is completely capable of doing this alone on any platform. -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Compare 2 database queries?!
Thanks for that Chris, using your pseudocode (see below) I have tried the following code: (N.B. I have a table called uniprot_entry_tbl which contains the protein_ids in a column called primary_acc_no) #checks to see if any of the proteins are already in the DB my $question = 'P09466'; my $result = $dbh-selectcol_arrayref(SELECT primary_acc_no FROM uniprot_entry_tbl WHERE primary_acc_no='P09466'); if ($accession eq $result) { print the protein is already in the database\n; } else { print the protein needs to be inserted into the database\n; $dbh-do(INSERT INTO uniprot_entry_tbl (primary_acc_no) values ('$accession')); } $dbh-disconnect; exit; However, when I run this code it throws back the error DBD::Pg::db selectcol_arrayref failed: ERROR: column p09466 does not exist at extract_ann_uni.pl line 41, GENO line 155. I know the SQL command is correct because I checked it manually but I don't know why it says the column doesn't exist?! Please help!! Quoting Chris Devers [EMAIL PROTECTED]: On Mon, 14 Mar 2005, SG Edwards wrote: I have a perl script that queries a protein database (uniprot) and puts protein data from the query into a PostgreSQL table. However, what I would like it to do is check if the protein is in my database already!! In my database I have a table with a column containing all the protein_ids so I can return this as a query. What is the best way/fastest to check the data in my table against the data I retrive from the UniProt database?! As pseudo-code -- if ( ! check_for_protein_in( $dbh ) ) { add_protein_to_database( $dbh, $protein ); } else { print The protein was already in the database.\n; } We could get into more detail about what these subroutines might look like, but to do so we'd need to know what code you've tried so far, and maybe a little bit about the database schema, or at least the fields in that table. I was thinking that you could do some kind of special SQL statement, with something like (making this up / definitely won't work): INSERT INTO uniprot VALUES ($id, $token{$id}, $marker{$id}) UNLESS EXISTS id=$id But as far as I can tell, PostgreSQL doesn't support such a construct, unless you can figure out how to hammer it into a SELECT sub-statement at the end rather than a (non-existent) EXISTS clause. -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: System o/p to a varaible
Anish Kumar K. wrote: Hi Hello, This program I use to get the last line from the log file cipe.log. and then write the line onto a text file a.txt system(tail -1 cipe.log a.txt); open INPUT,a.txt; my $line=INPUT; then I open the text file and read the value from the file handle. This invloves cumbersome process. I need to avoid writing to a file the o/p of the system command. Is there a way to assign to some variable... Use the File::ReadBackwards module: http://search.cpan.org/~uri/File-ReadBackwards-1.03/ use File::ReadBackwards my $bw = File::ReadBackwards-new( 'cipe.log' ) or die Cannot read 'log_file' $!; my $line = $bw-readline; John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: array of numbers with padded zeroes
Bryan R Harris wrote: I'm having trouble with this, and I'm sure someone out there has a really clever solution-- I have a hash, %data, with, say, 32 elements. From that, I need an array going from 01 to 32, i.e. 01, 02, 03, 04, etc. But if my hash had 750 elements, I'd want it to go from 001 to 750. I thought this should be easy, but I'm really struggling with it-- This is the best I've come up with: @allkeys = ('0' x (length(keys(%data)) - 1) . '1' .. keys(%data)); ... but it doesn't work. Any ideas? my $num = keys %data; my @allkeys = map sprintf( '%0*d', length( $num ), $_ ), 1 .. $num; John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Compare 2 database queries?!
My response breaks the flow of your script for clarity, but don't take that as me suggesting to just randomly move things around :-) On Tue, 15 Mar 2005, SG Edwards wrote: if ($accession eq $result) { print the protein is already in the database\n; ... print the protein needs to be inserted into the database\n; Nitpick: putting the variable in the print statement makes the print statment more useful: print protein $accession is already in the database\n; print protein $accession must be added to the database\n; my $result = $dbh-selectcol_arrayref(SELECT primary_acc_no FROM uniprot_entry_tbl WHERE primary_acc_no='P09466'); ... $dbh-do(INSERT INTO uniprot_entry_tbl (primary_acc_no) values ('$accession')); ... $dbh-disconnect; It may help to add error checking code to all of this, as per this page: http://www.oreilly.com/catalog/perldbi/chapter/ch04.html#ch04_error_0 You may already have one of these elsewhere in your code: $h-{PrintError} = 1; $h-{RaiseError} = 1; ...in which case you're way ahead of me :-) Also, are you *positive* that the PostgreSQL SQL query -- INSERT INTO uniprot_entry_tbl (primary_acc_no) VALUES ('p09466') -- is correct? Because it looks to me (and apparently to PostgreSQL) like you may have your data field being used as a column name in the query, which probably isn't correct :-) Put another way, if the SQL statement works directly against the database, such as in the `psql` interactive shell, then you should be able to use the statement in your DBI script. If it doesn't work, then it may help to see all the database sections of your code, along with file numbers so that the error output can be lined up by list readers. -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: array of numbers with padded zeroes
Wagner, David --- Senior Programmer Analyst --- WGO wrote: John W. Krahn wrote: Bryan R Harris wrote: I'm having trouble with this, and I'm sure someone out there has a really clever solution-- I have a hash, %data, with, say, 32 elements. From that, I need an array going from 01 to 32, i.e. 01, 02, 03, 04, etc. But if my hash had 750 elements, I'd want it to go from 001 to 750. I thought this should be easy, but I'm really struggling with it-- This is the best I've come up with: @allkeys = ('0' x (length(keys(%data)) - 1) . '1' .. keys(%data)); ... but it doesn't work. Any ideas? my $num = keys %data; my @allkeys = map sprintf( '%0*d', length( $num ), $_ ), 1 .. $num; Sorry, but I don't see how it works. I know it works because I tried it. Something is going on with the '%0*d', but it is by me and not even sure where I would look to see why it is working. perldoc -f sprintf So please what magic is happening here? The '*' character in the format string uses the next argument from the list so: sprintf( '%0*d', length( $num ), $_ ) Is equivalent to: sprintf( '%0' . length( $num ) . 'd', $_ ) But is safer. 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
input_record_separator is not supported on a per handle basis at ..file/linenum...?
Hi all, Is someone able to explain why I am getting the following error, how I might correct it? Sorry I'm a bit of a newbie to Perl I have recently updated the Perl package I am working with to ActivePerl 5.8.6 and am now getting this error: input_record_separator is not supported on a per handle basis at ..file/linenum...? Relevant lines of code:- $mif_fh-input_record_separator(undef); $mif_header = $mif_fh-getline; and $fh-input_record_separator(undef); $data_stream = $fh-getline; and $fh-input_record_separator(undef); eval($fh-getline); Any help/ advice would be greatly appreciated. Thanks, Tracey Simon
Re: input_record_separator is not supported on a per handle basis at ..file/linenum...?
[EMAIL PROTECTED] wrote: Hi all, Hello, Is someone able to explain why I am getting the following error, how I might correct it? Sorry I'm a bit of a newbie to Perl I have recently updated the Perl package I am working with to ActivePerl 5.8.6 and am now getting this error: input_record_separator is not supported on a per handle basis at ..file/linenum...? Relevant lines of code:- $mif_fh-input_record_separator(undef); $mif_header = $mif_fh-getline; and $fh-input_record_separator(undef); $data_stream = $fh-getline; and $fh-input_record_separator(undef); eval($fh-getline); Any help/ advice would be greatly appreciated. Which module(s) are $mif_fh and $fh an object of? What is the version number of the module(s)? Which version of Perl were you using before you updated? Did you update all your modules when you updated Perl? John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: System o/p to a varaible
-Original Message- From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 16, 2005 12:06 AM To: Perl Beginners List Cc: Anish Kumar K. Subject: Re: System o/p to a varaible On Mar 15, Chris Devers said: system($command) or die Couldn't run command '$command': $!; That needs to be system($command) == 0 or die ...; -- Or system ($command) and die... ; * Disclaimer: The contents of this E-mail (including the contents of the enclosure(s) or attachment(s) if any) are privileged and confidential material of MBT and should not be disclosed to, used by or copied in any manner by anyone other than the intended addressee(s). In case you are not the desired addressee, you should delete this message and/or re-direct it to the sender. The views expressed in this E-mail message (including the enclosure(s) or attachment(s) if any) are those of the individual sender, except where the sender expressly, and with authority, states them to be the views of MBT. This e-mail message including attachment/(s), if any, is believed to be free of any virus. However, it is the responsibility of the recipient to ensure that it is virus free and MBT is not responsible for any loss or damage arising in any way from its use * -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: input_record_separator is not supported on a per handle basis at ..file/linenum...?
[EMAIL PROTECTED] wrote: John W. Krahn [EMAIL PROTECTED] 16/03/2005 11:47 AM [EMAIL PROTECTED] wrote: Is someone able to explain why I am getting the following error, how I might correct it? Sorry I'm a bit of a newbie to Perl I have recently updated the Perl package I am working with to ActivePerl 5.8.6 and am now getting this error: input_record_separator is not supported on a per handle basis at ..file/linenum...? Relevant lines of code:- $mif_fh-input_record_separator(undef); $mif_header = $mif_fh-getline; and $fh-input_record_separator(undef); $data_stream = $fh-getline; and $fh-input_record_separator(undef); eval($fh-getline); Any help/ advice would be greatly appreciated. Which module(s) are $mif_fh and $fh an object of? What is the version number of the module(s)? Which version of Perl were you using before you updated? Did you update all your modules when you updated Perl? I've been taking a look at it and discovered a few things, but still can't quite make sense of it. Apparently this input_record_separator is a new line. The Input Record Separator variable is described in the perlvar.pod document and is usually a newline character and the perlport.pod document describes how newlines work on different platforms. perldoc perlvar perldoc perlport To give some background.. I am testing an app' that works as a .xla plugin, scripted in vba and perl, I didn't write it and the developer has disappeared. I'm a perl newbie, but not a coding newbie, so I can see a fair amount of what is going on. I updated from API517E to the latest 5.8.6.811 as the client was concerned with slowness of the app. I've performed testing and it all still works perfectly well, or so it appears, except for the above error during processing. I tried just commenting out the line of code, but I still get the error? ...I haven't updated any of the modules, apart to add in some really basic commenting. Really, I just want to get rid of the error that occurs whilst processing, and I guess take advantage of any IO, filehandling improvements that have been built in since the earlier release. I'll attach the relevant file, to make it easier for you to see what's happening.. just didn't want to send it to a list. In response to your questions: Which module(s) are $mif_fh and $fh an object of? These are filehandle objects The FileHandle module was useful for earlier versions of Perl but the version that you are currently using does not need this module. Just use lexical filehandles with open() like: open my $fh, '', $filename The FileHandle module inherits from IO::Handle which describes the correct way to use the input_record_separator method. perldoc IO::Handle What is the version number of the module(s)? um,...not sure, how can i determine this $ perl -MFileHandle -le'print $FileHandle::VERSION' 2.01 Which version of Perl were you using before you updated? 5.1.7 According to perlhist.pod there is no version 5.1.7 of Perl. perldoc perlhist #!/bin/perl -w It is usually recommended that you use the warnings pragma instead of the -w command line switch. perldoc perllexwarn It is also recommended that you use the strict pragma: use warnings; use strict; #note added 16/3/5 by tsimon, ADG #This package uses the mif template to build the mif file #It is the main package which calls each of the others to put the pieces together #This package calls MifPara,MifCell, MifTree and MifTable BEGIN { $local_dir = $0; $local_dir =~ s/(.*)\\([^\\]*)$/$1/; push(@INC, $local_dir); } The current way to do that is: use FindBin; use lib $FindBin::Bin; use MifPara; use MifCell; use MifTree; use MifTable; use File::stat; use Data::Dumper; use FileHandle; #- # Globals %default_column_widths = ( 'Gap' = 4.5, 'Value' = 16, 'Note' = 10 ); If you add the strict pragma then you will have to define all of these variables with my(). my %default_column_widths = ( Gap = 4.5, Value = 16, Note = 10, ); $leader_note_margin = 4.5; # Percentage of colour for cell shading is 30% # this coresponds to a fill value of 4 # 10% coresponds to 5 # Cell shading is now 10% $cell_fill = '5'; $cell_margin_with_paren = [ 0.0, 2.0, 2.5, 0.0 ]; # Following list are the catalogues # to be extracted from the FrameMaker # template if required. %required_catalogs = ( 'Units' = 1, 'CharUnits' = 1, 'ColorCatalog' = 1, 'ConditionCatalog' = 1, 'CombinedFontCatalog' = 1, 'PgfCatalog' = 1, 'FontCatalog' = 1, 'RulingCatalog' = 1, 'TblCatalog' = 1, 'VariableFormats' = 1, 'MarkerTypeCatalog' = 1, 'XRefFormats' = 1,