[7063] in Perl-Users-Digest
Perl-Users Digest, Issue: 688 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 1 08:17:16 1997
Date: Tue, 1 Jul 97 05:00:37 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 1 Jul 1997 Volume: 8 Number: 688
Today's topics:
Re: changing environmental variables <jpn@global.net.uk>
dir tree search <rferr@voicenet.com>
Re: dir tree search (Jean-Damien Durand)
Re: Empty loops... <rootbeer@teleport.com>
Filehandle [socket] refs <gandalf@n-vision.com>
Re: Filehandle [socket] refs <zenin@best.com>
Re: Help... OOP perl <rootbeer@teleport.com>
Re: Help... OOP perl <zenin@best.com>
Re: How can I debug a CGI script? <rootbeer@teleport.com>
HTTP SOCKET SUPPORT <jweaver@qntm.com>
Re: HTTP SOCKET SUPPORT <zenin@best.com>
Re: HTTP SOCKET SUPPORT <wayne@cta-challenge.com.au>
Re: HTTP SOCKET SUPPORT <rootbeer@teleport.com>
mail filters <syed.babar@amd.com>
Re: mail filters <kjj@primenet.com>
Re: Newbie: 500 Server Error message <hotline@asi.fr>
Re: Pattern matching question <pdcawley@aladdin.net>
PATTERN REPLACE <jweaver@qntm.com>
Re: Perl lib version doesn't match exe and sockets <rootbeer@teleport.com>
Re: Perl: deleting spaces etc in strings <sfairey@adc.metrica.co.uk>
Piping the instances from the Postgres database to PERL <michaely@pcm.com.au>
Re: Question: Output redirection (Tung-chiang Yang)
Re: Question: Output redirection (Tad McClellan)
Re: Rand command <rootbeer@teleport.com>
Re: SShell Windoww in Win95 disappes (Shelle)
Re: strange problem... <rootbeer@teleport.com>
Re: test (Andrew Starr)
TimeSorting (o-su ken'ichi )
Re: Zombie processes under system load <wayne@cta-challenge.com.au>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 01 Jul 1997 12:19:08 +0100
From: Jon Nangle <jpn@global.net.uk>
Subject: Re: changing environmental variables
Message-Id: <33B8E011.7C3EC32@global.net.uk>
Nathan Neulinger wrote:
> Don't know about NT, but on UNIX, environment variables are inherited from
> the parent process. Each new process gets it's own copy of the varibles.
> The only thing you could do is pass it on to a new process or eval the
> output of the perl script.
I had to do this years ago on an MS-DOG machine. I managed it, but it
required some nasty low-level C to do it. AFAIK you can't do it on Unix,
and if it's possible on NT at all, you definitely won't be able to do it
in Perl.
--
Jon Nangle
Global Internet
------------------------------
Date: 30 Jun 1997 23:13:48 GMT
From: "rferr" <rferr@voicenet.com>
Subject: dir tree search
Message-Id: <01bc85ab$caea8440$658667cf@rferr.voicenet.com>
are there any scripts available (or how would it be done) that read an
entire directory
tree structure file by file and search for a string in each file ?
thanks.
------------------------------
Date: Tue, 1 Jul 1997 06:56:24 GMT
From: ddurand@hpplus17.cern.ch (Jean-Damien Durand)
To: "rferr" <rferr@voicenet.com>
Subject: Re: dir tree search
Message-Id: <ECMoM1.7Cw@news.cern.ch>
> are there any scripts available (or how would it be done) that read an
> entire directory
> tree structure file by file and search for a string in each file ?
Glimpse, this is somewhat exactly my first perl script! I never changed it
since this time, so consider it as as *spaghetti-code*, *bad coded*,
*non-optimized*, and manifestly a beginner'try. Many people will find it
horrible-coded. And so do I, nowdays...
Cheers, Jean-Damien.
#!/usr/local/bin/perl
# word.pl - Text search utility
require "getopts.pl";
# First of all check the arguments...
# -----------------------------------
@actual_options = (h,v,A,n,g,G,r,o,f) ;
$error = 0 ;
$i = 0 ;
foreach (@ARGV) {
if (/^-(.*)/) {
$verify = $1 ;
if ($verify eq "h") {&wordhelp ; exit ;}
@match_options = "" ;
@match_options = grep $_ eq $verify, @actual_options ;
if (@match_options == "") {
$error = 1 ;
print STDERR "Error :: unknown option -$verify\n" ;
}
if ($verify eq "f") {
if (!$#ARGV > $i) {
$error = 1 ;
print STDERR "Error :: Nothing follows -f option\n" ;
} elsif ($ARGV[$i+1] =~ /^-/) {
$error = 1 ;
print STDERR "Error :: -f option should not be followed by another option\n" ;
}
} elsif ($verify eq "g") {
if (!$#ARGV > $i) {
$error = 1 ;
print STDERR "Error :: Nothing follows -g option\n" ;
} elsif ($ARGV[$i+1] =~ /^-/) {
$error = 1 ;
print STDERR "Error :: -g option should not be followed by another option\n" ;
}
} elsif ($verify eq "h" || $verify eq "A" || $verify eq "n" || $verify eq "r" || $verify eq "o" || $verify eq "G") {
if (!$#ARGV == "$i+1") {
if ($ARGV[$i+1] !~ /^-/) {
$error = 1 ;
print STDERR "Error :: Argument following option -$verify not allowed\n" ;
}
}
}
}
$i++ ;
}
if ($error == 1) {print STDERR "Type word -h for help...\n" ;}
$error = 0 ;
# No argument ?
# -------------
if ($#ARGV < 0) {$error = 1 ; }
# Last Argument valid ?
# ---------------------
if ($ARGV[$#ARGV] =~ /^-/) {
print STDERR " Error :: Last argument, the word to search, seem to be an option...\n" ;
$error = 1 ;
}
if ($#ARGV >= 1) {
if ($ARGV[$#ARGV-1] =~ /^-([g|f])/) {
print STDERR " Error :: Last argument, the word to search, belong to the -$1 option...\n" ;
$error = 1 ;
}
}
# Get options
# -----------
&Getopts ("hvAnGorg:f:");
# Help
# ----
if ($opt_h) { &wordhelp ; exit ; }
# Error in syntax
# ---------------
if ($error) { &wordhelp ; exit 1 ; }
# Where to search ?
# -----------------
$path = "." ;
if ($opt_f) { $path = $opt_f ; }
`ls $path > /dev/null` ;
if ($? != 0) {
print STDERR "Error :: $path is not accessible\n" ;
exit 1 ;
}
# What to search
# --------------
$word = $ARGV[$#ARGV] ;
if ($word eq "") {print STDERR " No word to search... Put it as the end of the arguments.\n" ; $error = 1 ; }
if ($word !~ /[a-zA-Z0-9]/) {
print STDERR " Warning : Strange character(s) in " . chr(34) . "$word" . chr(34) . "\n\n" ;
}
if ($error) { &wordhelp ; exit 1 }
if (!$opt_n) {
if ($path ne ".") {
print STDOUT " Search the word " . chr(34) . "$word" . chr(34) . " in " . chr(34) . "$path" . chr(34) . " ([y]/n) \? \n";
} else {
print STDOUT " Search the word " . chr(34) . "$word" . chr(34) . " in current directory ([y]/n) \? \n";
}
$rep=substr(`line`,0,1);
if ( $rep =~ /^n/i ) {exit 0 ;}
}
if ($opt_A) {$add_to_ls = "A" ;} else {$add_to_ls = "" ;}
chop ($testpath = `echo $path`) ;
if ($opt_G) {print STDOUT "Here \$path=<$path> and echo \$path give <$testpath>\n" ;}
if ($path ne $testpath) {
$interpolation = 1 ;
} else {
$interpolation = 0 ;
}
foreach (`ls -1$add_to_ls $path`) {
chop ($file = $_) ;
if ($opt_G) {print STDOUT "Here \$interpolation=$interpolation, \$file=$file, \$path=$path\n" ;}
if ($interpolation == 1) {
$totalpath = $file ;
} elsif ($file ne $path) {
$totalpath = "$path/$file" ;
} else {
$totalpath = $file ;
}
if ($opt_G) {print STDOUT "Here \$totalpath = $totalpath\n" ;}
if ($totalpath =~ /\.$/ || $totalpath =~ /\.\.$/) {next ;}
if (-d "$totalpath") {
if ($opt_r) {
if ($opt_v) {print STDOUT "Going in directory $path/$file\n" ;}
$options = "" ;
if ($opt_v) {$options = $options . " -v " ;}
if ($opt_g) {$options = $options . " -g $opt_g " ;}
if ($opt_r) {$options = $options . " -r " ;}
if ($opt_A) {$options = $options . " -A " ;}
$options = $options . " -n -f $totalpath " . $word ;
if ($opt_G) {print STDOUT "Calling $0 $options\n" ;}
system ("$0 $options") ;
}
} elsif (-r "$totalpath") {
if ($opt_v) {
print STDOUT "Scanning file $totalpath\n" ;
}
if ($opt_g) {$grep_opt = "-" . "$opt_g" ;} else {$grep_opt = "" ;}
if ($opt_o) {
if ($opt_G) {print STDOUT "Calling cat $totalpath | grep $grep_opt $word\n" ;}
system("cat $totalpath | grep $grep_opt $word") ;
} else {
# if ($opt_G) {print STDOUT "Calling cat $totalpath | grep $grep_opt $word > /dev/null\n" ;}
system("cat $totalpath | grep $grep_opt $word > /dev/null") ;
}
if ($? == 0) {
print STDOUT "## <$word> matched in $totalpath\n" ;
}
} else {
print STDERR "Warning :: $totalpath not readable.\n" ;
}
}
exit 0 ;
sub wordhelp {
print STDOUT <<"HELP" ;
word - Text search utility (Jean-Damien.Durand\@cern.ch)
Syntax : word [-h] [-v] [-n] [-o] [-r] [-A] [-G] [-g option] [-f file] word
[-h] This help (can be anywhere in option line)
[-v] Verbose mode.
[-n] Do not prompt for an answer before executing
[-o] Print output of grep.
[-r] Recursive call in subdirectories.
This will work only if the -f option catch
directories or if there is no -f option (
assuming then there are subdirectories in current one...)
[-A] Search also in files starting with a dot '.'.
[-G] Debug option.
[-g option] Option(s) for the grep command
[-f file] Files/directory to search within.
Do not forget to enclose it in brackets if wild characters.
Default is current directory.
Example : word text1
word -f \$DELPHI_PAM electron
word -g i -f ~ -o -v text
word -g i -r -f '*.pl' text
HELP
}
--
*******************************************************
* Jean-Damien Durand (Jean-Damien.Durand@cern.ch) *
* www : http://wwwcn.cern.ch/~ddurand/ *
*******************************************************
------------------------------
Date: Mon, 30 Jun 1997 16:28:55 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "David J. Clark" <dav@umiacs.umd.edu>
Subject: Re: Empty loops...
Message-Id: <Pine.GSO.3.96.970630162627.19121T-100000@kelly.teleport.com>
On Mon, 30 Jun 1997, David J. Clark wrote:
> In searching an array, I want to say something like:
>
> while($array[$i++] ne $string_to_look_for);
> Right now I just have:
>
> while(...) {0}
>
> which works, but seems kind of arbitrary.
So, if it works, what are you griping about? :-)
The compiler is smart enough to optimize that constant to Tumbolia, so you
don't have to worry that it's slowing things down. But you could even omit
it, if you wanted.
while (...) {} # Empty loop body
Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 01 Jul 1997 02:18:59 -0400
From: Alex Bertram <gandalf@n-vision.com>
Subject: Filehandle [socket] refs
Message-Id: <33B8A152.4B4C46F7@n-vision.com>
Hello!
I'm trying to right a single process perl server and I'm getting
tripped up in syntax. I've got an array to represent connections. @cons
Each connection is represented by a hash, and one of the fields needs to
be the socket filehandle. what I tried was this:
if ( (accept(NS, S)) && ( $! != &EAGAIN ) ) {
$cons[n]{handle} = *NS;
....
But the next time I call accept() with NS, it disconnects the
previous connection. So I'd like to be able to do something like this:
if ( (accept(*$cons[n]{handle}, S)) && ( $! != &EAGAIN ) ) {
....
But perl says I "cant use subscript on ref-to-glob cast". I can't do
accept(*cons->[n]{handle}, S) either. So i guess what i have to do is
create an anonymous file handle refrenced at $cons[n]{handle}, right? So
how do go about doing that?
Thanks in advance,
--
Alex Bertram (iy@n-vision.com)
Visit iy Internet Youth at http://www.n-vision.com/iy
------------------------------
Date: 1 Jul 1997 10:30:01 GMT
From: Zenin <zenin@best.com>
Subject: Re: Filehandle [socket] refs
Message-Id: <5pam79$3dl$1@nntp2.ba.best.com>
Alex Bertram <gandalf@n-vision.com> wrote:
> I'm trying to right a single process perl server and I'm getting
> tripped up in syntax. I've got an array to represent connections. @cons
> Each connection is represented by a hash, and one of the fields needs to
> be the socket filehandle. what I tried was this:
> if ( (accept(NS, S)) && ( $! != &EAGAIN ) ) {
> $cons[n]{handle} = *NS;
This should be:
$cons[n]{handle} = \*NS;
Note the backslash to force a reference to the type glob.
> But the next time I call accept() with NS, it disconnects the
> previous connection. So I'd like to be able to do something like this:
> if ( (accept(*$cons[n]{handle}, S)) && ( $! != &EAGAIN ) ) {
No need to deref a type glob ref when using it as a filehandle.
if (accept $cons[n]{handle}, S and $! != EAGAIN) {
> But perl says I "cant use subscript on ref-to-glob cast". I can't do
> accept(*cons->[n]{handle}, S) either. So i guess what i have to do is
> create an anonymous file handle refrenced at $cons[n]{handle}, right? So
> how do go about doing that?
I'd actually suggest never using an actual file(socket) handle, but
rather a filehandle object:
use FileHandle;
my $Server = new FileHandle;
...stuff to wait on $Sever...
$cons[n]{handle} = new FileHandle;
if (accept $cons[n]{handle}, $Server and $! != EAGAIN) {
...
--
-Zenin
zenin@best.com
------------------------------
Date: Mon, 30 Jun 1997 16:06:40 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Joshua Marotti <jpm@iti-oh.com>
Subject: Re: Help... OOP perl
Message-Id: <Pine.GSO.3.96.970630155938.19121Q-100000@kelly.teleport.com>
On 30 Jun 1997, Joshua Marotti wrote:
> package Class;
> sub new
> {
> my $type = shift;
> my $self;
> $self = shift;
> my @child_mf;
> my @child_dm;
> my @typedef;
> my $template_info;
> my %doctag;
> return bless \$self, $type;
> }
You're making a bunch of my variables, then never using them. That's an
OOPs. :-)
You probably want to implement your object with a hash, like this.
package Class;
sub new {
my $type = shift;
$self = {}; # Anon hash
$self->{child_mf} = [];
$self->{child_dm} = [];
$self->{typedef} = [];
$self->{template_info} = undef;
$self->{doctag} = {};
bless $self, $type; # Return value
}
Or, you could build those items into the anon hash from the start:
package Class;
sub new {
my $type = shift;
$self = {
child_mf => [],
child_dm => [],
typedef => [],
template_info => undef,
doctag => {},
};
bless $self, $type; # Return value
}
Now, within your methods, you can refer to such things as
$self->{typedef}[3] or %{$self->{doctag}}. Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 1 Jul 1997 01:37:25 GMT
From: Zenin <zenin@best.com>
Subject: Re: Help... OOP perl
Message-Id: <5p9n0l$gbs$1@nntp2.ba.best.com>
Joshua Marotti <jpm@iti-oh.com> wrote:
> If I use an object more than once, the new object still contains all the
> values that the old object has. I want both pieces of info, but I want
> them to be in separate objects...
>snip<
> package Class;
> sub new
>snip<
> I still want the class info, and I need to declare a new class, but when I
> do, the new class's attributes are the same as the last classes...
> In general - how do I individualize my objects?
It sounds like you are confusing package globles and object
fields. Are you looking for something this this maybe?:
package Class;
use strict;
use vars qw($SOME_VAR);
sub new {
my $Class = shift;
$Class = ref $Class || $Class;
my $Self = {};
$Self->{SomeArrayField} = [ 'foo', 'bar', 'cat', 'dog' ];
$Self->{SomeScalarField} = 'Some string';
$Self->{SomeHashField} = { foo => 'bar', cat => 'dog' };
return bless $Self, $Class;
}
sub printStuff {
my $Self = shift;
## Each object has it's own copy of these
print @{ $Self->{SomeArrayField} };
print %{ $Self->{SomeHashField} };
print "$Self->{SomeScalarField}\n";
## But this is globle to everything in this package
print "$SOME_VAR\n";
return 1;
}
__END__
--
-Zenin
zenin@best.com
------------------------------
Date: Mon, 30 Jun 1997 15:56:46 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: The Halls <bhall@mail.tds.net>
Subject: Re: How can I debug a CGI script?
Message-Id: <Pine.GSO.3.96.970630155323.19121P-100000@kelly.teleport.com>
On Mon, 30 Jun 1997, The Halls wrote:
> I'm using a complicated CGI script written by someone else in Perl on my
> web site. Every once in a while, it crashes, and all that shows up in
> the error log is a Premature End of Script Headers error.
If the script is written to use CGI.pm, you can run it under the perl
debugger from the command line. If it isn't, and if you can't retrofit it
to do that, you could try having it append its STDERR to a file. While
that's not perfect (since concurrency problems could mess up the file), it
will capture the error output, which may have some helpful warning text.
Of course, there's no substitute for re-writing the script without the
bugs. :-) Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Mon, 30 Jun 1997 15:53:05 -0700
From: Jay Weaver <jweaver@qntm.com>
Subject: HTTP SOCKET SUPPORT
Message-Id: <33B838D1.69FDCAD@qntm.com>
Are HTTP sockets supported under perl? How would I connect to a site
and copy the html page?
Thanks,
Jay
------------------------------
Date: 1 Jul 1997 10:32:19 GMT
From: Zenin <zenin@best.com>
Subject: Re: HTTP SOCKET SUPPORT
Message-Id: <5pambj$3dl$2@nntp2.ba.best.com>
Jay Weaver <jweaver@qntm.com> wrote:
> Are HTTP sockets supported under perl? How would I connect to a site
> and copy the html page?
perldoc perlipc
If you just want to do HTTP stuff however, check out the
LWP::* modules at your local CPAN. -LWP::Simple has a great
get() function to grab misc URLs.
--
-Zenin
zenin@best.com
------------------------------
Date: Tue, 01 Jul 1997 11:22:09 +1000
From: Wayne Blick <wayne@cta-challenge.com.au>
To: Jay Weaver <jweaver@qntm.com>
Subject: Re: HTTP SOCKET SUPPORT
Message-Id: <33B85BC1.119B@cta-challenge.com.au>
Jay Weaver wrote:
>
> Are HTTP sockets supported under perl? How would I connect to a site
> and copy the html page?
>
> Thanks,
> Jay
Have a look at the IO::Socket module available on CPAN.
Wayne Blick
------------------------------
Date: Mon, 30 Jun 1997 18:51:17 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Jay Weaver <jweaver@qntm.com>
Subject: Re: HTTP SOCKET SUPPORT
Message-Id: <Pine.GSO.3.96.970630184953.19121l-100000@kelly.teleport.com>
On Mon, 30 Jun 1997, Jay Weaver wrote:
> Subject: HTTP SOCKET SUPPORT
There's no need to shout! We're right here. :-)
> Are HTTP sockets supported under perl?
Perl has full support for TCP/IP networking, if that's supported by the
underlying system, of course.
> How would I connect to a site and copy the html page?
Use a module from CPAN. I'd say more, but they come with great docs and
examples. Hope this helps!
http://www.perl.org/CPAN/
http://www.perl.com/CPAN/
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Mon, 30 Jun 1997 17:02:08 -0700
From: Syed Babar <syed.babar@amd.com>
Subject: mail filters
Message-Id: <33B84900.5AD5@amd.com>
Can someone point me to perl mail filter examples
Thank you.
--
+---------------------------------------------------------------------+
Syed Babar
------------------------------
Date: 30 Jun 1997 18:21:00 -0700
From: Kevin Johnson <kjj@primenet.com>
Subject: Re: mail filters
Message-Id: <m2k9jbbm9z.fsf@primenet.com>
Syed Babar <syed.babar@amd.com> writes:
> Can someone point me to perl mail filter examples
In what context? You want to filter incoming email using perl?
If so, mailfolder is a good place to start.
It's available in CPAN in Raphael Manfredi's cubbyhole.
CPAN/authors/Raphael_Manfredi/
--
thx,
kjj@pobox.com http://www.pobox.com/~kjj/
------------------------------
Date: Tue, 01 Jul 1997 11:31:14 +0200
From: hotline <hotline@asi.fr>
To: Billy Chambless <billy@cast.msstate.edu>
Subject: Re: Newbie: 500 Server Error message
Message-Id: <33B8CE61.47989711@asi.fr>
Well for all the newbie QUESTIONS WITH NT & ODBC
check this new FAQ :
http://www.geocities.com/SiliconValley/Heights/9736
------------------------------
Date: 30 Jun 1997 12:12:33 +0100
From: Piers Cawley <pdcawley@aladdin.net>
Subject: Re: Pattern matching question
Message-Id: <54bu4ogx9a.fsf@gunnar.aladdin.net>
P Nibbs <pnibbs@icd.com.au> writes:
> Hi All,
>
> Just a simple pattern matching question.
>
> I would like to test for IP numbers between a certain range (203.63.0.0
> -> 203.63.255.255)
>
> The IP number is held within the variable $ENV{REMOTE_ADDR} and I am
> testing for it as follows:
>
> if ($ENV{REMOTE_ADDR} == /203.[0-63].[0-255].[0-255]/){
>
> This isn't working - can anyone please tell me what i am doing wrong?
You mean apart from almost everything? If you're trying to restrict
access to a certain set of pages then you should really be doing it
from .htaccess and even if that won't do what you want your regex is
so wrong as to be an almost textbook example of how not to do it.
if ($ENV{REMOTE_ADDR} =~ m{^203\.
(?:[0-5]?\d|6[0-3])\. #0-63
(?:[01]?\d{1,2}|2(?:[0-4]\d|5[0-5]))\. # 0-255
(?:[01]?\d{1,2}|2(?:[0-4]\d|5[0-5])) # 0-255
$
}
is a regex that should do what you want, but the other options
involving split almost certainly do the job a great deal better.
--
Piers Cawley -- Systems Genie for Aladdin
If a `religion' is defined to be a system of ideas that contains
unprovable statements, then Godel taught us that mathematics is not
only a religion, it is the only religion that can prove itself to be
one. -- John Barrow
------------------------------
Date: Mon, 30 Jun 1997 15:51:32 -0700
From: Jay Weaver <jweaver@qntm.com>
Subject: PATTERN REPLACE
Message-Id: <33B83874.A8C59220@qntm.com>
I would like to simplify my pattern replace process. I currently type
the following command at the prompt:
find . -print | xargs perl -pi -e 's#oldpattern#newpattern#g'
This edits all files from . down.
I would like to just type this:
replace oldpattern newpattern
I would also like to avoid this error when encountering directory names,
locked files, etc.:
Can't do inplace edit: file is not a regular file at replace line 8, <>
chunk 25.
Any suggestions?
Thanks,
Jay
------------------------------
Date: Mon, 30 Jun 1997 16:25:04 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Tracy Bednar <spectran@netcom.com>
Subject: Re: Perl lib version doesn't match exe and sockets
Message-Id: <Pine.GSO.3.96.970630162218.19121S-100000@kelly.teleport.com>
On Mon, 30 Jun 1997, Tracy Bednar wrote:
> Perl lib version (5.003) doesn't match executable version (5.00401)
That's a sign that you have perl 5.00401 running, but it's not finding its
libraries. Instead, it's finding the old 5.003 library files, so Config.pm
doesn't know what Perl's configuration is. Ask your administrator to make
sure that everything was correctly installed, and that 'perl -V' works.
Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 01 Jul 1997 10:55:00 +0100
From: Simon Fairey <sfairey@adc.metrica.co.uk>
To: X <eeiX@eei.ericsson.se>
Subject: Re: Perl: deleting spaces etc in strings
Message-Id: <33B8D3F4.446B@adc.metrica.co.uk>
X wrote:
>
> I'm new to this language and I was wondering could anyone tell me how to
> delete spaces from strings such as:
>
> 152 41-CAX 102 577
Try
$string = '152 41-CAX 102 577';
$string =~ s/\s*//g;
Simon
PS: If you want to strip leading/trailing spaces then see the FAQ.
------------------------------
Date: Tue, 01 Jul 1997 10:56:21 +1000
From: Michael Yeung <michaely@pcm.com.au>
Subject: Piping the instances from the Postgres database to PERL CGI script
Message-Id: <33B855B5.35625D8F@pcm.com.au>
HI all,
I'M DEVELOPING THE CGI script in PERL5 in order to get the instances or
records from the Postgres database. i know that in PERL script i've to
use the modules Pg for executing the SQL queries for the database.
moreover, i also need the CGI module in order to make the script working
in web.
however, i find difficulties to pipe the instances or records into a
PERL variable. Like for example,
#loginfo is one of the table in $dbname and selecting the records of
#which the username in loginfo is equal to 'abc'
use Pg;
$dbmain = 'template1';
$dbname = 'root';
use IO::Pipe;
$pipe = new IO::Pipe;
$conn = Pg::connectdb("dbname = $dbname");
$conn->exec("BEGIN");
$query = $conn->exec("declare log_cursor cursor for select
Start_Date, Start_Time, Session_Time from loginfo where User_Name
= \'$customer\'");
$MAX = $conn->exec("fetch 1 in log_cursor");
$conn->exec("END");
print "<P> The total number of entry is ", $MAX;
$MAX variable here is not the instances or records of the cursor in the
database but instead is PG_result of some scalar !
So that's why after executing the last line of the program. the web site
is not printing the instances of the cursor to which it point !!!!
Can anyone help me to solve it or help me to find any reference from
this ?
regards,
MIKE <michaely@pcm.com.au>
------------------------------
Date: Mon, 30 Jun 1997 23:26:15 GMT
From: tcyang@netcom.com (Tung-chiang Yang)
Subject: Re: Question: Output redirection
Message-Id: <tcyangECM3rr.J6J@netcom.com>
">&" is used for C Shell, not in Bourne Shell which Perl uses to interpret
'system' commands, if my memory is right.
===========================
Sudhakar Sannakkayala wrote on his Best Friend's Wedding:
: Hi,
: I'm trying to redirect the some stuff from the STDERR to a
: file.
: Eg. example.pl >& filename
: This works ... But if I call "system("example.pl >& filename");" from
: another perl script it gives me an error
: "sh: filename: Generated or received a file descriptor number that is
: not valid."
: Please enligthen me
: Thanks,
: Sudhakar.
--
========= Try the low-crossposting robomoderated 'alt.culture.taiwan' ===
soc.culture.taiwan, soc.culture.china (by SCC FAQ Team) FAQ's:
http://www.iglou.com/tcyang/Taiwan_faq.shtml, China_faq.shtml
------------------------------
Date: Mon, 30 Jun 1997 15:40:00 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Question: Output redirection
Message-Id: <0j59p5.8e5.ln@localhost>
Sudhakar Sannakkayala (sannakka@ptc.com) wrote:
: I'm trying to redirect the some stuff from the STDERR to a
^^^^^^
There is a good word to search for in the Perl docs...
: file.
: Eg. example.pl >& filename
: This works ... But if I call "system("example.pl >& filename");" from
^^^^^^^
There is a another thing to look up in the Perl docs...
: another perl script it gives me an error
So, system() is giving you trouble?
I guess we (_you_ already should have ;-) will have to go look it up
in the docs that are included with the perl distribution (perlfunc,
this time):
---------------------------
=item system LIST
Does exactly the same thing as "exec LIST" except that a fork is done
...
---------------------------
So, now we have to go read about exec():
---------------------------
=item exec LIST
The exec() function executes a system command I<AND NEVER RETURNS>. Use
the system() function if you want it to return.
If there is more than one argument in LIST, or if LIST is an array with
more than one value, calls execvp(3) with the arguments in LIST. If
there is only one scalar argument, the argument is checked for shell
metacharacters. If there are any, the entire argument is passed to
C</bin/sh -c> for parsing. If there are none, the argument is split
...
---------------------------
: "sh: filename: Generated or received a file descriptor number that is
^^
^^
: not valid."
How about that? The docs say it will invoke sh, and you are getting
an error message from sh. That matches up nicely.
Try running that argument to system() in sh (NOT in csh).
You get the same error message, right?
You are using csh syntax, but it is being fed to sh...
system("example.pl 2>filename"); # this is how it is done in sh
[
A word search for "STDERR" in the Perl FAQ finds only twelve lines.
One of them says: "How can I capture STDERR from an external command?"
Does that sound like it might be helpful?
I don't see how you could possible miss all this stuff when you
researched your problem before posting.
You _did_ research you problem before posting, didn't you?
]
: Please enligthen me
Use the docs, Luke.
We're not really here to read them for you, ya know...
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: Mon, 30 Jun 1997 16:21:24 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Rikky Alessi <ralessi@bright.net>
Subject: Re: Rand command
Message-Id: <Pine.GSO.3.96.970630160953.19121R-100000@kelly.teleport.com>
On Mon, 30 Jun 1997, Rikky Alessi wrote:
> I am having a problem with Rand. Apparently when I give it an
> upperbound, it exeeds or never reaches the bound.
Your copy of perl was probably compiled with the wrong value for
randbits. See what this gives you.
#!/usr/bin/perl
use Config;
srand;
for (1..1000) { $m=$_ if ($_=rand)>$m }
$n=log($m)/log(2);
$n=($m>1)?int($n):-int(-$n);
$r=$Config{randbits};
$n+=$r;
print "Randbits was $r and should be $n\n";
If the value of randbits was wrong, recompile Perl. Better yet, get the
newest source and compile that. Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Mon, 30 Jun 1997 21:00:40 GMT
From: shelle@interaccess.com (Shelle)
Subject: Re: SShell Windoww in Win95 disappes
Message-Id: <5p96po$30s_004@interaccess.interaccess.com>
"Rafal S. Konopka" <rafalk@hyde.park.uga.edu> wrote:
>I browsed through all the FAQ's available, but I couldn't find a satisfactory
>answer. If I run a perl perogram byy double clicking on the actual script,
>the shell window appears with the outpout, and then disappears. Yes, I
>know, somebody in one of the FAQ's DID say that perl is not meant to be
>run lie that, but ut DOES run, The thing is I cannot see the output.
>
>Does it mean that I can only run perl in the DOS shell window?
To see your program run in a DOS window...DON'T double-click the program:
Open a DOS window and type "perl proggy_name.pl". This of course assumes that
you read the part of the FAQ about associating your Perl filetypes (.PL and
CGI) with your Perl interpreter (PERL.EXE).
Michelle ----,-'-(@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I'm just a beginner with Perl but I read TFM....
Michelle Feigen ----,-'-(@ shelle@interaccess.com
http://homepage.interaccess.com/~shelle/
http://homepage.interaccess.com/~shelle/grafx/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
------------------------------
Date: Mon, 30 Jun 1997 18:42:01 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Sergio Stateri Jr <serginho@alpha.hydra.com.br>
Subject: Re: strange problem...
Message-Id: <Pine.GSO.3.96.970630183631.19121k-100000@kelly.teleport.com>
On 30 Jun 1997, Sergio Stateri Jr wrote:
> Hi! I did a script that send e-mails for everybody in a List...The problem
> is that when I put :
>
> $from = "teste@teste.com";
>
> Everything all right
If that code puts an e-mail address into $from, you must be using a
version of Perl from a long time ago. You should write it this way.
$from = 'teste@teste.com';
> But, I need to put the original sender, and if I put :
>
> $from = $email;
>
> ($email variable is the email address of sender, I take it from a file,
> per example, it'd be teste@teste.com). In the last case, the SMTP server
> return me :
>
> ERROR: Mail command failed sending:
> MAIL FROM:<teste@teste.com>
>
> 553 Invalid address syntax
Well, this looks like a disagreement with the mail system, rather than a
problem with Perl. But maybe when you read that address from a file, you
didn't chomp it to remove a trailing newline, or there's something else
wrong with it.
If you want, you could use code like this to see what the exact text value
of $from is.
print "The value of \$from is '$from', which is ",
unpack('H*', $from), " in hex\n";
Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Mon, 30 Jun 1997 20:09:34 -0500
From: atspublic@bigfoot.com (Andrew Starr)
Subject: Re: test
Message-Id: <atspublic-ya02408000R3006972009340001@news.qni.com>
In article <33B8297C.AE0@fcs.netguard.net>, "D.Burdick"
<burdick@fcs.netguard.net> wrote:
> test
See comp.test, alt.test, soc.test, etc. (but NOT non-test newsgroups) for
test purposes.
Put the word "ignore" in the subject line or body of message to avoid
getting 15-20 e-mails from 'bots around the world confirming receipt of
post on their news server. But if you really wish to test, then don't use
"ignore," as seeing post from your server only means it made it as far as
your server.
-Andrew
--
Andrew Starr <mailto:atspublic@bigfoot.com>
http://www.amherst.edu/~atstarr/eudora has my unoff. Eudora Site
http://www.amherst.edu/~atstarr/eudora/faq.html by Hank Zimmerman
I have no connection to Qualcomm other than being a happy customer!
If I am answering a question: please post followup questions to the
newsgroup as well as mailing me a copy. For new questions, please just post
to the newsgroup. Thank you.
------------------------------
Date: 1 Jul 1997 04:42:36 GMT
From: t95129ku@sfc.keio.ac.jp (o-su ken'ichi )
Subject: TimeSorting
Message-Id: <5pa1rs$jne$1@news.sfc.keio.ac.jp>
Hello, I hope you are fine.;-)
I'm thinking over how can I sort the time.
Like :
$inputTime="97/06/30/13:25:10"; # year/month/day/hour:minute:second
@time=(97/06/28/13:25:10, 97/06/29/13:25:10, 97/06/30/13:25:10,
97/07/01/13:25:10, 97/07/01/14:25:10);
foreach(@time){
####time sorting algorithm
if($_ <= $inputTime){
print $_;
}
}
This means I have to translate
the time parameter(year/month/day/hour:minute:second) into simple integer,
and sort the rusult.
HOW DO I TRANSLATE TIME INTO INTEGER NUMBER?
Thank you very much in advance!
>From Tokyo,
Ken'ichi Unnai
t95129ku@sfc.keio.ac.jp
------------------------------
Date: Tue, 01 Jul 1997 11:15:14 +1000
From: Wayne Blick <wayne@cta-challenge.com.au>
Subject: Re: Zombie processes under system load
Message-Id: <33B85A22.67CC@cta-challenge.com.au>
Thanks Randal,
> The SIGCHLD "stack" is one-bit deep. If two kids go away at precisely
> the same moment, you get only one call to your subroutine. When some
> mutters "UNIX signals are unreliable", this is precisely what they are
> pointing at: it's just one bit! That means the second kid is just
> gonna hang around, to get picked up when the *third* kid dies and the
> second SIGCHLD is handled.
>
> You need to wait for potentially multiple kids on each SIGCHLD.
> Extrapolating from perlipc(1) and perlfunc(1), the proper reaper is:
>
> use POSIX ":sys_wait_h";
>
> sub REAPER {
> {
> my $kid = waitpid(-1, WNOHANG);
> redo if $kid != -1;
> }
> }
That worked fine. The only thing stopping it now is a segmentation
fault.
Don't the Perl libraries like being interrupted?
Wayne Blick
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 688
*************************************