[12789] in Perl-Users-Digest
Perl-Users Digest, Issue: 199 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 20 11:07:16 1999
Date: Tue, 20 Jul 1999 08:05:10 -0700 (PDT)
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, 20 Jul 1999 Volume: 9 Number: 199
Today's topics:
basename regexp? <jona@ds10.hobby.nl>
Re: basename regexp? <gellyfish@gellyfish.com>
Re: CGI database question <mlopresti@bigfoot.com>
Re: flock() replacement in Win32 ? (elephant)
Re: Garbage Collection Performance (Reini Urban)
Re: How should I sort by different fields? <gellyfish@gellyfish.com>
Re: How should I sort by different fields? <Webdesigner@NewWebSite.com>
Re: How to compare fields (Greg Bacon)
Re: how to execute aliased command from Perl script?(+) <ckaiser@stockholm.ptloma.edu>
Re: How to get total line numbers in a text file ? (V. Balaji)
how to get total matched lines number ? <factory@factory.co.kr>
Re: MS-HTML demoroniser (Eugene van der Pijll)
Re: Need help with socket loop? <aqumsieh@matrox.com>
Re: negate regex? <dankirk@lucent.com>
Re: padding a number <ckaiser@stockholm.ptloma.edu>
Re: PERL & SQL <mlopresti@bigfoot.com>
Re: perl implementation: list data structure <tchrist@mox.perl.com>
Re: problem with searching database <marshalc@americasm01.nt.com>
Re: Problems implementing RobotUA <deep_dt@yahoo.com>
Re: Problems implementing RobotUA <gellyfish@gellyfish.com>
Re: Problems implementing RobotUA <ckaiser@stockholm.ptloma.edu>
Reading binary files <kims@emmerce.com.au>
Re: Reading binary files <gellyfish@gellyfish.com>
regexp fun! <jgc5a@j2.mail.virginia.edu>
Re: regexp fun! (Greg Bacon)
Re: regexp fun! (elephant)
Re: regexp fun! <marshalc@americasm01.nt.com>
Re: Subroutines in a deperate file <sethb@mitre.org>
Re: Subroutines in a deperate file <gellyfish@gellyfish.com>
that great DNS lookup script <delete.the.nospam.kayec@gov.ns.ca>
Re: that great DNS lookup script <ckaiser@stockholm.ptloma.edu>
Re: TPJ/Earthweb junk mail? (I R A Darth Aggie)
Re: TPJ/Earthweb junk mail? (Greg Bacon)
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 20 Jul 1999 16:56:35 +0200
From: Jona Andersen <jona@ds10.hobby.nl>
Subject: basename regexp?
Message-Id: <37948E1E.28C77299@ds10.hobby.nl>
Hi,
I need to know the name of my script.
$0 you'd say right? I know, but I just want the name, not the full
pathname.
I'd rather not use a shell
Now I don't speak too fluently regular expressions (nor perl, for that
matter),
So, how do I strip the full path?
Thanks,
Joe
------------------------------
Date: 20 Jul 1999 16:00:06 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: basename regexp?
Message-Id: <37948ef6@newsread3.dircon.co.uk>
Jona Andersen <jona@ds10.hobby.nl> wrote:
> Hi,
>
> I need to know the name of my script.
> $0 you'd say right? I know, but I just want the name, not the full
> pathname.
> I'd rather not use a shell
> Now I don't speak too fluently regular expressions (nor perl, for that
> matter),
> So, how do I strip the full path?
>
Well you can either use the module File::Basename or do something like:
($progname) = $0 =~ m%/([^/]+)$%;
check out the perlre manpage.
/J\
--
"I sign my paintings Vincent because people can't pronounce Van Gough"
- Vincent Van Gough
------------------------------
Date: Tue, 20 Jul 1999 10:36:53 -0400
From: matt <mlopresti@bigfoot.com>
Subject: Re: CGI database question
Message-Id: <37948985.81C9FB64@bigfoot.com>
Thanks you guys, abigail, adn Johnathan. I figured it out with your
help, it was a stupid mistake on my part. missing /"
Jonathan Stowe wrote:
> matt <mlopresti@bigfoot.com> wrote:
> >
> > print "<SELECT NAME = "xxxxxxx">";
> > ^ ^ ^ ^
>
> print qq%<SELECT NAME = "xxxxxxx">%;
>
> /J\
> --
> "Gary Glitter pulls out of Children in Need" - BBC News Website
------------------------------
Date: Tue, 20 Jul 1999 23:21:39 +1000
From: e-lephant@b-igpond.com (elephant)
Subject: Re: flock() replacement in Win32 ?
Message-Id: <MPG.11ff22f11e9c332b989b50@news-server>
Andreas Fehr writes ..
>On Tue, 20 Jul 1999 08:37:16 GMT, arpith@hotmail.com wrote:
>>The flock() command locks files in Unix. Is there an alternative command
>>in Windows 95 ? If so what is it (if possible with an example please :)?
>>If I do not use it, will the data files get seriously damaged ?
>
>flock does work under NT, it should work under Win95 too.
I recommend reading the FAQ before posting .. flock does not work under
Windows95 .. it's a known and documented issue
perlwin32faq5 (Quirks)
the original poster should also check out perlwin32faq4 (Windows 95/NT)
in which the never-before-dreamed-of question "How do I send email from
Perl for Win32?" is prophetically asked and answered
man .. these Fack things seem to answer all the questions that I see
people ask most frequently .. spooky !!
--
jason - remove all hyphens for email reply -
------------------------------
Date: Tue, 20 Jul 1999 13:28:55 GMT
From: rurban@xarch.tu-graz.ac.at (Reini Urban)
Subject: Re: Garbage Collection Performance
Message-Id: <37947390.449741263@judy.x-ray.local>
Jeremy Purdy <jerbyr@my-deja.com> wrote:
>I have a data-intensive application that I am writing in PERL. It uses
>a LARGE amount of memory while processing, but runs fairly efficiently.
>I just noticed, however, that at the end of the process, after the last
>line of the program, there is a pause of approx. 10 min where the
>program is waiting.
>
>I assume that the program is doing garbage collection at this point,
>cleaning up all of the memory which had been allocated to variables
>within subroutines and so forth. This delay just about doubles the
>processing time of the application, while processing a file of this
>size.
>
>Can anyone give me some tips on how to improve the performance of
>garbage collection. Possibly some better way to handle buffers and data
>arrays that would enable PERL to free the memory easier?
perl doesn't use a typical garbage collection as lisp/scheme/java,
(stop+copy or mark+sweep or improved versions)
rather simple reference counting,
which needs much more memory,
is much simplier to implement,
disallows cyclic data structures,
but guarantees no delays!
i would even refuse to call "reference counting" "garbage collection",
because it doesn't collect anything, anyway:
http://www.iecc.com/gclist/GC-faq.html
it's certainly your OS trying to revive some memory or doing some
paging, probably a virtual memory system. but certainly not perl.
of course you have to pay the same attention to memory issues as in
other conservative languages. (using conservative memory handling)
--
Reini Urban
http://xarch.tu-graz.ac.at/autocad/news/faq/autolisp.html
------------------------------
Date: 20 Jul 1999 14:13:35 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: How should I sort by different fields?
Message-Id: <379475ff@newsread3.dircon.co.uk>
Floyd Morrissette <Webdesigner@NewWebSite.com> wrote:
> In article <slrn7otaak.c9j.abigail@alexandra.delanet.com>,
> abigail@delanet.com wrote:
>
>>
>> FAQ.
>>
>> Abigail
>
>
> http://language.perl.com/newdocs/pod/perlfaq4.html would have been a
> better answer and definitely more helpful.
>
Why ? Why make someone connect to the internet, start a web browser and
so on when the document is or rather should be on their hard disk. Infact
simply pointing out that an answer can be found in the FAQ could be
construed as being more helpful as by the time they have found the answer
therein they will have also be exposed to the very of answers that can be
found and thus may not need to come back and ask another question.
/J\
--
"I suggest you apply some lubrication before any bending begins" -
Antoine de Caunes, Eurotrash
------------------------------
Date: Tue, 20 Jul 1999 14:48:23 GMT
From: Floyd Morrissette <Webdesigner@NewWebSite.com>
Subject: Re: How should I sort by different fields?
Message-Id: <7n227i$ttr$1@nnrp1.deja.com>
In article <379475ff@newsread3.dircon.co.uk>,
Jonathan Stowe <gellyfish@gellyfish.com> wrote:
>
> Why ? Why make someone connect to the internet, start a web browser
and
> so on when the document is or rather should be on their hard disk.
Infact
> simply pointing out that an answer can be found in the FAQ could be
> construed as being more helpful as by the time they have found the
answer
> therein they will have also be exposed to the very of answers that can
be
> found and thus may not need to come back and ask another question.
The fact that they read this message means there is a good chance they
are already connected to the internet and if they click on the link then
a browser starts for them. It may not be true of everybody but I think
most.
I know I don't have the FAQ on my hard disk so I cannot assume that
someone else does. But I can assume they have an internet connection.
And the link I provided gives a lot more than the person asked for. They
are exposed to the various answers that can be found and may not have to
come back to ask more questions.
But just stating "it's in the faq", what faq, where? Obviously the
person doesn't know that it may be on the hard because if he did he
would not have come here to ask. And he doesn't know that it is
available on the web. I know I had to ask where the faq was after
receiving such a response. Its like asking where to buy something and
somebody says its at the store. What kind of store? Where is it at?
Newbies need specific direction.
--
Get your web site from http://www.NewWebSite.com
Consultation is always free.
Help with cgi scripts.
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: 20 Jul 1999 14:17:29 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: How to compare fields
Message-Id: <7n20dp$soj$3@info2.uah.edu>
In article <slrn7p7dl2.oqh.abigail@alexandra.delanet.com>,
abigail@delanet.com (Abigail) writes:
: What is the difference between "a blue fish" and "19.2857" ?
They're the same. Only different.
Greg
--
Fenster: Treat me like a criminal, I'll end up a criminal.
Hockney: You are a criminal.
Fenster: Why you gotta go and do that? I'm trying to make a point.
------------------------------
Date: 20 Jul 1999 09:46:02 -0500
From: Cameron Kaiser <ckaiser@stockholm.ptloma.edu>
Subject: Re: how to execute aliased command from Perl script?(+)
Message-Id: <6Y%k3.24124$vw1.978834@newscene.newscene.com>
Artem Trunov <artem@slac.stanford.edu> writes:
>for example, if "ll" is an alias for "ls -al"
>system ("ll") ;
>or
>$status=`ll`;
>will return error: "Cant exec: no suxh file or directory";
Perl doesn't know enough to do this. How does it know what your aliases are?
If you really want to do this, try invoking your shell directly, e.g. if
you run csh:
system("/bin/csh -c ll");
In this example, don't add -f or this defeats the whole game by stopping csh
from invoking your local .cshrc or .login where such aliases may reside.
--
Cameron Kaiser * ckaiser@stockholm.ptloma.edu * posting with a Commodore 128
http://calvin.ptloma.edu/~spectre/ * "When in doubt, take a pawn." -- M:I
-- Supporting the Commodore 64 and 128: http://www.armory.com/~spectre/cwi/ --
head moderator comp.binaries.cbm * cbm special forces unit $ea31 [tincsf]
------------------------------
Date: 20 Jul 1999 13:09:37 GMT
From: balaji@cray.com (V. Balaji)
Subject: Re: How to get total line numbers in a text file ?
Message-Id: <7n1seh$hhp$1@murrow.corp.sgi.com>
How about using wc(1) instead of perl?
--
Balaji 1 609.452.6516
SGI/GFDL Princeton University
------------------------------
Date: Tue, 20 Jul 1999 22:30:30 +0900
From: "Yeong Mo/Director Hana co." <factory@factory.co.kr>
Subject: how to get total matched lines number ?
Message-Id: <7n1t46$l3q$1@news1.kornet.net>
if matchs one word in a line, how to get total matched lines number ?
something like the following;
($ex0, $categorys, $ex2) = split(/&&/, "$line");
if ($categorys eq "001") {
something here ???????
print "001 matchs total "16" lines ";
}
Thanks in advance
------------------------------
Date: 20 Jul 99 13:43:55 GMT
From: pijll@phys.uu.nl (Eugene van der Pijll)
Subject: Re: MS-HTML demoroniser
Message-Id: <pijll.932478235@ruunat.phys.uu.nl>
In <7n1n1a$paa$1@nnrp1.deja.com> Richard Lawrence <ralawrence@my-deja.com> writes:
>Whilst I fully applaud the idea of the demoroniser script I can't
>exactly see the entire Microsoft corporation quaking in its boots until
>someone actually makes it so that any old joe off the street can run
>the script without having to fix it first.
>I save it, I change #!/bin/perl to #!/usr/bin/perl, I run, I get:
>syntax error at ./demoron.pl line 28, near ">"
>syntax error at ./demoron.pl line 28, near """
<SNIP>
>Nice idea. Shame it doesn't work.
>Rich
I think you have tried to run the HTML version of the script, which is at
http://www.perl.com/language/misc/demoroniser.html
Try the URL without the .html, and you will find a ready to run plain text version:
http://www.perl.com/language/misc/demoroniser
Eugene
--
\
Eugene van der Pijll : pijll@phys.uu.nl
--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--
------------------------------
Date: Tue, 20 Jul 1999 09:02:08 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Need help with socket loop?
Message-Id: <x3yu2qzpj8x.fsf@tigre.matrox.com>
Daniel <dbohling@pacbell.net> writes:
>
> Hi all. I'm trying to adapt the unix domain client/server found
> in the
> camel book. I'm simply trying to get the client and server to "chat" at
> this point. They connect to one another just fine and will send single
> messages but if i try to make them loop while reading from STDIN (on
> client) to STDOUT (on server) it just sits. I assume it has something to
> do with buffering?
No ... your problem is called deadlock. In a client/server
environment, great care has to be taken in establishing a
good protocol where the client(s) can communicate back and forth with
the server. If you fail to do this, a deadlock situation will likely
occur where both a client and a server are sitting indefinitely
waiting for each other to send messages, which will never arrive.
> =======================client=================================
>
> #!/usr/bin/perl -w
> use diagnostics;
> use CGI qw(param);
> use Socket;
> use strict;
>
> #$| = 1;
> my ($rendezvous, $linein, $lineout);
>
> $rendezvous = shift || '/home/httpd/html/img/streamsocket';
> socket(SOCK, PF_UNIX, SOCK_STREAM, 0) || die "Socket: $!\n";
> connect(SOCK, sockaddr_un($rendezvous)) || die "Connect: $!\n";
>
> print SOCK "Connected here";
> print STDOUT "Connected here\n";
> while ($linein = <SOCK>) {
> print STDOUT $linein;
> }
The above while() loop never terminates. It just stays there waiting
for the server to say something. If the server is silent, the above
while() loop just hangs until the server sends a message. The same
thing happens on the server side.
Side note: Typically a server never attempts to initiate requests; it
listens to incoming calls from clients and simply responds to them.
You solution is to use the 4-argument form of select(). An easier
solution would be to use IO::Select, which is simply an object wrapper
around the select() function. Typical usage goes something like this:
my $readable_handles = new IO::Select();
my $writable_handles = new IO::Select();
$readable_handles->add($sock);
$readable_handles->add(\*STDIN);
while (1) {
my @ary = IO::Select->select($readable_handles,
$writable_handles,
undef,
1);
for my $nsock (@{$ary[0]}) {
do_something();
}
}
Check out the docs for IO::Select. Also, have a look at chapter 12 of
the panther (Advanced Perl Programming).
HTH,
Ala
------------------------------
Date: Tue, 20 Jul 1999 08:52:11 -0600
From: Daniel_P_Kirkwood <dankirk@lucent.com>
Subject: Re: negate regex?
Message-Id: <37948D1B.4BD921B0@lucent.com>
Tom, thanx for the hint.. I looked in the Ram book, FAQs, etc before
posting, but somehow I missed that one.. -dan
Tom Christiansen wrote:
> True if pattern C</PAT/> does not match, like C<$var !~ /PAT/>:
>
> /^(?:(?!PAT).)*$/s
>
> True if pattern C<BAD> does not match, but pattern C<GOOD> does:
>
> /(?=^(?:(?!BAD).)*$)GOOD/s
>
> --tom
> --
> Adding manpower to a late software project makes it later
------------------------------
Date: 20 Jul 1999 09:42:04 -0500
From: Cameron Kaiser <ckaiser@stockholm.ptloma.edu>
Subject: Re: padding a number
Message-Id: <UU%k3.24110$vw1.977942@newscene.newscene.com>
fl_aggie@thepentagon.com (I R A Darth Aggie) writes:
>On 19 Jul 1999 19:29:54 GMT, John Stanley <stanley@skyking.OCE.ORST.EDU>, in
><7mvubi$j4i$1@news.NERO.NET> wrote:
>Question: How do you pad a number with a single '0' (zero)?
>[Note: padding indicates to the left-hand-side of the value. Wouldn't want
> to get into any nasty debates over accuracy and signifcant digits with
> a physics professor...]
Why not something like
("00000000000$num" =~ /(.{number of total places})$/) && ($num = $1);
e.g.
$num = 5;
("00000000000$num" =~ /(.{2})$/) && ($num = $1);
print $num;
05
--
Cameron Kaiser * ckaiser@stockholm.ptloma.edu * posting with a Commodore 128
http://calvin.ptloma.edu/~spectre/ * "When in doubt, take a pawn." -- M:I
-- Supporting the Commodore 64 and 128: http://www.armory.com/~spectre/cwi/ --
head moderator comp.binaries.cbm * cbm special forces unit $ea31 [tincsf]
------------------------------
Date: Tue, 20 Jul 1999 10:44:17 -0400
From: matt <mlopresti@bigfoot.com>
Subject: Re: PERL & SQL
Message-Id: <37948B41.86FBF340@bigfoot.com>
I just did a simliar thing myself, if you post the code that you used to
try to accomplish the display feat, it would help.
ether_nut@my-deja.com wrote:
> I've been working on a PERL/SQL script that runs a simple query
> like : select distinct
> c.rowid
> c.column_name
> c.column_names
> from c.table_name
> where c.rowid='rowid' and
> c.column_name = ..etc
> After the query runs I can get it to generate a file & it will run
> the results through SQL*PLUS no problem, but I'm having problems making
> the query info show up on output from the PERL script (It's a web page
> which is embedded in PERL).
>
> Does anyone have an example of a good way to display the query results
> in PERL. (any example will do)
>
> Thanks
>
> Dave
> dave@worldexpress.com
>
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.
------------------------------
Date: 20 Jul 1999 07:07:15 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: perl implementation: list data structure
Message-Id: <37947483@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc, rurban@sbox.tu-graz.ac.at writes:
:Tom Christiansen <tchrist@mox.perl.com> wrote:
Oh for crying out loud! I did *not* write that! Please
be more careful in your attributions.
:>:How about random accesses? Are they O(1), like C arrays, or O(n), like linked
:>:lists?
:>:
:>:When you insert, is this a simple modification of a couple of pointers? or
:>:does it have more overhead, like copying a chunk of the sequence?
:>:
:>:Are these regular linked-lists? doubly linked-lists, structs containing stuff
:>:like length, last-node...?
:it's an pre-allocated continuous array of pointers (to scalars or SVs),
:with a fill-pointer, same as adjustable lisp vectors. out of a pool of
:pre-allocated sv's. the preallocated size for each AV is mostly larger
:than the actual array size, so that push or unshift operations don't
:need to copy, realloc(), that often.
Of course it is.
:I also highly recommend "Advanced Perl Programming" by Sriram
:Srinivasan.
You're talking to the wrong guy.
--tom
--
Von Neumann: "Anyone attempting to generate random numbers by
deterministic means is, of course, living in a state of sin."
------------------------------
Date: Tue, 20 Jul 1999 09:19:00 -0500
From: Marshall Culpepper <marshalc@americasm01.nt.com>
Subject: Re: problem with searching database
Message-Id: <37948554.D9AF17EA@americasm01.nt.com>
Peter wrote:
> how to make that kind of database search.
>
> For example, the database is simple text tile containing:
> name, yearsold, country
>
> how to force script to search and give mie result of how many
> 20 years old people are liveing in som country.
>
> So, the search script must filter yearsold and country.
>
> If you can help me, pleese do it.
> And an example is welcome too.
>
> All Best,
> Tarmo Mitt
> mitt@uninet.ee
maybe this will help:
code:
----------
#!/usr/bin/perl -w
open(FILE,"file");
while(<FILE>){
($name,$age,$country)=split(/:/);
$numofpeople++ if $age ==20 and $country="foobar";#counts number of
people that are 20 and live in foobar :)
}
print $numofpeople;
this assumes your data file has 1 record on each line, with each field
seperated by a colon
i.e
Joe:20:foobar
~Marshall
--
----------------------------------
just another guy trying to save the world
----------------------------------
------------------------------
Date: Tue, 20 Jul 1999 14:13:25 +0000
From: blob <deep_dt@yahoo.com>
Subject: Re: Problems implementing RobotUA
Message-Id: <37948405.34DD26E@yahoo.com>
blob wrote:
> Hi, I'm writing a web retrieval bot. The bot works well with
> LWP::UserAgent, but it seems to refuse to do anything when I try to use
> RbotUA instead. It could be complying witrh the robot.txt, of course,
> but this does not seem to be the problem.
>
> Does anyone know of some obvious problem that I've overlooked?
>
> ThanX
I have a few suggestions that may help
a. Make sure that there is nothing preceeding the shebang.
b. Don't use the -w switch or 'use diagnostics'.
c. unbuffer the output with '$| = 1;' as the first statement following the
shebang.
You may find that you are then able to use RobotUA.
------------------------------
Date: 20 Jul 1999 15:14:37 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Problems implementing RobotUA
Message-Id: <3794844d@newsread3.dircon.co.uk>
blob <deep_dt@yahoo.com> wrote:
>
> b. Don't use the -w switch or 'use diagnostics'.
>
Er why ?
/J\
--
"You've got to remember it was the 1980s. There were a lot of people
alive back then who died in the Second World War" - This Morning with
Richard Not Judy
------------------------------
Date: 20 Jul 1999 09:54:06 -0500
From: Cameron Kaiser <ckaiser@stockholm.ptloma.edu>
Subject: Re: Problems implementing RobotUA
Message-Id: <V30l3.24154$vw1.980162@newscene.newscene.com>
Jonathan Stowe <gellyfish@gellyfish.com> writes:
>>b. Don't use the -w switch or 'use diagnostics'.
>Er why ?
Because they're writing for the next Obfuscated Perl Contest?
--
Cameron Kaiser * ckaiser@stockholm.ptloma.edu * posting with a Commodore 128
http://calvin.ptloma.edu/~spectre/ * "When in doubt, take a pawn." -- M:I
-- Supporting the Commodore 64 and 128: http://www.armory.com/~spectre/cwi/ --
head moderator comp.binaries.cbm * cbm special forces unit $ea31 [tincsf]
------------------------------
Date: Wed, 21 Jul 1999 00:10:51 +1000
From: "Kim Saunders" <kims@emmerce.com.au>
Subject: Reading binary files
Message-Id: <932479856.815025@draal.apex.net.au>
Hello,
a quick question: Can someone pls help me out with a bit of code to read
data from a binary file (an image), and then print it out to STDOUT??? Just
can't find it ANYWAY, pls email me the 3 or whatever lines!
Thanks,
KimS
------------------------------
Date: 20 Jul 1999 15:39:10 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Reading binary files
Message-Id: <37948a0e@newsread3.dircon.co.uk>
Kim Saunders <kims@emmerce.com.au> wrote:
> Hello,
>
> a quick question: Can someone pls help me out with a bit of code to read
> data from a binary file (an image), and then print it out to STDOUT??? Just
> can't find it ANYWAY, pls email me the 3 or whatever lines!
>
The only difference in reading and printing a binary file is that on certain
platforms you will need to binmode() both the read and write file handles.
see the perlfunc entries for opn(),binmode(),print
/J\
--
"I sign my paintings Vincent because people can't pronounce Van Gough"
- Vincent Van Gough
------------------------------
Date: Tue, 20 Jul 1999 10:07:08 -0400
From: James Gerard Coleman <jgc5a@j2.mail.virginia.edu>
Subject: regexp fun!
Message-Id: <Pine.A41.4.05.9907201002590.86530-100000@node16.unix.Virginia.EDU>
i'm trying to match regexp, but not having too much success... actually,
i'm trying to take a value out of a line of text that has one of the
following two formats:
"-1:-4:-4 HTTP.005: User 498004652 timed out authentication"
"07:48:38 HTTP.001: User 498004652(38.11.249.163) authenticated"
i'm trying to strip the time value (yes, i know there's no negative time..
it's just what's being spit out to me, so i have to deal with it)
i tried using
$timeval = /{2}[0-9\-]:{2}[0-9\-]:{2}[0-9\-]\s/
to match two numberical digits (or a minus) colon, etc. but it didn't
return a value.
i also tried: /.*:.*:.*\s/
but that didn't work either..
help?
jim coleman
------------------------------
Date: 20 Jul 1999 14:39:21 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: regexp fun!
Message-Id: <7n21mp$t2s$1@info2.uah.edu>
In article <Pine.A41.4.05.9907201002590.86530-100000@node16.unix.virginia.edu>,
James Gerard Coleman <jgc5a@j2.mail.virginia.edu> writes:
: i'm trying to match regexp, but not having too much success... actually,
: i'm trying to take a value out of a line of text that has one of the
: following two formats:
:
: "-1:-4:-4 HTTP.005: User 498004652 timed out authentication"
: "07:48:38 HTTP.001: User 498004652(38.11.249.163) authenticated"
:
: i'm trying to strip the time value (yes, i know there's no negative time..
: it's just what's being spit out to me, so i have to deal with it)
if ($line =~ /^([^:]+):([^:]+):(\S+)/) {
print "Time: $1:$2:$3\n";
}
Greg
--
Cancelling other people's articles is juvenile. Threatening electronic
warfare over the Usenet is imbecilic. Repeat after me: " The netnews is not
real life. It's just 1s and 0s. It isn't that big a deal." Then go take a
walk outside and try to gain some perspective. -- Spaf
------------------------------
Date: Wed, 21 Jul 1999 00:59:17 +1000
From: e-lephant@b-igpond.com (elephant)
Subject: Re: regexp fun!
Message-Id: <MPG.11ff39ce7330c4d0989b51@news-server>
James Gerard Coleman writes ..
> "-1:-4:-4 HTTP.005: User 498004652 timed out authentication"
> "07:48:38 HTTP.001: User 498004652(38.11.249.163) authenticated"
>
>$timeval = /{2}[0-9\-]:{2}[0-9\-]:{2}[0-9\-]\s/
hee hee .. this is funny (sorry) .. just like the other quantifiers the
{n} quantifier comes AFTER the thing that you want to quantify
[0-9] can be replaced with [\d] if you like - more concise
but most importantly .. if all your time fields are of the form
beginning of string, char, char, colon, char, char, colon, char, char
then why bother with all that [0-9\-] stuff ? .. it'll be quicker and
simpler to just write
/^..:..:../
also .. just quietly .. in a scalar context a pattern match returns a
boolean success value .. NOT the text matched
you'll want to write something like this to get the values out .. in a
list context the 'm' operator (when used without the global option)
returns the parenthesised subexpressions
my($timeval) = /^(..:..:..)/;
more generally this is the same as
$_ =~ /^(..:..:..)/;
my $timeval = $1;
>i also tried: /.*:.*:.*\s/
that's because * is greedy .. so this will match up to the final colon on
the line .. not that it would work in the syntax that you used anyway
(because of the return value thing)
btw .. if you want to be sure of a really tight match .. eg. if other
lines maybe start with 'ab:cd:efg' and you don't want those matched then
use
my($timeval) = /^([\d-]\d:[\d-]\d:[\d-]\d)\s/;
--
jason - remove all hyphens for email reply -
------------------------------
Date: Tue, 20 Jul 1999 09:31:46 -0500
From: Marshall Culpepper <marshalc@americasm01.nt.com>
Subject: Re: regexp fun!
Message-Id: <37948852.5B62CB2B@americasm01.nt.com>
> help?
here ya go jim i tested this out and it works just fine:
$timeval =~ /(-?\d+):(-?\d+):(-?\d+)/;
have fun :)
~Marshall
--
----------------------------------
just another guy trying to save the world
----------------------------------
------------------------------
Date: Tue, 20 Jul 1999 09:41:18 -0400
From: Seth Berger <sethb@mitre.org>
Subject: Re: Subroutines in a deperate file
Message-Id: <37947C7E.D741DE3E@mitre.org>
When placing subroutines in a separate file, you need to end that
separate file with the line:
1;
This will return a true value to the require command and everything will
work.
Kevin Bilbee wrote:
>
> I am trying to put my commonly used subroutines in a seperate file, but when
> I run my script I get the following error message.
>
> /home/kbilbee/public_html/cgi-bin/lib/subprint.pl did not return a true
> value at main.pl line 4.
>
> Does anybody know what I am doing incorrectly?
>
> Main routine
> ----------------------------------------------------------------------------
> #!/usr/lib/bin/perl
>
> require "/home/kbilbee/public_html/cgi-bin/lib/subprint.pl";
>
> print print_hello();
>
> Subroutine
> ----------------------------------------------------------------------------
> # subprint.pl
> #
> #
>
> sub print_hello {
> return "hello";
> }
>
> Kevin Bilbee
> kbilbee@wgn.net
------------------------------
Date: 20 Jul 1999 15:32:09 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Subroutines in a deperate file
Message-Id: <37948869@newsread3.dircon.co.uk>
Kevin Bilbee <kbilbee@wgn.net> wrote:
> I am trying to put my commonly used subroutines in a seperate file, but when
> I run my script I get the following error message.
>
> /home/kbilbee/public_html/cgi-bin/lib/subprint.pl did not return a true
> value at main.pl line 4.
>
You must have
'I am the Lord of Hell Fire';
as the last line in subprint.pl ...
/J\
--
"Do you want to go to court today?" - BBC News Website
------------------------------
Date: Tue, 20 Jul 1999 11:38:09 -0300
From: "kayec" <delete.the.nospam.kayec@gov.ns.ca>
Subject: that great DNS lookup script
Message-Id: <bQ%k3.883$6T3.39627@sapphire.mtt.net>
Sometime ago i was pointed to a very fast DNS lookup script that did
multiple lookups at a time... very fast, very impressive.
Since then i've had a few problems and would like a copy of the
original script again...
Here are the comments at the top of the file (michael fuhr are you out
there?):
#!/usr/local/bin/perl -w
#---------------------------------------------------------------------------
---
# Usage: mresolv2 [ -t timeout ] [ file... ]
#
# Reads IP addresses and issues non-blocking DNS queries. Answers are
# sent to standard output in RR format:
#
# 1.1.168.192.in-addr.arpa. 86400 IN PTR host1.example.com.
#
# 1.2.168.192.in-addr.arpa. 86400 IN CNAME
1.0-16.2.168.192.in-addr.arpa.
# 1.0-16.2.168.192.in-addr.arpa. 86400 IN PTR host2.example.com.
#
# Michael Fuhr
# mike@fuhr.org
#
# Copyright (c) 1999 Michael Fuhr. All rights reserved. This program is
# free software; you can redistribute it and/or modify it under the same
# terms as Perl itself.
#
# $Id: mresolv2,v 1.1 1999/03/16 10:52:55 mfuhr Exp mfuhr $
#---------------------------------------------------------------------------
---
------------------------------
Date: 20 Jul 1999 09:56:03 -0500
From: Cameron Kaiser <ckaiser@stockholm.ptloma.edu>
Subject: Re: that great DNS lookup script
Message-Id: <B50l3.24161$vw1.980860@newscene.newscene.com>
"kayec" <delete.the.nospam.kayec@gov.ns.ca> writes:
>Sometime ago i was pointed to a very fast DNS lookup script that did
>multiple lookups at a time... very fast, very impressive.
Simply caching whatever you get back from gethostbyaddr() goes a long way.
Multiple lookups at a time -- do you mean asychronously?
--
Cameron Kaiser * ckaiser@stockholm.ptloma.edu * posting with a Commodore 128
http://calvin.ptloma.edu/~spectre/ * "When in doubt, take a pawn." -- M:I
-- Supporting the Commodore 64 and 128: http://www.armory.com/~spectre/cwi/ --
head moderator comp.binaries.cbm * cbm special forces unit $ea31 [tincsf]
------------------------------
Date: 20 Jul 1999 13:22:31 GMT
From: fl_aggie@thepentagon.com (I R A Darth Aggie)
Subject: Re: TPJ/Earthweb junk mail?
Message-Id: <slrn7p8u4v.k7e.fl_aggie@thepentagon.com>
On Mon, 19 Jul 1999 19:36:04 -0400, brian d foy <brian@pm.org>, in
<brian-ya02408000R1907991936040001@news.panix.com> wrote:
+ as dha told me earlier today:
+ Earthweb bites,
+ but Perl programmers bite back.
Hopefully, everyone involved has had their rabies shots. Sounds painful,
in any case.
James
------------------------------
Date: 20 Jul 1999 14:15:06 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: TPJ/Earthweb junk mail?
Message-Id: <7n209a$soj$2@info2.uah.edu>
In article <brian-ya02408000R1907991936040001@news.panix.com>,
brian@pm.org (brian d foy) writes:
: and, now that TPJ is big money, they should start paying real money
: for articles.
It's better than having to pay per-page publishing costs.
Greg
--
As a general rule, don't solve puzzles that open portals to Hell.
-- Ralph Mason
------------------------------
Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 1 Jul 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.
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 V9 Issue 199
*************************************