Re: Upgrading from Perl 5.8.0 to Perl 5.8.2
On Mon, 24 Nov 2003 17:19:25 +, Johnston Michael J Contr AFRL/DES wrote: What did I do wrong and how can I fix it? Do I need to uninstall Perl 5.8.0 or do I just need to recompile Perl 5.8.2 somehow? Any advice would be awesome. I upgraded as soon as Perl 5.8.2 hit the street, but I didn't want to fiddle with my exisiting Perl 5.8.0 installation (also from RH 9.0). My solution: Install Perl 5.8.2 in '/usr/local', the point '/usr/bin/perl' to the Perl executable located under the 'local' path; ln -s /usr/local/bin/perl /usr/bin/perl -- Tore Aursand [EMAIL PROTECTED] A teacher is never a giver of truth - he is a guide, a pointer to the truth that each student must find for himself. A good teacher is merely a catalyst. -- Bruce Lee -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: search and replace in complexed text file?
On Thu, 20 Nov 2003 13:37:33 -0800, Nick Ellson wrote: My problem is how to do a search that will stop at a username, reach forward in the file to find the next occurance of TYPE and then STATUS, make the replacements, and then continue searching the file for the rest of the usernames. Easy enough. What have you tried so far? -- Tore Aursand [EMAIL PROTECTED] A teacher is never a giver of truth - he is a guide, a pointer to the truth that each student must find for himself. A good teacher is merely a catalyst. -- Bruce Lee -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: matching query.
On Tue, 18 Nov 2003 21:22:07 +, Steve Massey wrote: I want to match Help Help ## match this Helps## not match this I am using syntax below, but it's not working $help = Help; if ($source =~ /^$help/) Do you really need to use a regular expression to do this? What about the 'eq' operator? if ( $source eq 'Help' ) { # Match } -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: CPAN or ?
On Tue, 18 Nov 2003 11:29:39 -0500, Tim wrote: I need some help in using CPAN or other means to figure out what modules are on my system. This is answered in the FAQ; perldoc -q installed Note that you'll have a new set of @INC libraries when you install a new Perl, which is a good thing; A lot of the modules may need to be recompiled with the new Perl. -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Can a regex match numbers?
On Tue, 18 Nov 2003 16:37:06 +, Jabez Wilson wrote: Is it possible to specify number matching in a regex, i.e. can you have something like: my $match =~ m/match_number_if_number_is_less_than_255/ instead of my $match =~ m/(\d{3})/; if ($1=255){my @array = @array +$1}? Yes, but would you? IMO, using regular expressions to check the value of something creates less readable code. I tend to prefer to first check if I'm really dealing with a number, and then checking the value of it in a good old fashion way; if ( $nr =~ m,^[-+]?\d+$, $nr 255 ) { # Match } I don't need to write that regular expression every time, of course, 'cause I've been nice enough to put it in a module so that I only need to write 'is_int($nr)' each time. (And the actual implementation of the is_int() function is heavier; It check if a number really _is_ a number - the above don't, really...) -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: beginners oops module
On Mon, 17 Nov 2003 12:46:08 +0100, Tore Aursand wrote: i wanna look at the (source code of) modules which give a basic understanding of OOPS programming style in Perl. any pointers will be helpful . Pointers to what? Just take a look at come of the OO modules/classes out there, if you want to. I would rather point you to a part of the Perl documentation relating to OO: perldoc perlobj perldoc perltoot perldoc perltooc And - of course: perldoc perlboot -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: File upload script
On Mon, 17 Nov 2003 01:08:46 -0800, perl wrote: In any case, I'm wondering if use CGI is the package to use [...] Why don't you bother finding out? 'perldoc CGI'. Search for 'upload'. -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Perl Equavlent
On Sun, 16 Nov 2003 23:24:29 -0800, R. Joseph Newton wrote: If you want to round, use: my $rounded = int ($float_value + 0.5); ...which only works if you have a positive number. You must make it a bit more foolproof; my $rounded = ($nr 0) ? int($nr + 0.5) : int($nr - 0.5); -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: beginners oops module
On Mon, 17 Nov 2003 16:43:55 +0530, km wrote: i wanna look at the (source code of) modules which give a basic understanding of OOPS programming style in Perl. any pointers will be helpful . Pointers to what? Just take a look at come of the OO modules/classes out there, if you want to. I would rather point you to a part of the Perl documentation relating to OO: perldoc perlobj perldoc perltoot perldoc perltooc -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: matching
On Mon, 17 Nov 2003 15:18:47 -0700, Eric Walker wrote: How do I get it to do more than one substitution in the string. By using the /g modifier. $_ = $$Rules{$yes}{rule_desc}; No. Don't _ever_ try to set $_ yourself, unless you _really_ have to (which you don't in this case). $_ = $$Rules{$yes}{rule_desc}; s//\\/; $$Rules{$yes}{rule_desc} = $_; These three lines could easily have been shortened down to only one; $$Rules{$yes}{rule_desc} =~ s//\\/g; However: Why do you need to quote the characters? -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Help with UNIX commands
On Fri, 14 Nov 2003 20:36:54 -0500, Mame Mbodji wrote: I am researching some unix commands and I would like to know if someone knows where I can find them online. What does this have to do with Perl? The obvious answer, though, is to tap twice on the TAB key, write down what you see, and then prepend each command with 'man' and then see what you get. Example: man cat Easy! :-) -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: What $| actually does?
On Sat, 15 Nov 2003 14:35:12 +0200, John wrote: Why the $I is required in a perl script? It isn't. (Does it help the perl to handle dynamically the memory?) No. Read the documentation 'perldoc perlvar'; If set to nonzero, forces a flush right away and after every write or print on the currently selected output channel. Default is 0 (regardless of whether the channel is really buffered by the system or not; $| tells you only whether you've asked Perl explicitly to flush after each write). STDOUT will typically be line buffered if output is to the terminal and block buffered otherwise. -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Help Required
On Fri, 14 Nov 2003 00:17:29 -0600, Andrew Gaffney wrote: In my cgi script I want to open some site let us suppose http://www.google.com use CGI; my $cgi = new CGI; print $cgi-header; print scriptlocation.href = 'http://www.google.com';/script There is a more correct way to do this using HTTP codes, such as: print HTTP/1.0 302 Found\n; print Location: www.google.com\n\n; Not quite right CGI.pm-wise, as the CGI module _has_ a redirect() function; use CGI; my $cgi = CGI-new(); print $cgi-redirect( 'http://www.google.com/' ); More information: perldoc CGI -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Parsing for base domain
On Fri, 14 Nov 2003 01:40:35 -0800, perl wrote: I would like to parse the servername to get the base domain or atleast x.com, x.org, x.net, etc. from something like www.x.com. There are modules on http://www.cpan.org/ to do this for you, but if you _only_ have the names you mentioned, you could always split into an array and the retrieve the two last elements of that array; my @parts = split( /\./, $host ); my $left = $parts[-2] || ''; my $right = $parts[-1] || ''; -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: validate email chars
On Wed, 12 Nov 2003 23:05:53 -0800, perl wrote: Can someone help me with validating email address chars? This is a FAQ: perldoc -q valid mail -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Counting (easy!)
On Thu, 13 Nov 2003 09:05:45 -0600, Dan Muey wrote: In Perl that is usually written as: for $count ( 1 .. 5 ) { print $count\n; } Or even easier: for(1..5) { print; } Or _even_ easier; print 1..5; Hah! :-) -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Version differences
On Thu, 13 Nov 2003 20:15:18 +0530, Sachin Mathur wrote: I Wanted to know what are the differences in version 5.005 and version v.5.8.0 of perl Check out perldelta for each version. -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Counting (easy!)
On Thu, 13 Nov 2003 16:19:32 -0500, Jimstone77 wrote: I have a list of email addresses in a text file one to a line. How would I seach for a particular email address? $email = [EMAIL PROTECTED]; while FILE { if ($email eq $_) { $OK = 1; } } Doesn't this work? I would have inserted a 'last' in the loop, though, and chomp'ed the $_; while ( FILE ) { chomp; if ( $email eq $_ ) { $OK = 1; last; } } -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Package Help
On Fri, 14 Nov 2003 07:47:36 +1100, Colin Johnstone wrote: my $formName = 'form'.$self-? my $formName = 'form' . $self-{'FRM_CNT'}; my ($proto, $sysData) = @_; my $class = ref($proto) || $proto; No need for all this. Just write: my $class = shift; my $sysData = shift; -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: regexp matching- real simple!
On Thu, 13 Nov 2003 18:15:40 -0500, Nandita Mullapudi wrote: I want my script to carry out a loop only if the number stored in $diff is positive, so i say if ($diff =~m/^[-\d+]/) {blah blah} but it won't work. why? That's pretty irrelevant in your case; You're using a cannon to get rid of your neighbours cat. As long as $diff is numeric, you can use this code; if ( $diff 0 ) { # ... } -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: question
On Wed, 12 Nov 2003 15:56:39 +, Dillon, John wrote: I´m new with perl. I need to write a program that reads data out of a form sent via internet and is able to interpret the data. I have written the form in html. Is perl right for the other parts? How can I do this easyly? Are there any pre-witten programs or modules existing for that? PHP is what I use. Why do you post PHP code in a Perl newsgroup? www.php.net is easier than anything I've found on perl. You mean that that the web-site www.php.net is easier than anything found on the programming language perl? Explain. See also database language on the slightly confusing www.mysql.com. How is the web-site www.mysql.com confusing? Explain. And what has that got to do with Perl? PHP database query looks like this: $myquery = SELECT table.field FROM table WHERE table.field = '$variable'; $result = mysql_db_query($db, $myquery, $connection) or die (myquery failed.); $arr = array(); $x = 0; while(list($a) = mysql_fetch_array($result)) { $arr[$x] = $a; $x++; } This code isn't safe, but that's not PHP's fault. What happens if $variable is messed with? Similary job is done with only one line using Perl's DBI module, and this code is even secure compared to the PHP code above: my $arr = $dbh-selectcol_arrayref('SELECT field FROM table WHERE field = ?', undef, $variable); Variables are GETed or POSTed automatically with the form on submit. That has nothing to do with the programming language on the server side, actually, but is a part of the HTTP implementation. You can use regex's also. So can Perl, right? While this is off-topic re Perl, [...] It really is! -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: DBI MYSQL
On Wed, 12 Nov 2003 13:48:26 -0500, Larry Sandwick wrote: #! /usr/bin/perl Always: use strict; use warnings; use DBD::mysql; No need to. DBI will take care of this (when you declary the database type to be 'mysql'). $dsn = DBI:mysql:webmaster,blackhole; my $dsn = DBI:mysql:database=webmaster;host=blackhole; As long as the user has access to the database 'webmaster' on the host 'blackhole', this should work. If it doesn't, then you should surf over to www.mysql.com and read the documentation. -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Fw: question
On Wed, 12 Nov 2003 19:44:02 +, John Dillon wrote: whereas php started as a HTML manipulation language and is good for database interaction, for which arrays are important. In which way are arrays _important_ for database interaction? The important things when dealing with databases is to get the job done in the best, most scalable and dynamic way. I still haven't seen _one damn thing_ that PHP does better than Perl, but I've seen a lot of things that can be done better in Perl than in PHP. That's not necessarily a bad thing, 'cause PHP is very web-centric, while Perl is easier to use when dealing with that _and_ other things (like system administration, for example). I'd love to see examples on what Perl can't do compared to PHP. -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Counting (easy!)
On Thu, 13 Nov 2003 01:05:37 +, Trent Rigsbee wrote: for ($count = 1; $count = 5; $count++) { print $count\n; } This is very C'ish. In Perl we tend to: for ( 1..5 ) { print $_ . \n; # sleep( 1 ); } Uncomment the sleep() thing if you want Perl to sleep for 1 second for each iteration. Try 'perldoc -f sleep' for more information on sleep(). What I wanted to do was to make each number appear in sequence like you see in a countdown (or up, in this case) instead of all on the screen at once. I'm not sure what you really mean, but if you want to replace the previous number with the new one, you need to send some backspaces (\b) to STDOUT; my $from = 1; my $to = 60; my $prev = 0; $| = 1; # We don't want to buffer the output for ( $from .. $to ) { print $_; sleep( 1 ); print \b x length($prev); $prev = $_; } If you really need your application to display some information on its progress, you really should check out Term::ProgressBar on CPAN: http://www.cpan.org/ Also, any methods or ideas on how to approach creating code in general? 1. Learn Perl. 2. Try to do something. 3. If #2 fails, read any documentation you can find. 4. comp.lang.perl.misc -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Help with Error Message: Can't use an undefined value as a hash reference
On Wed, 12 Nov 2003 18:29:01 -0500, Dan Anderson wrote: I'm completely lost trying to debug it because the line in question is a }. Well. I'm totally lost, too. There's a lot of things in the code which you can improve to make it more fail-safe, but for now: What line are you referring to? And could you please give some examples on what the input to this function could look like? Thanks. -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Playing with Numbers
On Mon, 10 Nov 2003 16:13:43 -0500, SilverFox wrote: Hi all, i'm trying to figure out how to test if a number is five digits and if not add zero/s in front to make it 5 digits. Any ideas? You don't necessarily need to test if a number is x digits. You purely tell Perl to treat it like x digits what-so-ever; $number = sprintf(%05d, $number); Hence, you might want to check if the number really _is_ a number, and that's a whole other story alltogether. :-) -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Representing a Database as XML
On Mon, 10 Nov 2003 16:44:04 -0500, Dan Anderson wrote: Does anyone know of a good module to use to represent a database (or SQL statements) as XML? What are you _really_ asking for here? Do you want to use XML to store your data, or do you want XML to store information about how to interact with any database? The latter doesn't make sense, though; That would be to create a language which multiple DB platforms comply with. SQL already does that, more or less (just try avoiding the DB-specific solutions). -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Loggin in from form
On Tue, 11 Nov 2003 16:06:18 -0600, Dan Muey wrote: What do I need to do to make a script that will take that input and log the user in to an apache .htaccess protected directory? Have you searched CPAN? I'm sure I've seen module(s) there which does what you request. -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Why is parsing your own form data a bad idea?
On Thu, 06 Nov 2003 19:37:51 +0100, Jenda Krynicky wrote: My point is still valid, though; Why do one want to use CGI::Lite instead of CGI.pm? Is it better? No. Define better. Well. Actually I guess it's a combination of all the other factors I listed. :-) Is it safer? No. Can't say. I guess not. But you can't be safer than safe, can you ;-) With CGI.pm you are sure that millions of other servers are using it, and thereby it's been tested more thoroughly. Is it faster? No. Oh yeah. See http://www.perlmonks.org/index.pl?node_id=145790 Neither of the benchmarks on that address uses a real-life mod_perl scenario as basis for the testing. -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Why is parsing your own form data a bad idea?
On Wed, 05 Nov 2003 17:22:43 -0600, Dan Muey wrote: If it comes to the point where you need to hack around CGI.pm, I'd say go with your original inclination to just do it yourself. Give me one example when you'd need to hack CGI.pm to handle input that you can't do without hacking it. This might not justify as hacking the CGI.pm, but once I had to do something really special related to session handling. The solution wasn't to hack, change or write my own CGI handling module, but simply subclass the original CGI.pm. -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Reading and from more than one filehandle / memory question
On Thu, 06 Nov 2003 10:31:18 -0600, James Edward Gray II wrote: my @results; [...] Wasn't it the whole point that the OP _couldn't_ store this in an array, as it would consume too much memory? The solution goes like this; 1. Define the files in an array 2. Start reading the first file 3. For each line in the first file, read a line from the other files. Push the lines to an array. 4. Process the array, output the result, go back to #3. -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: RFC on first perl script
On Thu, 06 Nov 2003 16:33:41 +, drowl wrote: #!/usr/bin/perl -w No big deal, but - IMO - easier to read, and it adds strict; #!/usr/bin/perl # use strict; use warnings; @dataFile=; # read in file from command line @standardRules=`cat standard.for.arf.txt` ; my @dataFile = ; my @standardRules = `cat standard.for.arf.txt`; Also have in mind that this is platform dependent, as there is no 'cat' command in DOS/Windows (or on many other platforms, I would guess). Instead of doing the whole work with open, read and close all the time, you could do as me: Write your own module which has a 'read_file' function; sub read_file { my $filename = shift || ''; my @lines = (); if ( $filename -e $filename ) { if ( open(FILE, $filename) ) { @lines = FILE; close( FILE ); chomp( @lines ); } } return ( wantarray ) ? @lines : join(\n, @lines); } This one is very simplified, but it gives you and idea. Next time you need to read a (text) file: my $text = read_file( 'text.txt' ); #split up main / pvc info ($siteLink,$siteNoOfPVCs,$siteAllPVCs)=split(/:/,$site,3); As long as we don't know what the contents of $site looks like, we can't comment on this. for ($i = 0; $i $siteNoOfPVCs ; $i++ ) { # loop for each PVC I guess this should do the trick: foreach ( @sitePVCs ) { # ... } -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Why is parsing your own form data a bad idea?
On Thu, 06 Nov 2003 13:21:15 +0100, Jenda Krynicky wrote: There is absolutely _no_ reason why one shouldn't use the CGI.pm module. There is one. If /s?he/ is using CGI::Lite instead ;-) In that case, there are many reasons. There are a lot of CGI::* modules out there. My point is still valid, though; Why do one want to use CGI::Lite instead of CGI.pm? Is it better? No. Is it safer? No. Is it faster? No. Is it more widely used? No. Does it come with the Perl distribution? No. -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Simple CGI Question
On Wed, 05 Nov 2003 01:26:20 -0500, Jack wrote: In my perl CGI script, I'm trying to extract the PID that corresponds to it. The '$$' variable holds the pid; perldoc perlvar How come it's not possible to do something like: print HTMLBODY; print `time`; print /BODY/HTML; No need to do a system call for 'time' here, when you got all you need built-in in Perl; perldoc -f localtime -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Regex search using scalar
On Tue, 04 Nov 2003 20:41:17 -0800, Paul Harwood wrote: I would like to enumerate a list and search through each element like so: [...] Why do you want to enumerate the list? Do you _really_ need to know the index of the current element? If really so: my $i = 0; foreach ( @list ) { $i++; if ( /match/ ) { # ... } } If (/$logs[i]/) Please post _real_ Perl code. The code above has no meaning and won't even compile. -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Top-posting
On Wed, 05 Nov 2003 14:45:09 -0500, Paul Kraus wrote: I don't see why it matters how you send your message. Please don't take this too hard, but it seems like you haven't been in the game long enough to understand _why_ there are rules on how one should keep an discussion going. There are _way_ too many _good_ reasons why one should _not_ top post. I don't bother repeating them, as a quick search on Google will give you the obvious answers. This is not a news group. It may propagate but its not a news group. It _is_ a newsgroup. It is a pain in the ass to have to remember to change the way I send a message based on the fact its going to the group. Please explain _why_ you have to remember how to send a message. Is it like this when you speak with different persons, too? You have to remember to speak differently to one of them? My company uses outlook. Too bad. There have been times in the past when I was forced to use that software, but I still managed to follow the rules; I just deleted the crap Outlook inserted in my replies, moved to the end of the message and then wrote my reply. You would think that the world was going to end because somebody was upset they didn't get to scroll through 500 posts. Quoting is a nice thing. It's a thing top posters don't care about, though; One should only keep what's relevant from the original post when replying to one. That way you _don't_ have to scroll past that many posts to find out what the thread is all about. -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Reading and from more than one filehandle / memory question
On Wed, 05 Nov 2003 14:47:53 -0500, Motherofperls wrote: I have some large files that all have data for filling one table. What is a table in this context? 1. I want to read from each of these files one line at a time at the same time without assigning the file to an array. Easy enough; Just open both files and read one line at a time from both of them. But what do you want to do if one of the files have more lines in it than the other? Does anyone have any example code? For what? Reading from files? What are you having trouble with? -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: help building hash on-the-fly?
On Wed, 05 Nov 2003 15:23:49 -0700, McMahon, Chris wrote: But an array doesn't suit my needs. What I really need is a hash where each item in the directory is a value associated with a key that is a number 1-n such that I could issue a print statement that would show something like (to oversimplify!): If I understand you correctly, you just want to map each directory/file with an incremental number. An array already have an internal number; the index of the actual element in the array. So: my @files = /dir/*; my $key = STDIN; my $element = $files[$key - 1] || No directory/file at position $key; print $element . \n; -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Why is parsing your own form data a bad idea?
On Wed, 05 Nov 2003 17:22:10 -0500, Dan Anderson wrote: So I got so far with my own creation and am wondering if it should be given the axe or continued. Axe it. Really. There is absolutely _no_ reason why one shouldn't use the CGI.pm module. -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to source an html-page (containing vars)
On Tue, 04 Nov 2003 09:49:43 +0100, David van der G wrote: I have a CGI-script that needs to print an html-page containing variables dependent on the choise you make. Don't mix Perl code and HTML (or other presentation data). Take a look at HTML::Template (or one of the many other template modules) on CPAN; http://www.cpan.org/ -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: ref's to subs
On Tue, 04 Nov 2003 13:58:41 -0500, mgoland wrote: %hash=( 1 = funca(), 2 = funcb(), ); Try this: %hash = (1 = \funca(), 2 = \funcb()); -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Web-based calendar script
On Thu, 30 Oct 2003 17:18:06 -0500, William.Ampeh wrote: I am looking for a Web-based calendar manager [...] What excactly is a calendar manager? To me it sounds like software (web based, this time) which manages calendars. Do you really have that many? :-) -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Data::Dumper-dump()ing a hash?
On Thu, 30 Oct 2003 23:45:25 +0100, Kevin Pfeiffer wrote: print Dumper(\$hash_ref); I guess $hash_ref already _is_ a hash reference, so you don't need to reference it again; print Dumper( $hash_ref ); -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Splitting OR Regex
On Thu, 30 Oct 2003 23:37:55 -0500, Scott, Joshua wrote: How can I split the data in a line by a single whitespace but also keep portions between quotes together? This is a FAQ: perldoc -q delimit -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Data::Dumper-dump()ing a hash?
On Thu, 30 Oct 2003 16:53:14 -0500, Dan Anderson wrote: my $dumper = Data::Dumper-new( [%entry], [ qw () ] ); my $dumpedvalues = $dumper-Dump(); print $dumpedvalues . \n; Why all this fuss? :-) I constantly use this syntax: use Data::Dumper; print Dumper( \%hash ); Never bothered to read the documentation for Data::Dumper. Maybe I should some day. -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Corrupted Data
On Thu, 30 Oct 2003 09:45:58 -0500, Jimstone77 wrote: open(OLD,$old) or die Can't Open File: $!; flock OLD, 2; open(NEW,$new) or die Can't Open File: $!; flock NEW, 2; while (OLD) { if ($_ =~ /NO_EMAIL/) { $count++; } else { print NEW $_; } } close(NEW) or die Can't Close File: $!; close(OLD) or die Can't Close Old: $!; First of all: Post your _actual_ code. The code above won't even compile, and it's really easy to see (or find out) why. Secondly, you're trying to write to a file you opened for reading. -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How Do I initialize an empty array
On Tue, 28 Oct 2003 11:53:44 -0700, Wiggins d Anconia wrote: or if you know the length of the array ahead of time: my @rows = ('','',''); I prefer the following instead: my @rows = ('') x 3; Easier to read...? -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to store arrays in hashes or objects?
On Tue, 28 Oct 2003 20:40:07 -0800, Richard Heintze wrote: I have an array stored in an object and I trying to compute the length of the array. This seemed to work initially: my $nColumns = [EMAIL PROTECTED]{component_titles}}}+1; $#array gives to the index of the _last_ element. If you want the length of the array (ie. the _number_ of elements), you should evaluate the array in a scalar context; my $length = @array; # or @{ $array } for array references Something changed, I don't know what, and perl started dying on the above statement with no error message or explanation. Really? Did you include strict, warnings and diagnostics? #!/usr/bin/perl # use strict; use warnings; use diagnostics; Always use these (at least strict and warnings) when developing Perl code. I had to resort to this technique: my @ComponentTitles = @{$me-{component_titles}}; my $nColumns = $#ComponentTitles+1 ; Could have been written as: my $nColumns = @{ $me-{component_titles} }; I don't really do anything to create to create this array -- I just start storing elements like this: $me-{component_titles}[0] = xyz; You could always initialise an array reference; $me-{component_titles} = []; And then you could assign values to it: $me-{component_titles}-[0] = 'xyz'; Are you sure you want to assign data directly onto an element index? Have you considered push()'ing data onto the array? I tried to create a second array and store it by reference like this: my $a = []; $me-{a} = \$a; $a is _already_ an array reference. No need to make a reference of a reference. :-) my @array= (); my $arrayref = [EMAIL PROTECTED]; -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: RE : SQL Syntax quickie
On Sun, 26 Oct 2003 06:30:11 +0100, SIMON Cedric wrote: For your query, try SELECT MAX(id) FROM table That works with mysql. That should work with most databases, but what happens if there's a new insert between the original insert and the SELECT statement above? This _could_ be solved by locking the table before the insert, and then unlocking it again after you've select the maximum id from the same table. -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: how to pass multi array as args
On Sun, 26 Oct 2003 01:52:21 -0700, perl wrote: sub mysub { my( $x, $y, $z ) = @_; Can I have three arrays instead? Why would you have that? There are a lot of advantages by using references. -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Array Reference Practice Help
On Sun, 26 Oct 2003 01:35:47 -0800, perl wrote: Is this a standard/normal/ok way to pass and use array by reference? Almost, I would say. #calling by reference showIt([EMAIL PROTECTED], [EMAIL PROTECTED]); sub showIt { my $a = $_[0]; #assinging by reference my $b = $_[1]; print a[0]: . $$a[0] . \n; #accessing by reference print b[0]: . $$b[0] . \n; } The 'showIt()' should rather be something like this: sub showIt { my $a = shift; my $b = shift; print 'a[0]: ' . $a-[0] . \n; print 'b[0]: ' . $b-[0] . \n; } As I _hope_ you can see, $a-[n] is easier to read than $$a[n]. Don't you agree? -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: RE : SQL Syntax quickie
On Sun, 26 Oct 2003 13:40:20 +, dan wrote: The MAX(id) didn't return anything [...] Are you sure about that? Generally, MAX(id) _always_ returns something, ie: SELECT MAX(user_id) FROM user This one will return the highest 'user_id' value, _or_ 0 if there are no records in the 'user' table. SELECT id FROM memodata ORDER BY id DESC Then you should also limit the expression, thus offloading the SQL server a bit; SELECT id FROM memodata ORDER BY id DESC LIMIT 1 then take the first line value and ignore the rest. With 'LIMIT' you don't need to worry about ignoring anything. Just ignore ignoring. :-) Ideally though i want the last line with the highest id number. If you want the last auto_increment value, you could always use the MySQL proprietary 'mysql_insertid'; my $stInsert = $dbh-prepare( ... ); $stInsert-execute(); $stInsert-finish(); my $last_insert_id = $stInsert-{ 'mysql_insertid' }; I know for a fact that another INSERT won't happen before the SELECT because they happen immediately one after the other. Do yuo really? Is there _always_ only one user using the script? -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: SQL Syntax quickie
On Sat, 25 Oct 2003 10:43:51 +0100, dan wrote: Basically what happens is the program enters information using INSERT, and then it needs to re-read the data it's just sent to verify it, and get the id number that auto_increment assigned it. You don't say anything about what RDBMS you're using? With MySQL you could easily look up the information you're looking for in the manual, while other database systems need other approaches. Stick with an RDBMS which gives you transactions. -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: printing same type of files from mutiple subdirectories of a directory
On Fri, 17 Oct 2003 09:06:24 -0700, A L wrote: Let's say there is a directory called Top. Within the Top directory, there are 26 subdirectories named A-Z. Within each of those A-Z subdirectories contain one or more filess that ends in .txt extension. Now, to print out the content within all those .txt files, what can you do to not type in each separate directory handle and file handle? 'perldoc File::Find' #!/usr/bin/perl # use strict; use warnings; use File::Find; find( \show_file, '/home/Top' ); sub show_file { return unless ( /\.txt$/ ); if ( open(FILE, $_) ) { while ( FILE ) { print $_; } close( FILE ); } else { # Couldn't open the file } } -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: email (HTML) pushed/pulled into web page
On Fri, 17 Oct 2003 06:35:13 -0700, Gregg O'Donnell wrote: I have a form, and the data from that form is formatted in HTML and emailed to recipients. Is there a way to save the HTML-formatted message as a separate file? And have a web page template call this file as a server-side include file? You mean using a file as a template? Sure. Take a look at the many template modules on CPAN. The idea is something like this: 1. Read form data 2. Read the template file 3. Put form data into the template file 4. Generate output from template The data also goes into a CSV file; [...] There are CSV modules on CPAN, as well. You might want to check them out. -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Comparing file dates with current date
On Thu, 16 Oct 2003 11:07:44 -0700, Paul Harwood wrote: I am trying to compare a file's modified timestamp with the current date. Take a look at the Date-related modules on CPAN. There are almost too many to list here, but those I use frequently (more or less), are: Time::Piece Date::Calc Date::Manip I guess Date::Calc is the most relevant for you in this case. -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Another sub clean up
On Tue, 14 Oct 2003 19:26:50 -0700, perl wrote: Can someone hlpe me clean up this trim? What do you actually mean by clean up? Make the code shorter and, maybe, more obfuscated? Why? Rule: remove all trailing blanks and newline/LF sub trim { my $string = shift; chomp( $string ); $string =~ s,^\s+,,; $string =~ s,\s+$,,; return $string; } This is clean _to me_, but I have no idea if you really need that chomp() thing. Never tested the code above. -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: finding a blank line
On Wed, 15 Oct 2003 02:24:25 -0500, Jerry Preston wrote: I know this is a no brainer, but this line of code does not always work: last if( /^\n/ or /^\s+\n/ ); Can't you check the length of the line? last unless ( length ); This will work if the line really _is_ blank. However, humans tend to look upon lines filled with spaces as blank lines, too. :-) -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: A trouble
On Tue, 14 Oct 2003 16:06:32 +, bastidas wrote: Suppose I have a file with, for example, 10 lines, every one composed by a inferior value and a superior value and a string. Every inferior value is equal to superior value of the before line. On the other hand, I have other file with, for example, 1000 lines with a only column of values and I want to create another column here with the value of the string if the value of the column is between two values (inferior-superior) of the same line in the first file, I mean, it would be several consecutive lines with the value of the string of the line 1 of first file, after, several consecutive lines with the value of the string of the line 2, and so on. Quite hard to understand what you mean, but I'll give it a try. Please have in mind that the code below is untested. Let's say that the first file has only 1 column with numbers, while the second file has 3 columns separated with one more more spaces. #!/usr/bin/perl # use strict; use warnings; my %data = (); open( F1, 'file1.txt' ) || die $!\n; while ( F1 ) { chomp; s,^\s+,,; # Remove leading spaces s,\s+$,,; # Remove trailing spaces $data{ $_ } = ''; } close( F1 ); open( F2, 'file2.txt' ) || die $!\n; while ( F2 ) { chomp; s,^\s+,,; # Remove leading spaces s,\s+$,,; # Remove trailing spaces my ($inf, $sup, $str) = split(/\s+/, $_, 3); foreach ( keys %data ) { if ( $_ $inf $_ $sup ) { $data{ $str } = $str; } } } close( F2 ); # You might want to sort %data here foreach ( keys %data ) { print $_ . \t . $data{ $_ } . \n; } Hope this helps! -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: is next implied in a set of if elsifs?
On Wed, 15 Oct 2003 17:34:33 -0400, Dan Anderson wrote: How is speed affected in the following scenarios: [...] Why don't you find out? Take a look at the Benchmark module. There is also a 'SWITCH' module out there, I think. You might look at that one, too. -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Which action button clicked?
On Tue, 14 Oct 2003 02:35:02 -0700, perl wrote: Can someone show me how to determine which button the user clicked? This hasn't all that much to do with Perl, really. input type=submit value=LEFT input type=submit value=RIGHT Name your input fields. For example something like this: input type=submit name=direction value=left / input type=submit name=direction value=right / Now, in your script: my $direction = $cgi-param( 'direction' ) || ''; -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: working on time
On Fri, 10 Oct 2003 14:57:47 +0200, [EMAIL PROTECTED] wrote: i search hiw can i work on time. i want to get day number and make -1 Check out the heap of Date-related modules on http://www.cpan.org/. -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: working on time
On Fri, 10 Oct 2003 12:13:45 -0400, Bill Akins wrote: Try this: #!/usr/bin/perl -w my @now = localtime; my $sec = ( $now[0] ); my $min = ( $now[1] ); my $hr = ( $now[2] ); my $day = ( $now[3] ); my $mth = ( $now[4] + 1 ); my $yr = ( $now[5] + 1900 ); $day = ($day -1); No! Do _not_ try this! What happens when you're using this code on the 1st of a month? I recently fallen in love (...) with Time::Piece (and Time::Seconds), which let me do this in a nifty way; #!/usr/bin/perl # use strict; use warnings; use Time::Seconds; use Time::Piece; my $today = localtime; my $yesterday = $today - ONE_DAY; my $tomorrow = $today + ONE_DAY; Install Time::Piece and do a 'perldoc Time::Piece' for more information. -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Fwd: required help
On Fri, 10 Oct 2003 08:40:17 -0500, James Edward Gray II wrote: I want to insert data from sms_log ie 10.100.208.254 server to 10.100.200.47 table ie sms_log1. Well. What have you tried so far? It should be easy as long as you create two database connections? -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: if (-d .....
On Wed, 08 Oct 2003 12:39:40 +0200, Daniel Stellwagen wrote: if (-d $file) What does it mean, and are there more Try 'perldoc -f -d'. -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Handling Dates Suggestions
On Wed, 08 Oct 2003 17:56:03 -0700, perl wrote: Can someone offers some recommendation into using dates? Take a look at CPAN [1] for Date-related modules. My personal favorite has become Time::Piece, although all the Date::* modules should be looked upon. [1] URL:http://www.cpan.org/ -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Add text to beginning every line
On Mon, 06 Oct 2003 14:20:05 -0400, Chris Charley wrote: Then, on the command line I type: perl prepend.pl somefile.txt, but somefile.txt does not have the changes(Line: linenumber). Try writing 'perl prepend.pl somefile.txt newfile.txt' instead. -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Chopping off firstlast character in a string
On Tue, 07 Oct 2003 12:56:50 -0400, Li, William wrote: Silly question, is there an equal but opposite function to chop in Perl? No. I'd like to remove the first and last character of a string and am looking for a simple way to do it. The most elegant way to do it, IMO, is to use a regular expression: $string =~ s/^.(.*).$/$1/; Another solution, and most probably a lot faster, is this one: $string = substr( $string, 1, (length($string) - 2) ); If you don't need the speed, stick with the first solution. -- Tore Aursand [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]