From chicks at chicks.net Wed Nov 1 06:18:10 2000 From: chicks at chicks.net (chicks@chicks.net) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] Larry's ALS talk (fwd) Message-ID: Very cool. -- "The number of Unix installations has grown to 10, with more expected." -- The Unix Programmer's Manual, 2nd edition, June '72 ---------- Forwarded message ---------- Date: Mon, 30 Oct 2000 10:34:22 -0700 (MST) From: Nathan Torkington To: perl6-announce@perl.org Subject: Larry's ALS talk Now available: mp3s, a full text transcription, his slides, and a bullet-point summary of the perl6 content. http://dev.perl.org/~ask/als/ Cheers; Nat From twebster at pcs.cnu.edu Sat Nov 4 10:27:15 2000 From: twebster at pcs.cnu.edu (Troy E. Webster) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] fork and exec In-Reply-To: Message-ID: Ok guys...I'm having issues here. I pretty much understand fork and exec and the relationships between parent and child processes. Or I thought I did. Basically I need to fork a child process and have the parent process wait on the child to finish up before continuing on. I think I've got a working piece of code to do this, but it's not working as expected. Here's the code (it's short) and then the output. After that is the output that I think is supposed to happen. They are different. if (!defined($kidpid = fork())) { #fork returned undef, so failed die "cannot fork: $!"; } elsif ($kidpid == 0) { #fork returned 0, so this branch is the child print "here in child before exec\n"; # this next command takes a word document and # writes an ANSII text version of it to disk # using antiword exec("./antiword ./uploads/$ARGV[0] > uploads/text.txt"); #if exec fails, fall thru to the next statement die "can't exec antiword properly: $!"; exit; } else { #fork returned neither 0 nor undef, so this branch is parent #wait for kid to finish up file write print "here before wait.\n"; waitpid($kippid, 0); print "here after wait.\n"; #now its safe to open up text.txt.... $cnt = chmod(0777, './uploads/text.txt'); if ($cnt == 0) { print "unable to chmod the text file."; warn "can't chmod the text file"; } open(FH, "./uploads/text.tx |") or print "Unable to open up the text.txt file: $!"; close(FH); } web4>perl thingy.cgi Cafeteria.doc here before wait. here after wait. here in child before exec can't chmod the text file at thingy.cgi line 52. unable to chmod the text file web4>perl thingy.cgi Cafeteria.doc here before wait. here in child before exec here after wait. any ideas?? Am I missing something here? troy ___________________________________________________________________________ ``Beware of bugs in the above code; I have only proved it correct, not tried it.'' -Don Knuth --------------------------------------------------------------------------- From twebster at pcs.cnu.edu Sat Nov 4 10:55:46 2000 From: twebster at pcs.cnu.edu (Troy E. Webster) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] Re: fork and exec In-Reply-To: Message-ID: sorry, there was a freakin typo I wasn't seeing till I started using -w like I should have in the first place. kidpid NOT kippid ... duh troy ___________________________________________________________________________ ``Beware of bugs in the above code; I have only proved it correct, not tried it.'' -Don Knuth --------------------------------------------------------------------------- From chicks at chicks.net Sun Nov 5 08:16:35 2000 From: chicks at chicks.net (chicks@chicks.net) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] Re: fork and exec In-Reply-To: Message-ID: On Sat, 4 Nov 2000, Troy E. Webster wrote: > sorry, there was a freakin typo I wasn't seeing till I started using > -w like I should have in the first place. Tee-hee. And I was so happy to see a little HRPM traffic. :-) -- "Pinky, you've left the lens cap of your mind on again." - The Brain From twebster at pcs.cnu.edu Mon Nov 6 15:23:23 2000 From: twebster at pcs.cnu.edu (Troy E. Webster) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] matching blank lines In-Reply-To: Message-ID: Ok time for a stupid question, I need a bullet proof way to match a blank line with whatever whitespace is on it. using $line eq "\n" isn't working in all cases. Isn't there a way to match *only* whitespace using the =~ operator? Thanks, Troy ___________________________________________________________________________ ``Beware of bugs in the above code; I have only proved it correct, not tried it.'' -Don Knuth --------------------------------------------------------------------------- From lbyrd at memach.com Mon Nov 6 16:40:26 2000 From: lbyrd at memach.com (Lyman Byrd) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] matching blank lines In-Reply-To: Message-ID: Would something like ^\s+$ work? Lyman On 06-Nov-2000 Troy E. Webster wrote: > Ok time for a stupid question, > > I need a bullet proof way to match a blank line with whatever > whitespace > is on it. > > using $line eq "\n" isn't working in all cases. > > Isn't there a way to match *only* whitespace using the =~ operator? > > Thanks, > Troy > > ______________________________________________________________________ > _____ > ``Beware of bugs in the above code; I have only proved it correct, > not > tried it.'' -Don Knuth > ---------------------------------------------------------------------- > ----- ---------------------------------- E-Mail: Lyman Byrd Tel: 757.543.6801x253 Date: 06-Nov-2000 Time: 17:39:01 The opinions expressed here do not necessarily reflect those of Metro Machine Corp. ---------------------------------- From chicks at chicks.net Mon Nov 6 17:08:11 2000 From: chicks at chicks.net (chicks@chicks.net) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] matching blank lines In-Reply-To: Message-ID: On Mon, 6 Nov 2000, Lyman Byrd wrote: > Would something like > ^\s+$ work? Yes. I prefer to: $line =~ s/\s+$//; next unless length $line; But you could also if ($line =~ /^\s+$/) { -- "Pinky, you've left the lens cap of your mind on again." - The Brain From chicks at chicks.net Sat Nov 11 15:58:45 2000 From: chicks at chicks.net (chicks@chicks.net) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] Lingua::Romana:Perligata - Perl for the XXIimus Century (fwd) Message-ID: This is amusing for the linguisticly inclined. -- "Pinky, you've left the lens cap of your mind on again." - The Brain ---------- Forwarded message ---------- Date: Fri, 10 Nov 2000 16:27:15 -0500 From: Edwin Wiles To: perl6-announce@perl.org Subject: Lingua::Romana:Perligata - Perl for the XXIimus Century Thought y'all might fins this interesting. http://www.csse.monash.edu.au/~damian/papers/HTML/Perligata.html From jeff at alanne.com Sat Nov 11 16:33:07 2000 From: jeff at alanne.com (Jeff Duffy) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] Lingua::Romana:Perligata - Perl for the XXIimus Century (fwd) In-Reply-To: References: Message-ID: <00111117330707.02055@cairhien> On Saturday 11 November 2000 16:58, you wrote: > This is amusing for the linguisticly inclined. ^^^^^^^^^^ Or linguistically, even :) -- For most people, the perceived usefulness of a computer language is inversely proportional to the number of theoretical axes that the language attempts to grind. --Larry Wall From chicks at chicks.net Sat Nov 11 16:36:48 2000 From: chicks at chicks.net (chicks@chicks.net) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] Lingua::Romana:Perligata - Perl for the XXIimus Century (fwd) In-Reply-To: <00111117330707.02055@cairhien> Message-ID: On Sat, 11 Nov 2000, Jeff Duffy wrote: > Or linguistically, even :) I really should enable spell-checking on the fly in pine. :-) -- "Pinky, you've left the lens cap of your mind on again." - The Brain From twebster at pcs.cnu.edu Mon Nov 13 16:17:59 2000 From: twebster at pcs.cnu.edu (Troy E. Webster) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] quick question In-Reply-To: Message-ID: Hey all I need some regular expression help again. I'm trying to match something that should (I thought) be pretty easy. It's actually versioning info that I want to get rid of. For example, the line could look like: 1.1.1.2 1.1.1 .1.1.1.1.1.1.1.1.2 so I tried $_ =~ /(\.*)((\d)(\.)(\d))+/ ... and a huge number of other permutations with the parenthesis. And I don't want to match money i decimal form ($1.25). Any help would be appreciated. Troy ___________________________________________________________________________ ``Beware of bugs in the above code; I have only proved it correct, not tried it.'' -Don Knuth --------------------------------------------------------------------------- From cusce at home.com Mon Nov 13 22:12:11 2000 From: cusce at home.com (Collin Cusce') Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] The page. Message-ID: <007301c04df1$10494bf0$40941718@cx782347a> Not to pick or anything, but the meeting agenda page needs to be updated. It's kinda strange to send people to the HRPM site only to have them notice (without much sleuthing) that it has not been updated in quite some time. I don't want to come off too nit-picky, but it does still have everything from the 28th of June and question marks around every recent month. Just wanted to remind you, being the pain in the ass i am. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/archives/norfolk-pm/attachments/20001113/70d07cac/attachment.htm From cusce at home.com Mon Nov 13 23:46:42 2000 From: cusce at home.com (Collin Cusce') Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] MySQL v. Postgres -- The Eternal Battle. Message-ID: <00d001c04dfe$441172c0$40941718@cx782347a> I was looking at PHPBuilder.com and found this interesting article where Postgres 7.1 went against MySQL 3.23.26beta and kicked its ass with steel-toed boots. I was wondering if you guys wouldn't mind telling me what is wrong with this picture so that I can be a wiser consumer in the future. http://www.phpbuilder.com/columns/tim20001112.php3 Monitor + Hammer = Good Clean Fun! -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/archives/norfolk-pm/attachments/20001114/f9771e90/attachment.htm From chicks at chicks.net Tue Nov 14 09:06:23 2000 From: chicks at chicks.net (chicks@chicks.net) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] The page. In-Reply-To: <007301c04df1$10494bf0$40941718@cx782347a> Message-ID: On Mon, 13 Nov 2000, Collin Cusce' wrote: > Not to pick or anything, but the meeting agenda page needs to be > updated. It's kinda strange to send people to the HRPM site only to > have them notice (without much sleuthing) that it has not been updated > in quite some time. I don't want to come off too nit-picky, but it > does still have everything from the 28th of June and question marks > around every recent month. Just wanted to remind you, being the pain > in the ass i am. Matt can testify that I sent an email last week saying we were going to work on it this week. Cynthia was working on it when I got up this morning and she doesn't read the mailing list. :-) Check it out this evening and let me know what you think. -- "Pinky, you've left the lens cap of your mind on again." - The Brain From chicks at chicks.net Tue Nov 14 12:30:20 2000 From: chicks at chicks.net (chicks@chicks.net) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] quick question In-Reply-To: Message-ID: On Mon, 13 Nov 2000, Troy E. Webster wrote: > I need some regular expression help again. I want a panel van with a big red "/?/" for regular expression emergency assistance. :-) > I'm trying to match something that should (I thought) be pretty easy. > It's actually versioning info that I want to get rid of. For example, > the line could look like: > > 1.1.1.2 > > 1.1.1 > > .1.1.1.1.1.1.1.1.2 > > > so I tried $_ =~ /(\.*)((\d)(\.)(\d))+/ > > ... and a huge number of other permutations with the parenthesis. > > And I don't want to match money i decimal form ($1.25). > > Any help would be appreciated. This is what I came up with: #!/usr/bin/perl -w @input = qw( $1.25 1.1.1.2 1.1.1 .1.1.1.1.1.1.1.1.2 ); foreach $in (@input) { $save = $in; $in =~ s/\d*(\.\d+){2,}//; print "'$save' turned into '$in'\n"; } -- "Pinky, you've left the lens cap of your mind on again." - The Brain From chicks at chicks.net Wed Nov 15 09:48:59 2000 From: chicks at chicks.net (chicks@chicks.net) Date: Thu Aug 5 00:08:11 2004 Subject: [twuug-announce] 29 Nov. - [HRPM] Meeting/Dinner Announcement Message-ID: Please pass the word on for the next Hampton Roads Perl Mongers meeting: What: The monthly Hampton Roads Perl Mongers Meeting http://norfolk.pm.org/ Who: Everyone in Hampton Roads interested in perl. There are no dues or signup requirements. All are welcome to attend. Where: Jefferson Lab in Newport News. Directions are on the web and below. When: 7:30 PM till whenever on Wednesday 29 November 2000 It's generally going to be on the last Wednesday of the month unless major holidays intervene. (This puts us consistantly one week before TWUUG.) FOOD!: 6 PM right across Jefferson from the Lab at Plaza Azteca. Good Mexican food. :-) Why: Why not? What could be better than to come and talk with others about the world's most fun programming language? Jabber, learn, teach, enjoy. Starbucks is not far away. Agenda: Whatever people on the HRPM mailing list decide! Various people who do perl rather often will be there to answer your perl questions. Some expected topics are on the site. ** Chris Hicks will be re-presenting the well-received, but not-so-well-attended presentation on advanced data structures in perl. Directions: http://norfolk.pm.org/location.shtml ( Have we finally got this right? - chicks ) Take 64 until you get to the exit for Oyster Point West. Upon exiting, you will be on Oyster Point Road headed toward Jefferson Ave. (If, after exiting, you find yourself approaching the Kiln Creek shopping center and passing Farm Fresh and Kmart, you've exited in the wrong direction, so turn around.) The third light ahead, and the biggest intersection, is Jefferson Ave. Turn left onto Jefferson and go to the second light. On your left is Jefferson Lab. On your right is Dixie Trailer Park. (On the right, near the first light on Jefferson coming from Oyster Point you will find Plaza Azteca. Yum.) Turn left into Jefferson Lab (Onnes Road) and go about 100 yards to the T-intersection at which Onnes ends. (Ignore the totally innocuous Guard Shack on your right.) Turn left and head (in between all the flag poles) directly to CEBAF Center where the meeting will be held. Turn right just before you reach the circular drive in front of CEBAF Center, and park in the parking lot you will see on your left. Find your way into the building and to the building atrium. The atrium is right off the circular drive. Room L104 branches off the atrium on the right. > 1. What is the possibility of this being added in the future? In the near future, the probability is close to zero. In the distant future, I'll be dead, and posterity can do whatever they like... :-) --lwall - -------------------------------------------------------------------------- * To unsubscribe from the TWUUG discussion list, either send e-mail to - twuug-announce-request@twuug.org with the word "unsubscribe" by itself - in the body of the message or visit: - http://www.twuug.org/lists/twuuglists.html - -------------------------------------------------------------------------- * To unsubscribe from the TWUUG discussion list, either send e-mail to - twuug-announce-request@twuug.org with the word "unsubscribe" by itself - in the body of the message or visit: - http://www.twuug.org/lists/twuuglists.html From twebster at pcs.cnu.edu Wed Nov 15 14:20:29 2000 From: twebster at pcs.cnu.edu (Troy E. Webster) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] nother one In-Reply-To: Message-ID: Hey, This may turn out to be a stupid question, but nothing ventured nothing gained... Is there a way to peek ahead in a foreach loop? For example, foreach $elem (@array){} can I look at $elem+1 while looking at $elem? I realize I can do the same type of loop using a while loop and then checking $array[i+1] (where i is the current element) but I was curious if there was a way to do it with a foreach loop. Thanks Troy ___________________________________________________________________________ ``Beware of bugs in the above code; I have only proved it correct, not tried it.'' -Don Knuth --------------------------------------------------------------------------- From chicks at chicks.net Wed Nov 15 14:36:12 2000 From: chicks at chicks.net (chicks@chicks.net) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] nother one In-Reply-To: Message-ID: On Wed, 15 Nov 2000, Troy E. Webster wrote: > This may turn out to be a stupid question, but nothing ventured nothing > gained... > > Is there a way to peek ahead in a foreach loop? > > For example, foreach $elem (@array){} > can I look at $elem+1 while looking at $elem? I realize I can do the same > type of loop using a while loop and then checking $array[i+1] (where i is > the current element) but I was curious if there was a way to do it with > a foreach loop. Not as far as I know. You'd have to do a for or while loop and keep track of some iterator variable. -- "Pinky, you've left the lens cap of your mind on again." - The Brain From kernell at sundog.larc.nasa.gov Wed Nov 15 14:52:27 2000 From: kernell at sundog.larc.nasa.gov (Robert Kernell) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] nother one Message-ID: <200011152052.PAA04075@sundog.larc.nasa.gov> Hmm, I just started learning Perl, but I don't think you can do it. Just a guess. Maybe you could make a copy of the array and use that in your foreach loop to peek ahead. > Hey, > > This may turn out to be a stupid question, but nothing ventured nothing > gained... > > Is there a way to peek ahead in a foreach loop? > > For example, foreach $elem (@array){} > can I look at $elem+1 while looking at $elem? I realize I can do the same > type of loop using a while loop and then checking $array[i+1] (where i is > the current element) but I was curious if there was a way to do it with > a foreach loop. > > Thanks > Troy > Bob Kernell Research Scientist Atmospheric Sciences Competency Analytical Services & Materials, Inc. email: r.w.kernell@larc.nasa.gov tel: 757-827-4631 From jrowan at visi.net Wed Nov 15 14:54:02 2000 From: jrowan at visi.net (Jeff Rowan) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] nother one References: Message-ID: <001101c04f46$3019b4f0$61b4a6cd@dp.asi> Sorry, no way to do it. It is part of what you give up in using the foreach syntax. but, you could do a look behind. /Jeff ----- Original Message ----- From: "Troy E. Webster" To: Sent: Wednesday, November 15, 2000 3:20 PM Subject: [HRPM] nother one > Hey, > > This may turn out to be a stupid question, but nothing ventured nothing > gained... > > Is there a way to peek ahead in a foreach loop? > > For example, foreach $elem (@array){} > can I look at $elem+1 while looking at $elem? I realize I can do the same > type of loop using a while loop and then checking $array[i+1] (where i is > the current element) but I was curious if there was a way to do it with > a foreach loop. > > Thanks > Troy > > ___________________________________________________________________________ > ``Beware of bugs in the above code; I have only proved it correct, not > tried it.'' -Don Knuth > -------------------------------------------------------------------------- - > > From mark at mrmark.com Wed Nov 15 15:25:41 2000 From: mark at mrmark.com (Mark D Wolinski) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] nother one In-Reply-To: Message-ID: The only way you could do it is something like this: $i=0; foreach (@array) { if ($_ = $array[$i+1]) { one forward compare } $i++; } But you have to make sure you don't compare @array+1. And if you do it this way, then you have to ask yourself why you don't really want to do a for loop. Chris could probably give a technical answer if a for loop is more expensive then a foreach or not... Mark W -----Original Message----- From: owner-norfolk-pm-list@pm.org [mailto:owner-norfolk-pm-list@pm.org]On Behalf Of Troy E. Webster Sent: Wednesday, November 15, 2000 1:20 PM To: norfolk-pm-list@happyfunball.pm.org Subject: [HRPM] nother one Hey, This may turn out to be a stupid question, but nothing ventured nothing gained... Is there a way to peek ahead in a foreach loop? For example, foreach $elem (@array){} can I look at $elem+1 while looking at $elem? I realize I can do the same type of loop using a while loop and then checking $array[i+1] (where i is the current element) but I was curious if there was a way to do it with a foreach loop. Thanks Troy ___________________________________________________________________________ ``Beware of bugs in the above code; I have only proved it correct, not tried it.'' -Don Knuth --------------------------------------------------------------------------- From chicks at chicks.net Wed Nov 15 17:09:57 2000 From: chicks at chicks.net (chicks@chicks.net) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] nother one In-Reply-To: Message-ID: On Wed, 15 Nov 2000, Mark D Wolinski wrote: > Chris could probably give a technical answer if a for loop is more > expensive then a foreach or not... I don't think there's much performance difference between them for most applications. The nice thing about the foreach is that you can modify the scalar and it affects the array itself. This makes many loops much simpler. :-) -- "Pinky, you've left the lens cap of your mind on again." - The Brain From jeff at alanne.com Wed Nov 15 20:41:50 2000 From: jeff at alanne.com (Jeff Duffy) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] MySQL v. Postgres -- The Eternal Battle. In-Reply-To: <00d001c04dfe$441172c0$40941718@cx782347a> References: <00d001c04dfe$441172c0$40941718@cx782347a> Message-ID: <00111521415003.28125@cairhien> On Tuesday 14 November 2000 00:46, you wrote: > > I was looking at PHPBuilder.com and found this interesting article > where Postgres 7.1 went against MySQL 3.23.26beta and kicked its ass > with steel-toed boots. Dude. I am a Postgres backer. but there's quite a bit wrong with this picture, not the least of which is that he has a single web page that requires 16 (!) queries to build. I'm already not impressed with this guy's coding skills. >I was wondering if you guys wouldn't mind > telling me what is wrong with this picture so that I can be a wiser > consumer in the future. Well, First, it's a benchmark, and a home-grown one at that, so it's fairly useless. Second, comparing Postgres and MySQL in that context is silly, since they are two different pieces of software aimed at two different markets. Lastly, if this guy says that head to head, without needing any advanced functionality, that Postgres smoked MySQL by that large a margin, he's either lying, smoking crack, or both. Now, if you want to know why I don't use MySQL for tracking systems data, but I do use Postgres ... :) Jeff -- For most people, the perceived usefulness of a computer language is inversely proportional to the number of theoretical axes that the language attempts to grind. --Larry Wall From chicks at chicks.net Thu Nov 16 09:12:04 2000 From: chicks at chicks.net (chicks@chicks.net) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] MySQL v. Postgres -- The Eternal Battle. In-Reply-To: <00111521415003.28125@cairhien> Message-ID: On Wed, 15 Nov 2000, Jeff Duffy wrote: > Lastly, if this guy says that head to head, without needing any > advanced functionality, that Postgres smoked MySQL by that large a > margin, he's either lying, smoking crack, or both. Thank you. I didn't have the energy. :-) -- "Pinky, you've left the lens cap of your mind on again." - The Brain From mshivers11 at home.com Sat Nov 18 15:04:26 2000 From: mshivers11 at home.com (Matt Shivers) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] Sorting and array of lines returned from 'ps' Message-ID: <000c01c051a3$22b54cc0$a58e1718@nwptn1.va.home.com> Hello all, I have an interesting sorting problem. I need to sort an array of lines returned from the 'ps' command. Each line contains the following information: PID, USER, UID, TIME, %CPU, %MEM, CMD I need to sort the array based on the different fields within each line. For instance, sort based on USER, then sort based on TIME, etc... depending on how the user wants the information displayed. I looked at the built in sorting options available in 'ps', but the 'ps' sort option doesn't contain all the fields I need to sort on. I also looked at the sort function built into Perl, but it looks to be a simple sort based on the entire element in the array. Has anyone sorted in this fashion before? Thanks, Matt -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/archives/norfolk-pm/attachments/20001118/f90e457e/attachment.htm From mshivers11 at home.com Sun Nov 19 14:22:11 2000 From: mshivers11 at home.com (Matt Shivers) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] Fw: Sorting and array of lines returned from 'ps' Message-ID: <001801c05266$6630f440$a58e1718@nwptn1.va.home.com> Trying this message again. ----- Original Message ----- From: Matt Shivers To: norfolk-pm-list@happyfunball.pm.org Sent: Saturday, November 18, 2000 4:04 PM Subject: Sorting and array of lines returned from 'ps' Hello all, I have an interesting sorting problem. I need to sort an array of lines returned from the 'ps' command. Each line contains the following information: PID, USER, UID, TIME, %CPU, %MEM, CMD I need to sort the array based on the different fields within each line. For instance, sort based on USER, then sort based on TIME, etc... depending on how the user wants the information displayed. I looked at the built in sorting options available in 'ps', but the 'ps' sort option doesn't contain all the fields I need to sort on. I also looked at the sort function built into Perl, but it looks to be a simple sort based on the entire element in the array. Has anyone sorted in this fashion before? Thanks, Matt -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/archives/norfolk-pm/attachments/20001119/3b8f16d9/attachment.htm From jeff at alanne.com Mon Nov 20 22:03:15 2000 From: jeff at alanne.com (Jeff Duffy) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] Sorting and array of lines returned from 'ps' In-Reply-To: <000c01c051a3$22b54cc0$a58e1718@nwptn1.va.home.com> References: <000c01c051a3$22b54cc0$a58e1718@nwptn1.va.home.com> Message-ID: <00112023031502.00831@cairhien> On Saturday 18 November 2000 16:04, you wrote: > I need to sort the array based on the different fields within each > line. For instance, sort based on USER, then sort based on TIME, > etc... depending on how the user wants the information displayed. A qsort won't do what you want for all of the fields, because it's an asciibetical sort. That means sorting on USER will work fine, but a simple Perl sort on say, PID will return the number 577 before the number 6, since it comes first in ascii. Try " ps aux | awk '{print $2}' | sort " to see what I mean. So now you've established that you need two sorts; a standard Perl sort (qsort) and one that returns numbers sorted in numeric order. What you need a Schwartzian Transform. I won't go into the details here, but you can read about it in recipe 4.15 of the Perl Cookbook, or at http://www.5sigma.com/perl/schwtr.html . If you're putting each value into an array element from the output of ps, you can build an array of array refs, and sort the dereferenced array field that corresponds to the field you wish to sort on to produce your output table. That calls for some fairly tricky bits of reference manipulation, but it works nicely for building tables on the fly. Chris probably has an easier answer for you. Jeff -- For most people, the perceived usefulness of a computer language is inversely proportional to the number of theoretical axes that the language attempts to grind. --Larry Wall From cornette at infi.net Tue Nov 21 08:30:35 2000 From: cornette at infi.net (Scott Cornette) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] Sorting and array of lines returned from 'ps' In-Reply-To: <000c01c051a3$22b54cc0$a58e1718@nwptn1.va.home.com> Message-ID: Once you have decided on which field you want sorted, you can try sorting the array using the perl sort operator with a subroutine passed as an argument. This will allow you to do comparisons by choosing whether you want a numeric or ASCII sort. For example, to sort a numeric field: sub numerically { $a <=> $b; } @sorted_array = sort numerically @unsorted_array; To sort a field of strings (ASCII based): sub ascii_string { $a cmp $b; } @sorted_array = sort ascii_string @unsorted_array; There are plenty of examples in the Camel book and Cookbook. Hope this helps, Scott Cornette -----Original Message----- From: owner-norfolk-pm-list@pm.org [mailto:owner-norfolk-pm-list@pm.org]On Behalf Of Matt Shivers Sent: Saturday, November 18, 2000 4:04 PM To: norfolk-pm-list@happyfunball.pm.org Subject: [HRPM] Sorting and array of lines returned from 'ps' Hello all, I have an interesting sorting problem. I need to sort an array of lines returned from the 'ps' command. Each line contains the following information: PID, USER, UID, TIME, %CPU, %MEM, CMD I need to sort the array based on the different fields within each line. For instance, sort based on USER, then sort based on TIME, etc... depending on how the user wants the information displayed. I looked at the built in sorting options available in 'ps', but the 'ps' sort option doesn't contain all the fields I need to sort on. I also looked at the sort function built into Perl, but it looks to be a simple sort based on the entire element in the array. Has anyone sorted in this fashion before? Thanks, Matt -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/archives/norfolk-pm/attachments/20001121/f8e0258d/attachment.htm From chicks at chicks.net Tue Nov 21 09:35:58 2000 From: chicks at chicks.net (chicks@chicks.net) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] Sorting and array of lines returned from 'ps' In-Reply-To: <00112023031502.00831@cairhien> Message-ID: On Mon, 20 Nov 2000, Jeff Duffy wrote: > Chris probably has an easier answer for you. Matt - can you send me (or the list) a short version of what you've got that loads the array? It'll take about 10 minutes, but I can quite easily write a comparator for sort that will do exactly what I think you want. :-) Having your code to start off with will save some time. Also - please note there is a module which is designed to make working with the process table reasonably painless and portable - Proc::ProcessTable (D/DU/DURIST/Proc-ProcessTable-0.28.tar.gz). I haven't used it, but I've liked what I've read about it. I've got a project where I want to play with it one of these days. :-) -- "Pinky, you've left the lens cap of your mind on again." - The Brain From chicks at chicks.net Tue Nov 21 10:04:52 2000 From: chicks at chicks.net (chicks@chicks.net) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] Sorting and array of lines returned from 'ps' In-Reply-To: Message-ID: On Tue, 21 Nov 2000, Scott Cornette wrote: > Once you have decided on which field you want sorted, you can try > sorting the array using the perl sort operator with a subroutine > passed as an argument. This will allow you to do comparisons by > choosing whether you want a numeric or ASCII sort. For example, to > sort a numeric field: > > sub numerically { $a <=> $b; } > > @sorted_array = sort numerically @unsorted_array; > > To sort a field of strings (ASCII based): > > sub ascii_string { $a cmp $b; } > > @sorted_array = sort ascii_string @unsorted_array; > > There are plenty of examples in the Camel book and Cookbook. That's precisely what I was thinking of doing for him. But instead of a single operation like ascii_string (which is redundant since that's 'cmp' is what sort uses by default!) ... I was thinking of something like: sub pid_array { ($x,$x,$x,$pida) = split (/ /,$a); ($x,$x,$x,$pidb) = split (/ /,$b); $pida <=> $pidb; } @sortedprocs = sort pid_array @rawprocs; Two things are relevant here: - The value of the last line of a sub is used as the return value if there is no explicit return value. This is a side effect and isn't as explicit as I'd like, but it's common practice and it's good to be familiar with it. - <=> and cmp are special in that they return -1 for less than, 0 for equal and 1 for greater than -- which is exactly what sort needs. If your sub returns those values consisantly, you don't need to use those operators to generate them. And as everyone has said the Camel (/Programming Perl/) and the Cookbook have lot's of useful information. I've got Camel 3E on my night stand and I'm hoping to dig into in the next few weeks! -- (My God, there's HRPM list traffic! Yay.) "Pinky, you've left the lens cap of your mind on again." - The Brain From mshivers11 at home.com Tue Nov 21 20:32:44 2000 From: mshivers11 at home.com (Matt Shivers) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] Sorting ps list - source code for server and client Message-ID: <001401c0542c$7eaaf080$a58e1718@nwptn1.va.home.com> Hello all, Warning it's a lot of code... Here is the code the server uses to load up the array: #----------------------------------------------------------------------------- # get_proc_info #----------------------------------------------------------------------------- sub get_proc_info { my $process_name = shift @_; my @ps_list = `ps -eo pid,uname,uid,time,%cpu,%mem,cmd`; my @usr_proc_list = grep {/$process_name/} @ps_list; my $num_procs = @usr_proc_list; # gets the number of instances of a proc. my @temp = "\n$num_procs instance(s) of $process_name running on $host_name\n\n"; # add contents of @usr_proc_list to @temp foreach $value (@usr_proc_list){ $temp[++$#temp] = $value; } # change newlines to question marks, so lines get transmitted across # the socket. foreach (@temp){ s/\n/\?/g; # /g ensures all occurences are substituted } # convert @temp into a scalar so it can be transmitted across # the socket. $lines = join("@", @temp)."\n"; # \n is necessary - terminates transfer return $lines; } And here is the code the client uses to decode and then display the array: #----------------------------------------------------------------------------- # search nodes # # Gets name of the program entered in the entry widget and sends the name # through the socket to the server. The server gathers information about the # program and returns the info to this client. The list of matching processes # is then displayed in the listbox widget. Error messages are printed in the # textbox widget. # # Parameters: # $sock - socket used for connecting the client to the server # $target - Hostname of machine running the server # $e_widg - TK widget: holds the name of the process to be searched for # $t_widg - TK widget: Error messages are displayed here # $l_widg - TK widget: Displays list of matching processes #----------------------------------------------------------------------------- sub search_nodes { my ($sock, $target, $e_widg, $t_widg, $l_widg) = @_; my $prog_name = $e_widg -> get(); # must get info from entry here due to # scoping issues my $in_buf = ""; if(!$prog_name){ t_del_ins($t_widg,"Enter a program name."); l_del_ins($l_widg, ""); } elsif ((!$sock) && (!$target)){ t_del_ins($t_widg,"Select a node."); l_del_ins($l_widg, ""); } elsif (!$sock){ t_del_ins($t_widg,"Error connecting to $target. Try again."); l_del_ins($l_widg, ""); } else { # Contact acheived. Send messages. t_del_ins($t_widg, "Searching nodes for instances of $prog_name."); l_del_ins($l_widg, ""); my $process_string = "1?". $prog_name . "\n"; print($sock $process_string); $SIG{ALRM} = \&timed_out; eval { alarm (5); $in_buf = <$sock>; alarm(0); }; if ($@ =~ /GOT TIRED OF WAITING/){ t_del_ins($t_widg, "Server on $target timed out..."); l_del_ins($l_widg, ""); } else { # split up incoming string into separate lines my @temp2 = split "@", $in_buf; # remove all ? from message foreach (@temp2){ s/\?//g; # /g ensures all occurences of ? are removed chomp $_; } my $numline = shift(@temp2); # print socket message t_del_ins($t_widg, "$numline\n"); l_del_ins($l_widg, @temp2); // display the array contents in the list widget } } } # end search_nodes -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/archives/norfolk-pm/attachments/20001121/c2c77033/attachment.htm From lbyrd at memach.com Tue Nov 21 06:58:50 2000 From: lbyrd at memach.com (Lyman Byrd) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] Fw: Sorting and array of lines returned from 'ps' In-Reply-To: <001801c05266$6630f440$a58e1718@nwptn1.va.home.com> Message-ID: JFRT (Just for the record) it worked the first time as far as I can tell. I certainly got it.. BTW interesting question.. Lyman On 19-Nov-2000 Matt Shivers wrote: > Trying this message again. > ---------------------------------- E-Mail: Lyman Byrd Tel: 757.543.6801x253 Date: 21-Nov-2000 Time: 07:57:42 The opinions expressed here do not necessarily reflect those of Metro Machine Corp. ---------------------------------- From chicks at chicks.net Thu Nov 23 14:22:55 2000 From: chicks at chicks.net (chicks@chicks.net) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] Fw: Sorting and array of lines returned from 'ps' In-Reply-To: Message-ID: On Tue, 21 Nov 2000, Lyman Byrd wrote: > JFRT (Just for the record) it worked the first time as far as I can > tell. I certainly got it.. BTW interesting question.. I looked at the headers of Matt's post and there was a significant delay (like 2 days) between when he sent it and when the list posted it. I didn't dig into it further, but if anybody posts something and you're not sure if it's gone out, you're more than welcome to contact me directly. -- "Pinky, you've left the lens cap of your mind on again." - The Brain From mshivers11 at home.com Thu Nov 23 22:48:52 2000 From: mshivers11 at home.com (Matt Shivers) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] Fw: Sorting and array of lines returned from 'ps' References: Message-ID: <002001c055d1$d7da2ee0$a58e1718@nwptn1.va.home.com> Thanks for all the input on this problem. Jeff's post about the Schwartzian Transform sure looks promising. I haven't attempted to implement the algorithm yet, but I will code it ASAP. Thanks again, Matt P.S. Sorry about the double post. I've had problems with e-mail generated from my home account in the past, so I am a little paranoid when I send stuff out. From chicks at chicks.net Sun Nov 26 12:26:44 2000 From: chicks at chicks.net (chicks@chicks.net) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] Sorting ps list - source code for server and client In-Reply-To: <001401c0542c$7eaaf080$a58e1718@nwptn1.va.home.com> Message-ID: On Tue, 21 Nov 2000, Matt Shivers wrote: > Warning it's a lot of code... That's what 'dd' is for. :-) I've attached my rewrite of Matt's script. There's a longish comment at the beginning which contains some minor nits, but the main point was to demonstrate creating a custom sort routine and I hope you will find this a decent example. -- "Pinky, you've left the lens cap of your mind on again." - The Brain -------------- next part -------------- #!/usr/bin/perl -w my $comments = q^ Minor nits: ----------- Let's hope the formatting got dorked in transmission. :-) Consistant indentation is a good idea! I changed my $num_procs = @usr_proc_list; to my $num_procs = scalar(@usr_proc_list); to be more explicit. This (like the other nits) doesn't affect how the program works, just how pretty it is and how easy it is to maintain. I also changed my @temp = "\n$num_procs instance(s) of $process_name running on $host_name\n\n"; to my @temp; push(@temp,"\n$num_procs instance(s) of $process_name running on $host_name\n\n"); but it could have also been written like my @temp = ("\n$num_procs instance(s) of $process_name running on $host_name\n\n"); and I would have been happy. I hate assigning scalars to arrays and believing Perl is going to coerce it for me. I also changed # add contents of @usr_proc_list to @temp foreach $value (@usr_proc_list) { $temp[++$#temp] = $value; } to push(@temp, sort pidorder @usr_proc_list); which is much easier to understand as well as considerably faster. ^; # test harness $debug = 1; # 0 for production, 1 for debugging $host_name = 'norfolk.pm.org'; if ($debug) { print get_proc_info('d'); } #----------------------------------------------------------------------------- # get_proc_info #----------------------------------------------------------------------------- sub get_proc_info { my $process_name = shift @_; my @ps_list = `ps -eo pid,uname,uid,time,%cpu,%mem,cmd`; # let's hope noone's user name conflicts with the process name # we're looking for my @usr_proc_list = grep {/$process_name/} @ps_list; # gets the number of instances of a proc. my $num_procs = scalar(@usr_proc_list); my @temp; push(@temp,"\n$num_procs instance(s) of $process_name running on $host_name\n\n"); # append sorted processes to @temp push(@temp, sort pidorder @usr_proc_list); return @temp if $debug; # change newlines to question marks, so lines get transmitted # across the socket. foreach (@temp) { s/\n/\?/g; # /g ensures all occurences are substituted } # convert @temp into a scalar so it can be transmitted across # the socket. $lines = join("@", @temp)."\n"; # \n is necessary - terminates transfer return $lines; } sub pidorder { my $pid = 0; # index into array my $copya = $a; my $copyb = $b; $copya =~ s/^\s+//; $copyb =~ s/^\s+//; my @a = split(/\s+/,$copya,7); my @b = split(/\s+/,$copyb,7); if (0) { my $proca = $a[6]; my $procb = $b[6]; $proca =~ s/\s+/ /g; $procb =~ s/\s+/ /g; print "comparing '$a[$pid]' to '$b[$pid]' ($proca,$procb)\n"; } return $a[$pid] <=> $b[$pid]; } From mshivers11 at home.com Mon Nov 27 16:48:30 2000 From: mshivers11 at home.com (Matt Shivers) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] Sorting ps list - source code for server and client References: Message-ID: <001301c058c4$29ce63c0$a58e1718@nwptn1.va.home.com> Chris, Thanks for the nits on my code. I'm always looking for ways to improve my code. I guess I was taking advantage of Perl on some of the lines (the scalar change and the push change), but it says something about Perl that those lines worked the way they were. Now that I think about it, relying on the internals of Perl to take care of things is kinda dangerous. If the internals change, the previously working code could blow up. That's a scary thought. Anyway, on the the problem at hand. I will have to sit down and parse your "pidorder" subroutine before I ask any questions. Thanks, Matt ----- Original Message ----- From: To: Sent: Sunday, November 26, 2000 1:26 PM Subject: Re: [HRPM] Sorting ps list - source code for server and client > On Tue, 21 Nov 2000, Matt Shivers wrote: > > Warning it's a lot of code... > > That's what 'dd' is for. :-) > > I've attached my rewrite of Matt's script. There's a longish comment at > the beginning which contains some minor nits, but the main point was to > demonstrate creating a custom sort routine and I hope you will find this a > decent example. > > -- > > > "Pinky, you've left the lens cap of your mind on again." - The Brain > From chicks at chicks.net Tue Nov 28 05:55:16 2000 From: chicks at chicks.net (chicks@chicks.net) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] Sorting ps list - source code for server and client In-Reply-To: <001301c058c4$29ce63c0$a58e1718@nwptn1.va.home.com> Message-ID: On Mon, 27 Nov 2000, Matt Shivers wrote: > Thanks for the nits on my code. I can't help it. I've sent comments and patches into the authors of several modules - all of which have been appreciated. > I'm always looking for ways to improve my code. As should we all. > I guess I was taking advantage of Perl on some of the lines (the > scalar change and the push change), but it says something about Perl > that those lines worked the way they were. Now that I think about it, > relying on the internals of Perl to take care of things is kinda > dangerous. If the internals change, the previously working code could > blow up. That's a scary thought. Perl internals of this sort are likely to be stable for a long time. Perl6 will have a translator for any perl5 code that needs the old semantics too. But a little explicitness and a few comments makes maintainability go up significantly. > Anyway, on the the problem at hand. I will have to sit down and parse > your "pidorder" subroutine before I ask any questions. I'll be happy to explain it if it seems that daunting. It's hard to tell what code is going to be bewildering after a while. -- "Pinky, you've left the lens cap of your mind on again." - The Brain From lbyrd at memach.com Wed Nov 29 15:52:02 2000 From: lbyrd at memach.com (Lyman Byrd) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] Meeting tonite !!! Message-ID: Dont forget the meeting tonite and dinner at 6pm.. C U There ! ! ! ! ! Lyman ---------------------------------- E-Mail: Lyman Byrd Tel: 757.543.6801x253 Date: 29-Nov-2000 Time: 16:50:54 The opinions expressed here do not necessarily reflect those of Metro Machine Corp. ---------------------------------- From chicks at chicks.net Thu Nov 30 00:48:36 2000 From: chicks at chicks.net (chicks@chicks.net) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] Meeting tonite !!! In-Reply-To: Message-ID: Well this was another low attendance night. I'm about ready to swear off my talk on advanced data structures. It either seems boring to everybody or it's jinxed. But I'm not going to worry about that for now, since we've got next month's meeting to worry about: December is an odd month. Our meeting is scheduled for the 27th. I'd like to do some sort of get together. (We've been told that the Lab won't be available since our sponsor will be out of town.) So - what do you guys want to do? Pool? Bowling? Warcraft? Starcraft? Quake? Any brainstorming will be appreciated. I'll refrain from proposing any sort of voting method for the alternatives. Let's operate like a herd. ;-) -- "Pinky, you've left the lens cap of your mind on again." - The Brain From mshivers11 at home.com Thu Nov 30 07:46:09 2000 From: mshivers11 at home.com (Matt Shivers) Date: Thu Aug 5 00:08:11 2004 Subject: [HRPM] Meeting tonite !!! References: Message-ID: <000701c05ad3$e55499a0$a58e1718@nwptn1.va.home.com> Hey Chris, Sorry about not attending last night. It's the week before finals and it's cram time. Ack!! I would like to do bowling in Dec. Later, Matt ----- Original Message ----- From: To: "HRPM" Sent: Thursday, November 30, 2000 1:48 AM Subject: Re: [HRPM] Meeting tonite !!! > Well this was another low attendance night. I'm about ready to swear off > my talk on advanced data structures. It either seems boring to everybody > or it's jinxed. But I'm not going to worry about that for now, since > we've got next month's meeting to worry about: > > December is an odd month. Our meeting is scheduled for the 27th. I'd > like to do some sort of get together. (We've been told that the Lab won't > be available since our sponsor will be out of town.) So - what do you > guys want to do? Pool? Bowling? Warcraft? Starcraft? Quake? > > Any brainstorming will be appreciated. I'll refrain from proposing any > sort of voting method for the alternatives. Let's operate like a herd. > ;-) > > -- > > > "Pinky, you've left the lens cap of your mind on again." - The Brain >