Re: mysql driver problem? (slightly off topic)
On 28/04/2005, Graeme McLaren wrote: Hi all, this is slightly off topic but I'm sure someone here has come across this problem. I cannot connect to mysql on my redhat 9 box. I ran: shell perl -MCPAN -e 'install Bundle::DBD::mysql'; and it did say that there was a problem but all I've manged to find out from google is that there maybe some c libraries missing. I don't know where to start with this, I've tried everything I can think of. Have you installed the MySQL-devel RPM, which is a prerequisite for the DBD::mysql installation? -- 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: Installing Downloaded Modules from CPAN
On 05/04/2005, Joel Divekar wrote: I am using Activestate Perl Ver 5.8.4 under Windows 2k and due to firewall I am not able to install packages using ppm / ppm3. Open your ActivePerl HTML documentation and locate PPM in the ActivePerl Components section of the TOC. Scroll down to the PPM, Proxies and Firewalls paragraph. It's explained there: NOTE: If none of the changes in this document work for you, you may download individual packages from here [ActivePerl 801 and later] or here [ActivePerl 613 and later] or here [ActivePerl 522 and earlier] and install them according to the directions in the README file contained within the ZIP file. If you want, you can also keep a local repository, with several .ppd files in a permanent repository directory, and their .tar.gz files in an x86 directory beneath that. -- 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: Lost here.. Use of uninitialized value in print?
On 04/04/2005, [EMAIL PROTECTED] wrote: open (TEXT, list.txt) or die Error. No such file\n; @rawtext=TEXT; close(TEXT); According to your own follow-up, @rawtext will have the following content: $rawtext[0] = '$file1.txt$' . \n; $rawtext[1] = '$file2.txt$' . \n; etc ... $list1 = @rawtext; @rawtext is evaluated in scalar context (because of the scalar lvalue). This gives the number of elements in @rawtext (or equivalent, the number of lines in your file) - this is an integer @files1to5 = split (/\$/, $list1); @files1to5 will have one element, $files1to5[0], containing the number of lines in your file - this is probably not what you want... I would do it like this: #! perl use warnings; use strict; my $infile = 'list.txt'; open (TEXT, $infile) or die $infile: $!; chomp(my @data = map { /^\$(.*)\$$/ } TEXT); close(TEXT); my $prompt = \nPlease enter the file you wish to select (q to quit): ; print $prompt; while ( chomp(my $selecteditem = STDIN)) {; last if $selecteditem eq 'q'; if ($selecteditem =~ /^(1|2|3|4|5)$/) { print You selected item $1, \n$data[$1-1]\n; } else { print Invalid input '$selecteditem'\n; } print $prompt; } (And you won't need the map {...} stuff if your input file doesn't contain the $ before and after the filenames.) -- 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: Program error
On 01/04/2005, GR Kumaran wrote: #!c:/sieperl/perl/5.8.0/bin/MSWin32-x86-perlio/perl use CGI; use warnings; use strict; my $page = new CGI; if (DEBUG) { open(DEBUGFILE, debug.txt) || die; $page-save(DEBUGFILE); close(DEBUGFILE); } Error what I get is Bareword DEBUGFILE not allowed while strict subs in use at test.cgi line 11. Use a reference to your filehandle glob: $page-save(\*DEBUGFILE); From the CGI.pm documentation: Perl purists will be pleased to know that this syntax accepts references to file handles, or even references to filehandle globs, which is the ``official'' way to pass a filehandle: $query = new CGI(\*STDIN); And you haven't defined DEBUG in your program, which give a similar error. -- 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: My own die message
On 30/03/2005, Ankur Gupta wrote: I have the following code : eval{ require file or die unable to find file; }; print $@; But it always prints Can't locate file in @INC. blah blah I want $@ to contain unable to find file. What am I doing wrong or it is not possible to override [EMAIL PROTECTED] The require fails before you die. You will need something like this: eval { require file; } print Your message if $@ $@ =~ m/^Can't locate file/; -- 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: db handles with fork()
On 30/03/2005, Ramprasad A Padmanabhan wrote: I am writing a perl application that connect to a database and then does a fork() The child completes the process and does a exit(), but the problem is it closes the database connection which the parent would like to use. Can I exit the child process without disconnecting the parent dbi handle Have you read the 'InactiveDestroy' entry in perldoc DBI? -- 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: HTML parsing
On 28/03/2005, Daniel Smith wrote: I was tasked with parsing a set of .html files in order to extract the data contained within some terribly formatted tables. [...] Can anyone shed some light? I used HTML::Treebuilder on a similar project once: #! /usr/bin/perl use warnings; use strict; use HTML::TreeBuilder; my $tree = HTML::TreeBuilder-new; $tree-parse_file('yourfile.html') or die Cannot open file: $!; # Get tables my @tables = $tree-look_down( '_tag', 'table' ); for my $t (@tables) { # Get rows my @rows = $t-look_down('_tag', 'tr'); for my $r (@rows) { print Row contents:\n; # Get 'th' and 'td' cells my @cells = $r-look_down('_tag', qr/(th|td)/); for my $c (@cells) { print \t, $c-as_text(), \n; } } } $tree-delete(); -- 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: Net::SSH::Perl error
On 29/03/2005, Lohit wrote: i have installed openssh for windows and am able to connect using ssh client. Now, while trying out Net::SSH::Perl module i get an error at my $sshh= Net::SSH::Perl-new($host); Can't map service name 'ssh' to port number. What happens if you specify the port in your constructor directly: my $sshh = Net::SSH::Perl-new($host, port = 22); -- 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: Module installation problem
On 29/03/2005, GR Kumaran wrote: I'm in Win98, I'd downloaded the SIEPERL from CPAN and installed. And I had downloaded MYSQL DBI also from CPAN, but do not know how to install it into SIEPERL. I had read PPM will do, so I tried 'ppm' alone in command prompt, then I got the following error message. None of my business, of course, but why don't you use ActivePerl? You won't run into these kind of problems if you do. -- 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: Internal links with cgi
On 26/03/2005, Ankur Gupta wrote: a href=http://127.0.0.1/link.cgi#word;word/a. When I click on the link word, I want the link.cgi to execute and then it should navigate to the word word. Add a name=word attribute to you anchor element: a name=word href=word/a -- 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: Web Service Client
On 22/03/2005, Atul Vohra wrote: [Top-posting fixed] Does anybody have a Web Service client in perl (SOAP stuff) to consume a Web Service. I have created Web Services using Remedy (ARS) and now need to write a cleint for the external customer. [...] I was hoping somebody actually handing me code snippets :-) This wasn't too hard to find (where did you look yourself?): http://www.perl.com/pub/a/2001/01/soap.html -- 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: 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
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: checking if its a real number
on Thu, 27 Feb 2003 00:30:56 GMT, [EMAIL PROTECTED] (T. Murlidharan Nair) wrote: I have a cgi that need to accept only numeric values. ie +ve or -ve real numbers. Is there a quick and easy way to check this. This is a FAQ. See perldoc -q float -- feliex -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: checking if its a real number
on Thu, 27 Feb 2003 13:34:40 GMT, [EMAIL PROTECTED] (Zentara) wrote: if (/\D/){ print has nondigits\n } if (/^\d+$/) { print is a whole number\n } if (/^-?\d+$/) { print is an integer\n } if (/^[+-]?\d+$/){ print is a +/- integer\n } if (/^-?\d+\.?\d*$/) { print is a real number\n } if (/^-?(?:\d+(?:\.\d*)?|\.\d+)$/) { print is a decimal number\n } if (/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/) { print a C float\n } It would be considered polite to indicate that you copied this information verbatim from the Perl FAQ. It would be wiser imho to explain to the OP how to find this in the FAQ himself instead of throwing him just one fish. -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: DBI question
on do, 27 feb 2003 16:57:59 GMT, Scot Robnett wrote: I have a script which is supposed to e-mail a user their username/password info as long as their e-mail address is in the database. The following code works if the address is in the database (it prints the approval page and sends the mail with the correct information), but if the address is -not- in the database I get a 500 error. I would do the following (untested!): my $email = $q-param('forgotten_password_email'); my ($username, $password) = $dbh-selectrow_array(qq{ SELECT UserName, UserPass FROM UserData WHERE EmailAddress = ? }, undef, $email); if ($username $password) { # email the new password and show confirmation } else { # show 'email address not found' message } -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: NULL insertion
on Mon, 24 Feb 2003 22:54:59 GMT, [EMAIL PROTECTED] (T. Murlidharan Nair) wrote: I need to insert NULL into the database using a perl CGI . So if a variable is to be made NULL in perl and it needs to be used in an sql statement what is best way to do it. Do I assign ' \N' to it or 'NULL' ? Thanks and Cheers always!! Read the section on 'Null Values' in perldoc DBI -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: help with HTTP::Request for POST
on di, 18 feb 2003 16:43:22 GMT, Scott Lutz wrote: What I am attempting to do, is do a server side form action redirect based on a regex on a field from the form. It now seems that this is just going to POST the form data, and leave the user hanging. Is HTTP::Request the best way to direct the user and the form data to the appropriate page? This is a vary slightly modified version of the example in the docs, and yet it returns no more data than this in my log, though the script is chmod'd 755 : [Mon Feb 17 17:04:05 2003] [error] [client 66.51.160.131] Premature end of script headers: /var/cgi-bin/parse.cgi Any help with what might be missing would be great You are *still* not producing any output... -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: file attributes under Win32
on Tue, 18 Feb 2003 08:42:11 GMT, [EMAIL PROTECTED] (Zeno Jauch) wrote: is it possible to access file attributes in a Win32 environment via Perl. I am interested not only in getting the DOS attributes like creation and modified date, but also the stuff that can be found on the second tab folder of the Properties dialog: File Version, Description, Product Version, etc. http://www.roth.net/perl/adminmisc/#GetFileInfo -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: help with HTTP::Request for POST
on Tue, 18 Feb 2003 00:57:57 GMT, [EMAIL PROTECTED] (Scott Lutz) wrote: This is a vary slightly modified version of the example in the docs, and yet it returns no more data than this in my log : [Mon Feb 17 17:04:05 2003] [error] [client 66.51.160.131] Premature end of script headers: /var/cgi-bin/parse.cgi Any help with what might be missing would be great Your program is not outputting anything. -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: substitute for NTs net use
on Mon, 17 Feb 2003 13:37:57 GMT, [EMAIL PROTECTED] (Joe Mecklin) wrote: Thanks for the info. I appreciate the ideas. Seeing your response, I obviously didn't phrase my request as well as I could have: I'm looking for a Perl module for Linux that allows net use functionality; does anyone know if such a module exists? I believe what is presented here is meant to be installed on a MS system. You will have to use the 'smbclient' command then. Perhaps there are some perl modules that interface with this command. You could try http://search.cpan.org/search?query=sambamode=all -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: linked lists?
on Sun, 16 Feb 2003 18:29:23 GMT, [EMAIL PROTECTED] (Jc) wrote: How would such a thing be done with Perl? This may help me understand C's version a little better. You may want to take a look at O'Reilly's Mastering Algorithms with Perl, by Jon Orwant, Jarkko Hietaniemi and John Macdonald, which has a whole chapter on advanced data structures, including linked lists. -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to resolve properly exception
on Fri, 14 Feb 2003 12:38:16 GMT, [EMAIL PROTECTED] (Khalid Naji) wrote: How can I write exception with Perl ? See, e.g., Object Oriented Exception Handling in Perl by Arun Udaya Shankar, available at http://www.perl.com/pub/a/2002/11/14/exception.html -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Want to find and process all *.csv files
on Fri, 14 Feb 2003 14:39:48 GMT, [EMAIL PROTECTED] (Chuck) wrote: I have ActivePerl 5.6.0 on Win2000 (in a DOS box). I want to find all .CSV files starting in the directory where the perl script is. I have a program but no files are processed. Can someone help me to get this to work? Here is the code: [code snipped] 'File::Find' ne 'Find::File' or why to use strict; -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to get a dir file list sans sub-dir names.
on Thu, 13 Feb 2003 00:21:03 GMT, [EMAIL PROTECTED] (Gan Uesli Starling) wrote: Am wanting to get a list of files in a directory, but only files which are not themselves further sub-directories. When I do this... opendir(DIR, $this_path) or die Can't opendir $this_path: $!; @file_list = glob(*); closedir(DIR); ...it gives all the files, including the files which are also directories. The 'glob' function has nothing to do with the 'opendir/readdir/closedir' functions. Try this: opendir DIR, $this_path; my @file_list = grep { -f } readdir DIR; closedir DIR; See perldoc -f -X for the filetest operators/functions. -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: The email format of this list.
on Thu, 13 Feb 2003 13:17:03 GMT, [EMAIL PROTECTED] (Zeus Odin) wrote: I am trying to avoid Windows. A little help will be greatly appreciated. Point your newsreader at nntp.perl.org. -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Help retrieving data from Win server
on Thu, 13 Feb 2003 14:29:41 GMT, [EMAIL PROTECTED] (Brian McGraw) wrote: ... but I'm kind of stumped as to the best way to retrieve disk space data from my Win machines. Have a look at Dave Roth's Win32::AdminMisc module. http://www.roth.net/perl/adminmisc/#GetDriveSpace I'm using Perl 5.8.0 on a Red Hat server, but the Win servers are not running perl, and since space is at a premium, I can't install it on the machines. Any suggestions? Invest in ActiveState's Perl Dev Kit (it includes PerlApp, a tool to create standalone executables from Perl programs): http://www.activestate.com/Products/Perl_Dev_Kit/ -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: nt event log
on Wed, 12 Feb 2003 15:18:00 GMT, [EMAIL PROTECTED] (Thomas Browner) wrote: Could some one give me example of how to print out nt event log's to an file or screen. If you are using ActivePerl, have a look at the Win32::EventLog module (especially example 1, which seems to do exactly what you want). -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: web server 500 error
on Tue, 11 Feb 2003 06:59:53 GMT, [EMAIL PROTECTED] (Samuel Mauntz) wrote: the error log on the web server spits out this line every time I try to access my script via a browser 63.201.89.246 - - [11/Feb/2003:00:42:48 -0600] GET /cgi-bin/schedule.pl HTTP/1.1 500 546 That line is not from the error log but from the access log. -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Workaround needed for epoch time truncation with gmtime
on Tue, 11 Feb 2003 00:31:22 GMT, [EMAIL PROTECTED] (Chris) wrote: Nice. Do you know a hack? I am limited to a small perl 5.6.1 distro. The hack you are looking for can be found in the source code of the Date::Manip module. -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: if exists with array
on di, 11 feb 2003 17:22:20 GMT, Dan Muey wrote: if(exists $hash{$key}) { ... } is there a way to do that with arrays? IE if there is an array element that is 'bob' then do this :: without having to do a foreach on the array See perldoc -q array contains in the Frequently Asked Questions. -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: if exists with array
on di, 11 feb 2003 15:54:36 GMT, Janek Schleicher wrote: On Tue, 11 Feb 2003 11:22:20 -0600, Dan Muey wrote: is there a way to do that with arrays? IE if there is an array element that is 'bob' then do this :: without having to do a foreach on the array Unless the arrays become too big, grep is your friend (perldoc -f grep) According to the FAQ I mentioned in another reply, it isn't ;-) -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: MySql LAST ID
on ma, 10 feb 2003 19:04:01 GMT, Mario Kulka wrote: $sth = $dbh-prepare (SELECT LAST_INSERT_ID() FROM $table); $sth - execute(); $ad_id = $sth-fetchrow_array(); $sth-finish(); ... The above works fine and gives me the last id, but what worries me is the possibility of someone submitting new record between the lines Insert record and the rest. Is that a valid concern? You don't have to worry about this, because the result of the LAST_INSERT_ID() function is maintained by the server on a per-connection basis. You do have to worry about your 'SELECT LAST_INSERT_ID() FROM atable' syntax though, which does not return what you expect. In fact, it returns as many rows as there are in atable, each containing the value of the auto_increment field generated in the last INSERT statement, regardless which table the INSERT statement whas issued for. -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Install Mod as NON-Root
on ma, 10 feb 2003 21:19:18 GMT, Jeff Westman wrote: How do you install a perl module to your home directory if you do not have root access ?? This a Frequently Asked Question. See perldoc -q own module -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Data Validation Issues
on vr, 07 feb 2003 18:54:25 GMT, Will wrote: Second, suppose they try a username that has already been taken. I need a way to kick back an error message to them. I tried setting the username field in the usrs table to UNIQUE, so that might help if someone tried to insert something already taken... I was thinking that if MySQL kicks back an error message, then DBI might be able to recongize it in such a way that I could use the return value... I dont know if that is completely feasible though... there may be other, better ways anyway... so I'm all ears... I would not rely on an error-message from the database, but check for the existence of a username myself, e.g. like such (untested): my $username = param('username'); # from webform my $dbusername = $dbh-selectrow_array(qq{ SELECT username FROM usertable WHERE username = ? }, undef, $username); if ($dbusername) { # username already in the database } else { # username not yet in the database } -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: changing passwords on nt
on vr, 07 feb 2003 16:50:08 GMT, Thomas Browner wrote: Is there a way to use perl to change nt password. If so could some tell me how to do it. See http://www.roth.net/perl/adminmisc/#SetPassword -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: how to test for numeric user input?
on Wed, 05 Feb 2003 06:52:18 GMT, [EMAIL PROTECTED] (Gary Merrick) wrote: I need to somehow test for user input being numeric. I think. :-) This is a frequently asked question: perldoc -q number/whole my $input = 'undef'; Here you are putting the literal string 'undef' into $input. Did you mean to write my $input = undef; until ($input eq exit) { print \nPlease type one of [list, imdb_number, exit]: ; chomp ($input = STDIN); if ($input eq list) { You don't need double quotes around $input. # do stuff } elsif ($input eq exit) { # Do nothing. You don't want to do nothing here (you want to exit;-) # Without this part, user gets Invalid input message before exiting. } # This part seems to catch any kind of invalid input, and it # never gets # to else. Why? I guess I need to test for # numeric input (if it's not, # it goes to else), and then # see if the number matches one of these: elsif ($input == 0120611||0106308||0088247||0267804||0094074|| 0102798||0120382||0196229||0272152||0109830) { First, since you are comparing strings (note the leading zeroes in your numbers), you need 'eq' instead of '=='. Second, 'eq' (and '==') have higher precedence than '||', so $a eq a || b really means ($a eq a) || b This expression is always true, even if $a is not equal to a, since b is true. You need to write $a eq a or $a eq b If you have a lot of values to compare against, you could use a hash: my %wanted = (); $wanted{$_} = 1 for qw(a b); if ($wanted{$input}) { # do stuff } -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Modifying the string entered
on Wed, 05 Feb 2003 05:04:34 GMT, [EMAIL PROTECTED] (Debraj Bhattacharyya) wrote: Enter the FILENAME : /usr/bin/xyz.sql My question is how to separate the directory path from the filename ,store it in different variables and then go to that particular directory to look for the file ? perldoc File::Spec -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Mysql Connection
on Tue, 28 Jan 2003 01:27:15 GMT, [EMAIL PROTECTED] (Pankaj Kapare) wrote: Hi, I am trying to connect to MYSQL through my perl script.I am using windows 2000 and activeperl. I am using Net::MySQL to connect with database.But it is giving error : Couldn't connect to /tmp/mysql.sock: at E:\PERLTR~1\perl\VALIDA~1.PL line 12 [...] my $mysql= Net::MySQL-new($DBHOST, $DBNAME , $DBUSER, $DBPASS); Try this instead: my $mysql = Net::MySQL-new( hostname = $DBHOST, database = $DBNAME, user = $DBUSER, password = $DBPASS, ); But why are you using Net::MySQL instead of DBI? -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: mail
on Fri, 15 Nov 2002 08:23:57 GMT, [EMAIL PROTECTED] (Thejaswi narayana) wrote: I have an assignment in which i have to separate mails based on the from field. I am working on Linux(Redhat 7.2). I want guidance from u ppl regarding this.I want to know how i can parse a mail header and details of the mail header. http://search.cpan.org/author/VPARSEVAL/Mail-MboxParser-0.35/ -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: md5 encryption.
on wo, 13 nov 2002 18:23:15 GMT, Christopher Burger wrote: Just a quick question. How can encrypt something with md5 encryption. I have passwords in a mysql database that are md5 encrypted. I was wondering if I can use something like $password = md5($input{'password'}; to get the input encrypted and then check against the sql field for proper login. You could use the md5_hex function from Digest::MD5, but there is another way without the need for this module. Suppose you have the following table definition: CREATE TABLE users ( username CHAR(10) NOT NULL PRIMARY KEY, password CHAR(32) NOT NULL ); You can then insert new users with my $sth_add_user = $dbh-prepare( qq{ INSERT INTO users VALUES (?, md5(?))') }); $sth_add_user-execute('Chris', 'Burger'); And you can check whether ($user, $pass) is a valid combination with my $sql_check_password = qq{ SELECT username FROM user WHERE username = ? AND md5(?) = password }; my ($username) = $dbh-selectrow_array($sql_check_password, undef, $user, $pass); if (defined $username) { # OK } else { # Not OK } -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Integrating Perl scripts in VB?
on Tue, 12 Nov 2002 10:11:05 GMT, [EMAIL PROTECTED] (Ben Crane) wrote: anyone know how to use perl scripts WITHIN a VB application? I want to get a directory listing of certain files into a VB array and wanted to use some of my already created perl scripts... Check out ActiveState's Perl Dev Kit at http://www.activestate.com/Products/Perl_Dev_Kit/ -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: how did they do it?
on Tue, 12 Nov 2002 04:47:04 GMT, [EMAIL PROTECTED] (Mariusz) wrote: They give an option to save ads for later display on one page. I looked up the source code and noticed that all their checkboxes have the same name (printad) and the values grow from zero up. That's easy, but how do you later capture which ad to display? When I tried to param the values from several checkboxes named the same but with different values (0,1,2,...) I just got zero from print $checkbox; The following bare-bones code works as advertised: #! /usr/bin/perl -w use strict; use CGI qw(:standard); print header(), start_html(); print start_form(), checkbox_group(-name='mygroup', -values=[1..10]), submit(-name = 'action', -value = 'Submit'), end_form(); if (param('action') param('action') eq 'Submit') { my @checked_values = param('mygroup'); print p(@checked_values); } print end_html(); Also note that they carry selected ads in previous pages forward in hidden variables, as in print hidden(-name = 'mygroup', -value = '1'); which ensures they will be part of the param('mygroup') array. -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
[OT]: URGENT virus warning
Through private communication I've been informed that another list member has received an email message from '[EMAIL PROTECTED]' with a subject line of 'Weekly postins statitistics - 37/2002'. This email message contained the so-called 'W32.Bugbear@mm' virus. I posted this message from '[EMAIL PROTECTED]' on September 16, through perl.beginners nntp-interface (and without a virus attached). After studying the virus information at http://securityresponse.symantec.com/avcenter/venc/data/ [EMAIL PROTECTED] the following quote from this webpage: The worm also can construct addresses for the From: field using information that it harvests from the infected computer. For example, the worm may find the addresses [EMAIL PROTECTED], [EMAIL PROTECTED] and [EMAIL PROTECTED] The worm could create an email message addressed to [EMAIL PROTECTED] and spoof the From: address, so that it appears to come from [EMAIL PROTECTED] The spoofed address can also be a valid email address that the worm finds on the system. In addition to the following list of subjects, the worm can create a new message as a reply to or forward of an existing message on the infected system. makes me conclude that the system of at least one of the list members is infected by this virus. I therefore advise all fellow list members who use Windows (especially those who correspond with the 'sprocket.lockergnome.com' domain) to go to the above-mentioned webpage and download and run the removal tool. Please stay alert. The infected computer probably contains other email adresses from 'perl.beginners' list members, so everybody on the list could receive the virus, and not necessarily with a subject or (part of) an email address related to Perl! -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Population of variables in hash values...
on do, 07 nov 2002 17:13:22 GMT, Tim Yohn wrote: Hey All, Is there an easy way to have variables in the value of a hash that are not populated until the value of the hash is used... my($domain); my(%hash) = ( 1 = '$domain' ); print_domain(test.com); sub print_domain() { my($domain) = @_; print eval $hash{'1'}; } See perldoc -f eval -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Securing/Encrypting Source
on do, 07 nov 2002 13:04:11 GMT, Dan wrote: It's occured to me with my perl program near completion, that the person that's hosting my program isn't.. let's say.. trustworthy enough to not steal source. [...] Any clues as to where I go from here? Find yourself a trustworthy person to host your program. -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: line feeds in perl scripts
on Tue, 05 Nov 2002 19:19:37 GMT, [EMAIL PROTECTED] (Sean Finnigan) wrote: What is the best way to replace line feeds in perl scripts that I copy from my PC to my Unix machine? They don't run on the Unix side unless I open an editor and find/replace the line feeds/carriage returns. http://www.perl.com/language/ppt/src/nlcvt/index.html -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: checking input syntax
on Tue, 05 Nov 2002 01:10:51 GMT, [EMAIL PROTECTED] (Jose Malacara) wrote: I would like to be able to force them use the server[number].[location] syntax and generate a warning if they don't. Would it be possible to add a second argument test after the first? Something like: ( $#ARGV eq server*.* ) or die usage: $0 server[number].[location]\n; $ARGV[0] $ARGV[0] =~ /^[a-z]+\d+\.[a-z]+$/i or die usage ...; -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Monthly posting statistics - October 2002
Monthly posting statistics for perl.beginners - October 2002. From 2002-10-01 to 2002-10-31 there were 1675 articles posted (81799 lines) by 326 authors, giving an average 5.14 articles per author, and an average article length of 49 lpa. The average number of articles per day was 54. There were 432 (26%) original articles, and 1243 (74%) replies (articles that started with 'RE:' in their subject line). 145 (44%) authors posted only one article. The authors top-10 by number of articles is as follows: All/Ori Lines lpa Author 95/04349 45 [EMAIL PROTECTED] (John W. Krahn) 74/12305 31 [EMAIL PROTECTED] (Jenda Krynicky) 51/01558 30 [EMAIL PROTECTED] (Jeff 'Japhy' Pinyan) 50/01799 35 [EMAIL PROTECTED] (Michael Fowler) 48/72797 58 [EMAIL PROTECTED] (James Edward Gray ... 47/54084 86 [EMAIL PROTECTED] (Beau E. Cox) 44/02003 45 [EMAIL PROTECTED] (David) 36/12241 62 [EMAIL PROTECTED] (Timothy Johnson) 36/21651 45 [EMAIL PROTECTED] (James Kipp) 34/11407 41 [EMAIL PROTECTED] (Paul Johnson) -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: APACHE CGI Configuration
on Thu, 31 Oct 2002 04:50:43 GMT, [EMAIL PROTECTED] (Vinai Ar) wrote: [ Please don't post multipart messages - post text only] I am entirely new to apache and CGI. Can any one help me out in making apache server to execute the CGI scripts. The error message that I got it couldn't spawn child process. I followed the steps to configure the httpd.conf file. Everything seems to be correct and the Apache server is running fine. I tried this in Win 2000. Pls. help me out. Do your scripts start with a shebang on the first line, pointing to a valid Perl interpreter? E.g. #! d:\perl\bin\perl.exe -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Grabbing a process ID
on Wed, 30 Oct 2002 19:48:24 GMT, [EMAIL PROTECTED] (Guy Davis) wrote: I am calling another perl script and it has failed occasionally from errors that I have not yet tracked down. What I want to do is grab and store the process id. Then check to see if that process id is still running at a later date when the script is re-run. Have your script write its pid to a file. Another question is there a way to grab the currently running processes on a linux system and parse through them in perl? Has anyone done this or do you know where I might get the code to do this? See e.g. http://perl.oreilly.com/cookbook/prog_psgrep.html -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: bad interpreter
on Thu, 31 Oct 2002 08:22:08 GMT, [EMAIL PROTECTED] (Karin Friberg) wrote: When I run my perl program I get: bash: ./checkit.pl: bad interpreter: No such file or directory What does that mean? Check your #! line at the top of your program. Does this point to a valid Perl interpreter? -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: code in CGI forms
on Thu, 31 Oct 2002 03:54:23 GMT, [EMAIL PROTECTED] (George Georgalis) wrote: and in the middle of a form, I want to run some code to generate some monotonous stuff. start_form, 'Name: ',textfield('name','',55),br, 'Phone/Fax: ',textfield('phone','',55),br, 'Address: ',textarea('addr','',5,35,20),br, [code to generate CGI code here] 'Date: ',textfield('date'), or , checkbox_group(-mkdate='', -values=['auto']),br, submit, end_form, How is that done? If you don't want to split the print statement for the form, you could put your 'monotonous stuff' in a function and include this in the print: print start_form, 'Name:', textfield('name', '', 55), br, calculate_monotonous_stuff(), br, submit, end_form; sub calculate_monotonous_stuff { # lengthy calculation return 'stuff'; } Also is there any way to use popup_menu without getting a line break after it? I never get linebreaks after a popup_menu unless I want to. Can you show some code? -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: splitting
on ma, 28 okt 2002 10:15:46 GMT, Javeed Sar wrote: i have big files, i want to split it and do a ftp to other sites, at the other site i should be able to join them and execute them, any of you are doing this type of thing, can anyone help me?? Look for 'split' and 'join' at http://www.perl.com/language/ppt/what.html if you want Perl-versions. -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Any Perl versions of ...
on za, 26 okt 2002 09:16:33 GMT, Paul Company wrote: I'm looking for the following programs written in portable Perl. What I mean by portable is the script doesn't contain system() or backticks (``). vi written in perl cvs written in perl gzip written in perl Stop looking - you won't find them ;-) -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Weekly posting statistics - 42/2002
Weekly posting statistics for perl.beginners - week 42 of 2002. From Monday 2002-10-14 to Sunday 2002-10-20 there were 373 articles posted (18397 lines) by 114 authors, giving an average 3.27 articles per author, and an average article length of 49 lpa. The average number of articles per day was 53. There were 103 (28%) original articles, and 270 (72%) replies (articles that started with 'RE:' in their subject line). 53 (46%) authors posted only one article. The authors top-10 by number of articles is as follows: All/Ori Lines lpa Author 23/0 970 42 [EMAIL PROTECTED] (John W. Krahn) 23/0 762 33 [EMAIL PROTECTED] (Jeff 'Japhy' Pinyan) 18/51082 60 [EMAIL PROTECTED] (James Edward Gray ... 16/0 475 29 [EMAIL PROTECTED] (Michael Fowler) 13/01036 79 [EMAIL PROTECTED] (Rob) 12/0 443 36 [EMAIL PROTECTED] (Jenda Krynicky) 11/1 794 72 [EMAIL PROTECTED] (Timothy Johnson) 11/0 659 59 [EMAIL PROTECTED] (Beau E. Cox) 7/2 557 79 [EMAIL PROTECTED] (Rakhitha M... 7/3 474 67 [EMAIL PROTECTED] (Folschette) -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: replacing numbers around a decimal
on wo, 16 okt 2002 20:03:31 GMT, Andrew Hughes wrote: I am creating a little calculator that is going to need to take a user entered number that will always have 2 decimal places (using sprintf). It could be 89562321.29 or it could be 101.00) and take the last 4 digits (with the period included, so five places) and do two things: 1)Store the number in a variable. For the two examples above that would be 21.29 and 01.00 respectively would be stored in their own variable x=21.29 or it could be x=01.00; and 2) replace the last 4 numbers (5 places) with 00.00 -- always. For the two examples above they would become 89562300.00 and 100.00. Can anyone point me in the right direction? my $number = 89562321.29; my $big = int($number/100)*100; my $small = $number - $big; printf(%.2f - %05.2f\n, $big, $small); -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Single Quote marks in a string
on do, 17 okt 2002 08:01:07 GMT, Andrew Hubbard wrote: I'm having problems with a text file I'm working on. I need to get the descriptions in from the text file and into a string for use in an SQL statement however some of the descriptions use a single quote mark in the description. This of course stops the sql statement from working. How can I get around this? I don't want to remove the quote. Use placeholders, like so: my $sth = $dbh-prepare(INSERT INTO atable VALUES(?,?)); my $value1 = Looks like 'single' quotes; my $value2 = No single quotes here; $sth-execute($value1, $value2); my $rset = $dbh-selectall_arrayref( qq{ SELECT atable.afield, atable.anotherfield FROM atable WHERE atable.anotherfield = ? }, undef, $avalue); -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Weekly posting statistics 41/2002
Weekly posting statistics for perl.beginners - week 41 of 2002. From Monday 2002-10-07 to Sunday 2002-10-13 there were 454 articles posted (22004 lines) by 124 authors, giving an average 3.66 articles per author, and an average article length of 48 lpa. The average number of articles per day was 65. There were 111 (24%) original articles, and 343 (76%) replies (articles that started with 'RE:' in their subject line). 53 (43%) authors posted only one article. The authors top-10 by number of articles is as follows: All/Ori Lines lpa Author 26/01470 56 [EMAIL PROTECTED] (John W. Krahn) 21/0 671 31 [EMAIL PROTECTED] (Jenda Krynicky) 20/0 869 43 [EMAIL PROTECTED] (David) 18/21013 56 [EMAIL PROTECTED] (Nkuipers) 16/11031 64 [EMAIL PROTECTED] (James Edward Gray ... 14/0 451 32 [EMAIL PROTECTED] (Michael Fowler) 13/4 595 45 [EMAIL PROTECTED] (Nikola Janceski) 13/0 593 45 [EMAIL PROTECTED] (Janek Schleicher) 11/0 612 55 [EMAIL PROTECTED] (Dharmender rai) 11/0 500 45 [EMAIL PROTECTED] (Paul Johnson) -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Weekly posting statistics - 40/2002
Weekly posting statistics for perl.beginners - week 40 of 2002. From Monday 2002-09-30 to Sunday 2002-10-06 there were 382 articles posted (17592 lines) by 114 authors, giving an average 3.35 articles per author, and an average article length of 46 lpa. The average number of articles per day was 55. There were 85 (22%) original articles, and 297 (78%) replies (articles that started with 'RE:' in their subject line). 58 (51%) authors posted only one article. The authors top-10 by number of articles is as follows: All/Ori Lines lpa Author 33/01361 41 [EMAIL PROTECTED] (David) 20/0 839 41 [EMAIL PROTECTED] (John W. Krahn) 17/1 926 54 [EMAIL PROTECTED] (James Edward Gray ... 14/1 562 40 [EMAIL PROTECTED] (Nkuipers) 12/0 464 38 [EMAIL PROTECTED] (Michael Fowler) 12/0 389 32 [EMAIL PROTECTED] (Jeff 'Japhy' Pinyan) 12/1 364 30 [EMAIL PROTECTED] (Jenda Krynicky) 11/0 569 51 [EMAIL PROTECTED] (Timothy Johnson) 11/0 527 47 [EMAIL PROTECTED] (Sudarshan Raghavan) 11/0 526 47 [EMAIL PROTECTED] (Robin Cragg) -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: SQL Table Rows
on Tue, 01 Oct 2002 10:50:26 GMT, [EMAIL PROTECTED] (Gary Stainburn) wrote: Nobody's mentioned: $countrow=$sth-rows; This way is more efficient that doing the 'select count(*)' as it's done from the same select query, and it also means that yo know beforehand how many rows you will be reading, which is often usefull, and is not possible if you use the countrow++ method. Unfortunately, my DBI documentation mentions: For `SELECT' statements, it is generally not possible to know how many rows will be returned except by fetching them all. Some drivers will return the number of rows the application has fetched so far, but others may return -1 until all rows have been fetched. So use of the `rows' method or `$DBI::rows' with `SELECT' statements is not recommended. -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Is there a searchable archive for this list
on Tue, 01 Oct 2002 15:24:40 GMT, Anidil Rajendran wrote: I dont find any search option in following site http://archive.develooper.com/beginners%40perl.org/ Try http://groups.google.com/advanced_group_search?group=perl.beginners -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Monthly posting statistics - September 2002
Monthly posting statistics for perl.beginners - September 2002. From 2002-09-01 to 2002-09-30 there were 1896 articles posted (87758 lines) by 322 authors, giving an average 5.89 articles per author, and an average article length of 46 lpa. The average number of articles per day was 63. There were 420 (22%) original articles, and 1476 (78%) replies (articles that started with 'RE:' in their subject line). 134 (42%) authors posted only one article. The authors top-10 by number of articles is as follows: All/Ori Lines lpa Author 178/07395 41 [EMAIL PROTECTED] (David) 88/05252 59 [EMAIL PROTECTED] (John W. Krahn) 65/02306 35 [EMAIL PROTECTED] (Sudarshan Raghavan) 55/02093 38 [EMAIL PROTECTED] (Michael Fowler) 53/23170 59 [EMAIL PROTECTED] (Timothy Johnson) 49/01912 39 [EMAIL PROTECTED] (Bob Showalter) 43/01575 36 [EMAIL PROTECTED] (Dharmender rai) 42/01665 39 [EMAIL PROTECTED] (Janek Schleicher) 34/21755 51 [EMAIL PROTECTED] (Nikola Janceski) 33/11815 55 [EMAIL PROTECTED] (Drieux) -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Insertion and Quotes
on Tue, 01 Oct 2002 17:55:21 GMT, Jessee Parker wrote: I'm a bit confused on why this is happening and I'm hoping someone can shed some light on things for me. I read in information from a file which is comma delimted and I use the parsing routine I found in the Perl Cookbook. When it hits a name with marks around it, it shifts everything over when doing the insert. I have put escape characters in the data before insertion for both quotes and apostrophes and when I run it with w single entry, it inserts correctly. When run on a longer list, the line that has the name in quotes shifts everything over by one during the insertion. I'm using MySQL as the database. Thanks in advance! Use placeholders and your quoting troubles will be over forever ;-) E.g.: my $sql = INSERT INTO atable VALUES (NULL, ?, ?); my $sth = $dbh-prepare($sql); $sth-execute($a_var, $another_var_with_embedded_quotes); -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Weekly posting statistics - 39/2002
Weekly posting statistics for perl.beginners - week 39 of 2002. From Monday 2002-09-23 to Sunday 2002-09-29 there were 483 articles posted (22798 lines) by 136 authors, giving an average 3.55 articles per author, and an average article length of 47 lpa. The average number of articles per day was 69. There were 109 (23%) original articles, and 374 (77%) replies (articles that started with 'RE:' in their subject line). 60 (44%) authors posted only one article. The authors top-10 by number of articles is as follows: All/Ori Lines lpa Author 47/01896 40 [EMAIL PROTECTED] (David) 21/0 831 39 [EMAIL PROTECTED] (John W. Krahn) 21/0 800 38 [EMAIL PROTECTED] (Michael Fowler) 17/0 661 38 [EMAIL PROTECTED] (Sudarshan Raghavan) 14/0 834 59 [EMAIL PROTECTED] (Timothy Johnson) 14/0 537 38 [EMAIL PROTECTED] (Jenda Krynicky) 14/0 463 33 [EMAIL PROTECTED] (Janek Schleicher) 13/0 403 31 [EMAIL PROTECTED] (Jeff 'Japhy' Pinyan) 12/1 284 23 [EMAIL PROTECTED] (Nkuipers) 9/2 446 49 [EMAIL PROTECTED] (James Edward Gray ... -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: CGI Script and getting the PID
on Mon, 30 Sep 2002 19:39:05 GMT, Jessee Parker wrote: Hi all, I've run into a bit of a problem. I need to see if a program is currently running. If it is, I want to display this on a web page that tells the status of the program (either on or off). The script I created which is probably longer than it needs to be, basically issues a system(ps -A) call and writes it out to a file which in turns gets parsed through. There is no need to use an intermediate file if you use a pipe: #! /usr/local/bin/perl -w use strict; open PS, /bin/ps -A | or die cannot fork: $!; while (PS) { # do your stuff } close PS; -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Expect-like Perl script
on Mon, 30 Sep 2002 20:52:54 GMT, Jose Malacara wrote: Hello. I am interested in writing a Perl script that can do the following: 1. read a list of user defined commands from a file 2. telnet (or possibly ssh) to a device such as a router, login, and interactively issue the commands read from the command list. 3. return the output from the commands to STDOUT or a file http://search.cpan.org/author/JROGERS/Net-Telnet-3.03/lib/Net/Telnet.pm -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Last day of Month
on Mon, 30 Sep 2002 21:12:56 GMT, Charlie Farinella wrote: I have an error popping up in an application that runs monthly reports and everymonth seems to leave off the last day's entries. The subroutine that determines the last day of the month is here: sub GetLastDayOfMonth { my( $sec, $min, $hours, $mday, $mon, $year ) = localtime( $_[0] ); return timelocal( 59, 59, 23, $monthDays[$mon], $mon, $year ); } Please tell us: a) how this function is called, and b) what's in the @monthDays array (and where it is defined). -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Last day of Month
on Mon, 30 Sep 2002 21:38:34 GMT, Charlie Farinella wrote: I don't know if this is helpful. Let me know. a) how this function is called, and if( $hashref-{'period'} eq '1' ) { $starttime = GetFirstDayOfMonth( $curtime ); $endtime = GetLastDayOfMonth( $curtime ); b) what's in the @monthDays array (and where it is defined). our @monthDays= qw( 31 28 31 30 31 30 31 31 30 31 30 31 ); This code seems OK to me? When are you running the report? On the last day of the month or the first day of the next month? -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: opening a list of files
on Wed, 25 Sep 2002 10:13:45 GMT, [EMAIL PROTECTED] (Adriano Allora) wrote: Hi to all, I need a script to open all the files in a directory and count all the words of them, but it doesn't work: $folder = pathname; opendir(KART, $folder); foreach (readdir(KART)){ if(grep /\.txt$/, $_){ $filename = $_; Try $filename = $folder/$_; -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Creating tables?
on Wed, 25 Sep 2002 17:16:19 GMT, Dan wrote: I've managed to get SQL working now. Just one query. How can I get perl to create a new table? I have the table's name set in $acctab, this is what i have, but it doesn't work.. how so? Try $dbh-do(CREATE ...); -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Array Handling
on Tue, 24 Sep 2002 13:46:32 GMT, Rohit Mishra-R53658 wrote: Is there any way to open a handle to an array as we open a handle to a file?? The condition being we can use that array handle everywhere we can use a file handle http://search.cpan.org/author/ERYQ/IO-stringy-2.108/lib/IO/ScalarArray.pm -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Weekly posting statistics - 2002/38
Weekly posting statistics for perl.beginners - week 38 of 2002. From Monday 2002-09-16 to Sunday 2002-09-22 there were 507 articles posted (23944 lines) by 127 authors, giving an average 3.99 articles per author, and an average article length of 47 lpa. The average number of articles per day was 72. There were 110 (22%) original articles, and 397 (78%) replies (articles that started with 'RE:' in their subject line). 50 (39%) authors posted only one article. The authors top-10 by number of articles is as follows: All/Ori Lines lpa Author 47/02160 45 [EMAIL PROTECTED] (David) 20/0 651 32 [EMAIL PROTECTED] (Sudarshan Raghavan) 16/01343 83 [EMAIL PROTECTED] (John W. Krahn) 14/0 773 55 [EMAIL PROTECTED] (Dharmender rai) 13/1 766 58 [EMAIL PROTECTED] (Nikola Janceski) 12/0 451 37 [EMAIL PROTECTED] (Michael Fowler) 12/8 387 32 [EMAIL PROTECTED] (Angerstein) 11/1 716 65 [EMAIL PROTECTED] (Tony) 11/1 583 53 [EMAIL PROTECTED] (Timothy Johnson) 11/4 291 26 [EMAIL PROTECTED] (Rp C987342) -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Perl MySQl query syntax
on Sun, 22 Sep 2002 17:53:29 GMT, Wiggins D'Anconia wrote: larry lefthook wrote: my $sth = $dbh-prepare('delete from cl_items WHERE date_time $exp_time2 '); You are single quoting your statement which means $exp_time2 is taken literally rather than interpolated should be: my $sth = $dbh-prepare(delete from cl_items WHERE date_time $exp_time2 ); $sth-execute(); Or (even better :-), use a placeholder: my $sth = $dbh-prepare('delete from cl_items WHERE date_time ?'); $sth-execute($exp_time2); -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: MySql - Perl question
on Sun, 22 Sep 2002 17:06:01 GMT, Mariusz wrote: I have a discount table that carries percentage discounts that should be looked up when the customer submits a discount code and taken into calculation of the total price. My table looks something like this: field names:|senior|student|... values:|0.20|0.50|... This is bad design. What you want is one table with two fields, like e.g. (untested): CREATE TABLE discounts ( discounttype CHAR(20) NOT NULL PRIMARY KEY, discountvalue FLOAT ); in which you store the following records: INSERT INTO discounts VALUES ('senior', 0.20); INSERT INTO discounts VALUES ('student', 0.50); # ... Then you say: my ($d) = $sth-selectrow_array(qq{ SELECT discountvalue FROM discounts WHERE discounttype = ? }, undef, $user_supplied_type); if (defined $d) { # $user_supplied_type is in database } else { # $user_supplied_type is not in database } # -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: something awry
on Tue, 10 Sep 2002 17:39:25 GMT, [EMAIL PROTECTED] (Mike Singleton) wrote: my @files = glob('3D2*.log'); my @f = split /s+/,$_,9; What's in $_? Did you mean /\s+/ ? print OUTF join(',',@f).\n; Never openend OUTF -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: s/// in a list -- How to do it ?
I have a list @listing whose output is like ... data/23_59_54_20_08_2002 how do i search and replace occurances of data/ with nothing ( ) s|^data/|| for @listing; -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Weekly posting statistics - 36/2002
Weekly posting statistics for perl.beginners - week 36 of 2002. From Monday 2002-09-02 to Sunday 2002-09-08 there were 344 articles posted (14565 lines) by 107 authors, giving an average 3.21 articles per author, and an average article length of 42 lpa. The average number of articles per day was 49. There were 79 (23%) original articles, and 265 (77%) replies (articles that started with 'RE:' in their subject line). 53 (50%) authors posted only one article. The authors top-10 by number of articles is as follows: All/Ori Lines lpa Author 29/01229 42 [EMAIL PROTECTED] (David) 25/01590 63 [EMAIL PROTECTED] (John W. Krahn) 19/0 235 12 [EMAIL PROTECTED] (Dharmendra rai) 18/0 548 30 [EMAIL PROTECTED] (Sudarshan Raghavan) 13/0 565 43 [EMAIL PROTECTED] (Bob Showalter) 13/2 405 31 [EMAIL PROTECTED] (Felix Geerinckx) 12/0 386 32 [EMAIL PROTECTED] (Jeff 'Japhy' Pinyan) 7/0 348 49 [EMAIL PROTECTED] (Drieux) 7/1 283 40 [EMAIL PROTECTED] (Timothy Johnson) 6/1 305 50 [EMAIL PROTECTED] (Wiggins D'Anconia) -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: sorting of arrays
on Thu, 05 Sep 2002 08:46:08 GMT, [EMAIL PROTECTED] (Zanardi2k2) wrote: Felix Geerinckx wrote: push @array, 3; is the same as $array[2] = 2; (...) Maybe a typo? push @array, 3; should be the same as $array[2] = 3; Indeed. Thanks for spotting it. -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Tips, optimizing script.
on Wed, 04 Sep 2002 07:44:01 GMT, [EMAIL PROTECTED] (David Samuelsson) wrote: [Why are you quoting yourself in an original post?] I want tips, on optimizing, and things that can be done smaller and better. Changes goes inside the box. use strict; my (@vobs,$vob,$view,$text,@views,@sviews,$viewname,$viewinfo); I usually declare my variables close to where I first need them. $a = localtime(time); Don't use '$a' (or '$b'). These are special variables for use with the 'sort' function. Did you notice how the undeclared variable '$a' doesn't generate an error, although strictures are turned on? `del $errors`; There is no need to spawn another process to delete a file. Perl has the 'unlink' function. See perldoc -f unlink. open (HTML,$html) or die error: $!; print HTML html\nhead\ntitleClearCase Views with You could use a here-document, or the construct print HTML qq{ A lot of HTML lines to print }; to avoid the repetition of 'print HTML' statements @vobs = `cleartool lsvob -s`; foreach $vob (@vobs) my @vobs = `cleartool lsvob -s`; foreach my $vob (@vobs) { as explained above { chomp $vob; print checkin $vob\n; open (A, cleartool desc -l vob:$vob |); Always, yes always check the return value of a system call while (A) { if ($_ =~ /.uuid./i) { chomp $_; $_ =~ s/.*\[uuid (.*)\]/$1/; $view = `cleartool lsview -s -uuid $_ 21`; chomp $view; if ($view =~ /.Error:./) { open (LOGFILE, $errors) or die cant open $!; print LOGFILE ERROR IN $vob: $view\n; } else { $text = $view $vob\n; push (@views,$text); } } } } @sviews = sort {lc $a cmp lc $b}@views; Your original $a variable to which you assigned the localtime is now gone. print Printing HTML to $html\n; foreach $view (@sviews) { ($viewname, $vob) = split (/\s+/, $view); $viewinfo = `cleartool lsview -l $viewname`; if ($viewinfo =~ /snapshot/) { print HTML tr\n\ttr bgcolor\=\\#99\\n\ttd$viewname/td\n \ttdSnapshot/td\n\ttd$vob/td; } else { print HTML tr\n\ttr bgcolor\=\\#99\\n\ttd$viewname/td\n \ttdDynamic/td\n\ttd$vob/td; } } If you use print qq{You don't have to escape your quotes}; -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Cookbook example
on Wed, 04 Sep 2002 06:23:20 GMT, [EMAIL PROTECTED] (Anidil Rajendran) wrote: expand the filename manually with substitution $filename =~ s{ ^ ~ ( [^/]* ) } { $1 ? (getpwnam($1)) [7] : ( $ENV{HOME} || $ENV{LOGDIR} || (getpwuid($)) [7] ) }ex; The auther says the following can me matched ~user ~user/blah ~ ~/blah Could someone make me clear how these can be matched by the pattern inside the parenthesis which is ( [^/]*) The real pattern, after removing the whitespace allowed by using the /x modifier is: /^~([^/]*)/ Which means: match '~' at the beginning of the string, then match and store in $1 any number (including none) of characters up to but not including the first '/'. You will have: filename $1 ~user user ~user/blahuser ~ (empty string) ~/blah(empty string) -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: handling microsoft word file
on Wed, 04 Sep 2002 10:53:41 GMT, [EMAIL PROTECTED] (Massimiliano Cialdi) wrote: there exist a perl module to manage ms word file? No, not to my knowledge. Unless you are working on Win32 and have MS Word available, in which case you can use Win32::OLE. -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Cookbook example (fwd)
on Thu, 05 Sep 2002 10:02:03 GMT, [EMAIL PROTECTED] (Sudarshan Raghavan) wrote: Not sure if this mail was sent properly, my apologies if you already have recd this. It was, as you could have found out yourself by going to http://nntp.x.perl.org/group/perl.beginners/ (or by using a newsreader instead of an email program ;-) -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: substr or anything like that
on Wed, 04 Sep 2002 16:00:06 GMT, Zanardi2k2 wrote: Is there something better than: $var1=substr($_, 0, 10) $var2=substr($_, 11, 16) $var3=... See perldoc -f pack perldoc -f unpack If you have e.g. the following layout: my $string = 123 456 ABC; i.e. 9 places for the first field and 10 places for the second field, you can use: my @data = unpack(A9 A10 A*, $string); -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: sorting of arrays
on Tue, 04 Sep 2001 12:15:37 GMT, Quincy Ntuli wrote: I understand that perl desides how it stores data in an array. Perl doesn't, you do. Data in an array is indexed by an integer. You, the programmer, choses at which position you put your data: $array[0] = 0; $array[1] = 1; Or, by using push, you take the next available position: push @array, 3; is the same as $array[2] = 2; Perl *does* decide in which order it iterates over the keys of a hash. -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Read, Write and Append -- is there more?
on Tue, 03 Sep 2002 13:11:47 GMT, [EMAIL PROTECTED] (James Edward Gray II) wrote: This is the easiest way, in my opinion. It'll work on files passes as command line arguments. Beware the replacing though, files will be modified in place and data may be lost! #!/usr/bin/perl -pi The loss of data can easily be prevented by using the following shebang instead: #!/usr/bin/perl -pi.orig which leaves a backup copy of your original data. See perldoc perlrun -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How did perl -d find perldb.pl?
on Sun, 01 Sep 2002 15:37:59 GMT, [EMAIL PROTECTED] (Chris) wrote: My question is How did perl -d manage to find perldb.pl? Have you read perldoc perldebug (especially the section on 'Debugger Customization')? -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Locating columns based on headings
on Mon, 02 Sep 2002 13:15:56 GMT, [EMAIL PROTECTED] (Sl003b0462) wrote: I have a csv file with column headings. As the file may be amended and the columns reordered I wish to read the headings and determine their location on each pass. How do I generate a list of fixed headings and determine their position, before extracting the corresponding field for each line. You don't say whether you are using a module for your csv parsing, so I assume you are rolling your own. You could use an array of hashes for your data: #! perl -w use strict; # warning: very simplistic csv parsing: # no embedded separator or quoting allowed # and no data checking # get header fields my @headers = split /[,\n]/, DATA; #get data my @data = (); while (DATA) { my %dataline = (); @dataline{@headers} = split /[,\n]/, $_; push @data, \%dataline; } print Dumper(\@data); __DATA__ field1,field2,field3,field4 1,abc,def,2 3,ghi,jkl,4 5,mno,pqr,6 -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: IO::Socket problem how to receive data?
on Sun, 01 Sep 2002 15:15:27 GMT, [EMAIL PROTECTED] (Anthony) wrote: I'm trying to learn IO::Socket and i have a little problem is that i DO NOT know how to receive data i use the recv function but doesn't work at all. [...] But I can send data to a perl program but I don't know how to translate it. Have you already checked out perldoc perlipc (especially the section on 'TCP Servers with IO::Socket')? -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Weekly posting statistics - 35/2002
Weekly posting statistics for perl.beginners - week 35 of 2002. From Monday 2002-08-26 to Sunday 2002-09-01 there were 361 articles posted (15689 lines) by 104 authors, giving an average 3.47 articles per author, and an average article length of 43 lpa. The average number of articles per day was 52. There were 82 (23%) original articles, and 279 (77%) replies (articles that started with 'RE:' in their subject line). 51 (49%) authors posted only one article. The authors top-10 by number of articles is as follows: All/Ori Lines lpa Author 29/01419 48 [EMAIL PROTECTED] (David) 29/1 698 24 [EMAIL PROTECTED] (Felix Geerinckx) 21/31218 58 [EMAIL PROTECTED] (Drieux) 20/0 593 29 [EMAIL PROTECTED] (Sudarshan Raghavan) 13/0 542 41 [EMAIL PROTECTED] (John W. Krahn) 12/4 431 35 [EMAIL PROTECTED] (Angerstein) 11/0 456 41 [EMAIL PROTECTED] (Bob Showalter) 11/0 212 19 [EMAIL PROTECTED] (Dharmendra rai) 10/0 267 26 [EMAIL PROTECTED] (Paul Johnson) 9/0 315 35 [EMAIL PROTECTED] (James Kipp) -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Monthly posting statistics - August 2002
Monthly posting statistics for perl.beginners - August 2002. From 2002-08-01 to 2002-08-31 there were 1682 articles posted (76692 lines) by 305 authors, giving an average 5.51 articles per author, and an average article length of 46 lpa. The average number of articles per day was 54. There were 390 (23%) original articles, and 1292 (77%) replies (articles that started with 'RE:' in their subject line). 129 (42%) authors posted only one article. The authors top-10 by number of articles is as follows: All/Ori Lines lpa Author 122/17 6634 54 [EMAIL PROTECTED] (Drieux) 103/62719 26 [EMAIL PROTECTED] (Felix Geerinckx) 81/03587 44 [EMAIL PROTECTED] (John W. Krahn) 75/03614 48 [EMAIL PROTECTED] (David) 55/14 3255 59 [EMAIL PROTECTED] (Nikola Janceski) 55/01864 33 [EMAIL PROTECTED] (Sudarshan Raghavan) 54/82370 43 [EMAIL PROTECTED] (Connie Chan) 50/01869 37 [EMAIL PROTECTED] (Bob Showalter) 37/01236 33 [EMAIL PROTECTED] (Janek Schleicher) 35/02368 67 [EMAIL PROTECTED] (Timothy Johnson) -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Error: requires explicit package name
on Fri, 30 Aug 2002 13:58:47 GMT, [EMAIL PROTECTED] (T) wrote: Global symbol $auto requires explicit package name [...] if ($Country eq Argentina) {my $auto = $q-param( '[EMAIL PROTECTED]' ); } and if ($Country eq Argentina) {$auto = $q-param( '[EMAIL PROTECTED]' ); } A lexical my declaration is only visible in the enclosing block. You should write: my $auto; if ($Country eq Argentina) { $auto = $q-param( '[EMAIL PROTECTED]' ); } See M-J. Dominus' Coping with Scoping article for an excellent introduction to scoping at http://perl.plover.com/FAQs/Namespaces.html -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: uniq elements of an array
on Fri, 30 Aug 2002 17:32:36 GMT, [EMAIL PROTECTED] (Sudarshan Raghavan) wrote: Why do you need to do a pattern match anyways? Just a @unique = grep{!$seen{$_}} @all_elements; should do You forgot to increment. The correct way is: @unique = grep{!$seen{$_}++} @all_elements; -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: find the lowest number?
on Fri, 30 Aug 2002 08:22:56 GMT, [EMAIL PROTECTED] (David Samuelsson) wrote: i get an array conataining a lot off numbers like this: 567 [snipped] 520 how do i find the lowest or the higest number in this series? There is no need to sort the full array (as others suggested) to just find the lowest and highest number when an O(n) operation will suffice: my ($min, $max); $min = $max = $array[0]; for (1..@array-1) { $min = $array[$_] if $array[$_] $min; $max = $array[$_] if $array[$_] $max; } print min = $min, max = $max\n; -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: find the lowest number?
on Sat, 31 Aug 2002 02:23:20 GMT, [EMAIL PROTECTED] (Sudarshan Raghavan) wrote: On 30 Aug 2002, Felix Geerinckx wrote: There is no need to sort the full array (as others suggested) to just find the lowest and highest number when an O(n) operation will suffice: Precisely the comment that I had a few months back for a similar question. Read through this thread http://archive.develooper.com/beginners%40perl.org/msg22716.html Thanks for this reference (from a time before I discovered the perl beginners list). Benchmark: timing 100 iterations of using_for, using_sort... using_for: 11 wallclock secs (11.60 usr + 0.04 sys = 11.64 CPU) @ 85910.65/s (n=100) using_sort: 8 wallclock secs ( 7.63 usr + 0.06 sys = 7.69 CPU) @ 130039.01/s (n=100) This if for a seven-element array. I did some testing myself for larger array sizes (times are in CPU seconds): Size Loop Sort 1000 0.00 0.01 1 0.02 0.08 10 0.13 1.03 20 0.24 2.18 30 0.37 3.35 So if you have more than 1000 numbers, the loop method will already be faster. In addition, it has the advantage that you don't need all the numbers to be present in memory, since you can calculate min/max while you read the numbers from file. For small array sizes, it doesn't matter which method you use, since the cpu time will be near zero anyway. For larger sizes it does matter, and the loop method is a clear winner. Therefor, imho, your suggestion in March (and mine now :-) to use a loop, is *always* preferable. -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: find the lowest number?
on Sat, 31 Aug 2002 03:51:39 GMT, [EMAIL PROTECTED] (Sudarshan Raghavan) wrote: I thought on similar lines too when that thread was on, but I convinced myself saying that an unsorted array of 1000 or more elements in your code is a poor design to start with :-) I beg to differ. From perldoc perldata (my emphasis): Normal arrays are *ordered* lists of scalars indexed by number, starting with 0 and with negative subscripts counting from the end. One of the main features of arrays (compared to hashes) is that you have full control over the order in which the elements are inserted. Many algorithms rely on this order (look e.g. at the GD::Graph module). -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: find the lowest number?
on Sat, 31 Aug 2002 04:30:34 GMT, [EMAIL PROTECTED] (Sudarshan Raghavan) wrote: My statement was far too general, what I should have said was to have a unsorted array of 1000 or more elements when your problem requires finding the max or min of that list is not a good design. Again, I beg to differ. I'll use the same example (GD::Graph) to explain myself. Say you want to graph a mathematical function y = f(x) for 0 = x = 1000. GD::Graph wants two arrayrefs, so you do: my ($x, $y); for (0..1000) { $x-[$_] = $_; $y-[$_] = f($_); } To have a nice looking graph, you want to have the top/bottom coincide with the max/min value of your function, so you need to calculate ymax and ymin, which, of course, you do in the same for loop that generates the (x,y) pairs. -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: uniq elements of an array
on Fri, 30 Aug 2002 18:26:03 GMT, Tom Allison wrote: david wrote: @hash{@all_elements} = (); now keys %hash gives you the unique elements. Would these exist but be undef? Why don't you write a little program to try it out, using the aptly named 'exists' and 'defined' functions? -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Need help
on Thu, 29 Aug 2002 20:40:19 GMT, David Wagner wrote: my %h = (); $h {1} = [ some string,other string,3 ] ; $h {2} = [ some string,other string,2 ] ; $h {3} = [ some string,other string,1 ] ; foreach my $MyKey (sort { $a-[1]=$b-[1] } map{[$_,$h{$_}[2]]} keys %h) { printf %-s - %-s\n, $MyKey-[0], $MyKey-[1]; } Output: 3 - 1 2 - 2 1 - 3 You don't need map in this case, a simple foreach my $MyKey ( sort { $h{$a}-[2] = $h{$b}-[2] } keys %h ) { printf %-s - %-s\n, $MyKey, $h{$MyKey}-[2]; } will work equally well without the need to create extra anonymous arrays. -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Customer Name Parsing
on Wed, 28 Aug 2002 10:11:16 GMT, [EMAIL PROTECTED] (Harry Jackson) wrote: What I would like to know is if there are any modules that can find similar matches in this data (soundex in Oracle is not quite up to the task). Have you already checked out http://search.cpan.org/author/MARKM/Text-Soundex-2.20/Soundex.pm http://search.cpan.org/author/JHI/String-Approx-3.19/Approx.pm -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]