Re: get list from database, email list
Johnson, Shaunn [[EMAIL PROTECTED]] quoth: *>Hi again: *> *>This is my first attempt at trying to pull info from a *>database ... but this is my goal: Examples are likely the best and fastest way to get a handle on something like this. I use the following hack to select cpan mirrors out of the db and mail out a notice to the mirrors that match the criteria. It's ugly, but it works :) I also highly recommend the DBI book http://dbi.symbolstone.org/ and all the examples from the DBI book are on-line http://examples.oreilly.com/perldbi/ e. #! /usr/local/bin/perl -w use DBI; use strict; my $dbh = DBI->connect( "your connect info here" ); my $sth = $dbh->prepare( " SELECT name,contact,retiredate,status FROM yourtable WHERE retiredate='' AND status='good' " ); $sth->execute(); while ( my ($name,$contact,$retiredate,$status) = $sth->fetchrow_array ) { open(SENDMAIL, "|/usr/lib/sendmail -t -f your\@email.address") || die("can't fork SENDMAIL: $!"); print SENDMAIL
UPDATE: RE: get list from database, email list
Update: I think I may be closer than I thought! In the original code, I *thought* I was bringing back the entire select output. I *believe* I was only bringing in one row. I am trying to recreate it by testing from another table. It brings the first row; but now, the 'fetchrow' part of it *seems* to be working, but it's only 'fetching ONE row'... How do I bring back an entire array / list from the select statement I just made? [code] #!/usr/bin/perl $debug=2; # Attempting to edit this so that email can be # set to user community (from sys_users) without # needing to get a list of users and THEN emailing them # created 14 Dec 01 -X use CGI qw(:standard); use Pg; require "/var/www/hminclude.pl"; $conn=dbOpen("dbname=database"); # hopefully, this get my column of email addresses # and puts it into an array for me to use later $contract=doquery('Contract Members'," select contract from mbr"); ($contract)=$contract->fetchrow; $users=doquery('Email Community'," SELECT email FROM users WHERE email ~* '[a-z]' ORDER BY upper(email) "); ($users)=$users->fetchrow; #while (($email)=$users->fetchrow) { # $new_users=$users; #}; # set the date open DATE, "date |"; $date=; chop $date; # should be the address of sender and users $addr='[EMAIL PROTECTED]'; $users=$result; #$message=param('message'); $boundary='!*@^$% Apache web server MIME boundary %$^#&@*!'; open MAIL, "|/usr/lib/sendmail -oi -t -odq " || print "no sendmail\n"; print MAIL < To: $addr Date: $date Subject: Apache mailing list request Mime-Version: 1.0 Content-type: multipart/mixed; Boundary="$boundary" Content-Disposition: inline --$boundary ontent-type: text/html; charset=us-ascii Content-Disposition: inline This is a list or message that would go to the list of users if we need to send them something. For your reference, the query executed is shown below: #$new_users $users $contract EOF ; close(MAIL) || print "can't close mail\n"; print "mail has been sent\n"; __END__ [/code] TIA -X
Help reqd.
> I have to make a script which will read a log file and find for error , > the string is like "err=0" if the no. is > 0 then I want the first coloumn > of line that's time stamp redirected to some other file or I can define > some RE that if err=2 , do this. > > Secondly the log file is rotaional and it keeps on increasing , can I do > some incremental chk on the file.? > TIA > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: If question
if (condition or condition) { do that; } ex: if ($foo = 3 or $foo = 6) {} if ($foo = 3 || $foo = 6) {} if ($foo eq "bar" or $foo eq "baz") {} if ($foo eq "bar" || $foo ne "baz") {} etc etc HTH Etienne Lance Prais wrote: > > Is it possible in Perl to compose and IF Statement as follows: > > if [condition] or [condition] > > Do this > > else > > Do this > > I know you can do the this > > IF [condition] > > else > > My question is it possible to add the extra or condition? > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] -- Etienne Marcotte Specifications Management - Quality Control Imperial Tobacco Ltd. - Montreal (Qc) Canada 514.932.6161 x.4001 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
get list from database, email list
Hi again: This is my first attempt at trying to pull info from a database ... but this is my goal: A few days ago, I was having problems emailing a list of users ('documentation about perl / email' ... thanks to Brett and Jenda for the pointers) and I got to thinking, "Why not go directly to the database, get the list of users and append \@domain.com at the end and send the message on it's way?" In my current script, however, I'm trying to figure out how to email myself the result of a select statement from a database. I think I'm shooting myself with a water pistol repeatedly. [code] #!/usr/bin/perl # Attempting to edit this so that email can be # set to user community (from users table) without # needing to get a list of users in a text file # and THEN emailing them # created 14 Dec 01 -X use CGI qw(:standard); use Pg; require "/var/www/hminclude.pl"; $conn=dbOpen("dbname=database"); # hopefully, this get my column of email addresses $result=doquery('Email Community'," SELECT email FROM users WHEREemail ~* '[a-z]' ORDER BY upper(email) "); # set the date open DATE, "date |"; $date=; chop $date; # should be the address of sender and users $addr='[EMAIL PROTECTED]'; $users=$result; #$message=param('message'); $boundary='!*@^$% Apache web server MIME boundary %$^#&@*!'; open MAIL, "|/usr/lib/sendmail -oi -t -odq " || print "no sendmail\n"; print MAIL < To: $addr Date: $date Subject: Apache mailing list request Mime-Version: 1.0 Content-type: multipart/mixed; Boundary="$boundary" Content-Disposition: inline --$boundary ontent-type: text/html; charset=us-ascii Content-Disposition: inline This is a list or message that would go to the list of users if we need to send them something. For your reference, the query executed is shown below: $users EOF ; close(MAIL) || print "can't close mail\n"; print "mail has been sent\n"; __END__ [/code] The SQL part works. The mail part works. But I'm not pulling (or trapping) the data that I want. The only thing I get is a message that says: [message] This is a list or message that would go to the list of users if we need to send them something. For your reference, the query executed is shown below: `PG_results=SCALAR(0x81a82a0)` [/message] How does that work? I don't understand how to query and have perl KEEP the data in some variable for me to print (or use) later. I'm not even sure how to check to see if I'm even connecting properly. By the way, I'm sorta looking at examples and attempting to 'learn as I go' ... yeah, I know. I need a better method of learning ... TIA -X
Re: If question
--- Lance Prais <[EMAIL PROTECTED]> wrote: > Is it possible in Perl to compose and IF Statement as follows: > > > if [condition] or [condition] > > Do this > > else > > Do this Lance, Yes, you can do this. Here's one way: my $x = 7; if ( $x > 5 or $foo eq 'bar' ) { # do this } else { # do the other thing }; Cheers, Curtis "Ovid" Poe = Senior Programmer Onsite! Technology (http://www.onsitetech.com/) "Ovid" on http://www.perlmonks.org/ __ Do You Yahoo!? Check out Yahoo! Shopping and Yahoo! Auctions for all of your unique holiday gifts! Buy at http://shopping.yahoo.com or bid at http://auctions.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: client-server communication
Hello Michael, Wednesday, December 12, 2001, Michael McQuarrie <[EMAIL PROTECTED]> wrote: MM> I am trying to get a client to communicate with a server located MM> on another host. I can get the 2 to connect, the server to send MM> data, and the client to receive the data on the other end but I MM> can not get the client to respond to the server. I am a beginner MM> with this so I don't really know where the problem would lie, MM> hopefully one of you do. I got most of this from examples. Here is MM> the server piece followed by the client. Thanks in advance. unfortunatelly, you've got bad examples... take a look at perldoc perlipc , which contains working client/server samples. Best wishes, Maximmailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: If question
Yes. Need to be careful in use of or/and or || / &&. They have different precedence. Use ()'s to control if in doubt. if ( condition1 or condition2 or condition3 ) { }elsif ( other condtions) { }else { } Wags ;) -Original Message- From: Lance Prais [mailto:[EMAIL PROTECTED]] Sent: Friday, December 14, 2001 14:24 To: [EMAIL PROTECTED] Subject: If question Is it possible in Perl to compose and IF Statement as follows: if [condition] or [condition] Do this else Do this I know you can do the this IF [condition] else My question is it possible to add the extra or condition? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Question about using an IF statement in searching a sub string
It's not clear from your post if you should expect $line to have a value when it encounters the if statement. You might find a 'print "<$line>\n";' right before the if statement really informative. The angle brackets are just in case $line is undef and you don't have warnings turned on. Peter C. -Original Message- From: Lance Prais [mailto:[EMAIL PROTECTED]] Sent: Friday, December 14, 2001 12:55 PM To: [EMAIL PROTECTED] Subject: Question about using an IF statement in searching a sub string I am using the following section of code to search a sub string to see a word is present: for(my $i=0; $i<22; $i++){}; #This will put you at row 23. $_=; my $line=$_; print substr($line, 42, 7); It returns: Running- which it should but if I use the following statment it always fails. Can you see the problem with this if statement? if (substr($line, 42, 7) eq'"Running"') #if statment to see if "Running" is present { while () { #Just to output some data to test chomp; #a) my $line=$_; print STDERR "\nline: $line"; } } else { #send email } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
If question
Is it possible in Perl to compose and IF Statement as follows: if [condition] or [condition] Do this else Do this I know you can do the this IF [condition] else My question is it possible to add the extra or condition? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
soft return
Hello all, I am new to here. Here is my question: what kind of line seperator in Linux text file can be recognized by MacOS text editor, e.g. Nisus Writer, as "soft return"? Thanks, Xiaodong __ Do You Yahoo!? Check out Yahoo! Shopping and Yahoo! Auctions for all of your unique holiday gifts! Buy at http://shopping.yahoo.com or bid at http://auctions.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Copy files from a location
On Thu, Dec 13, 2001 at 06:42:17AM -0600, Michael Pratt wrote: > Does anyone know how to go and get a file (with wild cards too) and dump > them to a specifed directory on a local machine from the internet. weather > it be ftp or http protocol? If so can I get an example? You probably want LWP::Simple; you can find it on CPAN. The documentation is pretty straightforward, and it will work with the ftp and http protocols, as well as various others. Michael -- Administrator www.shoebox.net Programmer, System Administrator www.gallanttech.com -- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to make a local variable a global variable in Perl
On Wed, Dec 12, 2001 at 05:42:11PM +0100, Jorge Goncalvez wrote: > Hi I have this code: > ... > sub MakeEth() > { > unless ($_Globals{NICIP_ADRESS}==$IPREAL[0]) > { > $_Globals{ETH_NETIF} eq "eth0"; You must have meant "=", not "eq", as in: $_Globals{ETH_NETIF} = "eth0"; > } > else{ > > $_Globals{ETH_NETIF} eq "eth0:1"; Same here: $_Globals{ETH_NETIF} = "eth0"; > > } > } > > ... > > sub StartDhcp() > { > my $_cmd = $_Os{$_Globals{OS}}{DHCPD} . " " . $_Globals{ETH_NETIF}; > system($_cmd); > } > > I wanted to make $_Globals{ETH_NETIF} affected by what it is in the scope > MakeEth because in the sub StartDhcp $_Globals{ETH_NETIF} is undef I would to > make it a variable global after been affected by sub MakeEth. You did not make %_Globals local to the MakeEth subroutine, so it is be default global. If you weren't seeing the results of the assignment it's because you were using "eq" instead of "=". "eq" is a comparison operator, "=" is the assignment operator. Michael -- Administrator www.shoebox.net Programmer, System Administrator www.gallanttech.com -- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
substr eq to string [was (incorrectly) Re: Summarizing tables]
"Lance Prais" <[EMAIL PROTECTED]> writes: > if (substr($line, 42, 7) eq'"Running"') #if statment to see if "Running" is if (substr($line, 42, 7) eq "Running" ) Because you had single quotes, you were looking for the string "Running" (*with* the double quotes around it - *9* characters). -- Michael R. Wolf All mammals learn by playing! [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Environment Variables..
On Wed, Dec 12, 2001 at 02:10:37PM +1000, Lorne Easton wrote: > As in the attached code: The variables do not "unlink" when the program > exits or when I specify to unlink. What variables? What do you mean by unlink? Do you mean the variables are removed from memory? Provided you're running this as a standalone program, and not embedded in something (say, mod_perl), then the variables, and any other memory the program is using, will be reclaimed by the system when the program exits. This is not something you have control over; it's handled by the operating system, not the program. > I.E: If I run this program once, then run it again with incorrect domain > specified it gives the same information. This is likely an issue with Win32::NetAdmin, or Windows itself. Perhaps you're getting some default that just happens to be what you asked for previously. Or perhaps Windows is remembering your previous request, and handing it back again. Michael -- Administrator www.shoebox.net Programmer, System Administrator www.gallanttech.com -- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Question about using an IF statement in searching a sub string
On Dec 14, Lance Prais said: >if (substr($line, 42, 7) eq'"Running"') #if statment to see if "Running" is You're using too many quotes. The value isn't `"Running"', but rather `Running'. if (substr($line, 42, 7) eq 'Running') { ... } or if (substr($line, 42, 7) eq "Running") { ... } -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for "Regular Expressions in Perl" published by Manning, in 2002 ** what does y/// stand for? why, yansliterate of course. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Question about using an IF statement in searching a sub string
if (substr($line, 42, 7) eq "Running") #best to use or if (substr($line, 42, 7) =~ /Running/) assuming it's Running (without quotes) and not "Running" (with quotes) that you are looking for Etienne Lance Prais wrote: > > I am using the following section of code to search a sub string to see a > word is present: > > for(my $i=0; $i<22; $i++){}; #This will put you at row 23. > $_=; > my $line=$_; > print substr($line, 42, 7); > > It returns: Running- which it should > > but if I use the following statment it always fails. Can you see the > problem with this if statement? > > if (substr($line, 42, 7) eq'"Running"') #if statment to see if "Running" is > present > { > while () > { #Just to output some data to test > chomp; #a) > my $line=$_; > print STDERR "\nline: $line"; > } > } > else > { > #send email > } > > > -- > 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] -- Etienne Marcotte Specifications Management - Quality Control Imperial Tobacco Ltd. - Montreal (Qc) Canada 514.932.6161 x.4001 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Question about using an IF statement in searching a sub string
I am using the following section of code to search a sub string to see a word is present: for(my $i=0; $i<22; $i++){}; #This will put you at row 23. $_=; my $line=$_; print substr($line, 42, 7); It returns: Running- which it should but if I use the following statment it always fails. Can you see the problem with this if statement? if (substr($line, 42, 7) eq'"Running"') #if statment to see if "Running" is present { while () { #Just to output some data to test chomp; #a) my $line=$_; print STDERR "\nline: $line"; } } else { #send email } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Summarizing tables
I am using the following section of code to search a sub string to see a word is present: for(my $i=0; $i<22; $i++){}; #This will put you at row 23. $_=; my $line=$_; print substr($line, 42, 7); It returns: Running- which it should but if I use the following statment it always fails. Can you see the problem with this if statement? if (substr($line, 42, 7) eq'"Running"') #if statment to see if "Running" is present { while () { #Just to output some data to test chomp; #a) my $line=$_; print STDERR "\nline: $line"; } } else { #send email } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: command-line way to search contents of files
You might want to check for the '-r' option in your system's grep command. On my Linux system and under Cygwin I can do something like grep -r 'search string' ./* or the '-d recurse' option should do the same thing. Good luck, Peter C. -Original Message- From: Thomas S. Dixon [mailto:[EMAIL PROTECTED]] Sent: Friday, December 14, 2001 5:36 AM To: [EMAIL PROTECTED] Subject: command-line way to search contents of files Greetings gurus, I've worked with perl somewhat for the past year, but never via the command line. I'd like to know if there's a short command-line way to search a given directory (recursively) for files containing a certain text string. I would think this would be some combination of a loop and grep, but I'm not quite sure where to start. This is perl 5.6.0 running on a linux system. Thanks, Tommy -- 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]
"IEExamples is not a valid short file name"
To the PERL community, I downloaded the file ActivePerl-5.6.1.630-MSWin32-x86 and installed it on my computer (Windows 98, P3). to test a batch client for BLAST application in molecular biology which uses PERL. I want to test the system if it fits to my applications. I was able to start the program and perform my first BLAST search. Now three days later I tried to follow my trial but failed when starting the PL File Win32-search-launcher2.8. I got a message: IEExamples is not a valid short file name. Can you all please help me to bring my trial to a successful end? Thanks very much in advance, Frank Maier e-mail: [EMAIL PROTECTED] _ Dr. Frank J. Maier Institute of General Botany (AMP III) University of Hamburg 22609 Hamburg Ohnhorststrasse 18 Phone: ++40/42816-393 Fax: ++40/42816-513 Handy: 0173/ 4532447 Private: ++4162/ 1561 e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: question on finding a word
> I am using the following piece of code to check > to see if on line 23 the word 'Running' appears > between pos 11 and 19. > > I have two questions. > > 1. Is this the correct format to do this? The style police are being kept at bay by unrulely Perl users, who keep chanting "There's More Than One Way To Do It". ;-) However, sometimes another approach is easier to maintain/read, so please allow me to have a go. My version looks like: # Open workflow.txt (better if we knew what this file was). open (WORKFLOW, '..\..\workflow.txt') or die "Cannot open Workflow $!\n"; # Extract 23rd line. my $line; do {$line = } until $. == 23 || eof; unless ($. == 23) { die "workflow.txt isn't even 23 lines long!\n" }; # Find position of "Running" after, but starting at position 11. my $position = index($line, "Running", 11); # Unless it appears between positions 11 and 19 we wish to send an email. if ($position == -1 or $position > 19) { # Send that email NOW! } # Close the file now we are finished. close (WORKFLOW) or die "Cannot close Workflow $!\n"; > 2. How can I just output that area that I am > checking to make sure it is looking at the > right place? My version should work just fine, but if you want try: $. = 20; do {print "$.: " . } until $. == 26 || eof; Enjoy, Jonathan Paton __ Do You Yahoo!? Everything you'll ever need on one web page from News and Sport to Email and Music Charts http://uk.my.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Not creating home dir....
Adding an entry to /etc/passwd on Unix/Linux does not add a home directory for that user. adduser or useradd or even linuxconf (depending on your flavor/distribution) takes care of that, but it is a seperate act from adding a user to /etc/passwd. That said you do have to add the directory yourself, which is not necessarily a bad thing, since not all users require a home directory, and you have complete control over where the directory is created, if at all. You could even add a few lines to your script to handle special cases, i.e. non-real users, certain groups etc. :-) On Thursday 13 December 2001 08:53 pm, Daniel Falkenberg rambled: > Hi all, > > I mean to do what I want I had to add the following system command is > there and easier way to do the following code add on...? > > #!/usr/bin/perl -w > > use Unix::PasswdFile; > > my $new_user = "test7"; > my $new_fname = "Test"; > my $new_lname = "Account"; > my $new_pass = "password"; > > my $pw = new Unix::PasswdFile "/etc/passwd"; > $pw->user("$new_user", $pw->encpass("$new_pass"), $pw->maxuid + 1, 45, > "$new_fname $new_lname", "/home/$new_user", "/bin/false"); > $pw->passwd("$new_user", $pw->encpass("$new_pass")); > $pw->commit(); > undef $pw; > system("pwconv $new_user"); > system("mkdir /home/$new_user"); > system("chown $new_user /home/$new_user"); > system("chgrp popusers /home/$new_user"); > > Thx, > > Dan > > Hello all, > > Could some one help me with the following code? Basically the code > works OK except for the fact that the user $new_user (s) home dir is not > created? > > #!/usr/bin/perl -w > > use Unix::PasswdFile; > > my $new_user = "test7"; > my $new_fname = "Test"; > my $new_lname = "Account"; > my $new_pass = "password"; > > my $pw = new Unix::PasswdFile "/etc/passwd"; > $pw->user("$new_user", $pw->encpass("$new_pass"), $pw->maxuid + 1, 45, > "$new_fname $new_lname", "/home/$new_user", "/bin/false"); > $pw->passwd("$new_user", $pw->encpass("$new_pass")); > $pw->commit(); > undef $pw; > system("pwconv $new_user"); > > Am I missing something here? > > Regards, > > Dan -- Michael D. Risser Software Engineer/Linux Administrator = Machine Vision Products, Inc. www.visionpro.com [EMAIL PROTECTED] -BEGIN PGP PUBLIC KEY BLOCK- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org mQGiBDuCrxARBADE9hdFrBY4oQG8dnGZo6HV1pPXdiS1yVhDA1Hp0nTcmhsAdBtu udBPkwwrVKATJYWQsRYBwbjE9WhyeGKXW95BkeUfDQo6YJBGBaeZSnfJhugdnoEv +UB3c7McRenM6dN0oeDBWhcylTMpdUEbM9BG3pHUrKIh/TECDESWsS2PRwCgkGMy HTSPVa3xzwAyt4C5FPINSkcEALHAysCwpYou3n1BOjjIR/lc2Wg9jMDxCL5Kf5qh JIfvPu5Ew/NjkcTtoUrF8Ag4++3/D9jaHpFiUvp5xKtd/CjI+zQmWYvan3Qa5D6D ZXNAvQzDpHMQ0PNed4lD6+a2unfMI22yh57WZ51nKajSGi3kbRd+564ZdM3BC3tU 30eaA/9uwrGaTCKUpku9Q7xOXRUTQOzPKMuUkGrHK84Fea8BhRYm3P/im6+mgKPu OeAZuxTX3KD8WyTz3wPc3C9RVkcOeii90r8AbztYFa3jq7ryAxXuIAJClDyvmVxz 0i0/QsUG7Qmh3bSqSEE8j0wS1d+oCK0vys/kzPQu4BlSIZYlArQ9TWljaGFlbCBE LiBSaXNzZXIgKFNvZnR3YXJlIEVuZ2luZWVyKSA8bWljaGFlbEB2aXNpb25wcm8u Y29tPohXBBMRAgAXBQI7gq8QBQsHCgMEAxUDAgMWAgECF4AACgkQ/ikO9QMSg3cj CwCfUw/OvLdfH3J6wDkgJkgwIZdJgmgAn1PAfxKjgiFXcteIpUtN6s988k1CuQEN BDuCrxIQBADw8yDbbWdO9pvyUpdWjWxTBBFo9eQexJFFap4b9KcpWDJWawZ6S/HU Cn+7zfbFb43AZa21mlon/vr7nwvlll7P/fa9S4kvk5twM8PcwM9O9yVxhOZeInXR NUBzqjpK8FfRZgt1TaOz/CpdacNAJ9i2cShvH6wcCbHxGL9rjAu+IwADBgQA0t8p 1ivBcABEmK4o+r5+uXZoQ4jUzDDN5bZmddQOQhyyMX/JUeBX7gxQ7r2cYJHIlcN+ FCeqUHLmgQ/Ky+gze61Yr+FeEBJ4EPklkHWu3RoS4aKlEtU688nm+8Mfph6nYl+n HzmaZjf5hz/mqvs5bzBCrw+xSSjNhJBrmj8qzIqIRgQYEQIABgUCO4KvEgAKCRD+ KQ71AxKDd2/JAJ9vnTOSbmB2XceA4gBaOsZg06s5lQCfYfRtXoy/Mbw82eS19NE/ w9t+V8g= =J9H/ -END PGP PUBLIC KEY BLOCK- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Summarising tables
"John W. Krahn" <[EMAIL PROTECTED]> writes: > #!/usr/bin/perl -w > use strict; > > my %data; > for my $file ( '/data/table1', '/data/table2' ) { > open IN, "< $file" or die "Cannot open $file: $!"; > while ( ) { > my ( $time, $in, $out ) = split; > $data{ $time }[0] += $in; > $data{ $time }[1] += $out; > } > close IN; > } Letting the empty diamond operator work on @ARGV would prevent you from having to code the open/close. That's the plus side. The minus side is that you don't have control over the open failure, so you have to be happy with the built-in version. This code is *different*, not *better* --- my %data; @ARGV = qw(/data/table1 /data/table2); while(<>) > my ( $time, $in, $out ) = split; > $data{ $time }[0] += $in; > $data{ $time }[1] += $out; } -- Michael R. Wolf All mammals learn by playing! [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: URL encoder
On Dec 14, Imtiaz ahmad said: >URL: >http://click.linksynergy.com/fs-bin/click?id=t14yfqjbQ8Q&offerid=28782.1 >049&type=4&subid=0 >Encoded URL: >http%3A%2F%2Fclick.linksynergy.com%2Ffs-bin%2Fclick%3Fid%3Dt14yfqjbQ8Q%26off >erid%3D28782.1049%26type%3D4%26subid%3D0 You want the aptly named module URI::Escape. It looks like you want to escape most characters. use URI::Escape; $URL = '...'; $safe = uri_escape($URL, '^A-Za-z0-9.-'); print $safe; -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for "Regular Expressions in Perl" published by Manning, in 2002 ** what does y/// stand for? why, yansliterate of course. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
URL encoder
Hi- Is there any program that allows you to encode URLs. Here is an example: URL: http://click.linksynergy.com/fs-bin/click?id=t14yfqjbQ8Q&offerid=28782.1 049&type=4&subid=0 Encoded URL: http%3A%2F%2Fclick.linksynergy.com%2Ffs-bin%2Fclick%3Fid%3Dt14yfqjbQ8Q%26off erid%3D28782.1049%26type%3D4%26subid%3D0 thanks. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Cookies on IE
Hello, In Internet Explorer, how do I turn on/off "cookies"? __ William -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: question on finding a word
On Dec 14, Lance Prais said: >I am using the following piece of code to check to see if online 23 the >word 'Running' appears between pos 11 and 19. Whenever you have specific information like that, a regex is often not the best approach to take. >#open a file with the filehandle >open WORKFLOW, "+<..\\..\\workflow.txt" or die "Cannot open Workflow $!\n"; >my $data = for (1..21); #Testing to make sure I am This discards lines 1 through 21. I thought you wanted to discard the first 22 lines. >seek(WORKFLOW, 22, 0); #This will put you at row 23.--- This is not what seek() does. seek FH, OFFSET, WHENCE; OFFSET is some number of bytes (not a line number), relative to WHENCE -- if WHENCE is 0, it's OFFSET bytes from the beginning of the file, if WHENCE is 1, it's OFFSET bytes from the current position in the file, and if WHENCE is 2, it's OFFSET bytes (you usually want OFFSET to be negative in this case) from the end of the file. Your call puts you 22 bytes from the beginning of the file. Not what you wanted. If you want to skip the first 22 lines of a file, just do: for 1 .. 22; >$_=; >/("Running")/; #Now if you want, you can also check > #to make sure that this was found in > #the right column by checking @- and @+ >if($-[0] == 10 && $+[0] == 18) You don't need parens around "Running" in your regex. And instead of using a regex here, why not simply test like so: $_ = ; if (substr($_, 10, 8) eq '"Running"') { # ... } You should also never use a regex in void context -- if it fails, you'll get the results from the previous successful regex shining through: "jeff" =~ /(ef+)/; print $1; # "eff" "joe" =~ /(ef+)/; print $1; # "eff" -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for "Regular Expressions in Perl" published by Manning, in 2002 ** what does y/// stand for? why, yansliterate of course. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
question on finding a word
I am using the following piece of code to check to see if online 23 the word 'Running' appears between pos 11 and 19. I have two questions. 1. Is this the correct format to do this? 2. How can I just output that area that I am checking to make sure it is looking at the right place? Thank you #open a file with the filehandle open WORKFLOW, "+<..\\..\\workflow.txt" or die "Cannot open Workflow $!\n"; my $data = for (1..21); #Testing to make sure I am #grabbing the correct data seek(WORKFLOW, 22, 0); #This will put you at row 23.--- $_=; /("Running")/; #Now if you want, you can also check #to make sure that this was found in #the right column by checking @- and @+ if($-[0] == 10 && $+[0] == 18) { #Send and email if the word is not found } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to interface perl with mysql
I'd say you've a bad DBI install. Does this script print the DBI version number? #!/usr/bin/perl use DBI; print "$DBI::VERSION\n"; @driver_names= DBI->available_drivers(); print "the drivers are : @driver_names"; exit; perl -w t.pl 1.20 the drivers are : ADO AnyData CSV Chart ExampleP Excel File Multiplex ODBC Oracle Pg Proxy mysql Tom On Thu, Dec 13, 2001 at 11:08:36PM -0800, Herry Sukardi wrote: > Hi all, > > I have a problem interfacing Mysql with perl. I used > red Hat linux 7.0 as the OS and it comes with perl > built in (perl-5.6.0-9). I installed MySQL server and > client downloaded from its web site (www.mysql.org), > the versions are: MySQL-3.23.44-1 and > MySQL-client-3.23.43-1. > I also installed modules that I think will be required > for interfacing mysql and perl ie. the DBI and DBD. > They are: Mysql-DBI-perl-bin-1.1825-1 and > DBI-perl-bin-0.93-1 > I get the following error: > 'Can't locate object method "available_drivers" via > package "DBI" at ./test line 3' > > When I run a script with @dbh=DBI->connect(.) > I also get smilar error of 'Can't locate object method > "connect" via package "DBI"' > Do I miss something ? Have I installed DBI correctly ? > How do I test the DBI ? Please help... > _ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
How can I get ahold of the DBI file needed for a ActiveState ppm install?
I have to put DBI and the DBD::ODBC driver on a Windows 2000 Server machine that's running Active State perl. The tricky thing is, the machine is not on the Internet, so I can't use the built in ppm utility to automagically go out and retrieve the ppd files that are used by ppm to build and install the modules. But, if I could grab those ppd files, I could burn them onto a CD, change the repository path on ppm to point at the CD drive, and I'd be in business. My problem is, I can't figure out how to actually get the ppd files. I've searched all through www.activestate.com and can't find them, and the CPAN repositories seem to just have the tar.gz version of the modules. Does anyone have any ideas? Chris Spurgeon Senior Design Technologist [EMAIL PROTECTED] This e-mail is intended solely for the above-mentioned recipient and it may contain confidential or privileged information. If you have received it in error, please notify us immediately and delete the e-mail. You must not copy, distribute, disclose or take any action in reliance on it. In addition, the contents of an attachment to this e-mail may contain software viruses which could damage your own computer system. While Electronic Ink, Inc. has taken every reasonable precaution to minimize this risk, we cannot accept liability for any damage which you sustain as a result of software viruses. You should perform your own virus checks before opening the attachment. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Best DBI for newbie
using DBD::ADO: set DBI_DSN=dbi:ADO:Provider=SQLOLEDB.1;Persist Security Info=False;Initial Catalog=pubs;Data Source=STLNTWK1 set DBI_USER=userid set DBI_PASS=passwd Modify Data Source to the host machine name. Tom On Fri, Dec 14, 2001 at 12:14:20AM -0800, scott.lutz wrote: > I am looking for the best way to connect to a MS SQL 7 database from a > remote Win2000 machine. > I have looked at DBI::ODBC.pm / Win32::ODBC.pm, but the documentation is > kinda weak for the win32 ports. > I have used the DBI::Oracle driver, so I can reference that. > > > > > --- Scott Lutz --- > _ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: system function question
Thursday, December 13, 2001, 8:28:53 PM, Mike Gargiullo wrote: > ok... I'm writing a perl program that will use scp to copy a file from > one machine to another securely. > The problem is that scp asks for the users password... how can I have > perl answer scp's request for a password... > by hand it looks like so; > $$scp -C test [EMAIL PROTECTED]:test > [EMAIL PROTECTED]'s password: > test 100% > |*| > 0 --:-- ETA > $$ > I would like to run the command like: > system("scp -C test [EMAIL PROTECTED]:test"); > But how do I then feed it the password for user bob ? there's a module called Net::SCP, which does scp in perl. it says: Q: How do you supply a password to connect with ssh within a perl script using the Net::SSH module? A: You don't. Use RSA or DSA keys. See the ssh-keygen(1) manpage http://theoryx5.uwinnipeg.ca/CPAN/data/Net-SCP/SCP.html although if you're determined to do it the other way, you could look at the Expect module: http://search.cpan.org/search?dist=Expect -- Best Regards, Daniel [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Not creating home dir....
Friday, December 14, 2001, 1:37:00 AM, Daniel Falkenberg wrote: > Could some one help me with the following code? Basically the code > works OK except for the fact that the user $new_user (s) home dir is not > created? > #!/usr/bin/perl -w > use Unix::PasswdFile; > my $new_user = "test7"; > my $new_fname = "Test"; > my $new_lname = "Account"; > my $new_pass = "password"; > my $pw = new Unix::PasswdFile "/etc/passwd"; $pw->>user("$new_user", $pw->encpass("$new_pass"), $pw->maxuid + 1, 45, > "$new_fname $new_lname", "/home/$new_user", "/bin/false"); $pw->>passwd("$new_user", $pw->encpass("$new_pass")); $pw->>commit(); > undef $pw; > system("pwconv $new_user"); > Am I missing something here? i haven't used the module, but looking at the documentation it doesn't say anything about creating the user's home directory. it looks like you can use Unix::PasswdFile to set the right entries in /etc/passwd, but you'll have to make sure the directories are there through other methods. -- Best Regards, Daniel [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: command-line way to search contents of files
check man perlrun im not sure what you're after, if it's just grep i'd suggest find . -type f -exec grep foo {} \; if you wanna do something about foo find . -type f -exec perl -pi -e 's/foo/bar/g' {} \; /Jon "Thomas S. Dixon" wrote: > > Greetings gurus, > I've worked with perl somewhat for the past year, but never via the > command line. I'd like to know if there's a short command-line way to > search a given directory (recursively) for files containing a certain > text string. I would think this would be some combination of a loop and > grep, but I'm not quite sure where to start. This is perl 5.6.0 running > on a linux system. > > Thanks, > Tommy > > -- > 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]
command-line way to search contents of files
Greetings gurus, I've worked with perl somewhat for the past year, but never via the command line. I'd like to know if there's a short command-line way to search a given directory (recursively) for files containing a certain text string. I would think this would be some combination of a loop and grep, but I'm not quite sure where to start. This is perl 5.6.0 running on a linux system. Thanks, Tommy -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Opening multiple files in a directory
You can use perl's glob operator (type perldoc -f glob at the command prompt for help) Wrap your script, except the exit(0) by while (<$some_dir_name/*.txt>) { # Assuming you are searching for .txt files. } hth, Sudarsan pn wrote: > Hello, > > My question: I would like to be able to have the > automically open all the files in a given directory, > one at a time, perform the "sed" operations, and then > save them to the directory. How can I do this ? > > Here is the script: > > #!/usr/bin/perl -w > > open (IN,"< orig_names.txt"); > open (OUT,">mod_names.txt"); > > while () { > chomp; > if ($_=~/^lname/i) { > > s/holt/henning/; > s/shultz/stultz/; > > } > > } > close (IN); > close (OUT); > exit(0); > > I would greatly appreciate your help in this regards. > > Thanks > > PN -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Opening multiple files in a directory
Hello, I have a script that opens a file, performs some "sed" operations, and then saves the edited file to a new file name. Currently, I have to supply the names of input and output files, within the script. My question: I would like to be able to have the automically open all the files in a given directory, one at a time, perform the "sed" operations, and then save them to the directory. How can I do this ? Here is the script: #!/usr/bin/perl -w open (IN,"< orig_names.txt"); open (OUT,">mod_names.txt"); while () { chomp; if ($_=~/^lname/i) { s/holt/henning/; s/shultz/stultz/; } } close (IN); close (OUT); exit(0); I would greatly appreciate your help in this regards. Thanks PN __ Do You Yahoo!? Check out Yahoo! Shopping and Yahoo! Auctions for all of your unique holiday gifts! Buy at http://shopping.yahoo.com or bid at http://auctions.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Summarising tables
On Friday 14 December 2001 04:39, you wrote: > Hi all, > > Need a little help on summarising 2 different tables into 1, based on a > particular field. > > The 2 tables (they are actually content from a log file) look like the > follow : > > Table #1 > > 1006788900 198 36 > 1006788600 29 35 > 1006788300 18 75 > 1006788000 19 65 > 1006787700 42 37 > 1006787400 29 26 > 1006787100 65 84 > 1006786800 6 87 > > Table #2 > > 1006789500 43 47 > 1006789200 23 64 > 1006788900 198 36 > 1006788600 29 35 > 1006788300 18 75 > 1006788000 19 65 > 1006787700 42 37 > 1006787400 29 26 > > They may not be of equal length. The first field is TIME, 2nd is INPUT and > 3rd is OUTPUT. Basically, what I want to do is to summarise the table based > on the first field (TIME). For example, if both tables have TIME as > 1006788600, INPUT and OUTPUT from both tables whose TIME is 1006788600 will > be summed up. Meaning the script needs to go thru the tables to look for > entries with the same TIME, and add the INPUT and OUTPUT together to form > another summaried table. I cannot help you with funky perl... But is a classic programming problem from the days of tape streamers and COBOL. It is called a `merge' , suprisingly. This is a very efficient way to merge large amounts of data. The only gotcha is that the files must be sorted on the merge key (ie TIME), which I am happily asuming since it is a timestamp. There might be the odd ocasion that the input files are not sorted( Machine bounced and the BIOS clock resets itself). Putting a sorted file thru a quick sort uses virtually no resources, and then you will be garanteed to get the correct results. This is a lot more typing but classic algorithms are such joy to code.. (For me anyway); Pseudo code: open file1, file2 (time1, input1, output) = read file1 (time2, input2, output2) = read file1 while not end of file file1 and file2 { if (time1 == time2 { input = input1 + input2 readboth = true; } if (time1 < time2) { input = input1 read1 = true; } if (time2 < time1) { input = input2 read2 = true; } write summary with input if (read1 || readboth ) { if not eof file1 then (time1, input1, output) = read file1 }; if (read2 || readboth ) { if not eof file2 (time2, input2, output2) = read file1 } readboth, read1, read2 = false } Regards Johan -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Summarising tables
Perl wrote: > > Need a little help on summarising 2 different tables into 1, based on a particular >field. > > The 2 tables (they are actually content from a log file) look like the follow : > > Table #1 > > 1006788900 198 36 > 1006788600 29 35 > 1006788300 18 75 > 1006788000 19 65 > 1006787700 42 37 > 1006787400 29 26 > 1006787100 65 84 > 1006786800 6 87 > > Table #2 > > 1006789500 43 47 > 1006789200 23 64 > 1006788900 198 36 > 1006788600 29 35 > 1006788300 18 75 > 1006788000 19 65 > 1006787700 42 37 > 1006787400 29 26 > > They may not be of equal length. The first field is TIME, 2nd > is INPUT and 3rd is OUTPUT. Basically, what I want to do is to > summarise the table based on the first field (TIME). For example, > if both tables have TIME as 1006788600, INPUT and OUTPUT from > both tables whose TIME is 1006788600 will be summed up. Meaning > the script needs to go thru the tables to look for entries with > the same TIME, and add the INPUT and OUTPUT together to form > another summaried table. > > Any easy way for me to do that other than putting the data into > an array or hash table, and compare them entry by entry?? The easiest way would be to use a hash: #!/usr/bin/perl -w use strict; my %data; for my $file ( '/data/table1', '/data/table2' ) { open IN, "< $file" or die "Cannot open $file: $!"; while ( ) { my ( $time, $in, $out ) = split; $data{ $time }[0] += $in; $data{ $time }[1] += $out; } close IN; } for ( sort keys %data ) { print "$_ @{$data{$_}}\n"; } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: system function question
> > ok... I'm writing a perl program that will use scp to copy a file from > one machine to another securely. > > The problem is that scp asks for the users password... how can I have > perl answer scp's request for a password... > > by hand it looks like so; > > $$scp -C test [EMAIL PROTECTED]:test > [EMAIL PROTECTED]'s password: > test 100% > |* > | > 0 --:-- ETA > $$ > > I would like to run the command like: > > system("scp -C test [EMAIL PROTECTED]:test"); > > But how do I then feed it the password for user bob ? I think that you can probably achieve this in a more secure way by altering your scp/ssh configuration. Having a quick look at the man page for my version of scp (running under Cygwin on Windows NT), you can operate scp in batch mode (by giving it the command line argument -B) which prevents it from asking for passwords or pass phrases. I would guess that you would still need an authentication mechanism in place though... It is possible to configure scp/ssh so that instead of needing a password, you use public/private key authentication. 'man ssh' and look at the section on RSA authentication. The advantage of this is that you don't need to store your password in plain text anywhere on you system. Hope this is of some use, Gareth -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Best DBI for newbie
I am looking for the best way to connect to a MS SQL 7 database from a remote Win2000 machine. I have looked at DBI::ODBC.pm / Win32::ODBC.pm, but the documentation is kinda weak for the win32 ports. I have used the DBI::Oracle driver, so I can reference that. --- Scott Lutz ---