Re: piped system commands
John, thanks for the perl approach. Mustn't forget about that! deb At 20:59:59, on 01.02.04: Cracks in my tinfoil beanie allowed John W. Krahn to seep these bits into my brain:, Deb wrote: I want to run a command inside a script. From the shell, here's the command: % ps -ef | /bin/egrep '/usr/lib/sendmail' | /bin/grep -v grep | /bin/awk '{print $2}' 19460 open PS, 'ps -ef |' or die Cannot open pipe from 'ps -ef' $!; my $pid; while ( PS ) { next unless m|/usr/lib/sendmail|; $pid = ( split )[ 1 ]; last; } close PS or die Cannot close pipe from 'ps -ef' $!; Or: my $pid; for ( `ps -ef` ) { next unless m|/usr/lib/sendmail|; $pid = ( split )[ 1 ]; last; } Or: my ( $pid ) = map +( split )[ 1 ], grep m|/usr/lib/sendmail|, `ps -ef`; John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- o _ _ _ _o /\_ _ \\o (_)\__/o (_) _ \_ _(_) (_)/_\_| \ _|/' \/ (_)(_) (_)(_) (_)(_)' _\o_ http://zapatopi.net/afdb.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
scripted piped system commands
Happy Almost New Year! I want to run a unix system command inside a script. From the shell, here's the command(s): % ps -ef | /bin/egrep '/usr/lib/sendmail' | /bin/grep -v grep | /bin/awk '{print $2}' 19460 What is returned is the pid of the process being grep'd. But, when I put this into a test script, snip my $pid = `ps -ef | /bin/egrep '/usr/lib/sendmail' | /bin/grep -v grep | /bin/awk '{print $2}'`; print \$pid is: $pid \n; snip And, here's the output: $pid is: root 19460 1 0 Dec 18 ?0:08 /usr/lib/sendmail -bd -q15m It seems to be only going as far as dropping off the grep (grep -v), and never executing the awk '{print $2}'. I've tried this with the system() call, with the same results. Please, what am I missing? :-( deb -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Use of uninitialized value complaint
I need help understanding why I'm getting this complaint, Use of uninitialized value in concatenation (.) or string at test.pl line 2. It says its unitialized, but isn't the my $status initializing the scalar? I'm so confused. Here's the code: #!/usr/local/bin/perl -w my $status = `ps -ef | /bin/egrep '/usr/lib/sendmail' | /bin/grep -v grep | awk '{print $2}'`; print $status; if ($status) { print We have sendmail\n; } else { print We don't\n; } And the output: Use of uninitialized value in concatenation (.) or string at test.pl line 2. root 19460 1 0 Dec 18 ?0:08 /usr/lib/sendmail -bd -q15m We have sendmail Thanks for any help, deb -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: piped system commands
At 17:50:40, on 12.30.03: Cracks in my tinfoil beanie allowed Andrew Gaffney to seep these bits into my brain:, Try changing the $2 to \$2. Perl is interpolating $2 before it gets to bash, so bash sees /bin/awk '{print }'. -- Andrew, Ah!!! That was it. I should have seen that. Thanks so much for pointing that out. deb -- o _ _ _ _o /\_ _ \\o (_)\__/o (_) _ \_ _(_) (_)/_\_| \ _|/' \/ (_)(_) (_)(_) (_)(_)' _\o_ http://zapatopi.net/afdb.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: piped system commands
At 15:58:26, on 12.30.03: Cracks in my tinfoil beanie allowed Bakken, Luke to seep these bits into my brain:, Instead of the useless 'grep -v grep', do this: % ps -ef | egrep '[/]usr/lib/sendmail' | awk '{print $2}' Ah, yes, much cleaner. Old habits die hard. :-) But, when I put this into a test script, Might I suggest finding the 'pid' file for sendmail and reading that instead? It should be under /var/run or some such directory... Not as reliable as checking the process table. The process could have been killed off, but the pid file is still there. Thanks for the better regexp, deb -- o _ _ _ _o /\_ _ \\o (_)\__/o (_) _ \_ _(_) (_)/_\_| \ _|/' \/ (_)(_) (_)(_) (_)(_)' _\o_ http://zapatopi.net/afdb.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Use of uninitialized value complaint
Please see response, inline: At 17:26:25, on 12.31.03: Cracks in my tinfoil beanie allowed Rob Dixon to seep these bits into my brain:, Hi Deb. Hi Rob! Perl is trying to expand $2 in your string. Since Perl's $2 is undefined it gives you the warning (full marks for using -w but 'use strict' would help even more). Ack! Caught me again. I guess I'm not paying attention! Change it to awk '{print \$2}' and it should work for you. HTH, Yup, did. You da man! deb -- o _ _ _ _o /\_ _ \\o (_)\__/o (_) _ \_ _(_) (_)/_\_| \ _|/' \/ (_)(_) (_)(_) (_)(_)' _\o_ http://zapatopi.net/afdb.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
piped system commands
Happy Almost New Year! I want to run a command inside a script. From the shell, here's the command: % ps -ef | /bin/egrep '/usr/lib/sendmail' | /bin/grep -v grep | /bin/awk '{print $2}' 19460 What is returned is the pid of the process being grep'd. But, when I put this into a test script, my $pid = `ps -ef | /bin/egrep '/usr/lib/sendmail' | /bin/grep -v grep | /bin/awk '{print $2}'`; print \$pid is: $pid \n; here's what I'm seeing , $pid is: root 19460 1 0 Dec 18 ?0:08 /usr/lib/sendmail -bd -q15m -- It seems to be only going as far as dropping off the grep, and not doing the awk '{print $2}'. I've tried this with the system() call, with the same results. What am I missing? :-( deb -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
matching hypenated strings
Here's some test code I'm working with: ## begin ## while ($name = DATA) { $name =~ /(\w*)\.*/; $name{$1}++; $name =~ /(\w+)/; print $ \n; } __DATA__ tibor.test.net mars.test.net moon-bx-r.test.net moon-bs-d.test.net moon-bt-321.test.net ## end ## This works for hostnames without hyphens, but when there is a hyphen in the name, everything after the hyphen is ignored. I've been trying things like $name =~ /[a-z]*\-*\-*/ with no luck. The data coming into the expression may or may not be fully qualified, so I can't just take everything to the left of .test.net, and the domain name may be different at times, anyway. So what I'm left with finding an expression that will match any alphanumeric, with 0 or more embedded dashes. It sounds simple, but I can't seem to find it. What am I missing? Thanks, d -- Please respond to the list... NOT to me directly. o _ _ _ _o /\_ _ \\o (_)\__/o (_) _ \_ _(_) (_)/_\_| \ _|/' \/ (_)(_) (_)(_) (_)(_)' _\o_ http://zapatopi.net/afdb.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: matching hypenated strings
At 10:17:47, on 11.25.03: Cracks in my tinfoil beanie allowed Brian Gerard to seep these bits into my brain:, And the clouds parted, and deb said... What am I missing? Two things: 1) The regex you're looking for is likely /[-\w]+/, which says match one or more dashes or word characters. This will slurp up everything up to the first non-word, non-dash character. Gagh, it's so simple. I had tried /[\w-] w/o the post-appended + and of course it failed. So close... 2) You can probably simplify your script to ## begin ## while (DATA) { (print $ \n and $name{$}++) if /[-\w+]+/; } Thanks, this helps a lot. :-) deb -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: matching hypenated strings
Hi Rob, At 18:44:10, on 11.25.03: Cracks in my tinfoil beanie allowed Rob Dixon to seep these bits into my brain:, Deb wrote: What am I missing? Hi Deb. You're missing the hyphen from the character class. The \w class is the same as [0-9A-Za-z_], and what you need is all of those characters plus 'hyphen'. This seemed a good time to showcase the much-misunderstood and underused qr// construct. If we do this: my $w = qr/[\w-]/; Learned something new - I was not aware of the qr// construct... But I'm left wondering what you're trying to do with the lines. $name =~ /(\w*)\.*/; $name =~ /(\w+)/; which I can't fathom. ;-) No doubt. My apologies for being sloppy. It was left over from a previous test and shouldn't have been included in the codelet of my first mesg. HTH, Yes! Thanks for sharing a new way to do this. Very nice. deb use strict; use warnings; my $w = qr/[\w-]/; # Word characters plus hyphen my %name; while (my $name = DATA) { $name =~ /($w*)/; $name{$1}++; print $1\n; } __DATA__ tibor.test.net mars.test.net moon-bx-r.test.net moon-bs-d.test.net moon-bt-321.test.net **OUTPUT tibor mars moon-bx-r moon-bs-d moon-bt-321 -- o _ _ _ _o /\_ _ \\o (_)\__/o (_) _ \_ _(_) (_)/_\_| \ _|/' \/ (_)(_) (_)(_) (_)(_)' _\o_ http://zapatopi.net/afdb.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Getopt module
Hi, Here's some (unfinished) code I am trying to use with Getopt::Std, #!/usr/local/bin/perl -w # use Getopt::Std; use diagnostics; getopts('hn:'); usage if (defined $opt_h); sub usage { print EOM USAGE: $0 [-h] -n [EMAIL PROTECTED] -h This message -n [EMAIL PROTECTED] EOM When it's executed, as test.pl -h here is what I get in response: Name main::opt_h used only once: possible typo at test.pl line 16 (#1) (W once) Typographical errors often show up as unique variable names. If you had a good reason for having a unique name, then just mention it again somehow to suppress the message. The our declaration is provided for this purpose. USAGE: test.pl [-h] -n [EMAIL PROTECTED] -h This message -n [EMAIL PROTECTED] The program is functional, but strict settings complain, right? So what do I do? I putting my $opt_h to initialize the variable, but then that just overwrites the setting from the commandline, as you might expect. What should I do to rid myself of the complaint? As far as I can tell, It's used only once, and that's all I need. So, what am I missing? Thanks, deb PS- I'm on the digest... -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Substituting a space with a comma
Thanks! I get it now! deb At 21:37:06, on 07.10.03: Cracks in my tinfoil beanie allowed Rob Dixon to seep these bits into my brain:, Deb wrote: Rob, you were very helpful in showing me how the split and join work, but since I wasn't looking to change anything in $line except to replace the character separating the email addrs, I used what you gave me, and rebuilt the $line. I think it's kinda ugly, though, and I'm wondering if there is a better way. Here's what I did: $line = 'units = [EMAIL PROTECTED] [EMAIL PROTECTED]:[EMAIL PROTECTED]'; next unless $line =~ /^units/; (my $units, my $rest) = split (/=\s+/,$line); my @addrs = split /[:;\s]+/, $rest; my $tmpline = join ',', @addrs; $line = $units . = . $tmpline . \n; This accomplishes the task, but I'm using a lot of temporary variables. Is there a better way? I thought you were looking for an explanation of the next unless $line =~ s/// line. 'join' is (almost) the exact opposite of 'split' and, given a separator and a list will return a string with the elements of the list delimited by the separator. Example join '#', 1, 2, 3, 4; returns '1#2#3#4' Your code above can be simplified, but it looks now like you're just wanting to rebuild the original data with commas in place of the colon, semicolon separators than you started with. Here's a variation on my original code which reads in your @lines array from the DATA handle. Lets work from this to try to get where you want to be. Depending on what you actually need it can be be reduced further. Rob use strict; use warnings; my @lines = DATA; chomp @lines; foreach my $line (@lines) { next unless $line =~ s/^units\s+=\s+//; my @emails = split /[:;\s]+/, $line; $line = 'units = ' . join ',', @emails; print $line, \n; } __DATA__ units = [EMAIL PROTECTED] [EMAIL PROTECTED]:[EMAIL PROTECTED] units = [EMAIL PROTECTED] units = [EMAIL PROTECTED] [EMAIL PROTECTED] OUTPUT units = [EMAIL PROTECTED],[EMAIL PROTECTED],[EMAIL PROTECTED] units = [EMAIL PROTECTED] units = [EMAIL PROTECTED],[EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- o _ _ _ _o /\_ _ \\o (_)\__/o (_) _ \_ _(_) (_)/_\_| \ _|/' \/ (_)(_) (_)(_) (_)(_)' _\o_ http://zapatopi.net/afdb.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Substituting a space with a comma
No problem, Charles. :-) Thanks for responding, though! deb At 19:34:15, on 07.09.03: Cracks in my tinfoil beanie allowed Charles K. Clarkson to seep these bits into my brain:, [snipped code] Holy Cow! Deb, I apologize. After reading Rob's answer, I re-read your message and I can't believe I couldn't understand what was in @lines. Perhaps I should stop hitting reply so quickly. Sorry, Charles K. Clarkson -- Head Bottle Washer, Clarkson Energy Homes, Inc. Mobile Home Specialists 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- o _ _ _ _o /\_ _ \\o (_)\__/o (_) _ \_ _(_) (_)/_\_| \ _|/' \/ (_)(_) (_)(_) (_)(_)' _\o_ http://zapatopi.net/afdb.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Substituting a space with a comma
Rob, you were very helpful in showing me how the split and join work, but since I wasn't looking to change anything in $line except to replace the character separating the email addrs, I used what you gave me, and rebuilt the $line. I think it's kinda ugly, though, and I'm wondering if there is a better way. Here's what I did: $line = 'units = [EMAIL PROTECTED] [EMAIL PROTECTED]:[EMAIL PROTECTED]'; next unless $line =~ /^units/; (my $units, my $rest) = split (/=\s+/,$line); my @addrs = split /[:;\s]+/, $rest; my $tmpline = join ',', @addrs; $line = $units . = . $tmpline . \n; This accomplishes the task, but I'm using a lot of temporary variables. Is there a better way? Thanks, deb At 00:29:16, on 07.10.03: Cracks in my tinfoil beanie allowed Rob Dixon to seep these bits into my brain:, Deb wrote: Rob, Errr, I think I see this. Seems more elegant than a strict search/replace. But, I don't understand this: next unless $line =~ s/^units\s+=\s+//; Substituting the left side with nothing? I must be reading this wrong. I do understand the split and join, though - I've used split a lot, but not join. I appreciate you giving an example. Sure. Look my $line = 'units = [EMAIL PROTECTED] [EMAIL PROTECTED]:[EMAIL PROTECTED]'; $line =~ s/^units\s+=\s+//; print [$line]\n; OUTPUT [EMAIL PROTECTED] [EMAIL PROTECTED]:[EMAIL PROTECTED] (the square brackets are there only to show that there's no leading or trailing whitespace). This line next unless $line =~ s/^units\s+=\s+//; says - Checking whether the line matches /^units\s+=\s+/ - If so, then remove the matched text and continue - Otherwise go fetch the next line HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- o _ _ _ _o /\_ _ \\o (_)\__/o (_) _ \_ _(_) (_)/_\_| \ _|/' \/ (_)(_) (_)(_) (_)(_)' _\o_ http://zapatopi.net/afdb.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Passing file handles to sub-routines ...
Try this (untested): #The variable $fh is not a filehandlie - you need to assign that: my $fh = somefile; open (FILE, $fh test) || die $!; # Open file for writing while (FILE) { print FILE Hello\n; } close (FILE); Some would say you don't need to do the close. Some say you do. I usually do explicitly, to be consistant. At 16:10:24, on 07.10.03: Cracks in my tinfoil beanie allowed Jamie Risk to seep these bits into my brain:, I'm a casual PERL programmer at best, and I have a working facsimile of the non-working code below. When I run it, I get an error print() on closed filehandle $fh at ./test.pl line [n]. This is just my first step to being able to pass file handles to my sub-routines. What have I missed? open my $fh, test || die $!; print $fh Hello!\n; close $fh; Secondly, how do I pass STDOUT has a file handle to a sub-routine? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- o _ _ _ _o /\_ _ \\o (_)\__/o (_) _ \_ _(_) (_)/_\_| \ _|/' \/ (_)(_) (_)(_) (_)(_)' _\o_ http://zapatopi.net/afdb.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Passing file handles to sub-routines ...
Please see correction, below: At 13:14:50, on 07.10.03: Cracks in my tinfoil beanie allowed deb to seep these bits into my brain:, Try this (untested): #The variable $fh is not a filehandlie - you need to assign that: my $fh = somefile; This line isn't quite right: open (FILE, $fh test) || die $!; # Open file for writing Should probably be, open (FILE, $fh) || die $!; # Open file for writing while (FILE) { print FILE Hello\n; } close (FILE); Some would say you don't need to do the close. Some say you do. I usually do explicitly, to be consistant. I've seen a couple of other posted answers to your question, which contradict what I thought was true - the variable $fh CAN be a filehandle. I haven't used that particular construct before. Always learning something new!!! d -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Substituting a space with a comma
Hi, I'm having trouble coming up with a regular expression for $lines in @lines of this form: units = [EMAIL PROTECTED] [EMAIL PROTECTED]:[EMAIL PROTECTED] units = [EMAIL PROTECTED] units = [EMAIL PROTECTED] [EMAIL PROTECTED] ' ^units = ' is expected, all the rest is not - ie, one or more addrs, but they must be comma separated, not space, semi-colon or colon separated. So far, I've got: foreach my $line (@lines) { if ($line =~ /^units/) { $line =~ s/:/,/g; $line =~ s/;/,/g; } } The part I'm having trouble with is replacing the space(s) between the addresses. I don't want to touch any other whitespace. Only the space or spaces which might separate more than one address. It's okay if there's a comma and a space, but anything else needs to be replaced with a comma. There also doesn't have to be a space after the comma. Only the comma is necessary. I can't seem to find the right incantation to replace just those spaces. HELP! :-) deb -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Substituting a space with a comma
Hi, I'm having trouble coming up with a regular expression for $lines in @lines of this form: units = [EMAIL PROTECTED] [EMAIL PROTECTED]:[EMAIL PROTECTED] units = [EMAIL PROTECTED] units = [EMAIL PROTECTED] [EMAIL PROTECTED] ' ^units = ' is expected, all the rest is not - ie, one or more addrs, but they must be comma separated, not space, semi-colon or colon separated. So far, I've got: foreach my $line (@lines) { if ($line =~ /^units/) { $line =~ s/:/,/g; $line =~ s/;/,/g; } } The part I'm having trouble with is replacing the space(s) between the addresses. I don't want to touch any other whitespace. Only the space or spaces which might separate more than one address. It's okay if there's a comma and a space, but anything else needs to be replaced with a comma. There also doesn't have to be a space after the comma. Only the comma is necessary. I can't seem to find the right incantation to replace just those spaces. HELP! :-) deb -- o _ _ _ _o /\_ _ \\o (_)\__/o (_) _ \_ _(_) (_)/_\_| \ _|/' \/ (_)(_) (_)(_) (_)(_)' _\o_ http://zapatopi.net/afdb.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Substituting a space with a comma
Rob, Errr, I think I see this. Seems more elegant than a strict search/replace. But, I don't understand this: next unless $line =~ s/^units\s+=\s+//; Substituting the left side with nothing? I must be reading this wrong. I do understand the split and join, though - I've used split a lot, but not join. I appreciate you giving an example. deb At 23:47:28, on 07.09.03: Hi Deb. Here's the way I'd do it. First check that the line starts with 'units' - whitespace - '=' - whitespace and strip it off in one statement. Then you seem to be left with a number of emails which are separated by any of colon, semicolon or whitespace, so just split on a regex which says just that and rejoin the list with commas. foreach my $line (@lines) { next unless $line =~ s/^units\s+=\s+//; my @emails = split /[:;\s]+/, $line; $line = join ',', @emails; } HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- o _ _ _ _o /\_ _ \\o (_)\__/o (_) _ \_ _(_) (_)/_\_| \ _|/' \/ (_)(_) (_)(_) (_)(_)' _\o_ http://zapatopi.net/afdb.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Logging to a file or FH?
I've got a script which opens a filehandle to write print statments to a file. But, I'm also running some system commands, and I would also like to send stdout and stderr to that filehandle. I could just echo text to a file, or I could use a filehandle. Which would be better? my $log = /tmp/log.$$; open(LOG, $log); print LOG Commencing maintenance\n; But, here's how I've handled stdout and stderr in a system statement: my $log = /tmp/log.$$; system(path-to-command $log 21); Is there a way to use a filehandle instead? Seems I'd have to take care of block and non-blocking I/O. Methinks it may be simpler just to stick with printing directly to $log and not the FH, LOG. Any advise is welcome! deb -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Logging to a file or FH?
(Apologies if this gets out to you more than once...) I've got a script which opens a filehandle to write print statments to a file. But, I'm also running some system commands, and I would also like to send stdout and stderr to that filehandle. I could just echo text to a file, or I could use a filehandle. Which would be better? my $log = /tmp/log.$$; open(LOG, $log); print LOG Commencing maintenance\n; But, here's how I've handled stdout and stderr in a system statement: my $log = /tmp/log.$$; system(path-to-command $log 21); Is there a way to use a filehandle instead? Seems I'd have to take care of block and non-blocking I/O. Methinks it may be simpler just to stick with printing directly to $log and not the FH, LOG. Any advise is welcome! deb -- o _ _ _ _o /\_ _ \\o (_)\__/o (_) _ \_ _(_) (_)/_\_| \ _|/' \/ (_)(_) (_)(_) (_)(_)' _\o_ http://zapatopi.net/afdb.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Logging to a file or FH?
Cool. I didn't know about the IPC::Open3 module. Will look at it. Thanks for the pointer! deb At 15:04:25, on 06.23.03: Cracks in my tinfoil beanie allowed John W. Krahn to seep these bits into my brain:, Deb wrote: I've got a script which opens a filehandle to write print statments to a file. But, I'm also running some system commands, and I would also like to send stdout and stderr to that filehandle. I could just echo text to a file, or I could use a filehandle. Which would be better? my $log = /tmp/log.$$; open(LOG, $log); print LOG Commencing maintenance\n; But, here's how I've handled stdout and stderr in a system statement: my $log = /tmp/log.$$; system(path-to-command $log 21); Is there a way to use a filehandle instead? Seems I'd have to take care of block and non-blocking I/O. Methinks it may be simpler just to stick with printing directly to $log and not the FH, LOG. You could do something like this: use IPC::Open3; my $log = /tmp/log.$$; open LOG, '', $log or die Cannot open $log: $!; print LOG Commencing maintenance\n; my $pid = open3( 0, 'LOG', 0, 'path-to-command' ); John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- o _ _ _ _o /\_ _ \\o (_)\__/o (_) _ \_ _(_) (_)/_\_| \ _|/' \/ (_)(_) (_)(_) (_)(_)' _\o_ http://zapatopi.net/afdb.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Using Devel::ptkdb module
I have been using the Devel::ptkdb module on SunOS, which is a really fine tool. However, the text in the code pane is extremely small. perldoc has a list of environment variables which can be used to manipulate X resources, and I tried, setenv PTKDB_CODE_FONT 9x12 And then I ran the debugger, but the font did not change in the code pane. But, if I run an xterm with xterm -fn 9x12 the xterm is displayed with the correct font size. Has anyone been able to manipulate the font size using this module? If so, what did you do to change the font size? Thanks, deb PS: I'm on the digest of this list. So, I advance my apologies if you don't hear a response from me right away. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Using Devel::ptkdb module
Jeff Westman [EMAIL PROTECTED] had this to say, Have you tried exporting PTKDB_CODE_FONT ? Not really - I should have said that I use tcsh, and environmental variables take effect immediately... Thanks for the response, though. deb -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
A Solution to: Using Devel::ptkdb module
I have found a solution. If I give PTKDB_CODE_FONT env variable a full font name, instead of just 9x12, it happily agrees to do my bidding. Don't know why it works this way, but it does. I'd have to dive into the code to find out, I'm sure. So, here's what I did, setenv PTKDB_CODE_FONT -misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso8859-1 This is not equivalent to 9x15, but that's okay, because it looks just fine. Thanks, deb I have been using the Devel::ptkdb module on SunOS, which is a really fine tool. However, the text in the code pane is extremely small. perldoc has a list of environment variables which can be used to manipulate X resources, and I tried, setenv PTKDB_CODE_FONT 9x12 And then I ran the debugger, but the font did not change in the code pane. But, if I run an xterm with xterm -fn 9x12 the xterm is displayed with the correct font size. Has anyone been able to manipulate the font size using this module? If so, what did you do to change the font size? Thanks, deb PS: I'm on the digest of this list. So, I advance my apologies if you don't hear a response from me right away. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ Do you Yahoo!? Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop! http://platinum.yahoo.com -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- There are 010 types of people in the world: those who understand binary, and those who don't. ô¿ô 111,111,111 x 111,111,111 = 12,345,678,987,654,321 (decimal) ~ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Appending to a string
Doh, you're sooo right. Thanks, d John W. Krahn [EMAIL PROTECTED] had this to say, Deb wrote: Wait. Using this construct, I can't seem to get the change to write out to the file, like I can to stdout. while (IN) { if ( /^That_Text\s=\s2/ ) { $_ .= $addText; }else { s/^This_Text.*$/That_Text = 2/; } You don't need the $_ since this is the default for regex searches and replaces. The line at ^shield remains untouched. The other lines modify the file just fine. Here's my code. sub editConfSettings { open (IN, tmpconf) or die cannot open for reading: $!\n; open (OUT, conf)or die cannot open for writing: $!\n; ^^^ You are opening conf for INPUT - you cannot write to it. open OUT, '', 'conf' or die cannot open for writing: $!\n; John -- use Perl; program fulfillment -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- There are 010 types of people in the world: those who understand binary, and those who don't. ô¿ô 111,111,111 x 111,111,111 = 12,345,678,987,654,321 (decimal) ~ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Appending to a string
Hi, I am modifying a file and replacing a string that I find, which works just fine. However, sometimes there is already a string there that I don't want to replace, but instead append something to it. Here's what I've got so far: (obligatory use statements not included here) while (IN) { s/^This_Text.*$/That_Text = 2/; } But now, I may already have That_Text = 2 which I don't want to replace, but instead append :New_Text = 4. What would be a good method for post-appending text? What about something like this? (Seems kind cumbersum.) my $addText = :New_Text = 4; while (IN) { if ( $_ =~ /^This_Text/) { my $text =~ /^*$/; my newText = $text . $addText } Recommendations? Thanks, d -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Appending to a string
Kewl! I didn't know you could do that, $_ .= $sometext; That's just what I needed. Beats the heck out of the search and replace I was doing when I didn't need to. Thanks all! d Wags had this to say, if ( /^That_Text\s=\s2/ ) { $_ .= $addText; }else { s/^This_Text.*$/That_Text = 2/; } You don't need the $_ since this is the default for regex searches and replaces. Wags ;) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Appending to a string
Wait. Using this construct, I can't seem to get the change to write out to the file, like I can to stdout. while (IN) { if ( /^That_Text\s=\s2/ ) { $_ .= $addText; }else { s/^This_Text.*$/That_Text = 2/; } You don't need the $_ since this is the default for regex searches and replaces. The line at ^shield remains untouched. The other lines modify the file just fine. Here's my code. sub editConfSettings { open (IN, tmpconf) or die cannot open for reading: $!\n; open (OUT, conf)or die cannot open for writing: $!\n; while (IN) { unless ($approve eq none) { s/^attendant/attendant = $approves/g; } unless ($to eq none) { s/^Appl.*$/Appl = $to/g; } unless ($shield eq none) { chomp; $_ .= :time=43.43\n if (/^shield/); } print OUT $_; } close (IN); close (OUT); } What am I missing here? Should I do another s///g; ? d -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Odd number of elements in hash assignment
The light is beginning to shine a little brighter... Joseph's cogent explanation of dereferencing is helpful. Thanks. Yesterday I went out and bought the 3rd edition to the Perl reference book by ORA (mine was a very old 1st edition). The 3rd edition has a whole lot more on references than the 1st edition even dreamed about including. (set me back $50, but in the long run should be well worth it) The only thing left now is to be able to add new key, values to the %Lists hash, as my program comes across them. deb -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Searchable archive for this list?
Does anyone know of a searchable archive for the [EMAIL PROTECTED] list? The archives I've located don't seem to be searchable... Thanks, d -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Odd number of elements in hash assignment
You know, I'm just not getting it I guess. When I read through simple of examples in perldsc and perlfunc, it seems straightforward enough, but when I try to put into practice everything, it doesn't go as I might expect. Recall this code I posted a day or two ago: 8- -- snip while (DATA) { chomp; ($listname, $field) = split(/:\s+/, $_); print \nListname is $listname,\nField is: $field\n; %hrLists = split(/\s+/, $field); $Lists{$listname} = \%hrLists; } __DATA__ list-1: -x abc -r tenb list-2: -x def -r ghi -h tenr list-3: -x fel -h asci list-4: -x foo -h nonasci -r bfab 8- -- snip Note the print in the while loop - essentially, when the hash is built, my goal is to be able to use $listname as a key to call up the value of a key in the 2nd level hash. I understand this: foreach $listname (sort keys %Lists) { print $listname\n; } But, I don't quite get how to get to the key values below that. I know I'm so close, but just not quite there... Could some kind soul give me a blow by blow what's happening here going from $Lists{$listname} = \%hrLists; to printing out the key, values by $listname? Thanks, deb -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Odd number of elements in hash assignment
I'm not sure what you're saying. Since this is an anonymous hash assignment, how do I pull out the $listkey? Do I need to pre-assign it? For example, I tried this, added to the previous program, foreach $listname (sort keys %Lists) { print $listname:\n; foreach $key (sort keys %Lists) { print \t$Lists{$key}\n; } } And the out put is, list-1: HASH(0x55750) HASH(0x55750) HASH(0x55750) HASH(0x55750) list-2: HASH(0x55750) HASH(0x55750) HASH(0x55750) HASH(0x55750) list-3: HASH(0x55750) HASH(0x55750) HASH(0x55750) HASH(0x55750) list-4: HASH(0x55750) HASH(0x55750) HASH(0x55750) HASH(0x55750) So, Iguess I just pulled out the reference to the location? My initial request remains, : But, I don't quite get how to get to the key values below that. I know I'm so : close, but just not quite there... : : Could some kind soul give me a blow by blow what's happening here going from $Lists{$listname} = \%hrLists; : to printing out the key, values by $listname? Timothy Johnson [EMAIL PROTECTED] had this to say, To get the values instead of the keys, you will have to do something like this: foreach $listkey (sort keys %Lists){ print $List{$listkey}\n; } Or, if you want the values sorted, you want something more like this: foreach $listkey (sort {$Lists{$a} cmp $Lists{$b}} keys %Lists){ print $List{$listkey}\n; } This part might look a little confusing at first: sort { $Lists{$a} cmp $Lists{$b} } keys %Lists but it's a useful trick, especially when your key is a reference or other unreadable variable. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Odd number of elements in hash assignment
Thanks, Steve, for your feedback. As I said in private email to Steve earlier today, I don't mind someone thumping the FM to me - problem is, I've been reading all the FM I could find, including all those mentioned here. Got the printouts right in front of me. But I've been confused by different approaches presented, vs. what I need to do... which is why I think I got close, but not quite there. I was still getting hung up in the syntax especially as it relates to anonymous data structures, vs named ones. Not really apples and oranges, but one really needs to understand syntactically how to pull it out of annonymous hashes, if you *don't* want to use a literal to obtain a key, $xKey = $hash{'-x'} to then iterate over the hash to get the value. Yuck. Still chewing on the bones... deb Steve Grazzini [EMAIL PROTECTED] had this to say, Don't mean to thump the FM, but have you seen the Access and Printing of a HASH OF HASHES section in perldsc? Your %Lists is a perfect %HoH. But anyway, as you've probably seen, the ordinary print a hash loop... for my $key (sort keys %Lists) { print $key = $Lists{$key}\n; } Produces something like this. list-1 = HASH(0x80fb32c) Where HASH(0x80fb32c) represents the hash reference. you created way... back.. here: $Lists{$listname} = \%hrLists; # ^ # backslash creates a reference # So what you've got is a nested data structure; a hash (%List) whose values are references to more hashes. To print it out, you just need two loops, an outer loop for %Lists, and an inner loop to iterate over the nested hashes. for my $list (sort keys %Lists) { print $list: \n; my $ref = $Lists{$list}; # # use %{$ref} to dereference # for my $key (sort keys %{$ref}) { print $key : $ref-{$key}\n; } } And besides perldsc, you might find these handy if you're learning/working-with references: $ perldoc perlreftut $ perldoc perlref -- Steve -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- There are 010 types of people in the world: those who understand binary, and those who don't. ô¿ô 111,111,111 x 111,111,111 = 12,345,678,987,654,321 (decimal) ~ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Odd number of elements in hash assignment
Still struggling with multilevel hashes. Below is my code snippet, obligatory use statments are in effect. I don't understand the error. Line 52 refers to the line %hrLists assignment - Where did I go wrong? Thanks, deb while (DATA) { chomp; ($listname, $field) = split(/:/, $_); print \nListname is $listname,\nField is: $field\n; %hrLists = split(/\s+/, $field); $Lists{$listname} = \%hrLists; } __DATA__ list-1: -x abc -r tenb list-2: -x def -r ghi -h tenr list-3: -x fel -h asci list-4: -x foo -h nonasci -r bfab I'm getting this output: Listname is list-1, Field is: -x abc -r tenb Odd number of elements in hash assignment at testhash2.pl line 52, DATA line 1. Listname is list-2, Field is: -x def -r ghi -h tenr Odd number of elements in hash assignment at testhash2.pl line 52, DATA line 2. Listname is list-3, Field is: -x fel -h asci Odd number of elements in hash assignment at testhash2.pl line 52, DATA line 3. Listname is list-4, Field is: -x foo -h nonasci -r bfab Odd number of elements in hash assignment at testhash2.pl line 52, DATA line 4. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Odd number of elements in hash assignment
Thanks for the quick reply... Okay, I could use Data::Dumper, but what do you mean by empty leading field? Am I dense? (probably!) I don't really want to use D::D module, so what would I do to alleviate this? Ensure no leading white space? I'll have to give that a try (but my kids are not lettying me tayp; fdsa right nows.) Tnx! Steve Grazzini [EMAIL PROTECTED] had this to say, Deb [EMAIL PROTECTED] writes: Still struggling with multilevel hashes. snip =20 while (DATA) { chomp; ($listname, $field) =3D split(/:/, $_); print \nListname is $listname,\nField is: $field\n; %hrLists =3D split(/\s+/, $field); $Lists{$listname} =3D \%hrLists; } =20 __DATA__ list-1: -x abc -r tenb list-2: -x def -r ghi -h tenr list-3: -x fel -h asci list-4: -x foo -h nonasci -r bfab =20 I'm getting this output: =20 Listname is list-1, Field is: -x abc -r tenb Odd number of elements in hash assignment ... =20 You're getting an empty leading field; =20 $ perldoc -f split=20 relevant bits =20 Splits a string into a list of strings and returns that list. By default, empty leading fields are preserved, and empty trailing ones are deleted. =20 If EXPR is omitted, splits the $_ string. If PATTERN is also omitted, splits on whitespace (after skipping any leading whitespace). Anything matching PATTERN is taken to be a delimiter separating the fields. (Note that the delimiter may be longer than one character.) =20 As a special case, specifying a PATTERN of space (' ') will split on white space just as split with no arguments does. Thus, split(' ') can be used to emulate awk's default behavior, whereas split(/ /) will give you as many null initial fields as there are leading spaces. A split on /\s+/ is like a split(' ') except that any leading whitespace produces a null first field. A split with no arguments really does a split(' ', $_) internally. =20 =20 So try something like this: =20 use Data::Dumper; =20 while (DATA) { chomp; my ($listname, $field) =3D split /:/; $Lists{$listname} =3D split ' ', $field; =20 # # would have helped you spot it... # print listname:'$listname'\n, field: '$field'\n,=20 Dumper $Lists{$listname}; } =20 HTH --=20 Steve =20 --=20 To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --=20 =3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D= -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-= =3D-=3D-=3D- There are 010 types of people in the world: those who understand binary, and those who don't. =F4=BF=F4 111,111,111 x 111,111,111 =3D 12,345,678,987,654,321 (decimal) ~=20 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Odd number of elements in hash assignment
All, Replying to my own post - yup, that did it. I removed the leading space(s), then did the hash ref assignment, and all was well. Whew! Thanks for the tip - and the pointer that I should have checked the docs... sometimes the problem is that I'm just not sure *which* doc would have the info I'm looking for! G'Day, deb Deb sez, Thanks for the quick reply... Okay, I could use Data::Dumper, but what do you mean by empty leading field? Am I dense? (probably!) I don't really want to use D::D module, so what would I do to alleviate this? Ensure no leading white space? I'll have to give that a try (but my kids are not lettying me tayp; fdsa right nows.) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cpan problems
Sometimes I really hate using cpan. It's 'help' isn't much. It's been since last october that I touched my cpan stuff, and now it's out of date. It's currently at v1.60. I wanted to upgrade, so I did a make Bundle::CPAN, which is supposed to do a get first. BUT, my cpan thinks that it needs to get v1.63, Can't open CPAN-1.63.tar.gz: No such file or directory Bad luck... Still failed! Can't access URL ftp://ftp.perl.org/pub/CPAN/authors/id/A/AN/ANDK/CPAN-1.63.tar.gz. Please check, if the URLs I found in your configuration file () are valid. The urllist can be edited. E.g. with 'o conf urllist push ftp://myurl/' Could not fetch authors/id/A/AN/ANDK/CPAN-1.63.tar.gz Giving up on '/home/deb/.cpan/sources/authors/id/A/AN/ANDK/CPAN-1.63.tar.gz' Note: Current database in memory was generated on Sun, 20 Oct 2002 21:52:34 GMT cpan Well, Duh. v1.63 has been superceded by v1.70 - so how do I tell cpan to grab v1.70?? One more question - if I finally get Bundle::CPAN upgraded to the latest and greatest, will that also update my static lists on what is available on CPAN? I tried to get File::Slurp, and it wants to get an older version that no longer exists - same as the cpan bundle. I guess all I really want to do is update the file lists, but I don't know how to do that. Thanks, deb -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- There are 010 types of people in the world: those who understand binary, and those who don't. ô¿ô 111,111,111 x 111,111,111 = 12,345,678,987,654,321 (decimal) ~ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: cpan problems
[EMAIL PROTECTED] [EMAIL PROTECTED] had this to say, I wonder if the fact that you are using 'make' instead of 'install' is causing this problem. It might only try and make the last version it knew about, rather than looking to see what the newest version is. Try doing install Bundle::CPAN instead. Tried. no luck. You should enter more than one url when configuring CPAN, the mirror you have listed above is a very busy one and I can not access it currently because there are to many users. Try adding 6-7 if you run into this problem consistently, try one that is close to your geographical location as well. Yeah, you're right, but I can get there no problem. You might try blowing away your .cpan and reconfiguring, who knows. Thought about that, but I'd rather solve the problem of updating the filelist information, and work through this. Just a couple of thoughts, HTH, Thanks, deb -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- There are 010 types of people in the world: those who understand binary, and those who don't. ô¿ô 111,111,111 x 111,111,111 = 12,345,678,987,654,321 (decimal) ~ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: cpan problems
Casey West [EMAIL PROTECTED] had this to say, Sounds like you need to update your CPAN index. Should solve all your problems. Use the 'reload index' command first. Also, you should consider using CPANPLUS (with the cpanp shell utility), it's the next generation CPAN interface. Ah! That did the trick. I didn't know about cpanplus. Will have to look into that when my current project is complete. Thanks for the tip! deb -- Contrary to popular opinion, Unix is user friendly, It just happens to be very selective about who it makes friends with. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: removing elements from an array
Why not use a foreach, test the element, then undef it when found? Or, use foreach, test the element, if != '0', then push it onto another array? David Gilden [EMAIL PROTECTED] had this to say, Hi, I would like to remove elements from an array that are eq to string '0' The following does not work, can someone shed some light on the proper way to do this. Thanks! Dave G. #!/usr/bin/perl -w @bag_quantity = ( '0', 1, '0', '0', '0', '0', '0', '0', '0' ); for (@bag_quantity){ shift if $_ eq '0'; } print @bag_quantity\n; == Cora Connection: Your West African Music Source Resources, Recordings, Instruments More! http://www.coraconnection.com/ == -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- There are 010 types of people in the world: those who understand binary, and those who don't. ô¿ô 111,111,111 x 111,111,111 = 12,345,678,987,654,321 (decimal) ~ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: shifting through arrays of line data
John W. Krahn [EMAIL PROTECTED] had this to say, Ok, here it is using the code you posted elsethread. modified code deleted Much more elegant than mine, but by looking at the output, it's still not quite right. Note that there really is no -m option. After running it I get this output: direct -h postal -x direct me-900 -h ten-me-900 -m e-900: -r timbu -x me-900 networks-users -h hidit -r tenbu -x networks-users uncrp -h pickit -r oakd -x uncrp Since this was getting me no where and I have a deadline looming (although I'm still trying to get a handle on multihashes), I've taken another, more successful tact. I'm using Sudarshan Raghavan's suggestion of GetOpt::Std - which I had actually attempted FIRST, with no luck... until Sudarshan's of using local @ARGV and split. Now, I'm a happy camper and may actually meet my deadline. I'm still not very comfy with contructing a datastructure for a multilevel hash, but it's more a matter of getting in more perl practice than I've been able to have, I think. In other words, keep on trucking...! Thanks to everyone who offered their expertise. deb -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: running perl under xinetd on linux
I'm no expert, but this sounds like a buffering problem. You might want to read, http://perl.plover.com/FAQs/Buffering.html deb [EMAIL PROTECTED] [EMAIL PROTECTED] had this to say, Is there an issue running perl under linux xinetd where xinetd is listening for connections on a UDP port and then forking the following perl code. When I do this, the perl code does not see any input on STDIN. How does one get at the data received on the socket by xinetd? Roger while (STDIN) { $input = $_; syslog('info', Read : $input) ; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- There are 010 types of people in the world: those who understand binary, and those who don't. ô¿ô 111,111,111 x 111,111,111 = 12,345,678,987,654,321 (decimal) ~ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
STILL shifting through arrays of line data
Okay, I'm still struggling. sigh I just cannot seem to get my mind to stop, look, and listen. Here's some code I'm working on: - 8- use strict; my %cmdLine; my $DBG = 1; while (DATA) { chomp; my ($adx, $rest) = (split(/\:/,$_)); if ($DBG) {print \$adx=\t$adx\n\$rest=\t$rest\n;} while ($rest ne ) { my ($opt, $arg, $newRest) = ($rest =~ /\s*([\-a-z]*)\s+([^ ]*)\s+(.*)/); $rest = $newRest; $cmdLine{$opt} = $arg; } } __DATA__ ten-me-900: -r timbu -x me-900 -h ten-me-900 hidit: -r tenbu -x networks-users -h hidit postal: -x direct -h postal pickit: -h pickit -x uncrp -r oakd - 8- Why doesn't the while loop iterate all of $rest? I can't seem to figure out how to get the loop to act on the entire $rest, and get it into the hash. What am I doing wrong? Thanks, d -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: shifting through arrays of line data
John wrote: Did you try the code I posted Friday? (Message-ID: [EMAIL PROTECTED]) John, Thanks, yes, I did. But, the syntax was new to me, and I've been reading up on it. I couldn't really get it to do what I want (see my previous post to this one). But, that's probably b/c I didn't explain very well. I hope I explained more completely in my posting just previous to this one. Thanks, deb John W. Krahn [EMAIL PROTECTED] had this to say, Deb wrote: Hi Guys, I have an array in which each element is a line commandline data. It looks something like this - @Array contains lines: post1: -r [EMAIL PROTECTED] -x cat-100 -h post1 post2: -x tel -h post2 post3: -h post3 -x hifi And so on. The order of the options varies, and there may or may not be a -r $arg on the line. These lines are parsed from a file with more lines, of which I extracted all the lines with -h: open (F, $File); while (F) { if ($_ =~ / -h /) { # remove crud s/ \\|//; s/\/some\/crud\/path argument //; s/\$//; # store what's left push @Array, $_; } } What I really need to do is build a relationship between the first field (which is the same as the argument to -h) and the argument to -x. The -x flag can be dropped, as they're not needed. So it looks like I need to build a hash based. If you want to put the data into a hash this may do what you want: $ perl -le' @array = ( post1: -r [EMAIL PROTECTED] -x cat-100 -h post1, post2: -x tel -h post2, post3: -h post3 -x hifi ); for ( @array ) { %hash = /(-[a-z])\s*((?!-)\S*)/g; $ = * ; print * @{[%hash]} *; }' * -r * [EMAIL PROTECTED] * -h * post1 * -x * cat-100 * * -h * post2 * -x * tel * * -h * post3 * -x * hifi * John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- There are 010 types of people in the world: those who understand binary, and those who don't. ô¿ô 111,111,111 x 111,111,111 = 12,345,678,987,654,321 (decimal) ~ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: STILL shifting through arrays of line data
Here's the modified script. I made some changes, as suggested, but there was no change in the output. I've included my entire script. My head is getting mighty flat from banging it against the wall. Oh, and I added use warnings; and I haven't got a clue what I need to do to fix those. sigh I'd *LOVE* to be able to use GetOpt::Std - but I wasn't able to get it to look at something other than @ARGV - I need to process files on the fly that have the lines as delineated in __DATA__, below. My goals are to see if the -x option exists, and if it does get its argument. I also need to do certain things based on -h and -r and their respective arguments. This would all tied to the argument of -x (I guess this would be the key to everything). -x arg always exists on these lines, while the others may or may not. The argument to -x is the root of everything else. I can see how I'd do this if I could use GetOpt::Std - is this possible given that it is not actually coming from the commandline? Here's my script... as it stands now: #!/bin/perl -w use warnings; use strict; my %cmdLine; my %newHash; my $DBG = 1; my ($onceMore, $opt, $arg); while (DATA) { chomp; my ($adx, $rest) = (split(/:/,$_)); if ($DBG) {print \$adx=\t$adx\n\$rest=\t$rest\n;} while (defined ($rest) $rest ne ) { my ($opt, $arg, $newRest) = ($rest =~ /\s*([\-a-z]*)\s+([^ ]*)\s+(.*)/); $rest = $newRest; $cmdLine{$opt} = $arg; } # parse the final tuple... my ($opt, $arg, $newRest) = ($rest =~ /\s*([\-a-z]*)\s+([^ ]*)\s+(.*)/); $cmdLine{$opt} = $arg; # Build out the data structure my $masterKey = $cmdLine{'-x'}; foreach my $opt (keys %cmdLine) { $newHash{$masterKey}{$opt} = $cmdLine{$opt}; } } foreach my $masterKey (sort keys %newHash) { print $masterKey\n; foreach my $opt (sort keys %{$newHash{$masterKey}}) { print \t$opt\t . $newHash{$masterKey}{$opt} . \n; } } __DATA__ ten-me-900: -r timbu -x me-900 -h ten-me-900 hidit: -r tenbu -x networks-users -h hidit postal: -x direct -h postal pickit: -h pickit -x uncrp -r oakd -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: STILL shifting through arrays of line data
(H, this should have been posted, but I don't see it - sorry if this actually becomes a double-posting...) Here's the modified script. I made some changes, as suggested, but there was no change in the output. I've included my entire script. My head is getting mighty flat from banging it against the wall. Oh, and I added use warnings; and I haven't got a clue what I need to do to fix those. sigh I'd *LOVE* to be able to use GetOpt::Std - but I wasn't able to get it to look at something other than @ARGV - I need to process files on the fly that have the lines as delineated in __DATA__, below. My goals are to see if the -x option exists, and if it does get its argument. I also need to do certain things based on -h and -r and their respective arguments. This would all tied to the argument of -x (I guess this would be the key to everything). -x arg always exists on these lines, while the others may or may not. The argument to -x is the root of everything else. I can see how I'd do this if I could use GetOpt::Std - is this possible given that it is not actually coming from the commandline? Here's my script... as it stands now: #!/bin/perl -w use warnings; use strict; my %cmdLine; my %newHash; my $DBG = 1; my ($onceMore, $opt, $arg); while (DATA) { chomp; my ($adx, $rest) = (split(/:/,$_)); if ($DBG) {print \$adx=\t$adx\n\$rest=\t$rest\n;} while (defined ($rest) $rest ne ) { my ($opt, $arg, $newRest) = ($rest =~ /\s*([\-a-z]*)\s+([^ ]*)\s+(.*)/); $rest = $newRest; $cmdLine{$opt} = $arg; } # parse the final tuple... my ($opt, $arg, $newRest) = ($rest =~ /\s*([\-a-z]*)\s+([^ ]*)\s+(.*)/); $cmdLine{$opt} = $arg; # Build out the data structure my $masterKey = $cmdLine{'-x'}; foreach my $opt (keys %cmdLine) { $newHash{$masterKey}{$opt} = $cmdLine{$opt}; } } foreach my $masterKey (sort keys %newHash) { print $masterKey\n; foreach my $opt (sort keys %{$newHash{$masterKey}}) { print \t$opt\t . $newHash{$masterKey}{$opt} . \n; } } __DATA__ ten-me-900: -r timbu -x me-900 -h ten-me-900 hidit: -r tenbu -x networks-users -h hidit postal: -x direct -h postal pickit: -h pickit -x uncrp -r oakd -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: STILL shifting through arrays of line data
Sudarshan Raghavan [EMAIL PROTECTED] had this to say, Did you look at the code that I posted at the end of my last mail? I'm so embarrassed! I totally missed it! Wow. This is just what I'm looking for. I'm going to try it out - but it will have to wait until morning (it's 2315 here, and I've got to get up in about 5 hours). I'll post again how it goes. (Although, I'm still in the same misery as far as the while loop and creating the hashes. I've really got to work that out too.) Thanks again, deb The secret of the universe is @*^^^ NO CARRIER Did anyone see my lost carrier? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: shifting through arrays of line data
This (code below) makes sense to me, but I was talking this over with a co-worker on Friday, and then I tried putting together some 2-dimensional hashes - which hurts my head at the moment. So I went to perl.plover.com/FAQs to read (again) his article on references, and I still have a mental block. Conceptually I understand multi-dimensioned hashes, but in practice I have a LOT of trouble with the syntax. I need to work hard to solidify how to put it together in a real coded situation. OTH, This code posted below makes more sense to my brain. I was on this track earlier, but digressed into the above approach - which is probably more elegant, but difficult for me to see how to do in practice. deb R. Joseph Newton [EMAIL PROTECTED] had this to say, Deb wrote: Hi Guys, I have an array in which each element is a line commandline data. It looks something like this - @Array contains lines: post1: -r [EMAIL PROTECTED] -x cat-100 -h post1 post2: -x tel -h post2 post3: -h post3 -x hifi The getRelationships sub here has a few less typos, and the test stub runs well. #!/usr/bin/perl -w use strict; use warnings; sub getRelationship($$); testGetRelationships(); sub testGetRelationships { my $string = post1: -r [EMAIL PROTECTED] -x cat-100 -h post1; my %relationships; getRelationship($string, \%relationships); foreach my $key (keys %relationships) { print $key:=$relationships{$key}\n; } } sub getRelationship ($$) { my ($commandline, $relationships) = @_; # print $commandline\n; #debug my @commands = split /\s+-/, $commandline; my $key = shift(@commands); foreach (@commands) { if (s/^x\s+//) {$$relationships{$key} = $_;} } } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- There are 010 types of people in the world: those who understand binary, and those who don't. ô¿ô 111,111,111 x 111,111,111 = 12,345,678,987,654,321 (decimal) ~ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
shifting through arrays of line data
Hi Guys, I have an array in which each element is a line commandline data. It looks something like this - @Array contains lines: post1: -r [EMAIL PROTECTED] -x cat-100 -h post1 post2: -x tel -h post2 post3: -h post3 -x hifi And so on. The order of the options varies, and there may or may not be a -r $arg on the line. These lines are parsed from a file with more lines, of which I extracted all the lines with -h: open (F, $File); while (F) { if ($_ =~ / -h /) { # remove crud s/ \\|//; s/\/some\/crud\/path argument //; s/\$//; # store what's left push @Array, $_; } } What I really need to do is build a relationship between the first field (which is the same as the argument to -h) and the argument to -x. The -x flag can be dropped, as they're not needed. So it looks like I need to build a hash based. But I can't can't grok how to parse each line out to do what I need, then move on to the next line (all lines are unrelated to each other). I've been using shift, but then I'm doing something like, (psuedo code): if ($_[0] eq -r) { $r = (shift);} but if sub 0 doesn't eq -r, and I shift until I get to -x, say, and use that for the $x = (shift), how can I be efficient to check again for -r, which I still haven't found? Is this making any sense? Thanks, deb -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- There are 010 types of people in the world: those who understand binary, and those who don't. ô¿ô 111,111,111 x 111,111,111 = 12,345,678,987,654,321 (decimal) ~ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: shifting through arrays of line data
Thanks, I know how to use split (I think). Since the data comes in any order, and I have to corellate it, I can't think of a way that split will fix me up - Maybe I'm missing something. Can you give me an example? deb Dan Muey [EMAIL PROTECTED] had this to say, perldoc -f split Will fic you up! Dmuey Hi Guys, I have an array in which each element is a line commandline data. It looks something like this - @Array contains lines: post1: -r [EMAIL PROTECTED] -x cat-100 -h post1 post2: -x tel -h post2 post3: -h post3 -x hifi And so on. The order of the options varies, and there may or may not be a -r $arg on the line. These lines are parsed from a file with more lines, of which I extracted all the lines with -h: open (F, $File); while (F) { if ($_ =~ / -h /) { # remove crud s/ \\|//; s/\/some\/crud\/path argument //; s/\$//; # store what's left push @Array, $_; } } What I really need to do is build a relationship between the first field (which is the same as the argument to -h) and the argument to -x. The -x flag can be dropped, as they're not needed. So it looks like I need to build a hash based. But I can't can't grok how to parse each line out to do what I need, then move on to the next line (all lines are unrelated to each other). I've been using shift, but then I'm doing something like, (psuedo code): if ($_[0] eq -r) { $r = (shift);} but if sub 0 doesn't eq -r, and I shift until I get to -x, say, and use that for the $x = (shift), how can I be efficient to check again for -r, which I still haven't found? Is this making any sense? Thanks, deb -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- =-=-=-=-=-=-=-=-=- There are 010 types of people in the world: those who understand binary, and those who don't. ô¿ô 111,111,111 x 111,111,111 = 12,345,678,987,654,321 (decimal) ~ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- There are 010 types of people in the world: those who understand binary, and those who don't. ô¿ô 111,111,111 x 111,111,111 = 12,345,678,987,654,321 (decimal) ~ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: shlock and retrying
Thanks, everyone. Looks like the approach is to determine how long I'm willing to wait, then count down from there. I especially like John's example of using time. deb John W. Krahn [EMAIL PROTECTED] had this to say, Maybe something like this will work for you? my $start = time; my $waitfor = 10 * 60; # 10 minutes while ( -e $somedir/.cache.LOCK ) { sleep 1; last if time - $start $waitfor; } -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- There are 010 types of people in the world: those who understand binary, and those who don't. ô¿ô 111,111,111 x 111,111,111 = 12,345,678,987,654,321 (decimal) ~ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
shlock and retrying
Hi, I need to modify some code that check for the existance of a lockfile: unless (shlock($somedir/.cache.LOCK)) { print $main'program_name: cache already running\n if $verbose; exit; } I don't want to exit if I find the lock there. What I need to do is back off for a short period of time (a few seconds?) then try again, until the lockfile is gone. I'm not sure what might be the best way to approach this. I'm not comfy with an indefinite loop, where if there is some problem removing the lockfile, my program would wait forever. I'd rather try for a few minutes, then exit with some error. Any pearls of wisdom out there? I could use a boost... Thanks, deb -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
map EXPR, LIST
Using perl v5.6.1 on Solaris. use warnings; use strict; I've got a hash of lists that I'm looping through: foreach $List (sort keys %HashofLists) { print Values for key \$List\:\n; map print (\t\$_\\n), @{$HashofLists{$List} }; } This works just fine, except that I am getting the following complaint when I run the program, print (...) interpreted as function at verify_lists.pl line 55. Line 55 is the map print line, above. This worked w/o complaint (I think!) back in perl 5.001, so my assumption is that v5.6.1 now requires a syntactically different way of writing this out? Since it works as expected, and I don't want the complaint to stdout/stderr, how would I write this such that perl will not complain? Thanks, deb -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- There are 010 types of people in the world: those that understand binary, and those that don't. ô¿ô ~ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: map EXPR, LIST
Hmmm, that's a useful work-around. I may use it, but I'm really interested in finding out what the correct invocaton of map EXPR, LIST would be. Anyone know? Thanks, deb Kipp, James [EMAIL PROTECTED] had this to say, if you wanted to keep the use warnings pragma in there you could use the CGI carp method to send errors off to to wherever: # at the top of the script use CGI::Carp qw(carpout); # redirect STDERR # could also send errs and warning to /dev/null open (ERRLOG, /tmp/err.out) or die can't open error file\n; carpout(\*ERRLOG); -Original Message- From: Deb [mailto:deb;tickleme.llnl.gov] Sent: Tuesday, November 12, 2002 2:12 PM To: Perl List Subject: map EXPR, LIST Using perl v5.6.1 on Solaris. use warnings; use strict; I've got a hash of lists that I'm looping through: foreach $List (sort keys %HashofLists) { print Values for key \$List\:\n; map print (\t\$_\\n), @{$HashofLists{$List} }; } This works just fine, except that I am getting the following complaint when I run the program, print (...) interpreted as function at verify_lists.pl line 55. Line 55 is the map print line, above. This worked w/o complaint (I think!) back in perl 5.001, so my assumption is that v5.6.1 now requires a syntactically different way of writing this out? Since it works as expected, and I don't want the complaint to stdout/stderr, how would I write this such that perl will not complain? Thanks, deb -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- There are 010 types of people in the world: those that understand binary, and those that don't. ô¿ô ~ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: map EXPR, LIST
Wow, I don't think I would've figured this out on my own for a long while. (Probably why my head is getting a little flat on one side...) Using print map { } list; works pretty well. I need to sit down with it for a while to understand it it better. Thanks for the nice explanation, Kipp. deb Paul [EMAIL PROTECTED] had this to say, --- Deb [EMAIL PROTECTED] wrote: Hmmm, that's a useful work-around. I may use it, but I'm really interested in finding out what the correct invocaton of map EXPR, LIST would be. Anyone know? Thanks, deb The problem in the stuff after the comma after the parens after a print, lol -w always carps about that. This calls print seperately for each thing anyway, though -- don't use map as a loop construct. You said map print (\t\$_\\n), @{$HashofLists{$List} }; Rather than that, either use foreach as in print \t\$_\\n foreach @{$HashofLists{$List} }; or (better, in my mind) just call print once, and use map to construct the argument list, like this: print map { \t\$_\\n } @{$HashofLists{$List} }; That's pretty efficient; print() gets one set of data to print, and map does what it's for -- mapping data to corresponding but different values. =o) One last change for readability: print map { qq(\t$_\n) } @{$HashofLists{$List} }; Personal preference, feel free to ignore it, lol... Paul __ Do you Yahoo!? U2 on LAUNCH - Exclusive greatest hits videos http://launch.yahoo.com/u2 -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- There are 010 types of people in the world: those that understand binary, and those that don't. ô¿ô ~ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: a speedy find grep?
Paul Johnson [EMAIL PROTECTED] had this to say, Bang tcgrep into google and see if that brings you any joy. Checking it out. Thanks for the reference (I forgot there was something in the Cookbook...) deb -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- There are 010 types of people in the world: those that understand binary, and those that don't. ô¿ô ~ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
a speedy find grep?
re: Unix From the command-line, I'm currently running a find command piped to xargs grep: find . -f print | xargs egrep some string to look for There is an occassional requirement that this be done and it must parse a hierarchy of directories and files which number in the many thousands. Run from the commandline takes a long, long time. I even re-niced the command -10 as root, but it still takes hours. Would perl be able to optimize the search and grep better than what I am currently doing? Ideas, jokes and rants are appreciated... :-) deb -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- There are 010 types of people in the world: those that understand binary, and those that don't. ô¿ô ~ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: a speedy find grep?
Jeff 'japhy' Pinyan [EMAIL PROTECTED] had this to say, Why not use the -r option to e?grep to do recursive searches? egrep -r pattern . H... Well, on Solaris 5.7, there is no -r option :-(. Could you, by any chance, be referring to a GNU egrep? If so, I can go check it out - I'm always up for a good util... deb -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- There are 010 types of people in the world: those that understand binary, and those that don't. ô¿ô ~ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Sendmail Problems
Hello! From the commandline, what is the output of % /usr/sbin/sendmail -bv [EMAIL PROTECTED] on the server which you cannot send anything? Also useful, would be any error output that was generated... Hard to say if this is a perl problem or sendmail, or...??? deb Johnstone, Colin [EMAIL PROTECTED] had this to say, Gidday from Downunder I have loaded the same script on two servers one will send to my home account and the other won't. I know sendmail path and perl path are correct in both instances while it won't send to my home account it will send to my hotmail account. Any Ideas! #!/usr/bin/perl print Content-Type: text/html\n\n; $from=colin.johnstone\@det.nsw.edu.au; $to=colinjohnstone\@ozemail.com.au; $subject=I\'m sending myself a test e-mail!; $sendmailpath=/usr/sbin/sendmail; open (SENDMAIL, | $sendmailpath -t); print SENDMAIL Subject: $subject\n; print SENDMAIL From: $from\n; print SENDMAIL To: $to\n\n; print SENDMAIL This is a test e-mail.\n\n; print SENDMAIL -Colin Johnstone; close (SENDMAIL); print(sending to...: $tobr); Colin Johnstone Website Project Officer Corporate Website Unit Public Affairs Directorate ph 9561 8643 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- There are 010 types of people in the world: those that understand binary, and those that don't. ô¿ô ~ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
summing totals by date
Hi, I have a file in the following format, mm/dd/yy,decimal_number. 07/01/02,8419 07/02/02,6344 07/03/02,6487 07/04/02,719 07/05/02,3768 07/06/02,1270 07/07/02,7 07/08/02,5179 07/09/02,9990 07/10/02,7968 07/11/02,7605 07/02/02,8892 07/03/02,5550 07/04/02,6483 07/05/02,786 07/06/02,4094 07/06/02,954 07/07/02,6 07/09/02,5232 07/10/02,10405 07/11/02,7600 07/12/02,7581 What I need to do is key on the date, then sum the numbers for the date, then send the date and sum to a file of the same format as above. So far, I've got this, $File = $ARGV[0]; open (F, $File) || die Oops, did you type the right filename?\n; while (F) { ($date, $number) = split , ; push (@{$numbers{$date}}, $number); } Does that look right? I'm not sure how to go from here. I really have a hard time understanding how to manipulate hashes. The syntax kills my brain. Any help would probably make my head quit hurting so much! deb -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- There are 010 types of people in the world: those that understand binary, and those that don't. ô¿ô ~ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: summing totals by date
Toby Stuart [EMAIL PROTECTED] had this to say, If i understand what u want, the following works (i'll leave the printing to another file up to you) snip Thanks for the quick reply, Toby. With your suggestions, here's what I have (and it works, too). I have some questions about it, because, as I said before, I think I understand hashes, just not what it takes to manipulate them. But I'm too tired right now to form a good question. I'll give this some thought and then post some questions. Again, thanks! deb #!/usr/local/bin/perl use strict; use warnings; my $fileout= ./stats.out; my $filein = $ARGV[0]; my %totals; my $date; my $count; open (F, $filein) || die Oops, did you type the right filename?\n; while (F) { chomp($_); ($date,$count) = split(/,/,$_); $totals{$date} += $count; } close(F); while ( ($date,$count) = each %totals) { open (F,$fileout) || die Cannot open $fileout for writing.\n; print F $date : $count\n; } close(F); -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- There are 010 types of people in the world: those that understand binary, and those that don't. ô¿ô ~ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: df hang inside script
* Anders Holm [EMAIL PROTECTED] [2002-07-02 10:31:29 +0100]: Why not see if the NFS has bombed out before trying to use it? Maybe just trying to do an ls or something which wouldn't need to hang your process, but rather give you a failure notice? (Sorry for the long time in getting back to everyone. Busy in other areas.) Yeah, that's good food for thought. Drieux had some pointers too. I can't just check for certain filesystems, I have to know what is mounted at a given time... But the fact that there is NFS server/ client game where they no longer make nice - well, I need to discover that before issuing the df cmd, methinks. I suppose I could check the log for error messages, but that is frought with other problems. Guess I'll need to keep mulling; maybe that ah-ha! moment will come to me soon... Thanks, deb -- If it dies, it's biology. If it blows up, it's chemistry, and if it doesn't work, it's physics. -- University bathroom graffito ô¿ô ~ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
df hang inside script
Hey Folks, Recently I had a problem where a *nix system NFS was hung on a server which had gone away, but the client hadn't umounted the filesystem. Later, this caused a script in cron to fail, in that a df command inside the script never completed, and instead it hung, causing the script to hang awaiting a completion of df, which it never got. 999 times out of 1000 this has not failed, but when that one time comes along, all hell breaks loose. I'm not sure what approach to take to alleviate the cascading failure. I'd prefer to just abort the df, log the error, and complete the rest of the script. Short of totally re-writing the script (it's not mine, to begin with), I would like to modify it. It's a simple system command being used: system (/usr/sbin/df -kl); Ideas? Thanks, deb =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Press any key... no, no, no, NOT THAT ONE!!! ô¿ô ~ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: lazy variable declaration
David, Could you turn off your MUA's option for sending your email messages out as quoted-printable? Reading your posts has been difficult at best on an xterm where there is no MIME. (see included text, below) It seems you're using mutt as an MUA - I think you should be able to configure it to send plain text. Thanks, deb Meanwhile, David T-G says: | | --0lgBsWZvwbEqroRZ | Content-Type: text/plain; charset=us-ascii | Content-Disposition: inline | Content-Transfer-Encoding: quoted-printable | | Janek, et al -- | | =2E..and then Janek Schleicher said... | %=20 | % David T-G wrote at Wed, 12 Jun 2002 19:42:46 +0200: | %=20 | =2E.. | % =20 | % In this limited context, yes. I wouldn't usually declare them all up f= | ront. | %=20 | % Well, I thought you never do (as I know you're not a beginner any more) | | Oh, I'm still a beginner, all right :-) | | | % But I know, some beginners do, so I was a little bit provocant :-) | | Good enough. | | | % =20 | =2E.. | % requirements. If you look at | % =20 | %my ($artist, $album, $track) ; | %while () | %{ | % ($artist, $album, $track) =3D split(/\//); | % if ( $track eq foo ) | % ... | %} | %=20 | % I would try to write it as | % while () { | %my ($artist, $album, $track) =3D split m:/:; | %if ($track eq $foo) { # $foo eq $foo :-) | % ... | %} | % } | | I don't see a difference here except that you're using a variable $foo | where I threw in a constant foo because it wasn't really important. If | the $track var in that example is undefined then it will throw an error, | right? So I don't see how writing it that way (aside from the nicer | split, which I'll also be doing in my next rewrite but at least I thought | of it before someone had to show me :-) will improve matters... | | | %=20 | % % I think, that it is my obligation to warn you | % % that use strict; use warnings; wasn't made for that way. | % =20 | % Now, them's fightin' word, pardner! Into the street! | %=20 | % I like fightings :-) | | *grin* | | | % But to say the truth, it reads harder than I meant it. | % Of course, TMTWTDI, as I only wanted to say, it could be dangerous this w= | ay. | | I understand, and I appreciate it. | | | %=20 | % Again it was adressed to the many beginners outside the world. | % In fact, curiously, to understand why strict declarations and warnings ar= | e needed, | % it's more a problem to java beginners than to perl beginners. | % I still try to understand why :-) | | Interesting. One more reason not to know java, I guess ;-) ducks | | | %=20 | =2E.. | % integrate single-case undef logic into the loop, no? | %=20 | % Yep, you're right! | % (But taking my way would force every loop an undef, doesn't it :-)) | | True :-) | | Hey, I could just undef *everything* between iterations and then I'd have | a higher probability of finding one, eh? :-) | | | %=20 | % I still don't quite get the whole our/local think yet. Still worki= | n' on that. | %=20 | % Oh, and I have always problems to explain it. | | No problem; I'll get there. | | Interesting... I just went to look for it in my 2e Camel book and can't | find it (only my and local). Hmmm... | | | % Well, when you'll understand the philosphy you never want to go back. | % It's like the difference between the goto statement from BASIC and subrou= | tines. | | I imagine and I can't wait :-) I need to really get OOP, too. | | | %=20 | % At the moment I'm storing then in a hash as | =2E.. | % some more data subroutine, which will also scope them locally. | %=20 | % That sounds good. | | Yay :-) | | | %=20 | % =20 | % Given all of that (*whew*), does it sound like I'm on the right track o= | r instead still Not Getting | % It Even If TMTOWTDI? | %=20 | % Yes. | % There are only some ways with a little bit more adventure :-) | | Good enough; one of these days I can lace up my boots and head off on a | rewrite then. As long as I'm not doing this flat-out incorrectly right | now it'll do. | | | %=20 | % (It's like with doubled code which one is an alert signal for me too for = | various reasons.) | | Yeah. I already have some of that and am trying to work them out to a | single subroutine. | | | %=20 | % Cheerio, | % Janek | | | Thanks HAND | | :-D | --=20 | David T-G * It's easier to fight for one's principles | (play) [EMAIL PROTECTED] * than to live up to them. -- fortune cookie | (work) [EMAIL PROTECTED] | http://www.justpickone.org/davidtg/Shpx gur Pbzzhavpngvbaf Qrprapl Npg! | | | --0lgBsWZvwbEqroRZ | Content-Type: application/pgp-signature | Content-Disposition: inline | | -BEGIN PGP SIGNATURE- | Version: GnuPG v1.0.7 (GNU/Linux) | | iD8DBQE9B6X0Gb7uCXufRwARAiPAAJ9MzNFMRlQxgsGH1DOOSmE7GoU+NgCfUL5Z | aFTDf2DHfbTJ+lD0E1cLDRo= | =qAAn | -END PGP SIGNATURE- | | --0lgBsWZvwbEqroRZ
make test of Text::Reflow
Hello, I installed perl module Text::Reflow on perl v5.6.1 for Solaris. It built fine, but make test fails in that it hangs on the first test. cpan test Text::Reflow Running test for module Text::Reflow Running make for M/MW/MWARD/Text-Reflow-1.04.tar.gz Is already unwrapped into directory /usr/local/cpan/build/Text-Reflow-1.04 Has already been processed within this session Running make test Use of uninitialized value in scalar assignment at /usr/local/pkg/perl-5.6.1/lib/5.6.1/CPAN.pm line 4658. Use of uninitialized value in hash dereference at /usr/local/pkg/perl-5.6.1/lib/5.6.1/CPAN.pm line 801. PERL_DL_NONLAZY=1 /usr/local/pkg/perl-5.6.1/bin/perl -Iblib/arch -Iblib/lib -I/usr/local/pkg/perl-5.6.1/lib/5.6.1/sun4-solaris -I/usr/local/pkg/perl-5.6.1/lib/5.6.1 test.pl 1..20 ok 1 ^C /usr/ccs/bin/make test -- NOT OK I don't know how to troubleshoot this, and find out wherein lies the problem. Any and all help would be appreciated, or even pointers to the appropriate email list(s). Thanks, deb -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: make test of Text::Reflow
Meanwhile, =?iso-8859-1?q?Jonathan=20E.=20Paton?= says: | | --- Deb [EMAIL PROTECTED] wrote: | Hello, | | Hiya! :-) Thanks for the swift reply. | I installed perl module Text::Reflow on perl v5.6.1 for Solaris. | | It built fine, but make test fails in that it hangs on the | first test. | | Okay, try again... does it still fail? If yes, then download the | module manually and follow the install instructions. Did this. Same results. | If it still | fails the problem is with Text::Reflow, otherwise it is the CPAN | module. Well, not quite. New wrinkle, on another system running 5.6.1, same Solaris (5.7), make test runs just fine: cpan test Text::Reflow Running test for module Text::Reflow Running make for M/MW/MWARD/Text-Reflow-1.04.tar.gz Is already unwrapped into directory /home/deb/.cpan/build/Text-Reflow-1.04 Has already been processed within this session Running make test Use of uninitialized value in scalar assignment at /usr/local/lib/perl5/5.6.1/CPAN.pm line 4658. Use of uninitialized value in hash dereference at /usr/local/lib/perl5/5.6.1/CPAN.pm line 801. PERL_DL_NONLAZY=1 /bin/perl -Iblib/arch -Iblib/lib -I/usr/local/lib/perl5/5.6.1/sun4-solaris -I/usr/local/lib/perl5/5.6.1 test.pl 1..20 ok 1 ok 2 ok 3 ok 4 ok 5 ok 6 ok 7 ok 8 ok 9 ok 10 ok 11 ok 12 ok 13 ok 14 ok 15 ok 16 ok 17 ok 18 ok 19 ok 20 /usr/ccs/bin/make test -- OK | Whichever it is, you can use 'rt.cpan.org' to submit a bug report... | and the information you gave below is probably enough to make them Okay, can do. | happy. Try upgrading CPAN before you do, but with Perl 5.6.1 you | shouldn't have to. Include any platform information as well. I just upgraded recently to 1.60. | If you have spare time, try using the CPANPLUS module instead. It | was announced on 'www.perl.com' recently. I'll try anything at this point. HOWEVER, I would still like to be able to troubleshooot this. But, I'm having heck of a time getting anywhere. | Jonathan Paton deb | __ | Do You Yahoo!? Me? No never... | Everything you'll ever need on one web page | from News and Sport to Email and Music Charts | http://uk.my.yahoo.com | | -- | To unsubscribe, e-mail: [EMAIL PROTECTED] | For additional commands, e-mail: [EMAIL PROTECTED] | | If it dies, it's biology. If it blows up, it's chemistry, and if it doesn't work, it's physics. -- University bathroom graffito ô¿ô ~ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Summary: make test of Text::Reflow
Answering myself here - found out it was the perl binary. For some reason the binary compiled for 64-bit execution would not make this module properly, but the 32-bit does. Go figure. Someone else is looking into why this might be the case. For now, I'm happy to use the 32-bit version. deb Meanwhile, Deb says: | | Hello, | | I installed perl module Text::Reflow on perl v5.6.1 for Solaris. | | It built fine, but make test fails in that it hangs on the | first test. | | cpan test Text::Reflow | Running test for module Text::Reflow | Running make for M/MW/MWARD/Text-Reflow-1.04.tar.gz | Is already unwrapped into directory /usr/local/cpan/build/Text-Reflow-1.04 | Has already been processed within this session | Running make test | Use of uninitialized value in scalar assignment at |/usr/local/pkg/perl-5.6.1/lib/5.6.1/CPAN.pm line 4658. | Use of uninitialized value in hash dereference at |/usr/local/pkg/perl-5.6.1/lib/5.6.1/CPAN.pm line 801. | PERL_DL_NONLAZY=1 /usr/local/pkg/perl-5.6.1/bin/perl -Iblib/arch -Iblib/lib |-I/usr/local/pkg/perl-5.6.1/lib/5.6.1/sun4-solaris |-I/usr/local/pkg/perl-5.6.1/lib/5.6.1 test.pl | 1..20 | ok 1 | ^C /usr/ccs/bin/make test -- NOT OK | | | I don't know how to troubleshoot this, and find out wherein lies | the problem. Any and all help would be appreciated, or even | pointers to the appropriate email list(s). | | Thanks, | | deb | | -- | To unsubscribe, e-mail: [EMAIL PROTECTED] | For additional commands, e-mail: [EMAIL PROTECTED] | | If it dies, it's biology. If it blows up, it's chemistry, and if it doesn't work, it's physics. -- University bathroom graffito ô¿ô ~ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
LWP
I've written a program that checks for the existence of a website by retrieving an HTTP header when fed a URL. It works beautifully on my server (NT running Windows '98) but locks when I installed it on my client's server (NT running Windows 2000). The important guts of the code are: use LWP::Simple; use CGI; CGI::ReadParse(*in); $url1 = $in{site}; if (!$in{backit}){ $base_url=$url1; $test=head($base_url); } if ($test !$in{backit}) { #etc. Any ideas on why this won't run on the other server? (I already made sure that the LWP module was installed.) - Deb Thompson Civil Environmental Consultants 800-365-2324 www.cecinc.com Tracking #: E51A87A7A965D511954600508BC28C5A9B439FC9