Re: HELP !! displaying Associate Array value pairs
On Tue, Sep 04, 2001 at 07:20:27PM +0200, Quincy Ntuli wrote: greetings I am trying to return the value from an associate array; i do not understand what i am doing wrong. ...code that others already commented on snipped... $theHash{'$sortedListing[1]'} =[$dbRec]; You have a quoting problem. You stuff *everything* you read into theHash at the key '$sortedListing[1]'. The single quotes make sure the content of the string inbetween isn't evaluated. To get the value of the variable $sortedListing[1] as the key to your hash, use double quotes (). And always remember: Data::Dumper is your friend: ... use Data::Dumper; ... print Dumper(\%theHash); will give you a nice pretty-printed dump of your hash which will show you the problem. print \$sortedListing[1] is ($theHash{'$sortedListing[1]'})\n; Note, that the single quotes inside the double quotes do nothing special like, hmmm, add more quoting. -- Well, then let's give that Java-Wussie a beating... (me) Michael Lamertz| +49 2234 204947 / +49 171 6900 310 Sandstr. 122 | [EMAIL PROTECTED] 50226 Frechen | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Reading Directory
On Wed, Sep 04, 2002 at 09:41:54PM +0200, Fabian Funk wrote: Hi, I'm pretty new to perl. I want to open a Directory with mp3 files an other files. My Poblem is i need only the mp3 files. How can i get only the mp3 files and not other files ? I tried: while (defined(my $file=readdir(DIR))) { Here you assign to $file... next if $file=~ /^\.\.?$/; and here you use it... next unless /\.[mp3]$/i; but here you use $_ instead. Besides that, you're matching all files *.m, *.p and *.3. Match for /\.mp3$/ instead. push(@files,$file); But i get Use of uninitialized value in pattern match (m//) What's wrong ??? That was the match on $_ which hadn't been set. BTW: perldoc -f readdir has a pretty good example for what you need to do. Try replacing your whole while construct with my @files = grep { -f $_ /\.mp3$/ } readdir DIR; -- Well, then let's give that Java-Wussie a beating... (me) Michael Lamertz| +49 2234 204947 / +49 171 6900 310 Sandstr. 122 | [EMAIL PROTECTED] 50226 Frechen | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: eval on a $SIG{KILL}- newbie question
I think Bob's theory 1 fits. The die is never called. You put an alarm handler into your program which is set for 10 seconds. I suppose the timeout for the ssh module is more like 30 seconds, so the alarm catches first. On Tue, Aug 27, 2002 at 01:46:20PM -0400, Chad Kellerman wrote: How do I catch the die() in an eval statement; I have been using: eval { alarm 10; $ssh-login($user); ($out, $error, $exit) = $ssh-cmd($cmd); alarm(0); }; # end of eval statement if ($@ =~ /Can't/) { try_again($ip, $host_name) = @_; } Since you didn't install your own signal handler for ALRM the standard handler emits a Alarm clock which you most likely find in $@. Try printing $@ instead of matching it, and you'll see what happened. -- Well, then let's give that Java-Wussie a beating... (me) Michael Lamertz| +49 2234 204947 / +49 171 6900 310 Sandstr. 122 | [EMAIL PROTECTED] 50226 Frechen | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: matching file extension .vbp and .dsp
On Wed, Aug 28, 2002 at 04:59:59PM +0530, Javeed SAR wrote: Hi, I am reading dirextory using ls. Don't. Use opendir and readdir. The 'perldoc -f readdir' gives you an example how to filter the result by using grep. How to match for .dsp and .vbp file extensions Is this right? if ($file1 =~ m/\.vbp$/) opendir DIR, /some/dir or die Cannot access /some/dir: $!\n; my @files = grep { -f /\.(ds|vb)p$/ } readdir DIR; closedir DIR; print @files; -- Well, then let's give that Java-Wussie a beating... (me) Michael Lamertz| +49 2234 204947 / +49 171 6900 310 Sandstr. 122 | [EMAIL PROTECTED] 50226 Frechen | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Multidimensional Associative Arrays --- do they exist ?
On Tue, Aug 27, 2002 at 01:20:32PM +0200, Q wrote: Greetings. Is there such a thing as mutlidimensional associative array ? FILE 1 ( Filename = 23_59_54_20_08_2002) = FIELD1FIELD2FIELD3 204060 FILE 2 (Filename = 23_59_55_20_08_2002) = FIELD1FIELD2FIELD3 302045 You already got an answer from Felix, but let me feed you a bit more information as base-knowledge: perldoc perldsc Read the Perl Data Structures Cookbook. There you'll find a nice overview about the stuff you need. perldoc perlref goes into far more detail, so take a look at that too. You can take your approach and build a hash of hashes my $stuff = { '23_59_54_20_08_2002' = { field1 = 20, field2 = 40, field3 = 60, }, '23_59_55_20_08_2002' = { field1 = 30, field2 = 20, field3 = 45, } } my $value = $stuff-{$fname}{field2}; # gives '40' or you could create an array of hashes: my $stuff = [ { filename= '23_59_54_20_08_2002', data= { field1 = ... } }, { filename= '23_59_55_20_08_2002', data= { ... } } } my $value = $stuff-[0]{field2} # gives '40' For both methods, You could store the data in an array if the fieldnames are of no interest to you: my $stuff = { '23_59_54_20_08_2002' = [ 20, 40, 60 ], ... ] my $value = $stuff-{23_59_54_20_08_2002}[2]# guess what and my $stuff = [ { filename= '23_59_54_20_08_2002', data= [ 20, 40, 60 ], }, ... ]; my $value = $stuff-[0][1]; # ditto It all depends on what you want to do with the final data. Do you want to easily access single elements? That would be a candidate for hashes. Do you want to iterate over your data to calculate statistics? Smells like arrays... And always remember: When it comes to complex data structures, Data::Dumper is your friend... -- Well, then let's give that Java-Wussie a beating... (me) Michael Lamertz| +49 2234 204947 / +49 171 6900 310 Sandstr. 122 | [EMAIL PROTECTED] 50226 Frechen | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Confirm a possible bug
On Thu, Jul 18, 2002 at 10:33:45AM -0400, Nikola Janceski wrote: I think I have stumbled onto a bug. I'd like one of the gurus (Jeff, druiex, Jenda or any perlguy.com) to confirm that my test is correct or if I missed something in docs. I'm not on that list, but I'll bite anyways :-) using Perl 5.6.1 on a Solaris sparc. #perl use strict; use warnings; my $wofile = noread;# text file with no read permissions my $file = canread; # text file with read perms if( -T $file ){ # will be true print exists\n if -e _; # will print } else { print doesn't exist\n unless -e _; } ## here's the possible bug if( -T $wofile ){ # will be false (you need read to determine if text file) ^^ correct... print exists\n if -e _; } else { print doesn't exist\n unless -e _; # will print BUT SHOULDN'T ^^ Why?!? The 'stat' structure is used. That structure has been filled by the -T, since the file has been accessed, regardless of the fact that the test for the 'text' type failed. The stat structure contains properties that rely on the working directories permissions and thus contains valid data. File permissions are irrelevant in that case. Or am I missing something? -- Well, then let's give that Java-Wussie a beating... (me) Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Confirm a possible bug
On Thu, Jul 18, 2002 at 04:53:46PM +0200, Michael Lamertz wrote: The 'stat' structure is used. That structure has been filled by the -T, since the file has been accessed, regardless of the fact that the test for the 'text' type failed. DUH! Me Idiot, Ugh! I mixed up || and in my own test and had thus printed the correct answer, but my test was bogus. Yepp, looks like the stat is empty... -- Well, then let's give that Java-Wussie a beating... (me) Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: email body question still
On Thu, Jun 13, 2002 at 11:27:05PM -0700, tom poe wrote: #! /usr/local/bin/perl -w open (IN, $file) or die Can't open $file: !$\n; while (IN) { # Skip lines unless we have a blank line next unless /^\s*?/; Nope. The comment doesn't match your code. The code says continue with the next line unless this line starts with *ZERO* or more spaces So first of all, your regexp should be /^$/ Since you want to match an empty line or /^\s*/ To match an empty or pure whitespace line. 2nd, your code just drops this single matching line, so it would print the message including the header without empty lines. What you want to do instead is either to a. split the reading into 2 loops, first skipping all the header lines until you reach an empty line b. use a flag to tell when to start slurping the body my $slurp = 0; while (IN) { $slurp = 1 if /^$/; next unless $slurp; ... -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Oracle and Perl
On Thu, Jun 06, 2002 at 08:34:24AM -0400, Naser Ali wrote: Hello everyone, I am planning to write perl programs to access Oracle database. What do I need to install and configure in Solaris 2.6 environment with Oracle 8i.? Where can I find some basic tutorials for beginners like my self. Any pointers will be appreciated. You need DBI DBD::Oracle It's been a while, so the following information might be outdated: On the Oracle side, I recommend a full install, because the build process for DBD::Oracle needs header files that are hidden somewhere in the example code packages of Oracle. We never really managed to figure out which option in the Oracle installer actually contained the missing headers :-) The 'make test' part of DBD::Oracle tries to connect as 'scott/tiger' - which I was told was a test user in old versions of Oracle - by default, so you need to set ORACLE_SID to an existing test user. Other than that, everything works pretty much as expected. -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Getting through a deep hash
On Fri, May 24, 2002 at 09:32:26AM -0400, Barry Jones wrote: my $results = $test-{testing_results}{testing_result}; if(ref($results) eq 'ARRAY') { for my $spot (@$results) { for my $key (keys %$spot) { if (ref($spot-{$key}) eq 'HASH') { if($key eq 'value_group') { ###my %vg = $spot-{$key}; and as you can see in the line with the ### I was just trying to put it into a new hash, but that is giving me this error: Reference found where even-sized list expected Which says that you don't have a hash there, but a hash-reference. $vg = $spot-{$key} will do the job. You will access it the same way you did with the other hash-refs $vg-{some_key} Let me reiterate on an little rant I did earlier here on the list: Data::Dumper is your friend! If you're stumbling over an error message that doesn't make sense to you, I recommend use diagnostics; which would have given you the following: -- snip -- Reference found where even-sized list expected at x.pl line 9 (#1) (W misc) You gave a single reference where Perl was expecting a list with an even number of elements (for assignment to a hash). This usually means that you used the anon hash constructor when you meant to use parens. In any case, a hash requires key/value pairs. %hash = { one = 1, two = 2, };# WRONG %hash = [ qw/ an anon array / ];# WRONG %hash = ( one = 1, two = 2, );# right %hash = qw( one 1 two 2 ); # also fine -- snip -- Also looking into perldoc perldiag would have given you the same information, although it's left to discussion if that message would actually have helped in your special case, now that I'm looking at it. -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: power of
On Wed, May 22, 2002 at 09:53:09AM -0400, Prachi Shroff wrote: Hi! This may sound as a very stupid question, but here it comes anyways. Has anybody come across a function that wold calculate the power of a number, like the pow function in C. Simply, x to the power of y. perldoc perlop Search for 'Exponentiation'. It's the '**' operator. -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: stdout and error to one file
On Mon, May 20, 2002 at 08:54:19PM -0700, [EMAIL PROTECTED] wrote: Hi, I try to write a script that redirects its output, both out and error, to a log-file, if it's possible to the screen as well. At the moment I'm doing this with open (FILE, whatever.txt); open (STDOUT, FILE); open (SDTERR, FILE); But now of course I don't have the output on the screen any more. Is it possible to get both? Yepp. Leaving the beginner's realm and entering the world of black magic... perldoc perltie Search for 'TIEHANDLE' in there... And some code to chew on... -- th.pl -- #!/usr/bin/perl use strict; use warnings; package th; use Exporter; use FileHandle; our @ISA = qw{Exporter FileHandle}; sub TIEHANDLE { my ($ctx, $fname, $old_fh) = @_; my $class = ref($ctx) || $ctx; my $fh = new FileHandle($fname) or die Cannot open logfile '$fname': $!\n; my $dup = new FileHandle($$old_fh) or die Cannot dup old filehandle: $!\n; my $self = { files = [ $fh, $dup ] }; if (fileno($$old_fh) == 2) { $self-{old_die} = $SIG{__DIE__}; $self-{old_warn} = $SIG{__WARN__}; $SIG{__DIE__} = sub { $self-die_handler(@_) }; $SIG{__WARN__} = sub { $self-warn_handler(@_) }; } bless $self, $class; } sub warn_handler { my $self = shift; print $_ @_ foreach @{$self-{files}}; } sub die_handler { my $self = shift; print $_ @_ foreach @{$self-{files}}; } sub PRINT { my $self = shift; print $_ @_ foreach @{$self-{files}}; } sub CLOSE { my $self = shift; $_-close() foreach @{$self-{files}}; } sub UNTIE { my ($self, $count) = @_; warn untieing $count inner refs if $count 1; $SIG{__WARN__} = $self-{old_warn} if defined $self-{old_warn}; $SIG{__DIE__} = $self-{old_die} if defined $self-{old_die}; } 1; package main; tie *STDERR, th, /tmp/my_log.txt, \*STDERR; print STDERR plain print\n; warn You are warned!\n; untie *STDERR; print STDERR Untied\n; -- th.pl -- Notes: tie *STDERR, th, /tmp/my_log.txt, \*STDERR; Since the constructor TIEHANDLE isn't passed the tied filehandle we need to pass it explicitely as the last parameter. sub TIEHANDLE: my $dup = new FileHandle($$old_fh) Since we catch writes to the original filehandle we need to duplicate it to avoid recursion print STDERR Failure calls th::PRINT which prints to STDERR and thus calls th::PRINT ... if (fileno($$old_fh) == 2) {... If we print to STDERR we need to catch $SIG{__WARN__} and $SIG{__DIE__}. We store the original handlers to daisy-chain to them after we did our printing. sub UNTIE: warn untieing $count inner refs if $count 1; Since our object still lives when we're in here, the ref-count is still 1. We can ignore that. But if we're 1, there's still some variable that's referencing us (my $t = tie ...). See 'perldoc perltie' for a discussion of that. Finally, we reestablish the old signal handlers. Since this is sample code we don't do any checking if it's sane to restore these. (They might have been overridden by other parts of your application...) And the results: -- snip -- nijushiho:~$ perl th.pl plain print You are warned! Untied nijushiho:~$ cat /tmp/my_log.txt plain print You are warned! nijushiho:~$ -- snip -- If you take a look at the perldoc, you'll notice that I only implemented a subset of the possible functions. Just add the others as you need them in your program... -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Setting limit coredumpsize
On Thu, May 16, 2002 at 09:02:44PM +0530, Mayank Ahuja wrote: Hi All I'm working on Unix (solaris) I want to set the coredumpsize to 0 Now i want to do the same using Perl script. I cannot use system or backticks (` `) because this will fork off a different shell. That would be /bin/sh where the name is 'ulimit', but that won't help you anyways, since the limit is per process and will only be inherited to child processes, just like the environment. So, you either need to start your perl script with a shell wrapper, setting the ulimit beforehand, or you use the BSD::Resource module http://search.cpan.org/doc/JHI/BSD-Resource-1.15/Resource.pm which lets you set the limits directly from within perl. -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: C/C++ Comment Extractor : Help!!
On Thu, May 16, 2002 at 09:18:49PM +0530, [EMAIL PROTECTED] wrote: Hi Perl Gurus, I'm trying to Implement a comment extractor from C/C++ Source files. (Being a newbie... I'm poor in regexes., and I think (?) , this can be pretty easy with regexps). Actually no, it's not easy. C++ comments (//...) are no problem since they end at EOL, but the others (/* ... */) are plain evil, especially with compiler flags for allowing nested comments. Look for Text::Balance, that should get you started. -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Setting limit coredumpsize
On Thu, May 16, 2002 at 05:24:47PM +0100, Jonathan E. Paton wrote: ln -s /dev/null core I thought you deserved a beating... just stick into any directory where you could have a core dump. You must be doing something mission critical to be desperate to stop these, but not mission critical enough to want to use them. until I read this previous paragraph. Phew! ;-) Why not just get cron to recurse over your directories eliminating core files when the filesystem gets a little cramped? In that case I'd recommend above solution as the lesser evil since it gives you at least a bit control over which cores to see and which not. Well, a *nice* daemon would chdir to '/' anyways, so putting that symlink there would be the same as traversing the tree and clobbering each and every coredump one can find, which again sucks. I know it is dumb, but why not just wrap your perl script in one of these coredump eliminating shell scripts - the child processes will get those properties. Or set the limit to disallow cores inside the shellscript. Oh, and Perl probably does have a way of doing this... try POSIX.pm, or the syscall function (you'll need to know what to look for, ask a C programmer how they do it). Nope, it's not in POSIX as far as I know. Hmm, never used syscall... Let's harvest some information: -- perldoc -f syscall -- syscall LIST ... The arguments are interpreted as follows: if a given argument is numeric, the argument is passed as an int. If not, the pointer to the string value is passed. You are responsible to make sure a string is pre- extended long enough to receive any result that might be written into a string. ... require 'syscall.ph'; # may need to run h2ph $s = hi there\n; syscall(SYS_write, fileno(STDOUT), $s, length $s); -- perldoc -f syscall -- H, looks easy enough... -- man getrlimit -- ... int getrlimit(int resource, struct rlimit *rlim); ... getrlimit and setrlimit get and set resource limits respectively. resource should be one of: RLIMIT_CPU /* CPU time in seconds */ RLIMIT_FSIZE /* Maximum filesize */ RLIMIT_DATA/* max data size */ RLIMIT_STACK /* max stack size */ RLIMIT_CORE/* max core file size */ RLIMIT_RSS /* max resident set size */ RLIMIT_NPROC /* max number of processes */ RLIMIT_NOFILE /* max number of open files */ RLIMIT_MEMLOCK /* max locked-in-memory address space*/ RLIMIT_AS /* address space (virtual memory) limit */ ... The rlimit structure is defined as follows : struct rlimit { rlim_trlim_cur; rlim_trlim_max; }; ... RETURN VALUE On success, zero is returned. On error, -1 is returned, and errno is set appropriately. -- man getrlimit -- That should get us started... -- snip -- nijushiho:~$ grep RLIMIT_CORE /usr/include/*/* 2/dev/null /usr/include/asm/resource.h:#define RLIMIT_CORE 4 /* max core file size */ /usr/include/bits/resource.h: RLIMIT_CORE = 4, /usr/include/bits/resource.h:#defineRLIMIT_CORE RLIMIT_CORE -- snip -- Aha, RLIMIT_CORE is 4... -- snip lim.pl -- #!/usr/bin/perl use warnings; use strict; my $lim = pack('LL', 0, 0); # Yepp, I grepped some more in /usr/include/* # to find out the sice of rlim_t print Failed: $!\n if syscall(SYS_getrlimit(4, $lim)) 0; my ($cur, $max) = unpack('LL', $lim); print CUR: $cur\n; print MAX: $max\n; -- snip lim.pl -- Let's start it... -- snip -- nijushiho:~$ perl lim.pl Returned Invalid argument CUR: 0 MAX: 0 nijushiho:~$ -- snip -- H, what's up here?!? Anybody any ideas? -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: proper way to start daemon
On Thu, May 16, 2002 at 12:16:58PM -0700, Matt Simonsen wrote: My best guess is I should have the script immediately fork a copy of itself then die while the forked copy still runs, but I haven't been able to figure out how to make that work. Any suggestions would be helpful, especially a sample loop like this that just forks a daemon to do something stupid like print foo ; forever. Ok, here's what we need to do to completely detach from our parent process - speak when we want to become a daemon: 1. get out of the parent's (in that case your shell's) process group. We'll have PPID 1 after this call. The only error that setsid can throw is EPERM which means that we already are process group leader. 2. move up to the root directory, so that we're not blocking filesystems that one might want to unmount (e.g. /opt) 3. close all those rotten filehandles who's output nobody will see anyways... -- daemonify -- #!/usr/bin/perl -w use strict; use POSIX qw/setsid/; my $child = shift; die Path to $child must be absolute\n unless $child =~ /^\//; unless (fork) { setsid(); chdir '/'; close STDIN; close STDOUT; close STDERR; exec $child;# or write your code here... die Mustn't happen: exec failed: $!\n; } # No need to reap since we detached... exit; -- daemonify -- and -- daemonified -- #!/usr/bin/perl use strict; use warnings; use Sys::Syslog; while (1) { syslog 'INFO', $0 ($$): %s, scalar localtime; sleep 1; } -- daemonified -- Test it like this: -- snip -- nijushiho:/tmp/try$ ls daemonified* daemonify* nijushiho:/tmp/try$ nijushiho:/tmp/try$ ssh localhost cd /tmp/try ./daemonify $PWD/daemonified nijushiho:/tmp/try$ tail -3 /var/log/messages May 17 00:18:01 nijushiho /tmp/try/daemonified (14462): Fri May 17 00:18:01 2002 May 17 00:18:02 nijushiho /tmp/try/daemonified (14462): Fri May 17 00:18:02 2002 May 17 00:18:03 nijushiho /tmp/try/daemonified (14462): Fri May 17 00:18:03 2002 nijushiho:/tmp/try$ ps -aef | egrep 'PID|daemonified' UIDPID PPID C STIME TTY TIME CMD mlamertz 14462 1 1 00:19 ?00:00:00 /usr/bin/perl /tmp/try/daemonified mlamertz 14483 13904 0 00:19 pts/200:00:00 grep daemonified nijushiho:/tmp/try$ kill 14462 nijushiho:/tmp/try$ !ps ps -aef | egrep 'PID|daemonified' UIDPID PPID C STIME TTY TIME CMD mlamertz 14510 13904 0 00:20 pts/200:00:00 egrep PID|daemonified nijushiho:/tmp/try$ -- snip -- As you see, the process was running and logging to syslog although the ssh immediately returned. The 'ps' told us that our PPID was 1 which is 'init'. That should be it, but I may have forgotten something since it's been a while that I needed that stuff frequently. To learn more about this kind of stuff, go and buy the late Richard Stevens Advanced Programming in the Unix(R) Environment. -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How do I???
On Wed, May 15, 2002 at 10:15:17AM -, Felix Geerinckx wrote: $y = $a[0] + $a[1]*$x + ... + $a[$n-1]*$x**($n-1) + $a[n]*$x**$n; This free Perl syntax should get you started. (Note to regulars: the '...' is *not* the three-dot version of the range operator :-) Yepp, it's the long awaited yadda-yadda-yadda operator that'll go into perl6. -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [Fwd: Perl documentation]
Sorry, late reply, but: On Tue, May 14, 2002 at 01:18:03PM -0400, Eley Greg wrote: Thank you for the input, but herein lies the problem... I do know off hand the Module::Name, I need to find the best ones depending on the task at hand. I need a way to rapidly scan these namespaces so that I can make the best informed decision. In case you're *not* using Debian Linux like I do (Gr) you can use the following command to check the list of installed modules and perldoc from there... perl -MExtUtils::Installed -le '$,=\n; print ExtUtils::Installed-new()-modules()' Otherwise, surf the hierarchy at http://search.cpan.org It's organized in a Yahoo-Portal way and gives a nice overview about what's there. BTW: The Best Ones (tm) is not really a specific request. If you're in need of a decision for a specific topic, come back and ask which ones are prefered. -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: PerlTK and subroutines
On Tue, May 07, 2002 at 10:14:00AM -0400, Zielfelder, Robert wrote: My problem is that when the master button is pressed, the first sub-script starts as it should and does the first few things it is supposed to. However, it too has a perlTK gui that asks the used for information. Instead of displaying this gui, the next script that the parent script sourced begins to run. do /genesis/sys/scripts/A/output/rout_out; Well, I'm on thin ice here since it's been some 2 years since I last touched Tk. I think it has to do with you already being inside the MainLoop of your main window. You need to make sure that the window/dialog rout_out opens is a toplevel element - or something along that line. As I said, it's been a while, but perhaps this helps as a pointer for more investigations on your side. -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Sorting problem
On Mon, May 06, 2002 at 03:17:39PM +0100, Richard Adams wrote: Hello, I've got an array of arrays, and want to sort by the 3rd element of the subarray. I then want to print out the sorted array, showing the index and values. E.g., Hmm, works for me with the exception of... I've tried @sorted = {$a -[2] = $b -[2]} @AoA but this gives a cannot there's a 'sort' missing before the block: -- mostly your code -- #!/usr/bin/perl use strict; use warnings; my @AoA = ( [23.56, 65.2, 12.4], [13, 56, 87], [45,876, 23], ); my @sorted = sort {$a-[2] = $b-[2]} @AoA; print $_-[2]\n foreach reverse @sorted; -- mostly your code -- gives me: -- snip -- nijushiho:/tmp$ perl x.pl 87 23 12.4 nijushiho:/tmp$ -- snip -- -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: foreach, my, and arrays
On Mon, May 06, 2002 at 12:04:14PM -0400, Jason Frisvold wrote: Here's another simple question I have an array of arrays and I want to use a foreach to do something with each entry... currently I do this : foreach my $item (@myarray) { my ($item1, $item2) = @$item; do stuff here } Is there a way to combine the first 2 lines? Is it any faster and less memory intensive? (granted it's not much now, but hey, I like optimizing things to death...) Something along the lines of : foreach my ($item1, $item2) (@myarray) { do stuff } Now, You are a very nasty person :-) Nope, at least by my knowledge that's not possible, but advocating to find the balance between readability and shortness you're left with a. accessing $item-[0], $item-[1] for very short loops without repetitive use if $item-[nn] b. using what you already do my ($item1, $item2) = @$item but - ignoring the fact that you probably just normalized your problem - you should use more specific names like my ($name, $id) = @user_info; for longer functions Since you're thinking about that way of shortening your code, I guess you're a more or less experienced programmer that is used to - and not afraid of - using the language's idioms. So consider above reply as a guide for the *real* beginners and not necessary for you. :-) -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Sorting problem-part2
On Mon, May 06, 2002 at 12:22:15PM -0400, David Gray wrote: Now I've got an array of hashes, where each hash can have different keys e.g., @aoh = ( {H3 =234, H1 =127, DNA =1, p135 =167}, {H4=24, H3=1550, DNA =25, p39 =67}, {H3 =34, H2A =125, DNA =5, p32 =7}, {H3 =24, H4 =156, DNA =123, p12 =13} ) And I'd like to order the array elements by virtue of the biggest value in the hash. perldoc -q sort a hash Nope, he's looking for a *nested* sort, since he has to find the largest value 'values %$a' and 'values %$b'. And as a nice addon, he mentions that the keys of the hashes can vary. -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Sorting problem-part2
Took me some time, but... On Mon, May 06, 2002 at 04:41:03PM +0100, Richard Adams wrote: Now I've got an array of hashes, where each hash can have different keys e.g., @aoh = ( {H3 =234, H1 =127, DNA =1, p135 =167}, {H4=24, H3=1550, DNA =25, p39 =67}, {H3 =34, H2A =125, DNA =5, p32 =7}, {H3 =24, H4 =156, DNA =123, p12 =13} ) And I'd like to order the array elements by virtue of the biggest value in the hash. 1. H3 1550 2. H3 234 3. H4 156 4. H2A 125 I'll call it the Partial Schwartzian Transformation on Acid ;-) Ok, ok, two messages ago I called Jason Friswold evil, but I just couldn't resist. :- So, this one's not for the faint of heart (tm), and for educational purposes only: -- snip -- #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @aoh = ( {H3 =234, H1 =127, DNA =1, p135 =167}, {H4=24, H3=1550, DNA =25, p39 =67}, {H3 =34, H2A =125, DNA =5, p32 =7}, {H3 =24, H4 =156, DNA =123, p12 =13} ); my @xsorted = sort { $b-[0]{$b-[1]} = $a-[0]{$a-[1]}; } map { [ $_, (sort { $_-{$b} = $_-{$a} } keys %$_)[0] ] } @aoh; print Dumper(\@xsorted); print $_-[1]: $_-[0]{$_-[1]}\n foreach @xsorted; -- snip -- Let's dissect that a littlebit: First of all, the Schwartzian Transformation is usually used as an optimization for sorting. You use it if the 'per-compare' computation is rather difficult. For an array @l it goes like this: A. create a temp list from @l with a. the actual data from @l b. the precomputed data from @l that's used for comparing 2 elements during sorting. B. sort that temp list using the precomputed field. C. create the sorted list by extracting the 'pure' data from @l from the now sorted temp list D. do it all in a fat combination of map sort map :- We need to skip step C, since we'd lose the information about the highest hash value if we just put all the data into the resulting array again. If you reverse-read above '@xsorted = ...' code you find A. create a temp list from @l..: map { [ # ...with the actual data from @l... $_, # ...and the precomputed... (sort { $_-{$b} = $_-{$a} } keys %$_)[0] ] } @aoh For each element in @aoh we're sorting the keys of that hash by comparing the hash's value at that key. Then we use only the first element of that resulting sorted list of hash keys, since that has the highest value. So, now we have a list ( [ original_item, highest_hash_key_for_that_item ], ... ) B. sort that temp list using the precomputed fields... sort { $b-[0]{$b-[1]} = $a-[0]{$a-[1]} } We can split that up and be a bit more verbose: sort { my ($a_orig_item, $a_key) = @$a; my ($b_orig_item, $b_key) = @$b; $b_orig_item-{$b_key} = $a_orig_item-{$a_key} } which is a bit longer but doesn't scare the kids that much. Now on for the questions and flames... -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Unique list
On Mon, May 06, 2002 at 11:40:10AM -0700, drieux wrote: I'm very confused by the idea of my %args = ( PARTITION = '', PARTITIONFILE = '', OUTPUTFILENAME = '', @_, ); why not the simpler my ( $outputFile, $partitionFile, $partition) = @_; I guess he over-idiomized: I use the above frequently to preinitialize objects: sub new { my $context = shift my $class = ref($context) || $context; bless { a_number = 42, some_text = 'I have a value', @_ }, $class } That way, one can do the following: my $obj = TheClass-new(some_other_value = 57, a_number = 12); Now, some OO_Bigott would most probably jump right into my face for allowing some user from the mob to add 'some_other_value' to our holy moly class object, but in most cases I don't consider that a problem - the OO_Bigott jumping, that is ;-) -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Finding last record without slurping.
On Wed, May 01, 2002 at 01:52:35PM -0500, Frank Newland wrote: Ladies and Gentlemen: I'm using a while loop to search for specific record. A record is a single line in your file? If I find the record, then I need to report that record and the trailer record. Sorry, insufficient english on my side. Is the 'trailer' record the one you read before the current record? I'm not slurping the file into memory so I can't use $openfile[$#openfile] approach. Not necessary. Use a 2 element circlular list fifo to store the elements while reading. -- untested -- my $current = 0; my @stash = (undef, undef); while (F) { chomp; # not necessary... $stash[$current] = $_; # store for later use if (/YOUR PATTERN/) { print Match is '$_'\n; print Prev is ' . $stash[1 - $current] . '\n; } $current = 1 - $current;# toggle for next run } -- untested -- The '$current = 1 - $current' is commonly used in games for selecting sprite coordinates on double-buffered screens :-) -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Getting contens of file into a hash
' = 'yes', 'cache size' = '256 KB', 'fdiv_bug' = 'no', 'fpu_exception' = 'yes', 'cpu family' = '6' }; nijushiho:~$ -- snip -- Just some food for thought (tm)... PS: use '//x'! -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Getting contens of file into a hash
Whooops: On Mon, Apr 29, 2002 at 02:12:27PM +0200, I wrote: On Mon, Apr 29, 2002 at 11:59:42AM +0100, Anders Holm wrote: Hi folks! You're right on track (with some exceptions, but read about that further down the page). my ($key, $value) = split /:/; make that 'split /\s*:\s*/;' will give you e.g. $key cpu family $value 6 -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Getting contens of file into a hash
On Mon, Apr 29, 2002 at 02:16:13PM +0100, Anders Holm wrote: Thank you Micheal!! Having loads of fun with this at the moment!! ;) There seems to be another caveat as well, SMP systems. ;) Fortunate enough to be able to test it on such a box at work. So, input would be something of the following: [anders@redhat anders]$ cat /proc/cpuinfo processor : 0 vendor_id : GenuineIntel ... processor : 1 vendor_id : GenuineIntel cpu family : 6 model : 8 Then how about the following: my $cpu_id = 'unknown'; while () { next unless /insert match here/; my ($key, $value) = ($1, $2); # Store them to avoid them # beiing overridden due to # a side effect $cpu_id = $val if $key eq 'processor'; $hash{$cpu_id}{$1} = $2; ... } Another option could be to start with '$cpu_id = 0' and increase it as soon as $hash{$cpu_id}{$key} is already defined. $cpu_id++ if exists $hash{$cpu_id}{$key}; $hash{$cpu_id}{$key} = $value; There are now 2 empty lines that'd need to be stripped out, or I'll be getting : Use of uninitialized value in hash element at ./cpuinfo.pl line 27, CPUINFO line 19. That's the reason I usually write the next unless /match/; my @fields = ($1, $2, ...); Perl's behaviour to leave $nn alone in case the match fails will finally be fixed with 5.8 as far as I remember, but I could mix that up with Perl 6. -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: setruid?
Aye, that's been a nice demonstration of how to approach a dubious problem with too few information. Really! So don't consider this message as an answer to your post, but more like an addendum: On Thu, Apr 25, 2002 at 08:03:30PM +0100, Jonathan E. Paton wrote: Hang on... did I miss something... what exactly is a S-plus script? Maybe you should allow for the I've never heard program X problem by providing a link. I'm sorry, but I have no idea what it is, but on this occasion google helped: http://www.google.com/search?hl=enq=%2B%22S-plus%22 Now, it looks too complicated to approach it from a Lets see how it works prespective - so we move onto the error message. One addition. Try http://www.google.com/search?q=s-plus+perl instead. The first link S-Poetry will lead you to the information that S and S-Plus have an interface to perl. The 4th link will tell you -- snip -- S-plus is an extremely powerful object-oriented statistical programming language/environment -- snip -- Basically we haven't found out anything about how to solve our problem, but now we can be pretty sure that we're really dealing with perl here. setruid( ) not implemented at sdos.pl lone 10. I'm not sure what this means The script is broken hearted as some vital OS feature (?) is missing. Now lets try and find the cause of the pain. If I'm not mistaken, you should ask them to fix the typo too. Not necessary... and I couldn't find it in any of the Perl books that I have. perldoc perl That one's good... perldoc -f open But I still don't know why you looked there... I'd tried perldoc POSIX instead (and nope, you won't find anything there :-) gets you there faster! Okay, not book replacements but they really help. Neither my unix manpages nor perl's documentation, so it's back to google for a last ditch effort: http://www.google.com/search?hl=enq=%2Bsetruid and you'll notice that it is a Unix program/function... I'm running ActivePerl 5.6 on a Windows 98 system. Ok, you're there. Just to give you the final answer on where that call most probably comes from: Perl doesn't have a setruid function, but if you look at the name and perhaps the system's man page you'll learn that the call SETs the Real UserID which perl does by assigning a value to $ or when 'USEing English' $REAL_USER_ID That's one of the things one just has to know to know them :-) but perldoc perltoc could have hinted to the solution. perltoc is always my fallback if I don't find any information where I expected it, but you'll have to do some more generic searches in the page like '/real.*user' or '/user.*id' since you wouldn't know if it's 'user-id', 'userid' or 'user-id'... BTW: Searching for 'setruid' in 'perltoc' will lead to d_setruid in 'perldoc Config' which at least would hint to the fact that this call might or might not be compiled in. -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Debugging and 'uninitialized value in concatenation' question
On Thu, Apr 25, 2002 at 02:49:16PM -0400, Jason Frisvold wrote: Judging from the subject lines coming across the list today, I think I'm gonna toss this question out there and then duck and cover... :-) Hmm, I can't see any obvious reason to flame that post. It's a technique and style question that looks perfectly valid to me. I have 2 actual questions. I'll try to be as specific as possible.. :-) Question #1. I always stumble over that myself, and have no valid solution up to now. I was always thinking about having a special perl binary compiled wqith -DDEBUGGING for that, but never too the time to really try that. Look at 'perldoc perlrun' and search for -Dletters or -Dnumber to see what I'm talking about. Question #2. Relating to the debugging, there are several instances where I have variables that are only defined based on the definition of other variables that exist elsewhere. Kind of like : sub dummy { if ($a == 10) { my $b = 0; } } $b is a local variable, so whenever the subroutine is exited, $b vanishes into the ether. The problem is that I have $b in several debug statements because I want to see it when it's used, I don't understand your problem here. If you want to see the debugging output where it's used, then your debug statement should be near where $b is used - speak inside the scope of $b - so $b would be declared, and thus no warning. Or do you have one FAT debugging statement at the end of your function? But that wouldn't give you the information you needed anyway. -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Backing up two days from localtime
On Fri, Apr 26, 2002 at 09:32:04AM +0100, Jonathan E. Paton wrote: I need to back up two days from localtime and I can't figure out how to do it. Currently I'm doing this just so I can work out the rest of the program: [Ignore me if you aren't on a Unix like platform] Hi, You should seriously consider installing the 'at' job manager for run-once tasks, or 'cron' to schedule tasks regularly. Try to avoid spreading time-scheduling around, especially into memory hungry Perl processes that just sit around doing nothing. man at man cron I think you're missing the point here. It's quite a common task to work on logfiles that are a day or two old and have a timestamp in their filename. Sometimes these files are just required to be kept where they are for some days, and then one has exactly the problem the original post described. He'll still use cron to schedule his script, but the script will need to 'calculate' the filename of the n-days old logfile. -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Backing up two days from localtime
On Fri, Apr 26, 2002 at 08:32:21AM -0400, Tara Calishain wrote: I'm anticipating coming across this same problem with user input dates, and I don't expect the seconds trick will work for that one. For example, say a user specified $day-$month-$year and ten days, and I wanted to generate a date string for every day going back ten days. Although Randal L. Schwartz posted a hillarious comment on Date::Manip (http://archive.develooper.com/beginners%40perl.org/msg22416.html) you should take a look at that module. I have used it quite a lot to let people pass more or less generic time/date specifications to my scripts. It does for example things like that: -- snip -- nijushiho:~# perl -MDate::Manip -le 'print UnixDate(44 days ago, %Y%m%d)' 20020313 nijushiho:~# -- snip -- It comes at a price though, so I wouldn't use it to process some 20 million lines of webserver logs in a nightly run :-) -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: help about perl -pi -e
On Thu, Apr 25, 2002 at 10:25:18AM +0200, Alain wrote: Hello all, I've the following problem: I need to erase about 150 lines (always the same lines) at the end of a serie of files. What I have done in the shell is: #perl -pi -e s/sub html_base[\s\S]*// *cgi 2 options: A. perl -p0i -e 's/sub html_base.*//s' *.cgi reads the whole file in one (-0 means $/ = \000), then the '/s' at the end of the regexp treats the whole $_ that now contains the complete file as a *single line*. Problems: -0 only works with text files, since binaries might contain 0-bytes. use -00777 to be absolutely safe, since there's no character 256. Due to the '/s' you can't match on beginning or end of line anymore. B. perl -li -ne '$x = 1 if /^sub_html_base/; print unless $x' *.cgi The '-n' does mostly the same as -p, except it doesn't print. That's up to you, so now you have the option not to print. I usually use the '-l' since I don't need to care for the '\n' when replacing text, but that's not necessary here. Problems: Longer to type and most probably slower. For both versions read 'perldoc perlrun' and look up the details of '-0' and '-n', and eventually '-l'. -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: FIFO handeling
On Thu, Apr 25, 2002 at 10:04:38AM +0100, Rus Foster wrote: Hi All, I've got a small problem with a FIFO. Using the following code snippet #!/bin/perl simple but valid code snipped ... Now if I do something like cat /tmp/tp9100 and pass characters this works. However when I send ^D the script exists. Is there anyway to avoid this and keep the file handel open Not when typing into the fifo :-) Create a binary file that contains all possible byte values with the following command: perl -e 'print chr($_) foreach (0 .. 255)' bin.dat Then start your script with myscript fifoed_bin.dat and cat bin.dat /tmp/my_fifo Then 'diff bin.dat fifoed_bin.dat'. There should be no difference. The Ctrl-D character is the End-Of-File command for the input handler of your *shell*, so hitting Ctrl-D tells your shell to close the output filehandle into the fifo and thus your script stops since it gets an appropriate response from it's input filehandle. Try it with the binary data files, it really should work as expected. If you need to keep your program running, wrap all of it in a while (1) { ... } # --- I can't wait for that yadda-yadda-yadda operator in perl 6 :-) block, so you reopen the fifo whenever it gets closed. -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: problems with split
On Thu, Apr 25, 2002 at 02:34:55PM +0200, [EMAIL PROTECTED] wrote: hi, i have a data file test1.txt as follows: 551356835||1|7684940|47534900|0 .. my code should open test1.txt, read in the data, convert it an print it into test2.txt : ($nodeid, $nameid, $type, $longitude, $latitude, $altitude) = split (|, $line); THAT ^^^ is your problem. -- perldoc -f split -- split /PATTERN/,EXPR,LIMIT split /PATTERN/,EXPR split /PATTERN/ ... -- perldoc -f split -- See the '/' around PATTERN? That means that we're dealing with a regular expression, and '|' is a special char for regexps. Your split says Split at NOTHING OR NOTHING, since that '|' basically means OR. Since NOTHING can't be matched you split after each character. If you write it like split /\|/, $line it'll work. More information can be found in perldoc perlrequick or perldoc perlretut The section you're looking for starts with 'Matching this or that' in both documents. Take a look at 'perldoc -f quotemeta' if you're running into similar problems when using more complex matching and generated search expressions. -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: help about perl -pi -e
On Thu, Apr 25, 2002 at 05:02:10AM -0700, John W. Krahn wrote: Michael Lamertz wrote: A. perl -p0i -e 's/sub html_base.*//s' *.cgi reads the whole file in one (-0 means $/ = \000), \000 is a reference to a numeric literal, \000 is the null character which doesn't reads the whole file in one Yepp, that wasn't intended to be a proper perl expression but more kind of symbolic. I used the C notation where \nnn puts raw characters into strings %-) Sorry, that was unclear. -0 only works with text files, since binaries might contain 0-bytes. use -00777 to be absolutely safe, since there's no character 256. Octal 0777 is not equal to 256. $ perl -le'print 0777' 511 Again you're right. That'll teach me to not only type but also think when I post next time @-) Due to the '/s' you can't match on beginning or end of line anymore. If you use the /m modifier then ^ will match the beginning of a line and $ will match the end of a line. Yepp, but this isn't what he needed. He wanted to match up to EOF. I only mentioned it so he was aware of the, hmmm, side effect. -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: multiple greps in if()
On Thu, Apr 25, 2002 at 01:54:53PM +0100, [EMAIL PROTECTED] wrote: Hi anyone have any ideas on how example 2 or 3 below should correctly be written ??? Actually your code can be interpreted in different ways. I guess you'll need the following: -- perldoc -f grep -- grep BLOCK LIST grep EXPR,LIST This is similar in spirit to, but not the same as, grep(1) and its relatives. In particular, it is not limited to using regular expressions. Evaluates the BLOCK or EXPR for each element of LIST (locally setting $_ to each element) and returns the list value consisting of those ele- ments for which the expression evaluated to true. In scalar context, returns the number of times the expression was true. -- perldoc -f grep -- if(grep /Handicap|Help/, $source) { this seems to work Then we'll leave it alone :-) I will however nag about using grep to match on a single string. grep should be used to filter lists of strings. For the single string, just use a normal regexp. if(grep /(Handicap Help)/, $source) { this does not work Hmm, I suppose you want only lines that contain both words regardless of their order? if (grep { /Handicap/ /Help/ } @sources) { ... } Should do what you want. ideally I would like multiple grep pairs ie.. if(grep /(Handicap Help) || (Friend Foe)/, $source) { this does not work Same as above. The BLOCK can be as complex as you wish. if (grep { (/Handicap/ /Help/) || (/Friend/ /Foe/) } @sources) { ... } See 'perldoc -f sort' for similar uses of the BLOCK style of filter functions. -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to find module dependencies
On Thu, Apr 25, 2002 at 09:36:16AM -0500, Elaine -HFB- Ashton wrote: Michael Lamertz [[EMAIL PROTECTED]] quoth: * *PS: I've made the mistake to install quite a handful of modules via *Debian packages instead of CPAN and they are *NOT* installed in *'site_perl' but somewhere in '/usr/local/share' and are also *NOT* *registered in perllocal. That's *NOT* funny, Debians! Do they turn up with CPAN.pm or ExtUtils::Installed? Nope: -- snip -- nijushiho:~$ perl -MExtUtils::Installed -le 'print foreach ExtUtils::Installed-new()-modules()' Apache::XML2Template Data::FormValidator Data::FormValidator::Tutorial Perl Regexp::Common Term::ANSIColor nijushiho:~$ -- snip -- but -- snip -- nijushiho:~$ perldoc Template Template(3)User Contributed Perl DocumentationTemplate(3) NAME Template - Front-end module to the Template Toolkit SYNOPSIS use Template; ... -- snip -- It's definitely *not* in the list ExtUtils knows about. It's no problem since I know what I installed and at least Debian offers a consistent naming scheme. dpkg -l 'lib*-perl' does the job, but I still consider that behaviour unfriendly and non-standard. Just why couldn't they use site-perl?!? Sigh, I'm ranting again... -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Improving the Quality of Our Beginners was Re: Write permissions and other rights
On Thu, Apr 25, 2002 at 10:45:31AM -0500, Ron Goral wrote: Sorry Michael. I was not clear there. I was not saying that *you* flamed *me*. That did not happen. I was speaking in a general sense to the flamers on this board. Please accept my apology for creating this misconception. No, no, no! No need to apologize. I only replied since I was afraid I didn't make myself clear and sounded as if I attacked you %-) As for Unix file permissions, have a look at the cover of Learning Perl. At the top of mine it says UNIX Programming. Aha, sorry, never read that one, but I agree that with that sentence in the title these topics should be covered, either as a standalone chapter or near the corresponding functions. I do agree that the mysteries of the *NIX OS should not be covered in a list like this, but some issues Oink, objection your honor. One's mystery is the other's daily work. I've written quite my share of daemons and server programs, but that might be black magick for others, so even if it's way over the head of a complete beginner, for the average Unix-Joe this is still basic knowledge and is IMO appropriate to be explained here too. A perl beginner will post this kind of questions here, since he cannot decide if this is an advanced topic or a standard problem, so things like that should be posted here as long as they relate to the person's perl code. However, the point of this response is, again, to apologize to you, Michael, for inadvertently implying that you had flamed me and I had words for you. This was not the case at all. Again, no reason for this! :-) I think we're about as much in sync concerning the topic of this thread as we can be. Take care - Mike -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to find module dependencies
On Wed, Apr 24, 2002 at 10:09:49AM +0530, sharan wrote: Hello, How to find the module dependencies? I have used many modules in my tool development, and i given all the modules used with my tool package. But when the tool is installed on Windows at the customer places they are getting problems as some of the module use some depenedent modules. Is there any way to find out what are all the modules that are dependent. If you know that you're 'use'ing all your modules at the beginning and don't load any modules during the execution using 'require' and 'import', then it should be sufficient to dump %INC. -- snip -- #!/usr/bin/perl use strict; use warnings; use Data::Dumper; print Dumper(\%INC); -- snip -- will give you -- snip -- nijushiho:~$ perl check.pl $VAR1 = { 'Exporter.pm' = '/usr/share/perl/5.6.1/Exporter.pm', 'Carp.pm' = '/usr/share/perl/5.6.1/Carp.pm', 'XSLoader.pm' = '/usr/lib/perl/5.6.1/XSLoader.pm', 'strict.pm' = '/usr/share/perl/5.6.1/strict.pm', 'warnings/register.pm' = '/usr/share/perl/5.6.1/warnings/register.pm', 'warnings.pm' = '/usr/share/perl/5.6.1/warnings.pm', 'overload.pm' = '/usr/share/perl/5.6.1/overload.pm', 'Data/Dumper.pm' = '/usr/lib/perl/5.6.1/Data/Dumper.pm' }; nijushiho:~$ -- snip -- Of course in this case they are all core modules, but you could filter that list by looking for 'site_perl' in the path. PS: I've made the mistake to install quite a handful of modules via Debian packages instead of CPAN and they are *NOT* installed in 'site_perl' but somewhere in '/usr/local/share' and are also *NOT* registered in perllocal. That's *NOT* funny, Debians! I've not verified this, but I guess that could be a problem with other Linux distros too. -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Improving the Quality of Our Beginners was Re: Write permissions and other rights
Aye, it seems I missed the part of this thread where you got flamed, and couldn't find anything in the archive either. However: On Wed, Apr 24, 2002 at 09:17:46AM -0500, Ron Goral wrote: snippage ... Yes, I can read the perldocs and the manpages, but, incredibly, these are written with the notion that I have a half a clue about how to interpret what chmod means. And yes, yes, yes, reading more and more documents means that eventually, you will come to understand a word or two here or there. However, the plain and simple fact is that until there is a document written that assumes the reader knows NOTHING AT ALL about the *NIX environment ... Let me start with: Flaming a post that shows missing understanding of Unix file permissions is inappropriate and doesn't do this list any good. And: Yepp, you're right. Perl itself was written to solve specific problems, and these *were* problems exclusively in the host and Unix environment. Times have changed a bit and to find the balance between explaining to the non-unix people the business of our (Unix folks) daily life and make the documentation short and to the point on one hand, on the other explanatory enough so you guys know what this stuff is all about is not easy. Unix file permissions are - except for the concept of the directory hierarchy - about the first things you learn when starting with unix, so for some people it's hard to understand if anybody has a problem with this. *Many*, many of the functions you find when using 'perldoc' come directly from the underlying C-library that's more or less common to all Unix systems, and that's documented in the man pages. So the question here is if it's perls job to explain these concepts. I don't think so. Perl should come with perl documentation and leave the system specific part to specialized documentation. ActiveState's perldocs that explain perl's connection to the Win32 API don't explain the underlying concepts either. These things should be explained in the system documentation - and the average Linux distro e.g. comes with a truckload full of documentation in that area. That's btw. the Unix way to do things: One program for one job, but that one should be highly efficient. However, an appropriate answer on *this* *list* should have been a pointer to at least one or two introductory Unix books and perhaps some webpages (and although I dare to post this long rand I'm actually not able to provide you with any one, since I never read one %-) It's always hard to bootstrap oneself on a new platform, to get a grip on the system and a feeling for where to look for more information... Keep going, and keep on posting stuff here, you'll see, it'll get better, and you most probably wont get flamed by a kid with too much thestosterone everyday... -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Passing a variable to a DOS batch file
On Sat, Apr 20, 2002 at 08:07:09PM -0400, Paul Lombardo wrote: I need to do the following: if the perl script fails I need to pass a variable to the batch file so it can exit with a proper failure message when the perl script succeeds I need to pass a variable to the batch file so it can exit with a proper success message. I have tried setting ENV{ERRORLEVEL} on failure I have tried exit() and nothing seems to work. Nope, that won't work, since the Environment is only passed over to child processes, not parents. Since the NT shell lacks critical features like backquotes, the only thing I see that's left is a kind of status file that you write on error. You can check the existance and content of that file if your script returns an error. -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: browsing html pages
On Fri, Apr 19, 2002 at 10:22:44AM +0200, Martin wrote: Hi Yo! As a Perl rookie I've got a serious problem trying to find out how to write a code which should do the following stuff: connect to specified URL using HTTP, send GET / PUT messages and process the output (web page) from the server. I went throug my Perl guidebook but found nothing according to this subject. Can anybody give me a hint (and/or suggest a good reference guide for Perl on the internet) ? You'll need LWP::Useragent, or for a minimal approach LWP::Simple (which comes with the same packate) for requesting your page from the server. Then you'll need HTML::Parser for reading and parsing your webpage. Both modules and their dependencies are available from the CPAN and come with a lot of documentation and sample code. Once you've installed them, I suggest starting with perldoc lwpcook which is the libwww-perl cookbook. From there on, you can decide if it's sufficient to use LWP::Simple or if you need the full fledged LWP::UserAgent. Once you have your page, depending on what you need to do with it, You can either use HTML::Parser to do everything on your own, or use one of the available sub modules like HTML::LinkExtor or HTML::TreeBuilder. perldoc HTML::Parser perldoc HTML::LinkExtor perldoc HTML::TreeBuilder There are more modules for this kind of stuff. Click yourself through the module hierarchy at http://search.cpan.org, perhaps you'll find something that exactly fits your needs befor rolling your own... Ask if you run into trouble... -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Remote Shell
On Sat, Apr 20, 2002 at 04:58:22PM +0530, Mayank Ahuja wrote: In one of my applications, I get machine name as input from the user. What my application needs to do is to remote login on this machine and start a daemon. The scripts for running the daemon are ready, but how can i login to a remote machine using PERL. Summary: Is there a PERL equivalent of rsh or remsh or rlogin on UNIX? Yepp: Net::SSH Net::SSH::Perl Net::Telnet All available on the CPAN. To do it yourself, you could use the 'Expect' module to control whatever remote access software you use (telnet, rsh, ssh). -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Remote Shell
On Sat, Apr 20, 2002 at 08:13:19AM -0700, drieux wrote: On Saturday, April 20, 2002, at 04:28 , Mayank Ahuja wrote: [..] Summary: Is there a PERL equivalent of rsh or remsh or rlogin on UNIX? my ($user , $hostname , $command_to_run ) = ThatFunkThatSetsTheses(); my $cmd = rsh -n -l $user $hostname $command_to_run; Which is sufficient for simple single command problems, but if you're in need of more complex stuff, you need an interactive shell. At that point you're reading 'perldoc perlipc' and start fiddling with IPC::Open3 and friends and run into all kinds of line buffering problems ('perldoc IPC::Open3' discusses this too). The before mentioned 'Expect' module aims at working around these, but it's been about 2 years back since I last used them, so my information might be outdated. -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: running external perl scripts
On Fri, Apr 19, 2002 at 08:50:04AM +, A Taylor wrote: So if the result of the password check is False then i want to run a perl script called 'password.pl'. If the password is true I want to run a script called 'page.pl' (for example). But how do i tell perl to run 'password.pl' or 'page.pl' ? The easiest way to call an external command is the 'system' function (perldoc -f system). There are other methods (perldoc perlipc), but that one should be sufficient for your needs. I could write all these pages into one script and do a check that says if password is True do this else do that .. but there must be a way of calling perl scripts external to the one that is running ??? Hmm, this sounds as if you have a. legacy code that has to be used or b. a design problem With very little effort, you can store the functionality of password.pl and page.pl in a Module and *use* that module. You have the source in an external file, so your main program doesn't get cluttered, but you now have internal access to your functions instead of relying to an external program where exchange of error messages and things like that are rather limited. If your sub programs are nicely written and don't make use of global variables, it should more or less be sufficient to do the following -- MyPass.pm -- package MyPass; # -- Should be same as filename without .pm # INCLUDE your password.pl here 1; # -- That's needed -- Password.pm -- *IF* your password.pl is written clean enough - no globals - the only change you should need to make is to wrap all the main program code in a function that you can call from your overlying program. You call that function by use MyPass; ... MyPass::MyMainFunction(...) as you can call all the other functions and (now module)global variables in your module file by prefixing them with MyPass::. The same goes for your page.pl. The big advantage of this is code reuse, since you can now use MyPass in other applications that use the functionality. That's the caveman approach to perl modules, but it should get you started. For further information read perldoc perlmod perldoc perlboot perldoc perltoot -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: proxy server that listens on 2 ports
On Fri, Apr 19, 2002 at 07:40:35PM +1000, Conan Chai wrote: hi all, i'm writing a simple proxy server that listens on 2 ports, 1 for browser and another for admin client. the admin client is for administrative tasks such as adding new users and reseting downloaded bytes. i'm currently using the IO::Select module but this mode is blocking I/O, so i intend to change to use fork(), here comes the question, i'm not sure how to listen to 2 ports using fork(). pls quote examples if possible. thanks Huh? But IO::Select is exactly what you want. And of course it's blocking, since you don't have anything to do while waiting for a connection anyways. What you do is this: Add both ports to your select queue, then wait for a connection. As soon as a connection arrives, accept it, fork yourself and loop back to the select while the forked childprocess does the hard work. -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to test if a module is installed ?
On Fri, Apr 19, 2002 at 06:02:32PM +0200, Dennis Senftleben wrote: Hi ! My perlscript uses the Image::Size module. It works fine if it is installed, but if not I get a compilation error msg. How can I test with perl if it is installed on my system ? Is there something like if ( -e Image::Size ) { use Image::Size ;} else { print( module not installed);} Although two other people already have answered, I think I can add a bit more information: First of all: In your case, it seems as if the application should behave as it already does: 'die' if not all requirements are fulfilled. If, however, you want to run anyways, but with limited features, first let's look into the documentation: perldoc -f use gives us: -- snip -- use Module VERSION LIST use Module VERSION use Module LIST use Module use VERSION Imports some semantics into the current package from the named module, generally by aliasing cer- tain subroutine or variable names into your pack- age. It is exactly equivalent to BEGIN { require Module; import Module LIST; } except that Module must be a bareword. -- snip -- So what you can do is this: -- snip -- #!/usr/bin/perl use warnings; use strict; BEGIN { eval { require Data::Dumper; import Data::Dumper; }; eval { require funky_named_mod; import funky_named_mod; }; } print Dumper({a = 1, b = 2, c = 3}) if $INC{'Data/Dumper.pm'}; print Unavailable_function() if $INC{'funky_named_mod.pm'}; -- snip -- Now you can decide what to do at runtime. Stuff the parts that are dependand on Module_X into a clause checking %INC for the corresponding key 'Module_X.pm'; Search for '%INC' in perldoc perlvar -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: swich user
On Tue, Apr 16, 2002 at 11:30:08AM +0200, walter valenti wrote: Hi, i've got a demon i perl that start from root. I would like that after the starting (when starts, does some operation like root), it swiches like other user with low privileges (es. like Apache, starts from root and swiches at www-data). I'm trying the POSIX module, using the function: POSIX::setuid, and POSIX::setgid but nothing. You don't need the POSIX module, perl can do this on its own. If you take a look at 'perldoc perlvar' and search for UID, you find the following: -- snip -- $REAL_USER_ID $UID $ The real uid of this process. (Mnemonic: it's the uid you came from, if you're running setuid.) -- snip -- What you really should change is the 'Effective User ID': -- snip -- $EFFECTIVE_USER_ID $EUID $ ... (Mnemonic: it's the uid you went to, if you're running setuid.) $ and $ can be swapped only on machines supporting setreuid(). -- snip -- Try the following code snippet: -- snip -- #!/usr/bin/perl use strict; use warnings; $|++; use constant USER = 'nobody'; use constant GROUP = 'nogroup'; my $uid = getpwnam(USER); my $gid = getgrnam(GROUP); print Started as $:$( / $:$)\n; $ = $uid; $) = $gid; print Changed to $:$( / $:$)\n; while (1) { print Still alive...\n; sleep 10; } -- snip -- Here's my session with the code: -- snip -- nijushiho:~# ./snippet [3] 5313 nijushiho:~# Started as 0:0 105 0 / 0:0 105 0 Changed to 0:0 105 0 / 65534:0 105 0 Still alive... Still alive... ps -aef | grep snippet nobody5313 5114 0 13:23 pts/100:00:00 /usr/bin/perl ./snippet root 5315 5114 0 13:24 pts/100:00:00 grep snippet nijushiho:~# kill %3 nijushiho:~# [3]+ Terminated ./snippet nijushiho:~# -- snip -- As you can see, 'snippet' ran as user 'nobody'. Remember that you need to have appropriate permissions to switch users (speak you need to be root). Read Stevens' Advanced Programming in the Unix Environment for *all* the information about this kind of topics. Ask if you need to know more... -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: get PID od existing process
On Tue, Apr 16, 2002 at 12:49:40PM +0100, Dermot Paikkos wrote: Hi Guru's SYS stuff: perl 5.05 on Tru64 Unix. I am writing a script that needs to find the process IDs of a couple of processes (so they can be killed nicely). Under the csh i would usually do ps -e| grep process. I am not sure if I can do something like this using system or if there is a module that would save a lot of work. I was thinking of doing something like: $output = `system(ps -e)` and doing some regexp on $output. Would that seem like the way to go? Yepp, backticking ps is much easier to do portable than using the proc filesystem structures... (Surfing over to search.cpan.org I found Proc::ProcessTable which looks as if it supports a vast variety of different platforms, so you might take look at this too.) But keep in mind that there are still alot of differences in the output of ps among platforms. BTW: it's $output = `ps -e` You don't need the 'system' inside the backquotes. Think about using qx{} instead of the backquote operator if you need to do more complex stuff in the shell. -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: automagic web query ?
On Mon, Apr 15, 2002 at 10:42:45AM +0200, Martin A. Hansen wrote: im trying to write a script that does a search on a remote website. the script needs to fill in a form field with a search word and save all the results. there is three different form fields on the webpage, but im only interested in the first one. the results comes in 10 per page only, and i would like the script to follow the links so i get all results. can this be done with perl? (i think so). Yepp, as can with about any other language... can anyone help me out here? Sure, but since this is the beginners list and not the 'free code' list, I'll only give you some pointers for a start. You'll a more or less uptodate perl. And at least the two Modules LWP::UserAgent # This one dl's the pages... HTML::Parser# ...and this one parses them and all their dependencies. Actually, if you know what the form look like - and you most likely will know, since you have to fill it - there's no need to read and parse the form page, except if there are some hidden values that are generated dynamically. Basically, you create an Request Object (read 'perldoc lwpcook' to learn how) where you stuff all your form values in, then you let LWP download the answer page. Depending on how much details you need to know about the structure of your document, you could then try to match the data you need with regular expressions (perldoc perlrequick, perldoc perlretut, perldoc perlre), provide your own parser which you can subclass from HTML::Parser (perldoc HTML::Parser) or use an already existing special parser that fits your needs - like e.g. HTML::LinkExtor which harvests all links from out of a HTML page. Once you have your list of links, the remaining part is mostly repetitive stuff: create a request object, download, optionally parse, and again... and again... Ok, if you're still with me that far down the mail, feel free to ask about details... -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: PROBLEM WITH THE USES OF USE STRICT
Aye, although I agree with Jonatha's rewrite of your loop, he actually didn't answer your question for *why* your code doesn't work: On Fri, Apr 05, 2002 at 04:16:42PM -0800, Jaimee Spencer wrote: #!/usr/bin/perl -w use strict; print (What is 7 times 7? \n); chop(my$input_answer = STDIN); my$answer = 49; until($input_answer == $answer) { print (No that is wrong! Try again. \n); chop(my$input_answer = STDIN); Here =^^ 's your problem. You *re*declaring $input_answer inside the until block. The 'until' sees the outer variable that you only entered once. The newer input variable is hidden inside the surrounding curly braces and never reaches the 'until' clause. Read 'perldoc perlsyn' and look for the section called Compound statements The concept of a 'scope' is explained here. Also read about 'lexically declared variables' - I dunno where exactly that stuff is documented. Leaving out the 'my' is what's solving your problem, because you don't declare a new '$input_answer' then, but continue to use the previously used one. -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: getopt::std
On Fri, Apr 05, 2002 at 04:05:13PM -0500, Michael Gargiullo wrote: I'm on a Redhat 7.0 box with the default install of Perl. I want to use the Getopt::std module, but it's not installed. I went to cpan.org and they have the docs, but it looks like that module is supposed to be installed with the perl executables, not as a seperate module. Any ideas? Yepp. The name you want is 'Getopt::Std'. The Module names are case sensitive. I would be very suprised if RedHat removed a library that comes with the core perl package. -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Split input on whitespaces - Another approach
This one should be a reply to the original poster, but I already deleted the head of this thread... I just love modifiers (perldoc perlsyn)! my %wc; while () { $wc{$_}++ foreach split; } by using perldoc -f split's If EXPR is omitted, splits the $_ string. If PATTERN is also omitted, splits on whitespace (after skipping any leading whitespace). Fun questions for the beginners to meditate over: What's the value of $_ after the split line in case you would like to use it, and why :-) -- If we fail, we will lose the war. Michael Lamertz| +49 221 445420 / +49 171 6900 310 Nordstr. 49| [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany| http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: date
On Fri, Feb 08, 2002 at 04:32:58PM +0531, Mayank wrote: Hi all Is there a module/or some function to do calculations on date e.g. if today is 1st March, and i want the date for previous day (i.e. 28th or 29th Feb) The Date::Manip, although not the fastest, is by far the most comfortable module I know for that job. Another popular module is Date::Calc. -- If we fail, we will lose the war. Michael Lamertz| [EMAIL PROTECTED] Nordstr. 49| http://www.lamertz.net - http://www.perl-ronin.de 50733 Cologne | Priv:+49 221 445420 Germany| Mobile: +49 171 6900 310 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: objects and hash
On Fri, Feb 08, 2002 at 12:54:58PM +0100, Roman Fordinal wrote: problem? Yes! :.. Roman Fordinal :.. project manager Well, as a Project Manager you should, perhaps, be a bit more specific about what you want :-) sub new { my $procc=shift; my $text=shift; my $self={}; return 0 unless $email; Is that ---^^ global? And what's it for? my @body=split('\n',$text); foreach (@body) { @ref=split(':',$_); $self-{header}-{$ref[0]}=$ref[1]; } You cannot be sure that you now have a valid header. What if there's a quoted mailheader *inside* the message content? You need to make sure you only weed out the header section of the mail and ignore the body, since you'd overwrite your valid headers. Check out this sample-mail: -- snip -- From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Some stuff... Dear List members, can anybody enlighten me on why my mails bounce? Here are my headers: ...cut here... From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: overridden ... -- snip -- And gone are your real header fields. And besides from that you'd have another headerfield called 'Here are my headers' with an empty value. Go to http://search.cpan.org and look for some mailparsing module there. There are things like Mail::Box that'll assist you in parsing emails... -- If we fail, we will lose the war. Michael Lamertz| [EMAIL PROTECTED] Nordstr. 49| http://www.lamertz.net - http://www.perl-ronin.de 50733 Cologne | Priv:+49 221 445420 Germany| Mobile: +49 171 6900 310 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: A more perlish way
On Wed, Feb 06, 2002 at 03:05:29PM +0100, Jorge Goncalvez wrote: I tried this: @Symlink=($program_path\\install.lnk, $program_path\\linux.ram.lnk, $program_path\\alize\\install.lnk, $program_path\\alize\\startup.txt.lnk); foreach (@Symlink) { if (-e $_) { system rm $_; } } but it seems not to work?Why? Looking at the '\\' in your filenames suggests that you're running Windows? The 'rm' program is a Unix program and although there are versions for Windows too - using Cygwin e.g. - you most probably just don't have 'rm'. Look here: -- snip -- kanku-dai:~$ perldoc -f unlink unlink LIST unlink Deletes a list of files. Returns the number of files successfully deleted. ... If LIST is omitted, uses $_. -- snip -- The perl builtin 'unlink' does what 'rm' does, but from within perl, so you don't need to rely on external software. Handily, it accepts lists, so given your above example you can remove your 'foreach' with unlink @Symlink; BUT WARNING: The checks are still missing. That's no real problem since 'unlink' simply ignores the missing files, but here's how you could do them anyways: a.) unlink grep { -e $_ } @Symlink; b.) -e $_ unlink foreach (@Symlink); Check the documentation for grep (perldoc -f grep) to learn more about that. Basically grep gets a piece of code and a list. It runs the code for each element in the list and returns as result a new list that contains all elements that let the passed code return a 'true' value. You could do the same like this: my @newlist; foreach (@Symlink) { if (-e $_) { push @newlist, $_ } } unlink @newlist; b. looks a bit more cryptic but I think still explainable: We use 2 programming idioms here: shortcut evaluation and modifiers. First, lets talk about the modifiers: -- snip from 'perldoc perlsyn' -- Simple statements ... Any simple statement may optionally be followed by a SIN- GLE modifier, just before the terminating semicolon (or block ending). The possible modifiers are: if EXPR unless EXPR while EXPR until EXPR foreach EXPR -- snip -- What this short sentence implies is that you can add a clause to any simple expression. if (-e $my_file) { unlink $my_file; } is equivalent to unlink $my_file if -e $my_file; Same goes for the 'foreach' loop: foreach (@Symlink) { unlink } could also be written unlink foreach @Symlink; Above statement already does the job, but we wanted to include the test for existence of the file, which brings us to shortcuts: Shortcut evaluation is the simple concept of bailing out of the condition as soon as it cannot any longer be true. A '' test is only true if both sides of it are true. So if the left side of the '' fails there's no need to look at the right side, so the whole expression fails immediately. Since functions like 'unlink' return a value, we can use them as part of that '' statement, which brings us back to our example: -e $_ unlink If the file doesn't exist, perl skips the left half of the '' so the 'unlink' is never called for non-existant files. Now we have a working expression that we can round up with our 'modifier' foreach -e $_ unlink foreach (@Symlink) Voila. -- If we fail, we will lose the war. Michael Lamertz| [EMAIL PROTECTED] Nordstr. 49| http://www.lamertz.net - http://www.perl-ronin.de 50733 Cologne | Priv:+49 221 445420 Germany| Mobile: +49 171 6900 310 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: sort on anonymous array elements as hash values
On Wed, Feb 06, 2002 at 05:35:44PM +0100, birgit kellner wrote: my %hash = ( 'keyone' = ['firstvalueone', 'firstvaluetwo], 'secondkey' = ['anothervalueone', 'valuetwoforsecondkey'], 'keythree' = ['thirdvalueone', 'thirdvaluetwo'] ); Can I sort the hash on the second element of the anonymous array? The hash itself cannot be sorted, since it's a hash, not a list. However, you can store the keys of the hash in a list that's sorted by your criteria: -- snip -- my @order=sort { $hash{$a}[1] cmp $hash{$b}[1] } keys %hash; print @order; -- snip -- 'perldoc -f sort' to find out about codeblocks in the sort command. Basically, 'sort' needs a compare function. That function knows two parameters '$a' and '$b' and returns their relation (perldoc -f cmp). Internally, I believe 'sort' then does a qsort, calling your provided comparism-code each time it has to decide what to do next. The result is the ordered list of hash-keys. Output should be: firstvaluetwo thirdvaluetwo valuetwoforsecondkey Ah, you don't want the hash sorted, but only the ordered values of the 2nd column? Similar procedure: -- snip -- print sort map { $_-[1] } values %hash; -- snip -- 1st: 'perldoc -f values', 'perldoc -f map'. 'values %hash' gives you a list that contains all right-side parts of the hash print values %hash; gives ARRAY(0x80f60ac) ARRAY(0x8102f24) ARRAY(0x8102edc) Not very helpful, but that's how your array-references look from the inside. Now, the 'map' acts kind like a filter, applying some code to each element of a list and returning a new list that contains all the results of that codeblock. The codeblock gets its parameters via $_, thus '$_-[1]' means 'on each value of %hash give me the 2nd array element. Then that list is then put into sort - you have read 'perldoc -f sort' by now, haven't you? H, did I make sense? -- If we fail, we will lose the war. Michael Lamertz| [EMAIL PROTECTED] Nordstr. 49| http://www.lamertz.net - http://www.perl-ronin.de 50733 Cologne | Priv:+49 221 445420 Germany| Mobile: +49 171 6900 310 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Pack trouble
Hans ([EMAIL PROTECTED]) wrote: Someone please enlighten me. I can't for the world figure out what is wrong here. Your understanding of the packer is wrong :-) - I create a main window. - In this window I create a frame. You don't need a frame that covers the whole window - except for design reasons. - In this frame I create four buttons. And that's your problem. - The buttons need to be packed like this: TOP LEFT RIGHT BOTTOM1 BOTTOM2 Ok, lets draw some lines around this, but beforehand let me explain how the packer works. If you create elements in your window and pack them with a '-side =', then a piece with the size of your element is cut off along the full size of the remaining window space. +---+ +---+ | | | New thing | | | +---+ | | - pack(-side='top') - | | | | | Remainder | | | | | | | | | +---+ +---+ - pack(-side = 'top'): +---+ | New thing | +---+ | | | Remainder | | | | | +---+ - pack(-side = 'right'): +---+ | Old thing | +---+---+ | | N | | Remainder | e | | | w | | | | +---+---+ - pack(-side = 'bottom'): +---+ |very old thing | +---+---+ | Remainder | O | | | l | +---+ d | |New| | +---+---+ Does this clear things up a bit? So what you need to do is: - create window - create top button - create 2nd floor frame - put 2 buttons - side = 'left' into 2nd floor frame - optionally create 3rd floor frame If the remaining 2 buttons take up all the space that's left, this step isn't needed - put the last 2 buttons in either the remaining window space or the 3rd floor frame. -- If we fail, we will lose the war. Michael Lamertz | [EMAIL PROTECTED] / [EMAIL PROTECTED] Nordstr. 49 | http://www.lamertz.net 50733 Cologne| Work: +49 221 3091-121 Germany | Priv: +49 221 445420 / +49 171 6900 310
Re: Got a project for Perl but need some help
Andrew Teo ([EMAIL PROTECTED]) wrote: Just curious, how would you send an attachment? Get MIME::Lite from CPAN. -- If we fail, we will lose the war. Michael Lamertz | [EMAIL PROTECTED] / [EMAIL PROTECTED] Nordstr. 49 | http://www.lamertz.net 50733 Cologne| Work: +49 221 3091-121 Germany | Priv: +49 221 445420 / +49 171 6900 310
Re: [BPQ] help!! any idea whats wrong with this??
Timothy Kimball ([EMAIL PROTECTED]) wrote: : Because someone (and with apologies to all, I don't recall off the top : of my head who)correctly pointed out to me earlier in this thread that : using map() here was inefficient. map() builds and returns an array, so : there's no point in using it in this void context. Aside from that, : both do the same thing. The postfix for is cleaner. =o) I agree that the postfix is cleaner, but when I benchmark these, map looks faster- though several months ago, map was slower (IIRC). Maybe something changed in 5.6.0 to make map faster in a null context...? Here's the script output (Perl 5.6.0 on an Ultra 10): Whoa! It was me who noted that the map should be avoided in void context, but trying your benchmark, I had the same results. However, since I did some benchmarks on my own *before* stating that map should not be used, I had some completely different results. I was suspicious, since your results are by far too fast - an U10 is not that much of a big machine, isn't it? ;-) ...hack, hack, hack... Ah, a Heisenbug. There's a problem with your benchmarking: -- snip -- my @lines = qw( ... timethese(500_000,{ 1. map = 'map { s/a// } @lines', -- snip -- Inside 'timethese', @lines is unknown and thus empty. Looks as if the Benchmark module ignores '$@' after the eval, but I haven't checked for that. But fact is, you're running 500_000 loops on en empty list, and map doesn't need to create any new list at all - well, at least it looks as if map is *pretty* fast on empty lists. There are 2 modifications required in your benchmark: a. make the @list array global, so it's visible inside 'timethese' b. make sure the s/ doesn't truncate the string, so there's still some work to do after 10 test loops. (I did that by replacing s/ with a switching tr...) ( c. as a not really necessary addon I decided to create more random test data (yes, I *am* using nested maps there :- ). ) Here's my version of your benchmark: -- snip -- kanku-dai:~$ cat check.pl #!/usr/bin/perl -w use strict; use Benchmark; use vars qw{@lines}; my @chars=('A'..'Z', 'a'..'z', 0 .. 9, ' '); @lines=map { join('', @chars[map { rand @chars } (0 .. 63)]) } (1 .. 10); timethese(500_000,{ 1. map = 'map { tr/abAB/baBA/ } @lines', 2. foreach = 'foreach ( @lines ) { tr/abAB/baBA/ }', 3. for = 'tr/abAB/baBA/ for @lines', }); -- snip -- Here are the new results: -- new -- kanku-dai:~$ perl check.pl Benchmark: timing 50 iterations of 1. map, 2. foreach, 3. for... 1. map: 7 wallclock secs ( 6.95 usr + 0.01 sys = 6.96 CPU) @ 71839.08/s (n=50) 2. foreach: 9 wallclock secs ( 8.38 usr + 0.01 sys = 8.39 CPU) @ 59594.76/s (n=50) 3. for: 9 wallclock secs ( 8.13 usr + 0.01 sys = 8.14 CPU) @ 61425.06/s (n=50) kanku-dai:~$ -- new -- So, it looks as if you're right, map *IS* a bit faster on small data sets, but not in the dimensions that your benchmark suggested. Increasing the amount of data makes that difference go away however. Here's the data for 500 benchmark loops over 10_000 lines of data: -- mod_new -- kanku-dai:~$ perl check.pl Benchmark: timing 500 iterations of 1. map, 2. foreach, 3. for... 1. map: 10 wallclock secs ( 9.71 usr + 0.04 sys = 9.75 CPU) @ 51.28/s (n=500) 2. foreach: 9 wallclock secs ( 9.58 usr + 0.01 sys = 9.59 CPU) @ 52.14/s (n=500) 3. for: 9 wallclock secs ( 9.44 usr + 0.02 sys = 9.46 CPU) @ 52.85/s (n=500) kanku-dai:~$ -- mod_new -- Conclusion: The perlfaq6 information seems outdated, so the only argument against map is the question of style, readability and personal taste - naturally, I stick with my style ;-) Mike -- If we fail, we will lose the war. Michael Lamertz | [EMAIL PROTECTED] / [EMAIL PROTECTED] Nordstr. 49 | http://www.lamertz.net 50733 Cologne| Work: +49 221 3091-121 Germany | Priv: +49 221 445420 / +49 171 6900 310
Re: DBI and Oracle
Emma Wermström (EMW) ([EMAIL PROTECTED]) wrote: Hi! I'm a beginner (to databases aswell as perl) trying to use perl code embedded in html to access an Oracle database. The trouble I'm having is that the database requires two login procedures. The first one to access the actual database and a second one to access SQL (sql+) within the database. How can I implement this using the $dbh-connect() ? I'm not sure I understand what you mean. As I interprete your question, the first login happens during some telnet/ssh connect on the machine, and the second is the SQL+'s username and password prompt? Using DBI things are different. DBD::Oracle can talk directly to a database listener on a foreign machine, without the need to open a shell on that machine or start SQL+, so providing the $DBI-connect(...) with the correct data - the one you type into SQL+ - should be sufficient. -- If we fail, we will lose the war. Michael Lamertz | [EMAIL PROTECTED] / [EMAIL PROTECTED] Nordstr. 49 | http://www.lamertz.net 50733 Cologne| Work: +49 221 3091-121 Germany | Priv: +49 221 445420 / +49 171 6900 310
Re: Repeated Words
Helio S. Junior ([EMAIL PROTECTED]) wrote: Hello, How do i read a simple file and look for repeated words in each line, writing out the words i have found and the numbers of line they were found? Well, that sounds like a homework to me, thus no sample code... Think about using either a hash or an array for storing the previous line's words. When using a hash, you can easily look up if the word in the current line has been there and report it. When you use an array, do a 'perldoc -f grep' to find out how to look for words in there. Do a 'perldoc perlvar' to find out how to get the current input's line number. Mike -- If we fail, we will lose the war. Michael Lamertz | [EMAIL PROTECTED] / [EMAIL PROTECTED] Nordstr. 49 | http://www.lamertz.net 50733 Cologne| Work: +49 221 3091-121 Germany | Priv: +49 221 445420 / +49 171 6900 310
Re: Parsing the output
[EMAIL PROTECTED] ([EMAIL PROTECTED]) wrote: snippage My code is my @vob_list = system (cleartool lsvob) ; foreach $entry (@vob_list) { print This is first '$entry' ; } use 'perldoc perlop' and look for 'qx'. The system call doesn't catch the output of the called program. For this you need either the qx operator or backticks - also explained in the qx section of the docs. -- If we fail, we will lose the war. Michael Lamertz | [EMAIL PROTECTED] / [EMAIL PROTECTED] Nordstr. 49 | http://www.lamertz.net 50733 Cologne| Work: +49 221 3091-121 Germany | Priv: +49 221 445420 / +49 171 6900 310
Re: pulling out part of a /path/to/a/file
Sandor W. Sklar ([EMAIL PROTECTED]) wrote: Hi, folks ... I'm generating a list of files (from a find subroutine) and putting them in an array. The list looks like ... /home4/dsadmin/7790/DocuShare/documents/b003/File-11523.1 /home4/dsadmin/7790/DocuShare/documents/b003/File-11587.1 /home4/dsadmin/7790/DocuShare/documents/b003/File-11651.1 /home4/dsadmin/7790/DocuShare/documents/b004/File-1156/html/main.htm /home4/dsadmin/7790/DocuShare/documents/b004/File-1604/html/main.htm (... a small sample) and I'm trying to get just the File- part of each line; some lines that I am matching against will have a trailing slash, with additional path info that I'm not interested in; other lines will have a period and a number following, which I am also not interested in. Is there any special reason why you don't regexp your information from out of the line? -- If we fail, we will lose the war. Michael Lamertz | [EMAIL PROTECTED] / [EMAIL PROTECTED] Nordstr. 49 | http://www.lamertz.net 50733 Cologne| Work: +49 221 3091-121 Germany | Priv: +49 221 445420 / +49 171 6900 310
Re: pulling out part of a /path/to/a/file
Kevin Meltzer ([EMAIL PROTECTED]) wrote: Just use the basename() method from File::Basename; # perl -MFile::Basename -e 'print basename(/tmp/foo/003/File-11523.1)'; File-11523.1 That won't help him with this line: /home4/dsadmin/7790/DocuShare/documents/b004/File-1156/html/main.htm Casey's is the way to do it. -- If we fail, we will lose the war. Michael Lamertz | [EMAIL PROTECTED] / [EMAIL PROTECTED] Nordstr. 49 | http://www.lamertz.net 50733 Cologne| Work: +49 221 3091-121 Germany | Priv: +49 221 445420 / +49 171 6900 310
Re: @INC variable :please help
Rajakumar Theja ([EMAIL PROTECTED]) wrote: Hi, I'm new to perl, so please help. My installation of DBD::Oracle for Oracle 8.1.6 failed. After reaching a dead end and not getting any help from dbi-users, I decided to copy over a previous installation of the perl directory tree which includes DBI and DBD from another machine. Whoa! This is an absolute nono. Depending on what other packages you built, what compiler and local libraries you have, what Oracle Version you have running, you can break all sorts of stuff. I guess rebuilding a fresh perl is - with the help of the CPAN module usually faster than figuring out library dependencies for hours. *WARNING* CPAN works best if you have a direct internet connection. A socks proxy will do too, but I have no idea how things are with a http-proxy. What was the problem with the DBD build? As a hint, you need the Oracle samples installed, since these provide the headers you need to compile the DBD stuff. Assuming you're on some Unix box, here are some general pointers of how I would continue from here. *THINK HARD BEFORE YOU TRY THIS*. If you decide to reinstall, save the old tree in case something really breaks. Then take a deep look at the 'site-perl' directory tree inside perl's lib directory, and write down the packages that have been installed there. As a rule of thumb, all directories inside your local site-perl tree correspond to a package name. Additionally, you have to look into the directory that describes your machine type, e.g. i386-linux. Things that lie there should also correspond to CPAN packages. Move the complete perl tree to the side, fetch the sources and do the usual things to build perl - should be something like: ./Configure -Dprefix=/where/you/want/it -Dcc=your-compiler -des make make test make install then continue with perldoc CPAN then, after reading do perl -MCPAN -e shell follow the setup procedure and start installing the packages you noted earlier. DBD::Oracle will most probably fail to install from out of the CPAN module, so be prepared to build this by hand by typing 'look CPAN' in the CPAN shell prompt. Keep asking if you're stuck... Mike -- If we fail, we will lose the war. Michael Lamertz | [EMAIL PROTECTED] / [EMAIL PROTECTED] Nordstr. 49 | http://www.lamertz.net 50733 Cologne| Work: +49 221 3091-121 Germany | Priv: +49 221 445420 / +49 171 6900 310
Re: Help on lib/modules Please!!
Arante, Susan ([EMAIL PROTECTED]) wrote: Can't locate loadable object for module ABC::Test in @INC (@INC contains: c:/perl/lib c:/perl/site/lib .) at - line 1 Dan's suggestion sounds good. Look into a directory that describes your machine type and processor below the site directory. Perhaps there's more of your 'ABC'-structure lying around, since that's where the compiled C-libraries go. E.g., I have on my machine two Apache-Trees: /usr/lib/perl5/site_perl/5.6.0/Apache that's the obvious one, and /usr/lib/perl5/site_perl/5.6.0/i386-linux/Apache here's the other part. -- If we fail, we will lose the war. In most states the penalty for an adult who rapes a child is twenty years plus -- UNLESS that adult happens to be related to the child, in which case the maximum sentence is PROBATION. There is legislation now pending in Congress to change all this. IF YOU CARE, ACT! http://www.careact.org Michael Lamertz | [EMAIL PROTECTED] / [EMAIL PROTECTED] Nordstr. 49 | http://www.lamertz.net 50733 Cologne| Work: +49 221 3091-121 Germany | Priv: +49 221 445420 / +49 171 6900 310