[11662] in Perl-Users-Digest
Perl-Users Digest, Issue: 5262 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 30 20:03:56 1999
Date: Tue, 30 Mar 99 17:00:20 -0800
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, 30 Mar 1999 Volume: 8 Number: 5262
Today's topics:
Re: 8.3 problem / win32 perl pl2bat trickito@my-dejanews.com
Re: changing to numeric month (Abigail)
Re: changing to numeric month (Larry Rosler)
Re: Comment controls (Larry Rosler)
Re: foreach loop works, for loop not (Larry Rosler)
Re: foreach loop works, for loop not <wmooney@voicenet.com>
Re: foreach loop works, for loop not (Larry Rosler)
Re: Graphics in Perl link@ipass.net
help joining lines <hojo@i-tel.com>
Re: help joining lines <cassell@mail.cor.epa.gov>
HELP: Overwriting data within a file (Mario D'Alessio)
Re: how to find local system IP address in Perl <mtsprd@carol.net>
How to use set uid in Perl? <fuchin@mail.nwos.lucent.com>
New to perl: why doesnt this work? <umwattsr@cc.umanitoba.ca>
Re: New to perl: why doesnt this work? (Jordan I. K. McClure)
Re: New to perl: why doesnt this work? (Mark Maurer)
Re: New to perl: why doesnt this work? <gregm@well.com>
Re: One liner to remove the nth occurrence <uri@home.sysarch.com>
Re: One liner to remove the nth occurrence <uri@home.sysarch.com>
Re: Perl with Access DB <greg2@surfaid.org>
Re: Problems writing to a file <rick.delaney@home.com>
Regular expression bug? (Sean McAfee)
Re: Regular expression bug? (Ilya Zakharevich)
Suppressing output from an externally run program... (Jim Matzdorff)
Re: Suppressing output from an externally run program.. (Darren Greer)
Re: Syntax error in embedded foreach loops <cassell@mail.cor.epa.gov>
Trouble with DBD-Oracle-0.46 (Darren Greer)
Re: use strict senthilr@email.com
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 31 Mar 1999 00:08:36 GMT
From: trickito@my-dejanews.com
Subject: Re: 8.3 problem / win32 perl pl2bat
Message-Id: <7drp1u$gf5$1@nnrp1.dejanews.com>
nope, the exact same path info is passed with cmd.exe.
In article <9GWL2.6421$6W3.10603261@firenze.visi.net>,
"scott nelson" <srnels@facstaff.wm.edu> wrote:
> Try using .cmd as the extension, rather than .bat. The 16-bit dos command
> shell that interprets .bat files is command.com. the 32-bit command shell
> that reads .cmd files is cmd.exe.
>
> Scott Nelson
> College of William and Mary
>
> <rupert@no.spam.leeds.ac.uk> wrote in message news:36F2D8E9.3B0F@no.spam...
> > > the problem is that the path info on the file that perl 'recieves' is
> > > 8.3 (in other words /interf~1/blahbl~1/...). My local machine as well
> > > as the target machine both run the newest versions of dos and don't
> > > normally constrain me to 8.3 directory names. Is it the fact that
> > > i'm running it as a batch file? why is this happening? anyone know
> > > a work-around???
> >
> > Please don't take this as an endorsement for NT.
> >
> > That various operating systems differ in what they regard as
> > good filenames is one of the more obvious problems when writing
> > cross-platform scripts or tools.
> >
> > I think that you need to get access to the way that your OS
> > encodes the real name into the short name that the directory
> > structure understands. Maybe NT has a means to do this for
> > you. There are numerous NT FAQ sheets on the web. If not, you
> > will perhaps have to roll your own. Maybe the Microsoft
> > documentation will help you.
> >
> > One alternative, which I have used successfully is to encode
> > the files, the filenames, and the directory structure in a
> > tar or ZIP file, whose name can be expressed in those characters
> > which the OSes can handle correctly, you can then untar or unzip
> > at your end and re-gain the correct names.
> >
> > Ben.
>
>
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 30 Mar 1999 23:54:27 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: changing to numeric month
Message-Id: <7dro7j$85t$1@client2.news.psi.net>
Uri Guttman (uri@home.sysarch.com) wrote on MMXXXVII September MCMXCIII
in <URL:news:x7r9q6wvj5.fsf@home.sysarch.com>:
## >>>>> "JS" == John Stanley <stanley@skyking.OCE.ORST.EDU> writes:
##
## JS> In article <37021c27.10918169@news.bmc.com>,
## JS> Christian M. Aranda <christianarandaOUT@OUTyahoo.com> wrote:
## >> I wrote a small function which changes the written month (Jan Feb Mar,
## >> etc.) to it's corresponding number (1 2 3, etc.). Here is the
## >> function:
## >>
## >> I am looking to improve this code because there must be a better way
## >> to do this (perhaps a foreach, but I'm not sure how to go about it).
## >> Commence the shredding!! All suggestions are appreciated!
##
## JS> When you think "I want to look something up by what it contains", think
## JS> "associative array".
##
## JS> $gmonth = "Dec";
## JS> %months = qw(Jan 0 Feb 1 Mar 2 Apr 3 May 4 Jun 5 Jul 6 Aug 7 Sep 8 Oct 9
## JS> Nov 10 Dec 11);
##
## JS> print "month number is " . $months{$gmonth} . "\n";
##
## ugly init!
##
## hash slices to the rescue!
##
## @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
##
## @month2num{ @months } = 0 .. $#months ;
##
## print "month number is " . $months{$gmonth} . "\n";
Uhm, that doesn't quite work. You probably mean
print "month number is " . (1 + $months2num{$gmonth}) . "\n";
Or:
$i = 0;
%months = map {$_ => ++ $i}
qw /Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/;
print "month number is $months{$gmonth}\n";
Abigail
--
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$r=-2449231+gm_julian_day+time);do{until($r<$#r){$_.=$r[$#r];$r-=$#r}for(;
!$r[--$#r];){}}while$r;$,="\x20";print+$_=>September=>MCMXCIII=>()'
------------------------------
Date: Tue, 30 Mar 1999 16:39:24 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: changing to numeric month
Message-Id: <MPG.116b0e948ed0639b9897f4@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <x7oglawplk.fsf@home.sysarch.com> on 30 Mar 1999 17:59:51 -
0500, Uri Guttman <uri@home.sysarch.com> says...
> >>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:
> LR> In article <x7r9q6wvj5.fsf@home.sysarch.com> on 30 Mar 1999 15:51:42 -
> LR> 0500, Uri Guttman <uri@home.sysarch.com> says...
> >> hash slices to the rescue!
> >>
> >> @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
> >>
> >> @month2num{ @months } = 0 .. $#months ;
> LR> Indeed, that is a cleaner and somewhat faster initialization. But the
> LR> initialization of the hash overwhelms the time for the lookup. Unless
> LR> the lookup is taking place lots of times and the initialization is done
> LR> once only, the simple 'index' solution that I posted it a clear winner.
>
> true. the original poster never mentioned the need for speed. he was
> stumped on how to do it in general. also the hash idea is good to
> promote as it handle variable length strings, dynamically created arrays
> (that could be done with the index too),
The subtext of my submission was that hashes are over-promoted. Their
value is only for multiple lookups. For a simple lookup, why bother to
create an elaborate data structure? The simple 'for' loop over a list
of possible matches, with 'last' on match, is faster than the best hash
lookup. (See the expanded benchmark below.) The problem with the for'
loop is "Too many perl-ops, Herr Mozart!", which the 'index' formulation
takes care of nicely.
>
> where is $_[0] coming from in the hash subs? i don't see any real month
> names being passed around there.
Holdover from a previous test with the code in a subroutine. It doesn't
matter much for a hash, as the success or failure time is about the
same.
> also try using a list of '' month names for the init. i think it would
> be a lot faster than the runtime call of split used by qw. (that is
> changed to a compile time call of split in some new version or perl).
Not *this* version (ActivePerl 5.005_02 build 509). You are certainly
right about that. I noted it here recently. Use of 'qw' in a loop
considered harmful to speed.
> also you should test the failure mode of the hashes (unless $_[0] WAS
> failure mode).
None of the benchmarks tests for failure. That was noted in my original
post.
#!/usr/gm/bin/perl -w
use Benchmark;
$months = 'JanFebMarAprMayJunJulAugSepOctNovDec';
@months = $months =~ /(...)/g;
@months{@months} = 0 .. 11;
timethese(1 << (shift || 0), {
For1 => sub { my $i = -1;
'Jan' eq $_ and return ++$i for @months },
For2 => sub { my $i = -1;
'foo' eq $_ and return ++$i for @months },
Hash1 => sub { $months{'Jan'} },
Hash2 => sub { my %months = qw(Jan 0 Feb 1 Mar 2 Apr 3 May 4
Jun 5 Jul 6 Aug 7 Sep 8 Oct 9 Nov 10 Dec 11);
$months{'Jan'} },
Hash3 => sub { my %months; @months{qw(Jan Feb Mar Apr May
Jun Jul Aug Sep Oct Nov Dec)} = 0 .. 11;
$months{'Jan'} },
Hash4 => sub { my %months; @months{@months} = 0 .. 11;
$months{'Jan'} },
Index1 => sub { index($months, 'Jan')/3 },
Index2 => sub { index($months, 'foo')/3 },
Index3 => sub { index($months, 'foo') },
});
__END__
Benchmark: timing 131072 iterations of For1, For2, Hash1, Hash2,
Hash3, Hash4, Index1, Index2, Index3...
For1: 3 wallclock secs ( 1.94 usr + 0.00 sys = 1.94 CPU)
For2: 8 wallclock secs ( 7.06 usr + 0.00 sys = 7.06 CPU)
Hash1: 1 wallclock secs ( 0.66 usr + 0.00 sys = 0.66 CPU)
Hash2: 22 wallclock secs (21.59 usr + 0.00 sys = 21.59 CPU)
Hash3: 16 wallclock secs (16.59 usr + 0.00 sys = 16.59 CPU)
Hash4: 9 wallclock secs ( 8.58 usr + 0.00 sys = 8.58 CPU)
Index1: 0 wallclock secs ( 0.91 usr + 0.00 sys = 0.91 CPU)
Index2: 2 wallclock secs ( 1.01 usr + 0.00 sys = 1.01 CPU)
Index3: 0 wallclock secs ( 0.70 usr + 0.00 sys = 0.70 CPU)
> interesting that a plain hash is still faster than a short index and
> /. i bet the / kills the time for index as it takes 2 perl ops while a
> hash is one.
Yes (see Index3). But it's the hash initialization that really kills.
--
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 30 Mar 1999 15:09:54 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Comment controls
Message-Id: <MPG.116af99ef572f4a19897f3@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <37013FB0.2E9B279F@agcs.com> on Tue, 30 Mar 1999 14:18:40 -
0700, Andy Cantrell <cantrela@agcs.com> says...
...
> This example code will indicate an error in line 51.
> #!/usr/local/bin/perl
> # line 50
> $str = 'error line, no semicolan'
> print "$str\n";
>
> I haven't poured over the camel book looking for this.
> The index has a few things to say about #'s but I guess
> they didn't hit the right note with me and so I turned
> here. Any feedback?
Look in perlsyn, under the heading "Plain Old Comments (Not!)"
--
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 30 Mar 1999 14:57:23 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: foreach loop works, for loop not
Message-Id: <MPG.116af6aa7e92ece19897f2@nntp.hpl.hp.com>
In article <7drfvi$f4$1@gellyfish.btinternet.com> on 30 Mar 1999
21:33:38 -0000, Jonathan Stowe <gellyfish@gellyfish.com> says...
...
> for $i ( 1 ... 3 )
> {
> # blah
> }
Or, in this case (to conserve the world's limited supply of dots, of
which I wasted three above myself), more usually written as:
for $i ( 1 .. 3 )
{
# blah
}
--
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 30 Mar 1999 18:08:30 -0500
From: Bill Mooney <wmooney@voicenet.com>
Subject: Re: foreach loop works, for loop not
Message-Id: <Pine.GSO.3.96.990330180640.11017A-100000@unix01>
On 30 Mar 1999, David Efflandt wrote:
> Someone was trying to use a perl script I have to test if a bunch of
> webservers were online. The subroutine works. The part giving trouble
> was trying to iterate through a bunch of IP URL's with a 'for' loop. I
> haven't figured out why the script hangs after the first iteration. I
> even tried a different intermediate variable in case the $i was being
> affected by its use in string context, but that did not work either.
> Using a list with a 'foreach' instead works fine.
>
> Following is just a brief example.
>
> Anyone know why this hangs after the first iteration? Subroutine is being
> executed once, but then something hangs and the second $url never prints:
>
> for ($i=1; $i<=3; $i++) {
> $url = 'http://192.168.1.' . $i;
> print "$url\n";
> &wwwtest($url);
> )
Could it be that your closing your for loop for a paren instead of a
bracket?
-Bill
------------------------------
Date: Tue, 30 Mar 1999 16:43:26 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: foreach loop works, for loop not
Message-Id: <MPG.116b0f867248aa409897f5@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <Pine.GSO.3.96.990330180640.11017A-100000@unix01> on Tue, 30
Mar 1999 18:08:30 -0500, Bill Mooney <wmooney@voicenet.com> says...
> On 30 Mar 1999, David Efflandt wrote:
...
> > Anyone know why this hangs after the first iteration? Subroutine is being
> > executed once, but then something hangs and the second $url never prints:
> >
> > for ($i=1; $i<=3; $i++) {
> > $url = 'http://192.168.1.' . $i;
> > print "$url\n";
> > &wwwtest($url);
> > )
>
> Could it be that your closing your for loop for a paren instead of a
> bracket?
Then it wouldn't be executed even once, would it? (Syntax error, you
know.)
--
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 30 Mar 1999 23:04:50 GMT
From: link@ipass.net
Subject: Re: Graphics in Perl
Message-Id: <7drlac$d75$1@nnrp1.dejanews.com>
> which platform are you using?
> have you looked at CPAN?
>
> There are these modules: GD (draws to gifs/xbm, not directly
> to the screen ),
> OpenGL.
>
> GD is available on Un*x and Win32.
>
> Fancy porting the OpenGL to Win32, as it isn't on Activestate yet, is
> anybody porting it at the moment?
>
> Do you do any (spit) DirectX , fancy writing a C extention to perl as an
> exersize?!
I'm using the current Activestate build. I want the graphics written
directly to the screen like C's BGI library. I'm no good with C at the
moment, is there anyway I can do this through writing a module? Anyway, all
I need is the simple putpixel command and perhaps some graphics
initialization. I found some way to do it in Win32::GUI, unfortunately I
can't find any documentation on it and I can't do anything to test its speed
(much less change pen color)...
DirectX fancy writing to C... God, I wish. Thanks! -David
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Wed, 31 Mar 1999 00:20:19 GMT
From: hojo <hojo@i-tel.com>
Subject: help joining lines
Message-Id: <7drpnr$h03$1@nnrp1.dejanews.com>
my problem: I need to search for a particular pattern and then join the line
with that pattern to the line above it. the pattern is the beginning of the
line and two spaces /^ /. Here is my script, but I am not sure how to check
for the pattern:
#!/usr/bin/perl -wT
use strict
my @inline;
my @outline;
open (RAWCCC,"cap2") || die "Something went wrong\n";
@inline = <RAWCCC>;
close RAWCCC || die "Something else went wrong\n";
foreach $i (0 .. $#inline){
if (/^ /) { #line 11
@outline = $inline[$i-1].$inline[$i];
}
}
print "@inline";
perl reports the following as it goes throught the loop:
Use of uninitialized value at ./ccs line 11.
=-=-=-=-=-=-=-=-=-=
David Hajoglou
Sys. Admin., Abbreviator
=-=-=-=-=-=-=-=-=-=
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Tue, 30 Mar 1999 16:46:28 -0800
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: help joining lines
Message-Id: <37017064.CFFC4544@mail.cor.epa.gov>
hojo wrote:
> my problem: I need to search for a particular pattern and then join the line
> with that pattern to the line above it. the pattern is the beginning of the
> line and two spaces /^ /. Here is my script, but I am not sure how to check
> for the pattern:
>
> #!/usr/bin/perl -wT
> use strict
All right!! -w and -T and 'use strict'! Nice work!
> my @inline;
> my @outline;
> open (RAWCCC,"cap2") || die "Something went wrong\n";
> @inline = <RAWCCC>;
> close RAWCCC || die "Something else went wrong\n";
And you checked your open() and close() too! Nice going.
>
> foreach $i (0 .. $#inline){
> if (/^ /) { #line 11
Oh. You want to match against $i here.
if ($i =~ /^ /) {
> @outline = $inline[$i-1].$inline[$i];
> }
> }
> print "@inline";
>
> perl reports the following as it goes throught the loop:
> Use of uninitialized value at ./ccs line 11.
Yep. And it was right, too.
HTH,
David
--
David L. Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: 31 Mar 99 00:08:38 GMT
From: dalessio@manatee.cig.mot.com (Mario D'Alessio)
Subject: HELP: Overwriting data within a file
Message-Id: <dalessio.922838918@manatee>
Keywords: HELP: Overwriting data within a file
I'm attempting to write a script which will overwrite
data within a file. Here's a simplified code example:
# Open file for read-write
open ( FILEHANDLE, "+< $file" ) or die "cannot open $file";
# Seek to a position within the file
seek ( FILEHANDLE, $filesize - $tag_indicator_length - $tag_length, 0 );
# Overwrite the existing data with new data
print FILEHANDLE, $new_data;
close FILEHANDLE
I threw in some "tell FILEHANDLE" to watch the current file
position. It SEEKs correctly to the proper position, but the print
statement always appends rather then writing at the current file
position.
The Programming Perl book states "Note that the opposite of read
is simply a print...", so I assumed that if I can read from the
newly SEEKed position, I can write there. If I remember correctly,
the op system keeps a separate read file pointer and a write file
pointer, right? So, how do I get Perl to move the write file pointer?
Any help appreciated. Thanks.
Mario
PS: You'll notice that I use the file size in my "seek" call above,
instead of doing something like this:
seek( FILEHANDLE, $tag_indicator_length + $tag_length, 2 );
Seeking to the WHENCE of 2 doesn't work for me. Any ideas?
**********************************************************
* ____ ____ ___ *
* __/\__ Mario D'Alessio ((oo)) //oo\\ /o o\ *
* \RUSH/ dalessio@cig.mot.com \__/ \__/ \_O_/ *
* |/\| Work: (847) 632-2323 Moe Larry Curly *
* 9am to 6pm Central Time *
* *
**********************************************************
------------------------------
Date: Tue, 30 Mar 1999 18:57:01 -0500
From: "Ken Bauman" <mtsprd@carol.net>
Subject: Re: how to find local system IP address in Perl
Message-Id: <bzdM2.404$H5.18360@news3.ispnews.com>
Greg Bacon wrote in message
<7drjju$8gk$1@info2.uah.edu>...
>Did you try getting your nodename from
POSIX::uname?
Well, I just tried that and got an
error: this function not implemented on
this architecture. :( Yeah, I know,
it's Win95, get a real OS.
Unfortunately I don't have a choice
right now. But ...
Good news, bad news, and more good news.
Faq 9 does have the answer if you
correct the errors (at least in my copy
of the Faq). The Faq said to do..
use Socket;
use Sys::Hostname;
my $host = hostname();
my $addr =
inet_ntoa(scalar(gethostbyname($name))
|| 'localhost');
Nope, that doesn't work. I changed it
to ..
use Socket;
use Sys::Hostname;
my $host = hostname() ||
'localhost';
my $addr =
inet_ntoa(scalar(gethostbyname($host)));
That worked!! :) Now the bad news.
I have two network cards, and this
method only gets the first card's
address. Turns out I really need the
other one. Finally took another look at
gethostbyname() to see it really returns
a list of stuff, including all?
addresses. So I did..
use Socket;
use Sys::Hostname;
my $host = hostname() ||
'localhost';
my ($name, $aliases, $addrtype,
$length, @addrs) = gethostbyname($host);
my $num_addrs = @addrs;
for (my $i = 0; $i < $num_addrs;
$i++)
{
print "\nAddress $i is: ",
inet_ntoa($addrs[$i]);
}
Voila! That got'em all.
Thanks for your help, Greg.
Ken Bauman
------------------------------
Date: Tue, 30 Mar 1999 18:38:49 -0500
From: Fu Chin Liu <fuchin@mail.nwos.lucent.com>
Subject: How to use set uid in Perl?
Message-Id: <37016089.C7F968CD@mail.nwos.lucent.com>
Does anyone know how to set uid in Perl?
e.g. How can I set the user id to root while the perl process is ran by
other uid and get the permission to change the permission of the files
which are owned by root.
Then uid can be changed back to continue running the rest of the script?
Thanks
------------------------------
Date: Tue, 30 Mar 1999 17:36:20 -0600
From: "no1buTmE" <umwattsr@cc.umanitoba.ca>
Subject: New to perl: why doesnt this work?
Message-Id: <7drmql$ses$1@canopus.cc.umanitoba.ca>
Hello,
I am trying to teach myself Perl and I an having a hard time even getting
started. I copied this example from a text line for line:
#!/usr/local/bin/perl
print "content-type: text/html";
print "<html><head><title>Town Crier</title></head>\n";
print "<body bgcolor=navy text=white>\n";
print "<h1><center>Hello World</center></h1>\n";
print "<h2> It's all good\n";
print "and all's well.\n";
print "</h2></body></html>\n";
and I cant get it to go. I have:
Changed the permissions using chmod 755 hello.cgi ( I have also tried 775
and 777: no dif)
Changed the permissions on my cgi-bin directory
Confirmed the correct location of the perl interpretor
I think that I have left enough white space after the content type line;
when I test it at the UNIX shell using
perl -p hello.cgi
It spits it back with no problems and when I call it from my browser it
prints everything.
You can try it:
http://home.cc.umanitoba.ca/~umwattsr/cgi-bin/hello.cgi
I dont think there are any problems with the program as I copied it exactly,
and I know a little C++ and quite a bit of HTML; I know the importance of
correct syntax. My weakness is UNIX, I just don't know it. Other that how
to get around and do basic stuff anyway. If you know what Im doing wrong I
would really appreciate your help.
You can email me at
mogwai@nospam.pangea.ca
remove the nospam part, of course :)
Thank you very much.
------------------------------
Date: 30 Mar 1999 23:39:05 GMT
From: jimcclur@ews.uiuc.edu (Jordan I. K. McClure)
Subject: Re: New to perl: why doesnt this work?
Message-Id: <7drnap$fk7$1@vixen.cso.uiuc.edu>
no1buTmE (umwattsr@cc.umanitoba.ca) wrote:
: Hello,
: I am trying to teach myself Perl and I an having a hard time even getting
: started. I copied this example from a text line for line:
:
: #!/usr/local/bin/perl
:
: print "content-type: text/html";
One problem is this should be:
print "content-type: text/html\n\n";
jordan
--
If at first you don't succeed, skydiving is not for you.
------------------------------
Date: 30 Mar 1999 23:57:28 GMT
From: mwmaurer@pace1.cts.mtu.edu (Mark Maurer)
Subject: Re: New to perl: why doesnt this work?
Message-Id: <slrn7g2pfk.eor.mwmaurer@pace1.cts.mtu.edu>
In article <7drmql$ses$1@canopus.cc.umanitoba.ca>, no1buTmE wrote:
>Hello,
>I am trying to teach myself Perl and I an having a hard time even getting
>started. I copied this example from a text line for line:
>
>#!/usr/local/bin/perl
>
>print "content-type: text/html";
>
>print "<html><head><title>Town Crier</title></head>\n";
>print "<body bgcolor=navy text=white>\n";
>print "<h1><center>Hello World</center></h1>\n";
>print "<h2> It's all good\n";
>print "and all's well.\n";
>print "</h2></body></html>\n";
>
>I think that I have left enough white space after the content type line;
Bzzt! No, you didn't. Try this line:
print "Content-type: text/html\r\n\r\n"
along those lines, you don't really need the \r's, but I always put them in
anyways.
hope that helps...
--
Mark Maurer markm@dct.com Programmer, DCT Technologies
mwmaurer@mtu.edu Senior, Michigan Technological University
"During my service in the United States Congress, I took the initiative in
creating the Internet." -- Al Gore
------------------------------
Date: Tue, 30 Mar 1999 16:22:43 -0800
From: Greg McCann <gregm@well.com>
Subject: Re: New to perl: why doesnt this work?
Message-Id: <37016AD2.4DE39E0F@well.com>
As someone else mentioned, it should indeed be...
print "content-type: text/html\n\n";
However, after looking at your URL, your problem appears to be more serious than
that.
Your web server is serving your cgi script as text - not executing it. Is this
the first time you have tried to run cgi on this server?
Although the exact method depends on the server you are using, you have to do
something in your server configuration to tell it that all scripts with a
certain extension (or all scripts in a certain directory) are to be *executed*,
not just passed on as text.
Greg
no1buTmE wrote:
> Hello,
> I am trying to teach myself Perl and I an having a hard time even getting
> started. I copied this example from a text line for line:
>
> #!/usr/local/bin/perl
>
> print "content-type: text/html";
>
> print "<html><head><title>Town Crier</title></head>\n";
> print "<body bgcolor=navy text=white>\n";
> print "<h1><center>Hello World</center></h1>\n";
> print "<h2> It's all good\n";
> print "and all's well.\n";
> print "</h2></body></html>\n";
>
> and I cant get it to go. I have:
>
> Changed the permissions using chmod 755 hello.cgi ( I have also tried 775
> and 777: no dif)
> Changed the permissions on my cgi-bin directory
> Confirmed the correct location of the perl interpretor
>
> I think that I have left enough white space after the content type line;
> when I test it at the UNIX shell using
> perl -p hello.cgi
> It spits it back with no problems and when I call it from my browser it
> prints everything.
> You can try it:
>
> http://home.cc.umanitoba.ca/~umwattsr/cgi-bin/hello.cgi
>
> I dont think there are any problems with the program as I copied it exactly,
> and I know a little C++ and quite a bit of HTML; I know the importance of
> correct syntax. My weakness is UNIX, I just don't know it. Other that how
> to get around and do basic stuff anyway. If you know what Im doing wrong I
> would really appreciate your help.
>
> You can email me at
> mogwai@nospam.pangea.ca
>
> remove the nospam part, of course :)
>
> Thank you very much.
--
======================
Gregory McCann
http://www.calypteanna.com
"Be kind, for everyone you meet is fighting a great battle." Saint Philo of
Alexandria
------------------------------
Date: 30 Mar 1999 18:05:03 -0500
From: Uri Guttman <uri@home.sysarch.com>
Subject: Re: One liner to remove the nth occurrence
Message-Id: <x7k8vywpcv.fsf@home.sysarch.com>
>>>>> "GB" == Greg Bacon <gbacon@itsc.uah.edu> writes:
GB> In article <7drg4d$8h7$1@nnrp1.dejanews.com>,
GB> dboude@my-dejanews.com writes:
GB> : If anyone is able, could you help me with the proper RE that will
GB> : remove the 3rd occurrence of a double quote within a string?
GB> Well, I don't know about proper regular expression, but this works:
GB> my $hit = 0;
GB> $str =~ s/"/++$hit == 3 ? '' : '"'/ge;
well i do!
perl -pe 's/(".*?".*?)"/$1/'
this seems to work fine on my few test lines. i haven't thoroughly
tested it but it looks good to me.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: 30 Mar 1999 18:11:56 -0500
From: Uri Guttman <uri@home.sysarch.com>
Subject: Re: One liner to remove the nth occurrence
Message-Id: <x7hfr2wp1f.fsf@home.sysarch.com>
>>>>> "UG" == Uri Guttman <uri@home.sysarch.com> writes:
UG> perl -pe 's/(".*?".*?)"/$1/'
UG> this seems to work fine on my few test lines. i haven't thoroughly
UG> tested it but it looks good to me.
here's another one i just created. this has the advantage of the count
being visible in the {} modifier. then you could make that value a
variable.
perl -pe 's/((:?".*?){2})"/$1/'
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Wed, 31 Mar 1999 00:06:34 +0100
From: Greg Griffiths <greg2@surfaid.org>
To: Mark Choi <choic@cs.man.ac.uk>
Subject: Re: Perl with Access DB
Message-Id: <370158FA.D681BC0A@surfaid.org>
as mentioned before, your best choice is ODBC.pm from
http://www.roth.net/odbc/ although DBI is another good option if you
want cross platform support.
Mark Choi wrote:
>
> Hi mates
>
> Do you know how to retrieve data from an Access DB using Perl? Anyone
> got a script about it??
>
> Thank for for your time.
>
> Mark
------------------------------
Date: Tue, 30 Mar 1999 23:17:20 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Problems writing to a file
Message-Id: <37015D7A.7631B563@home.com>
[posted & mailed]
brackett@pobox.com wrote:
>
> Should be straightforward, right? Well, it's not working -- and what's
> worse, it works intermittently. FWIW, I'm running under Windows.
^^^^^^^^^^^^^^^^^^^^^^^
A sure sign of connection problems.
>
> use LWP::Simple;
> use URI::URL;
> use strict -w;
>
> open (DATA,">>newdata")
> or die "Couldn't open floatdata for writing: $!\n";
Good error checking.
> open (INDICES,"data.txt")
> or die "Couldn't open data.txt for reading: $!\n";
Good.
> while (defined ($main=<INDICES>)) {
> chomp ($main);
> $first = substr($main,0,1);
> my $url = url("http://www.foobar.com/$first/$main.html");
> my $content = get($url);
Bad. You should check if get() succeeded. It returns undef if not.
perldoc LWP::Simple
--
Rick Delaney
rick.delaney@home.com
------------------------------
Date: Tue, 30 Mar 1999 23:38:02 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Regular expression bug?
Message-Id: <ufdM2.473$9Y5.2655248@news.itd.umich.edu>
$str = " DELETE";
@match = $str =~ / +(\S)? +DELETE/;
print "@match\n";
This prints "D", indicating that the "D" in "DELETE" is consumed twice by
the regular expression.
Rewriting the capturing parentheses as (\S?) or (\S)?? gives the behavior I
would expect.
--
Sean McAfee mcafee@umich.edu
print eval eval eval eval eval eval eval eval eval eval eval eval eval eval
q!q@q#q$q%q^q&q*q-q=q+q|q~q:q? Just Another Perl Hacker ?:~|+=-*&^%$#@!
------------------------------
Date: 31 Mar 1999 00:11:48 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Regular expression bug?
Message-Id: <7drp84$gvp$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Sean McAfee
<mcafee@waits.facilities.med.umich.edu>],
who wrote in article <ufdM2.473$9Y5.2655248@news.itd.umich.edu>:
> $str = " DELETE";
> @match = $str =~ / +(\S)? +DELETE/;
> print "@match\n";
>
> This prints "D", indicating that the "D" in "DELETE" is consumed twice by
> the regular expression.
>
> Rewriting the capturing parentheses as (\S?) or (\S)?? gives the behavior I
> would expect.
This is a known bug with backtracking. (Reported by Philip Hazel some
time ago.)
I'm still thinking how to redo backtracking in a more formal manner
(currently it is a hodgepodge of different tricks, I have no idea why
these tricks happen to work in so many cases).
Sorry for inconveniences,
Ilya
------------------------------
Date: 30 Mar 1999 16:26:56 -0800
From: syran@best.com (Jim Matzdorff)
Subject: Suppressing output from an externally run program...
Message-Id: <7drq4g$3l4$1@shell18.ba.best.com>
I was wondering if there was a way of making a system call (that is to
say, run a shell program) in perl and suppressing all output that that
system call (shell program) produces.
For instance, I want to run gdb from perl to, essentially, make
something crash. I don't want any of the output of gdb from appearing
on the console.
I have tried to redirect all output to /dev/null, and have tried to use
back-ticks to slurp up any output, but it doesn't seem to work. Would
this be a case of not being able to do it? (as if...)
Danke in advance,
--jim
--
--
One tequila, two tequila, three tequila, floor.
------------------------------
Date: Wed, 31 Mar 1999 00:47:37 GMT
From: drgreer@qtiworld.com (Darren Greer)
Subject: Re: Suppressing output from an externally run program...
Message-Id: <37017075.335043226@news.qgraph.com>
This is what I use....with success:
system("cmd 1>/dev/null");
Try that...
Darren
On 30 Mar 1999 16:26:56 -0800, syran@best.com (Jim Matzdorff) wrote:
-->I was wondering if there was a way of making a system call (that is to
-->say, run a shell program) in perl and suppressing all output that that
-->system call (shell program) produces.
-->
-->For instance, I want to run gdb from perl to, essentially, make
-->something crash. I don't want any of the output of gdb from appearing
-->on the console.
-->
-->I have tried to redirect all output to /dev/null, and have tried to use
-->back-ticks to slurp up any output, but it doesn't seem to work. Would
-->this be a case of not being able to do it? (as if...)
-->
-->Danke in advance,
-->--jim
-->
-->--
-->--
-->One tequila, two tequila, three tequila, floor.
------------------------------
Date: Tue, 30 Mar 1999 16:30:35 -0800
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: Syntax error in embedded foreach loops
Message-Id: <37016CAB.929E915D@mail.cor.epa.gov>
Gabriel Richards wrote:
> I'm new to Perl.
Very few of us were never in this state. Don't worry about it.
> My code is generating the following syntax errors:
>
> syntax error in file listings.cgi at line 32, next 2 tokens "$i @keywords"
> syntax error in file listings.cgi at line 36, next 2 tokens "}"
> syntax error in file listings.cgi at line 41, next 2 tokens "}"
> syntax error in file listings.cgi at line 47, next token "}"
I suggest that you get in the habit of using the -w flag in all your
programs. It will help. A lot. Also, the perldiag manpage is a great
help in decoding any cryptic error messages. Just type 'perldoc perldiag'
and search for the error of your choice - or use the html version if
you have it.
> The following are the respective lines and some of the context:
I really appreciate your numbering the lines. Not all posters think to.
In fact, not all posters think to post their code either. I think it's
all those commercials from the Psychic Friends Hotline that are to blame.
:-)
> sub getrecords {
> #stuff
> while (<DBASE>) {
> ($id,$keywordstring,$name,$sponsor,$award,$eligibility,$due,
>
> $Contactn,$Contactp,$add1,$add2,$city,$state,$zip,$phone,$email,$web,$info)=
> split("\t", $_);
> @keywords = split (/ /, $keywordstring);
> $counter = 0;
> foreach $i @keywords { #line 32
Bingo! Right where the error message told you to look. foreach is
expecting to find an array inside parens right after $i . And so you
need to fix the next line too.
> foreach $j @request {
> if ($j eq $i) { $counter += 1}
BTW, the C idiom $counter++ lives in Perl too. Try it, you'll like it!
> }
> } #line 36
> if ($counter = $#request + 1) {
> #do stuff
> } #line 41
> }
> } #line 47
These errors I can't track. They may in fact be due to Perl choking
on parsing lines 32 and 33, or they may be due to errors in the parts
you elided.
BTW, it looks like you're trying to do some sort of matching between
elements of @request and elements of @keywords. Take a look at the FAQ
covering "How can I tell whether an array contains a certain element?"
and "How do I compute the ... intersection of two arrays?" They might
help you and speed up your code.
How did I know this was what you wanted? the Psychic Friends Hotline,
of course. You see, they knew I wanted some help... :-)
David
--
David L. Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Wed, 31 Mar 1999 00:13:22 GMT
From: drgreer@qtiworld.com (Darren Greer)
Subject: Trouble with DBD-Oracle-0.46
Message-Id: <370166ca.332568478@news.qgraph.com>
Howdy all.
I recently installed DBD-Oracle-0.46. I also installed DBI, as to
DBD's requirements.
Now here is the problem. If I use the perl executable which was
included with the DBD file, the test.pl program runs fine. That
program cycles through making connections to the database, and a few
other tests.
However, if I use the system install perl executable I get this error:
{
Connecting
to '' (from command line, else uses ORACLE_SID or TWO_TASK -
recommended)
as 'user/userr' (via ORACLE_USERID env var or default - recommend
name/passwd@dbname)
(ORACLE_SID='QTI', TWO_TASK='')
/usr/lib/dld.sl: Unresolved symbol: pthread_mutexattr_default (data)
from blib/arch/auto/DBD/Oracle/Oracle.sl
/usr/lib/dld.sl: Unresolved symbol: pthread_attr_default (data)
from blib/arch/auto/DBD/Oracle/Oracle.sl
/usr/lib/dld.sl: Unresolved module for symbol: sltsrsa (code) from
blib/arch/auto/DBD/Oracle/Oracle.sl
Abort(coredump)
}
Here is the version info for the system installed perl:
5.004_04 built for PA-RISC2.0
Here is the version info for the included perl executable:
5.004_04 built for PA-RISC2.0
Seeing as the versions are both identical, I am at a loss as to what
the problem could be. Any help would be greatly appreciated,
Darren
------------------------------
Date: Tue, 30 Mar 1999 23:50:40 GMT
From: senthilr@email.com
Subject: Re: use strict
Message-Id: <7dro0d$fib$1@nnrp1.dejanews.com>
> The following code
>
> use strict;
> $a = 1;
> print "$a\n";
>
$a is a special global pre-defined. Used for sorting purposes.
Hope it helps,
..Senthil.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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 5262
**************************************