[17134] in Perl-Users-Digest
Perl-Users Digest, Issue: 4546 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 7 06:13:11 2000
Date: Sat, 7 Oct 2000 03:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <970913107-v9-i4546@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 7 Oct 2000 Volume: 9 Number: 4546
Today's topics:
Re: [UPDATE] mod_perl and ActiveState perl (v5.6.0 618) <randy@theory.uwinnipeg.ca>
Re: [UPDATE] mod_perl and ActiveState perl (v5.6.0 618) <jbaker6953@yahoo.com>
Re: [UPDATE] mod_perl and ActiveState perl (v5.6.0 618) <jbaker6953@yahoo.com>
Re: A Print Statement Problem <bwalton@rochester.rr.com>
Re: A Print Statement Problem <bwalton@rochester.rr.com>
ActivePerl 5.6 on NT 4.0/IIS4 not working cbutler@nospaam.cbjd.net
apache web server set up problems running perl cgi scri <wedeking@msa.attmil.ne.jp>
creating (key) index files from text files robbelljr@my-deja.com
Re: creating (key) index files from text files <bwalton@rochester.rr.com>
Different Ways to Obtain a Client`s IP ? <dontmail@me.com>
Re: Different Ways to Obtain a Client`s IP ? <zigouras@mail.med.upenn.edu>
Re: Different Ways to Obtain a Client`s IP ? (Martien Verbruggen)
Re: Formating output to be read in a form. <bart.lateur@skynet.be>
how can I get perl CGI to work with win32 perl and win3 <wedeking@msa.attmil.ne.jp>
Re: how can I get perl CGI to work with win32 perl and <>
Re: How do I get a cgi script to load a url <lr@hpl.hp.com>
how to remove this using subsitute <dsa@dassda.com>
Re: macros (was Re: why it's called a "hash" (and a who (David Combs)
OK - last flock Q <mikecook@cigarpool.com>
Re: OK - last flock Q <mikecook@cigarpool.com>
Re: Parsing improvements <martinschneider8659@my-deja.com>
Re: Parsing improvements <bart.lateur@skynet.be>
Please help on "processing data problem" tvn007@my-deja.com
Re: PP, 3rd ed.??? (Logan Shaw)
Re: Rounding Integers (Logan Shaw)
Re: Rounding Integers <bart.lateur@skynet.be>
Re: STDERR>&STDOUT <anmcguire@ce.mediaone.net>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 6 Oct 2000 23:10:11 -0500
From: "Randy Kobes" <randy@theory.uwinnipeg.ca>
Subject: Re: [UPDATE] mod_perl and ActiveState perl (v5.6.0 618)
Message-Id: <8rm7v9$8ks$1@canopus.cc.umanitoba.ca>
"Jerry Baker" <jbaker6953@yahoo.com> wrote in message
news:39DE833E.C4581F6A@weirdness.com...
> The problem only occurs if Apache is installed as a Windows NT service
> (this is Windows 2000 I'm running). If you start the Apache Service, and
> then stop it, it crashes. If you start Apache from the command line and
> use apache -k shutdown, it does not crash.
Do any of the troubleshooting hints at
http://www.apache.org/docs/win_service.html
help? I assume that your vanilla apache without
mod_perl enabled can be run fine as a service ....
best regards,
randy kobes
------------------------------
Date: Sat, 07 Oct 2000 06:02:37 GMT
From: Jerry Baker <jbaker6953@yahoo.com>
Subject: Re: [UPDATE] mod_perl and ActiveState perl (v5.6.0 618)
Message-Id: <39DEBC7C.1DFEFE7F@weirdness.com>
Randy Kobes wrote:
>
> Do any of the troubleshooting hints at
> http://www.apache.org/docs/win_service.html
> help? I assume that your vanilla apache without
> mod_perl enabled can be run fine as a service ....
>
> best regards,
> randy kobes
I don't understand? I am not having any problems running Apache as a
service sith mod_perl. The only thing is that perl56.dll causes an
access violation in Apache.exe when the service is shutdown. None of the
tips in that page address anything like this.
--
Jerry Baker
PGP Key:
http://pgpkeys.mit.edu:11371/pks/lookup?op=get&search=0x8B9F6300
------------------------------
Date: Sat, 07 Oct 2000 06:15:44 GMT
From: Jerry Baker <jbaker6953@yahoo.com>
Subject: Re: [UPDATE] mod_perl and ActiveState perl (v5.6.0 618)
Message-Id: <39DEBF8F.9A4C8832@weirdness.com>
Jerry Baker wrote:
>
> Randy Kobes wrote:
> >
> > Do any of the troubleshooting hints at
> > http://www.apache.org/docs/win_service.html
> > help? I assume that your vanilla apache without
> > mod_perl enabled can be run fine as a service ....
> >
> > best regards,
> > randy kobes
>
> I don't understand? I am not having any problems running Apache as a
> service sith mod_perl. The only thing is that perl56.dll causes an
> access violation in Apache.exe when the service is shutdown. None of the
> tips in that page address anything like this.
>
> --
> Jerry Baker
I should have mentioned that my configuration already includes all of
those suggestions. The crash still happens.
--
Jerry Baker
PGP Key:
http://pgpkeys.mit.edu:11371/pks/lookup?op=get&search=0x8B9F6300
------------------------------
Date: Sat, 07 Oct 2000 05:41:26 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: A Print Statement Problem
Message-Id: <39DEB789.4A1EFCE9@rochester.rr.com>
Michael wrote:
>
> Hello,
> This is my first posting to this group. As a relative beginner to
> Cgi/Perl I am trying find out more about the rules of HTML 'Here' documents
> as mine seem to be going wrong. I have produced HTML documents with CGI
> before but now I am trying to insert more complicated HTML it doesnt work.
>
> What are the basic things I should be looking out for that could stop the
> script?
> ie, symbols or white spaces.
>
> In the following script ignore the perl but please look at the head of the
> HTML as this seems
> to be stopping the script from working. If I remove most of the Javascript
> it works just fine....
> should I be using a print statement on everyline instead?
> Any comments would be gladly received!
...
> Michael
...
Couple of things, Michael:
1. Don't post voluminous code. Two or three lines that illustrate your
problem are sufficient, like:
print <<END;
this line has an @array in it, and @array doesn't exist, so it will bomb
END
If you can't find a few lines right off, keep looking -- the problem
must be in the lines you didn't include.
2. You should
use CGI;
for this stuff. It is much easier, much better and much less broken
than the parse-it-yourself stuff. See:
perldoc CGI
3. Your problem is the including of unescaped @ characters in your
here-document. If you put a \ in front of them, then it (or at least
the here-document bit) will work. If you actually had a arrays existing
with names specified, they would have been interpolated in. See:
perldoc "<<HERE"
or
perldoc '<<HERE'
(depending on the quoting method your OS's shell uses).
--
Bob Walton
------------------------------
Date: Sat, 07 Oct 2000 05:46:59 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: A Print Statement Problem
Message-Id: <39DEB8D6.6DF4D2F5@rochester.rr.com>
Bob Walton wrote:
...
> 3. Your problem is the including of unescaped @ characters in your
> here-document. If you put a \ in front of them, then it (or at least
> the here-document bit) will work. If you actually had a arrays existing
> with names specified, they would have been interpolated in. See:
>
> perldoc "<<HERE"
Sorry, make that:
perldoc -q "<<HERE"
or
perldoc -q '<<HERE'
>
> or
>
> perldoc '<<HERE'
>
> (depending on the quoting method your OS's shell uses).
>
> --
> Bob Walton
--
Bob Walton
------------------------------
Date: Sat, 07 Oct 2000 06:17:40 GMT
From: cbutler@nospaam.cbjd.net
Subject: ActivePerl 5.6 on NT 4.0/IIS4 not working
Message-Id: <39e2bf2f.61277274@news-server>
I've tried to setup the most recent version of ActivePerl 5.6 on a brand
new WinNT 4.0 webserver 128Mb RAM, SP4, IIS4.0.
The PerlScript examples included with the release worked on the server but
would not work on a browser on a workstation accessing the webserver.
Thinking that security setup might be a problem, I checked the settings for
the Perl directory. Everyone had "full control". I reset the directory
and subdirectories to give Everyone "full control". PerlScript then ceased
to function on a browser on the server.
The install notes for Perl for IIS 4.0 were followed (ie. application
mappings were set and Path was correct).
Any ideas on what I need to do to get PerlScript to run on a NT 4.0
webserver?
------------------------------
Date: Sat, 7 Oct 2000 16:38:27 +0900
From: "Dan and Shelly" <wedeking@msa.attmil.ne.jp>
Subject: apache web server set up problems running perl cgi scripts
Message-Id: <8rmjkq$h4k$1@newsflood.tokyo.att.ne.jp>
I found out I had to edit a configuration file to get the apache web server
to run on my windows me machine.
I set the server name in my configuration file to: 127.0.0.1
Now I can get files in my cgi-bin directory to execute perl scripts only
using batch files. I have a file in my cgi-bin directory called
first.bat that has the following command:
perl "C:\Program Files\Apache Group\Apache\cgi-bin\first.pl"
and in the "first.pl" file I have:
use::CGI;
print "Content-type:text/html\n\n";
print "<html><head><title>Test Page</title></head>\n";
print "<body>\n";
print "<h2>Hello, world!</h2>\n";
print "</body></html>\n";
and in my index.html file I have the link:
<a href=http://127.0.0.1/cgi-bin/first.bat>first cgi</a>
When I put http://127.0.0.1/ in the run dialog in the start menu
and click on the "first cgi" link in the index file that comes up, the below
text gets displayed in the browser:
C>perl "C:\Program Files\Apache Group\Apache\cgi-bin\first.pl"
Content-type:text/html
Hello, world!
The problem is that I don't want to display the text before the
"Hello, world!"
How can I have cgi scripts run, but not display the unwanted text?
Is my perl script really running and printing to the browser window or is
the browser merely displaying the text in file "first.pl"?
This cgi stuff seems a lot more difficult to set up than it should be. I've
been racking my brains for weeks and still no joy. I feel like I should
just trow in the towel and not bother with it anymore.
Dan
------------------------------
Date: Sat, 07 Oct 2000 04:31:16 GMT
From: robbelljr@my-deja.com
Subject: creating (key) index files from text files
Message-Id: <8rm8uk$g8e$1@nnrp1.deja.com>
I am beginning to understand how to use the tell and seek functions to
provide fast access to records in long text format files. I believe
one solution is to sort the data into several instances and create
index files that take advantage of the sorts. My current problem is
avoiding the memory drain that seems unavoidable during the process of
placing the original data into a sequence that makes the index files
useful. Please tell me if I'm on the wrong track and/or suggest how I
could avoid loading my source file into the @orders array below.
Thanks! Rob Bell
# $shiplist = tab delimited text file as exported by MS Excel
if (open THEFILE,"$shiplist") {
my (@orders);
while (<THEFILE>) {
$_ =~ s/\r//;
$_ =~ s/\n//;
my (@thisrow) = split(/\t/,$_);
if ($thisrow[4] =~ /\d/) {
# $thisrow[4] is my key (order number) field
# the data is not always "pure" thus the test for digits above
# and the cleanup below
$thisorder =~ s/\D//g; # remove non-digits from order number
$thisorder =~ s/^0?//; # for cosmetic reasons only
my $thisorder=$thisrow[4];
# I'm adding the cleaned up key field to the front of each line
# so I can perform a sort on @orders
push (@orders,"$thisorder\t$line");
}
}
close THEFILE;
@orders = sort {$a <=> $b} @orders;
# an entry to the "index" will occur for every N records
my $indexblock=1000;
my $currentrec=0;
if (open ORDERSFILE,">$ordersfile") {
if (open INDEXFILE,">$ordersindex") {
foreach my $order (@orders) {
$currentrec++;
if (($currentrec/$indexblock) == int($currentrec/$indexblock)) {
# $currentrec is an even multiple of $indexblock
$thisorder = substr($order,0,index($order,"\t"));
$thisbytes = tell(ORDERSFILE);
print INDEXFILE "$thisorder\t$currentrec\t$thisbytes\n";
}
print ORDERSFILE "$order\n";
}
}
else {print "error opening $ordersindex : $!";}
close ORDERSFILE;
close INDEXFILE;
}
else {print "error opening $ordersfile : $!";}
}
else {print "error opening $shiplist : $!";}
sub findfast {
# $seeking = order number to be found
# $ordersindex = index file
# $ordersfile = file in order number sequence
my $found=0;
if ($seeking) {
my ($startatline,$startatbytes) = 0;
if (open INDEXFILE,"$ordersindex") {
while (<INDEXFILE>) {
my ($orderno,$lineno,$atbytes) = split(/\t/,$_);
last if ($orderno > $seeking);
$startatline=$lineno;
$startatbytes=$atbytes;
}
close INDEXFILE;
if (open THEFILE,"$ordersfile") {
seek THEFILE,$startatbytes,0;
while (<THEFILE>) {
my $thisorder=substr($_,0,index($_,"\t"));
if ($thisorder == $seeking) {
$found=1;
push (@matched,$_);
}
elsif ($thisorder > $seeking) {last;}
}
}
else {print "error opening $ordersfile : $!";}
close THEFILE;
}
else {print "error opening $ordersindex : $!";}
}
# @matched may contain more than one line beginning with the
# key order number
# if $found then @matched is processed
}
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Sat, 07 Oct 2000 05:17:21 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: creating (key) index files from text files
Message-Id: <39DEB1E5.F71949C0@rochester.rr.com>
robbelljr@my-deja.com wrote:
>
> I am beginning to understand how to use the tell and seek functions to
> provide fast access to records in long text format files. I believe
> one solution is to sort the data into several instances and create
> index files that take advantage of the sorts. My current problem is
> avoiding the memory drain that seems unavoidable during the process of
> placing the original data into a sequence that makes the index files
> useful. Please tell me if I'm on the wrong track and/or suggest how I
> could avoid loading my source file into the @orders array below.
> Thanks! Rob Bell
>
...
A technique for indexing text files that works great is to use a hash
tied to a DBM-style file (probably DB_File is best for most platforms).
Pass through the data a line at a time, and every time you find an item
for the index, append the result of the tell function followed by a
delimiter (like : ) to the value of a hash key with the index item as
the key. Then finding all occurrences of that item in the text file
later means retrieving the key, splitting it on /:/, and using the seek
function to go to the right places in the text file for retrieval of
each item.
Index updates are easy, too, as long as they always go on the end of the
file. Seek to the last place indexed in the file, and continue the
process of building the tied hash from there.
The result is lighning fast lookups, even for huge datasets. If an
index item occurs very frequently, it will generate a long value, though
-- but items like that can probably be deleted from the index, as they
won't be helpful in finding a record anyway. During the build process,
just delete keys that get too long.
HTH.
--
Bob Walton
------------------------------
Date: Sat, 7 Oct 2000 07:17:23 +0100
From: "Philip Lancefield" <dontmail@me.com>
Subject: Different Ways to Obtain a Client`s IP ?
Message-Id: <39dec098.0@d2o313.teliauk.com>
Here`s my question. I want to record the IP addresses of people visiting my
site. The simple way to do this is to use the environmental variables the
client browser provides. However, there may be occasions when a visitor is
using a proxy to disguise their real IP address. For security reasons it is
important that I obtain the real IP address of the person. I know that, for
instance, you can obtain the real IP of a user who is using a proxy for HTTP
and FTP by connecting to the security port. So what I would like the answer
to is -
a) Is it possible to write programs in Perl that will connect to the
following ports of the client machine (e.g. using Internet Explorer) -
Secure, FTP, Gopher, Socks, when a CGI script is called ?
b) Once I have a connection to any of the ports mentioned above will I be
able to obtain an IP number for the port on the client using Perl ?
c) If it is possible to obtain individual IP numbers from these ports can
anyone point me in the direction of a website, book, or even provide me with
some sample code to help me write a suitable program that will examine the
clients ports and gather IP addresses ? I am assuming that the average user
will have standard numbers for their ports.
Any help will be much appreciated. I can send you my e-mail address if
needed.Thanks in advance.
------------------------------
Date: Sat, 7 Oct 2000 02:34:14 -0400
From: Nico F Zigouras <zigouras@mail.med.upenn.edu>
Subject: Re: Different Ways to Obtain a Client`s IP ?
Message-Id: <Pine.OSF.4.10.10010070233220.2844-100000@dolphin.upenn.edu>
On Sat, 7 Oct 2000, Philip Lancefield wrote:
>Here`s my question. I want to record the IP addresses of people visiting my
... Here's my answer: this isn't a Perl question.
<snip the rest of the totally unrelated crap>
------------------------------
Date: Sat, 7 Oct 2000 18:02:16 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Different Ways to Obtain a Client`s IP ?
Message-Id: <slrn8ttijo.jr6.mgjv@martien.heliotrope.home>
On Sat, 7 Oct 2000 07:17:23 +0100,
Philip Lancefield <dontmail@me.com> wrote:
> Here`s my question. I want to record the IP addresses of people visiting my
> site. The simple way to do this is to use the environmental variables the
> client browser provides. However, there may be occasions when a visitor is
> using a proxy to disguise their real IP address. For security reasons it is
> important that I obtain the real IP address of the person. I know that, for
> instance, you can obtain the real IP of a user who is using a proxy for HTTP
> and FTP by connecting to the security port. So what I would like the answer
> to is -
You seem to be confused, about many things. There are much simpler ways
to obtain the IP address. There are many reasons that proxy servers are
used, hiding 'real' IP addresses probably being at the bottom of that
list. You can't base security on IP addresses, unless you manage the IP
addresses that you want to base the security on. You cannot obtain the
real IP address of anyone on the Web, simply because there is no such
thing as a real IP address. Even if there was, you wouldn't be able to
get it. Even if you could, many IP addresses of people using proxies
won't make any sense to you, because they're internal addresses.
But most of all, you are confused about where you are posting this
so-called problem of yours. This is a group about Perl. Not about the
We, proxies, IP addresses or what you seem to think is security.
Find youself another place to ask this. But rest assured, you won't get
an answer that will satisfy you, anywhere.
> a) Is it possible to write programs in Perl that will connect to the
> following ports of the client machine (e.g. using Internet Explorer) -
> Secure, FTP, Gopher, Socks, when a CGI script is called ?
Oh. Perl content. Oh, no, no Perl content.
Ok, tell me... If I'm using a proxy server, how are you ever going to
find out which IP address to connect to, on whichever port? Chicken,
egg. Do you even know how this whole TCP/IP thingy and sockets and stuff
works? if not, you better read up on that first.
Besides.. How many machines do you know that are routinely used to run
MSIE, and also have Secure (whatever), socks or FTP servers running?
> b) Once I have a connection to any of the ports mentioned above will I be
> able to obtain an IP number for the port on the client using Perl ?
You will NOT be able to get a connection to any of those ports. You can
connect to the proxy. You will most likely not be allowed.
> c) If it is possible to obtain individual IP numbers from these ports can
> anyone point me in the direction of a website, book, or even provide me with
> some sample code to help me write a suitable program that will examine the
> clients ports and gather IP addresses ? I am assuming that the average user
> will have standard numbers for their ports.
You cannot. No book. No website. The average user wil not have an FTP
server, Socks server, or secure whatever server running. You don't
understand what you're asking questions about.
> Any help will be much appreciated. I can send you my e-mail address if
> needed.Thanks in advance.
Not needed.
Now, for any other CGI or Web related questions, ask in
comp.infosystems.www.* somewhere. The above has nothing, nada, not even
remotely, anything to do with Perl.
Martien
--
Martien Verbruggen |
Interactive Media Division | Freudian slip: when you say one
Commercial Dynamics Pty. Ltd. | thing but mean your mother.
NSW, Australia |
------------------------------
Date: Sat, 07 Oct 2000 09:09:28 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Formating output to be read in a form.
Message-Id: <p1qttssdqlsf2766u5bl25n9vqaf1drqp5@4ax.com>
Jürgen Exner wrote:
>> I don't have shell access.
>
>I can hardly believe that. What kind of OS are you using? I honestly haven't
>heard of any OS that doesn't support at least some sort of shell
The Macintosh?
But at least, MacPerl has an excellent POD reading tool included: Shuck.
--
Bart.
------------------------------
Date: Sat, 7 Oct 2000 15:11:55 +0900
From: "Dan and Shelly" <wedeking@msa.attmil.ne.jp>
Subject: how can I get perl CGI to work with win32 perl and win32 apache?
Message-Id: <8rmeft$3eh$1@newsflood.tokyo.att.ne.jp>
I downloaded the win32 apache web server and the win32 activestate perl. I
installed apache as a service and started the service. I put a perl script
in the cgi-bin directory and tried to open it with my ie5 browser in windows
me.
If I associate files ending in .cgi with the perl command line interpreter,
the perl program runs in an ms-dos windows.
If I associate the .cgi files with internet explorer, the program doesn't
get executed by ie5, it only displays the text of the program in the ie5
browser.
I want the output of the program to be directed to the browser but it
doesn't work that way - it goes to a dos window instead.
Here is the perl program whose output I am trying to direct to the browser
window but keeps outputing to an msdos window instead:
use::CGI;
print "Content-type:text/html\n\n";
print "<html><head><title>Test Page</title></head>\n";
print "<body>\n";
print "<h2>Hello, world!</h2>\n";
print "</body></html>\n";
How can I test to see if my apache web server program is working correctly?
Dan
------------------------------
Date: Sat, 7 Oct 2000 08:05:09 GMT
From: "david" <>
Subject: Re: how can I get perl CGI to work with win32 perl and win32 apache?
Message-Id: <39ded87f@news.qut.edu.au>
Hullo there! Add this line to the start of your perl script:
#!C:\Program Files\Perl\bin\perl.exe
Of course, change the drive letter and directories to suit (if necessary).
Hopefully this helped!
------------------------------
Date: Sat, 7 Oct 2000 00:42:28 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: How do I get a cgi script to load a url
Message-Id: <MPG.144873bfd8a5effe98ae1a@nntp.hpl.hp.com>
In article <39DE8068.47A0DF3F@vpservices.com>, jeff@vpservices.com
says...
> Mario wrote:
...
> > Try this:
> > print "Location:http://www.bbc.com\n";
>
> There's only three things wrong with your advice:
>
> 1) You are leading the OP away from CGI.pm which was strongly
> recommended to him.
>
> 2) You have not answered the OP's question, which was, "how does the
> CGI.pm redirect method work".
>
> 3) You didn't put the required two carriage returns after the URI.
>
> But hey, that's only three mistakes in one line of code, imagine what
> you could do with a full script.
4) You didn't put the required space after the colon.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Sat, 7 Oct 2000 17:27:14 +0800
From: DT <dsa@dassda.com>
Subject: how to remove this using subsitute
Message-Id: <MPG.14496d4395b452d0989688@news.cyberway.com.sg>
Hi,
I have a string like this (with \n):
$HTML='111111111 <script>aaaaaa aaaaaa</script>/n 222222
2222222 <script>bbbb bbbbb</script> 333333333';
If I would to use:
$HTML =~ s/<script.*[^s].*<\/script>//oi;
the text in between the scripts tags
I will get $HTML to be "11111111", but I $HTML to be "11111111 222222
22222222 3333333".
Can anyone help? Thanks
------------------------------
Date: 7 Oct 2000 04:29:33 GMT
From: dkcombs@panix.com (David Combs)
Subject: Re: macros (was Re: why it's called a "hash" (and a whole lot more))
Message-Id: <8rm8rd$fg$1@news.panix.com>
In article <eli$0009302253@qz.little-neck.ny.us>,
Eli the Bearded <elijah@workspot.net> wrote:
>In comp.lang.perl.misc, Andrew N. McGuire <anmcguire@ce.mediaone.net> wrote:
>> On Sat, 30 Sep 2000, Jeff Pinyan quoth:
>> JP> The macro is not a function. It's more like this code is plopped in
>> JP> where PERL_HASH(...) is. If we wrote this in Perl, we'd have to use
>> JP> a function, because Perl doesn't have the concept of macros.
>> That is not entirely true...
>>
>> #!/usr/bin/perl -wP
>> use strict;
>> #define P print
>>
>> P "hello, world\n";
>> __END__
>
>That can be generalized with source filters (Filter::*) to include
>perl or shell scripts to find and expand macros, thus removing the
>need for a C preprocessor on the system.
>
Please show an example or two, just to make
it "concrete" in my (and others'?) head(s).
Thanks!
------------------------------
Date: Fri, 6 Oct 2000 22:09:30 -0700
From: "Michael Cook" <mikecook@cigarpool.com>
Subject: OK - last flock Q
Message-Id: <keyD5.2465$S1.392758@news.uswest.net>
Hello,
I have done quite a bit of flock research & below is what I came up with
as a safe way to lock files. My question is: If I have to lock more than 1
file in a script, should I undefine $OFH after each use? Or maybe use a
different designator for the flush each use?
Thanks a million!!!
Michael
open (MEMBERS, "db/members") or die("Unable to open db/members: $!");
$OFH=select(MEMBERS); $| = 1; select($OFH);
flock(MEMBERS, LOCK_EX) or die "can't write-lock db/members: $!";
while ($line=<MEMBERS>)
{
chomp $line;
@line=split(/:/,$line);
$userexists=$line[0];
if ( ($userexists) eq ($regdata{"Pool Number"}) )
{
$rawinfo=$exists;
}
}
close (MEMBERS);
--
== CigarPool ==
http://www.cigarpool.com
------------------------------
Date: Fri, 6 Oct 2000 22:10:24 -0700
From: "Michael Cook" <mikecook@cigarpool.com>
Subject: Re: OK - last flock Q
Message-Id: <bfyD5.2466$S1.393504@news.uswest.net>
Oops - I'm using: use Fcntl qw(:DEFAULT :flock); at the top of the script...
Michael
--
== CigarPool ==
http://www.cigarpool.com
"Michael Cook" <mikecook@cigarpool.com> wrote in message
news:keyD5.2465$S1.392758@news.uswest.net...
> Hello,
> I have done quite a bit of flock research & below is what I came up
with
> as a safe way to lock files. My question is: If I have to lock more than 1
> file in a script, should I undefine $OFH after each use? Or maybe use a
> different designator for the flush each use?
> Thanks a million!!!
> Michael
>
> open (MEMBERS, "db/members") or die("Unable to open db/members: $!");
> $OFH=select(MEMBERS); $| = 1; select($OFH);
> flock(MEMBERS, LOCK_EX) or die "can't write-lock db/members: $!";
> while ($line=<MEMBERS>)
> {
> chomp $line;
> @line=split(/:/,$line);
> $userexists=$line[0];
> if ( ($userexists) eq ($regdata{"Pool Number"}) )
> {
> $rawinfo=$exists;
> }
> }
> close (MEMBERS);
>
> --
> == CigarPool ==
> http://www.cigarpool.com
>
>
>
------------------------------
Date: Sat, 07 Oct 2000 08:15:47 GMT
From: Martin Schneider <martinschneider8659@my-deja.com>
Subject: Re: Parsing improvements
Message-Id: <8rmm3h$pu5$1@nnrp1.deja.com>
In article <39db572e.49878829@news.newsguy.com>,
kcivey@cpcug.org (Keith Calvert Ivey) wrote:
> I wrote:
> >Martin Schneider <MartinSchneider@TNTSoftware.com> wrote:
> >
> >>For example I get this:
> >>
> >>WINMM.dll 4.00 10/14/96 03:38:00 149264 C:\WINNT\System32\USER32.dll
> >>4.00 11/18/99 11:04:00 335120 C:\WINNT\system32\KERNEL32.dll 4.00
> >>11/18/99 11:04:00 375056 C:\WINNT\system32\
> >>
> >>But I want this:
> >>
> >>WINMM.dll 4.00 10/14/96 03:38:00 149264 C:\WINNT\System32\
> >>USER32.dll 4.00 11/18/99 11:04:00 335120 C:\WINNT\system32\
> >>KERNEL32.dll 4.00 11/18/99 11:04:00 375056 C:\WINNT\system32\
> >
> >An example often isn't enough to know the actual specification,
> >but perhaps your lines are always six whitespace-separated
> >fields. In that case, something like this (untested) might
> >work:
> >
> > my $data;
> > { local $/; $data = <>; } # slurp entire file
> > $data =~ s/\s+/ /g; # convert whitespace to single spaces
> > $data =~ s/((?:\S+ ){5}(\S+)) /$1\n/g; # put in newlines
> > print $data;
>
> Obviously I should have tested that. I had thought better of
> posting untested code (even when labeled) but then accidentally
> hit the "Post" button, and my cancel is unlikely to do much
> good. Try this instead, which assumes all the lines end in a
> backslash and begin with something that matches /\w+\.dll /:
>
> my $data;
> { local $/; $data = <>; } # slurp entire file
> $data =~ s/\s+/ /g; # convert whitespace to single spaces
> $data =~ s/(?<=\\)(?=\w+\.dll )/\n/g; # put in newlines
> print $data;
>
> --
> Keith C. Ivey <kcivey@cpcug.org>
> Washington, DC
>
Jim, Keith,
Thank you very much for the help. I now have a fast, useful tool.
Jim,
You're right, I somehow pasted $data instead of $messy. My mistake.
After struggling to understand the regular expressions, I think I've
figured out that "(?<" is a lookbehind modifier. However in
Friedl's "Mastering Regular Expressions" (Nov.'97) he states that
lookbehind is unsupported (p.171). Yet in ActiveState Build 522
perlre.html, there appears to be support. Can anyone help clarify?
--
Thank you,
Martin Schneider
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Sat, 07 Oct 2000 09:08:01 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Parsing improvements
Message-Id: <ugptts0s1ca4j9vigcctnq5sk13cd4n97g@4ax.com>
Jim Mauldin wrote:
>Also, for the benefit of the OP and myself
>
>s/(?<!^)($mod)/\n$1/;
>
>can't do the very thing it was intended to do because lookbehind
>patterns can only match fixed width patterns, or atoms, and not
>zero-width assertions like ^. Shame on me.
s/(?<=.)($mod)/\n$1/g;
But this looks like overkill.
$_ = <<'_';
WINMM.dll 4.00 10/14/96 03:38:00 149264 C:\WINNT\System32\USER32.dll
4.00 11/18/99 11:04:00 335120 C:\WINNT\system32\KERNEL32.dll 4.00
11/18/99 11:04:00 375056 C:\WINNT\system32\
_
tr/ \t\n\r/ /s;
s/(?<= )(?=[a-z-A-Z])/\n/g;
print;
__END__
WINMM.dll 4.00 10/14/96 03:38:00 149264
C:\WINNT\System32\USER32.dll 4.00 11/18/99 11:04:00 335120
C:\WINNT\system32\KERNEL32.dll 4.00 11/18/99 11:04:00 375056
C:\WINNT\system32\
--
Bart.
------------------------------
Date: Sat, 07 Oct 2000 07:00:18 GMT
From: tvn007@my-deja.com
Subject: Please help on "processing data problem"
Message-Id: <8rmhm1$m0a$1@nnrp1.deja.com>
Hi
Would someone please help me on this:
The problem is : I must replace 1 or 0 with a character 'X' on the
previous row if the character of the next row is 'L' or 'H'
As an Example:
I have a big file (this is just small sample) as shown below:
abc
(XF_S 1
(XF_S 0
(XF_S L
(XF_S H
I would like to have the ouput as follow:
abc
(XF_S 1
(XF_S X
(XF_S L
(XF_S H
THe script I wrote does not give me the output I want:
#!/usr/local/bin/perl5
$input_file = $ARGV[0];
open (FD,$input_file)|| die "cannot open";
$output_file = 'output';
open (LVMADR,">$output_file")|| die "cannat opne";
while ($line = <FD>){
chomp $line;
if ($line =~ /^\(XF_S/){
$char = substr ($line,7,1); }
if (($char =~/H|L/) && ($previous_char =~ /1|0/)){
substr($line,7,1) = 'X';}
if ($line =~ /^\(XF_S/){
$previous_char= substr ($line,7,1);
}
print "$line\n";
}
Below is the output from my script:
abc
(XF_S 1
(XF_S 0
(XF_S X
(XF_S H
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 7 Oct 2000 03:27:24 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: PP, 3rd ed.???
Message-Id: <8rmmpc$epb$1@provolone.cs.utexas.edu>
In article <39DE7C71.D2217AD6@stomp.stomp.tokyo>,
Godzilla! <godzilla@stomp.stomp.tokyo> wrote:
>kj0 wrote:
>> Therefore, I would like to read
>> only those parts of the new 3rd edition that are substantially new
>> relative to the first two editions. What would those be?
>
>You say you have read both earlier editions of _Programming Perl_
>in thier entirety. Why do you not know what is new in this
>third edition? A quick glance at its table of contents and
>foreword would tell you almost instantly, what is new.
Perhaps the original poster was trying to ask what's new so that they
can make a decision whether to procure this book. They will only be
interested to read those sections which have changed, so they want to
know what sections those are. (If there were only a few new chapters
and none of the topics were relevant to what they want to know, then
they might decide not to buy it.)
- Logan
------------------------------
Date: 7 Oct 2000 03:23:57 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Rounding Integers
Message-Id: <8rmmit$eoa$1@provolone.cs.utexas.edu>
In article <39DE9739.8F183A9F@stomp.stomp.tokyo>,
Godzilla! <godzilla@stomp.stomp.tokyo> wrote:
>There is no clear rule for rounding off numbers which
>are not decimal in nature.
Sure there is. If you have a function round() that rounds things, then
you can define a function round_granular() that rounds them to
multiples of a certain number:
sub round_granular
{
my ($x, $granularity) = @_;
return ($granulatiry * round ($x / $granularity));
}
Note that this can also works if $granularity is a fraction. So, you
can use this function to round to the nearest one-tenth, or you can use
it to round to the nearest 1/32nd.
>Reason for this is rounding
>off numbers left of a decimal place, gives an extremely
>wide margin of error,
Wide relative to what? All that matters is the application. Rounding
72 and 123 to 100 might not be wide for some application. Perhaps
you're computing something having to do with students' classifications
and you want to round to the nearest multiple of 30 semester-hours so
you can easily group them according to freshmen, sophomore, etc. (In
that case, you might want to round down, but the same idea applies.)
>Why do you want to introduce so much error into your numbers?
Who says it's error?
- Logan
------------------------------
Date: Sat, 07 Oct 2000 09:10:36 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Rounding Integers
Message-Id: <e4qttss1iv7ein7ad398dgvb8gr3tarf9t@4ax.com>
vivi16@my-deja.com wrote:
>Can you use sprintf(); to round integers?
Yes. Round it as a floating point number with zero digits after the DP.
--
Bart.
------------------------------
Date: Fri, 6 Oct 2000 23:03:58 -0500
From: "Andrew N. McGuire " <anmcguire@ce.mediaone.net>
Subject: Re: STDERR>&STDOUT
Message-Id: <Pine.LNX.4.21.0010062300350.12847-100000@hawk.ce.mediaone.net>
On Fri, 6 Oct 2000, Chethan Anand quoth:
CA> Hello,
CA>
CA> I have a small problem.
CA> I have one statement "my $cmd = open(QBTFILE, "$arg 2>&1 |");" .
CA> This statement is not being executed on NT. When I see the variable it
CA> says undef .
CA>
CA> This is happening on one system. Can you help me out ??
Your answer is in the documentation.
anm
--
$please ++; $please ++;
open TFM, 'perldoc -f open |'
and read TFM, $now, $please
for our $sake; die
"Just another Perl Hacker\n";
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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.
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 V9 Issue 4546
**************************************