[21848] in Perl-Users-Digest
Perl-Users Digest, Issue: 4052 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 31 14:05:55 2002
Date: Thu, 31 Oct 2002 11:05:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 31 Oct 2002 Volume: 10 Number: 4052
Today's topics:
Re: *** PERL monitor script...*** <jwillmore@cyberia.com>
Re: [OT] Re: Open a HTML page not using redirect <nobull@mail.com>
Re: Can someone look at this for loop? (Rob)
Re: cron and sendmail - body of message missing?!?... (Chris Milkosky)
format of .db.pag file ? <jim.bloggs@eudoramail.com>
How can I check STDIN in a fork or a child's variable (David E. Shapiro)
Re: How to pass control character to a telnet session (David E. Shapiro)
Re: How to pass control character to a telnet session <nobull@mail.com>
Re: how to share socket handle across related process <someone@somewhere.nl>
Re: log files for previous month <robert.bunney@hotmail.com>
Re: perl error with oracle <rereidy@indra.com>
Re: perl error with oracle (Helgi Briem)
Re: perl error with oracle <g-preston1@ti.com>
Re: perl error with oracle <g-preston1@ti.com>
Pulling MAC address on win32 <andrew.hutchinson@vanderbilt.edu>
Re: Regex Pattern Evaluation (Tad McClellan)
Re: Regex Pattern Evaluation <phileasfog@hotmail.com>
Re: Regexp to match a C-style string <pinyaj@rpi.edu>
Re: Regexp to match a C-style string <garry@ifr.zvolve.net>
telnet in perl <a@b.c>
Re: Why is this an infine loop??? (Leaffoot)
Re: Why is this an infine loop??? (Adam Hapworth)
Re: Why is this an infine loop??? <ilovebritishbeef@yahoo.com>
Re: Why is this an infine loop??? <nobull@mail.com>
windows/unix filename woes (Leaffoot)
Re: windows/unix filename woes (Helgi Briem)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 31 Oct 2002 16:56:35 GMT
From: James Willmore <jwillmore@cyberia.com>
Subject: Re: *** PERL monitor script...***
Message-Id: <20021031115626.47a49157.jwillmore@cyberia.com>
You may also want to try Webmin. It's a not-so-pure Perl application
with lots of other extras, including SSL support, verbose logging and
the ability to limit who can use the script.
> > I am just starting out in perl/cgi scripting...i have done some
> > simple programs , what i want to do is to have a 'system status'
> > web page which has all of our unix box names on it...what i want
> > is a perl script that i can embed into html to monitor these two
> > unix systems, any alerts or if they crash i want this system
> > staus webpage to show the system staus, can this be done...or is
> > there any perl/cgi script that can do the job ....thanks in
> > advance...indy
>
> Try Netsaint, Big Brother, Big Sister, and the like. You may be
> interested in MRTG too.
------------------------------
Date: 31 Oct 2002 18:15:16 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: [OT] Re: Open a HTML page not using redirect
Message-Id: <u9n0oufpaj.fsf@wcl-l.bham.ac.uk>
"ee ee" <ee@ee.ee> writes upside down:
> I disagree that it's nothing to do with Perl
Disagreeing with obviously true statements is a pointless exercise.
> i'm trying to control HTML from within Perl using the Perl commands,
And if you were trying to output gramatically/idomatically correct
German would questions about German grammar and idiom become
"something to do with Perl"?
> ok there is an element of HTML in there but you guys seem to have
> the broadest knowledge
And a lot of the people who post here are fluent (or even native)
speakers of German - but that does not make it acceptable to come here
to ask questions about German!
Occasionally you'll find that quite often the odd thread here does
digress into discussion of HTML, German or netiquette but none of
these are actually related to Perl.
> "Jeff Zucker" <jeff@vpservices.com> wrote in message
> news:3DC0647E.90702@vpservices.com...
> >
> > But since this has nothing to do with perl, why don't we just drop it.
Please do so.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 31 Oct 2002 06:30:38 -0800
From: rob835@hotmail.com (Rob)
Subject: Re: Can someone look at this for loop?
Message-Id: <6841b10c.0210310630.5cc36a74@posting.google.com>
rob835@hotmail.com (Rob) wrote in message news:<6841b10c.0210301253.708fbd44@posting.google.com>...
I see the light now :)
I knew it had to be something simple but yet hard for me to see.
Thanks to all who responded.
------------------------------
Date: 31 Oct 2002 07:21:26 -0800
From: cmilkosk@comcast.net (Chris Milkosky)
Subject: Re: cron and sendmail - body of message missing?!?...
Message-Id: <c1fe2478.0210310721.2cc78e32@posting.google.com>
"Bob Dover" <dover@nortelnetworks.com> wrote in message news:<app3mc$6j1$1@bcarh8ab.ca.nortel.com>...
> "Chris Milkosky" wrote...
> >
> > I run the script, and it runs fine from the commandline, but when I
> > plop it in cron, the body is missing!
>
> I've had problems using cron in the past due to its not picking up all
> of my normal environment settings. You might try using 'at' instead,
> which does copy your environment as part of the setup for execution.
> If that doesn't do it, you'll need to show more of your script.
I think I discovered my problem. As it turns out, it is related to
another program that is called within the script. This program is
returning values I guess I didn't expect, causing the script to bomb
out with a Divide by 0. This may actually be caused by environment
variables as you suggested. The pipe to sendmail was already open at
the time, so it just closed, and the rest of the message didn't
appear.
In other words - my fault.
Thanks for the help Bob! I'm going to try using "at" too...
Chris
------------------------------
Date: Thu, 31 Oct 2002 17:27:15 -0000
From: "doofus" <jim.bloggs@eudoramail.com>
Subject: format of .db.pag file ?
Message-Id: <aprp5m$4emsf$1@ID-150435.news.dfncis.de>
Can anyone shed any light on the likely format of databe files whose =
extensions are .db.pag and .db.dir.
I know dbm.pag etc are DBM. But what about those ones.
--=20
Sorry if this has been posted in the wrong place. Just thought someone =
might know offhand
Best Wishes,
Lord Doofus
------------------------------
Date: 31 Oct 2002 10:06:04 -0800
From: david.shapiro@bti.com (David E. Shapiro)
Subject: How can I check STDIN in a fork or a child's variables in a parent?
Message-Id: <2c75e852.0210311006.b6725ae@posting.google.com>
Hello,
I have a program that waits for a user to enter something. However, I
need it to timeout after awhile if they do not select an option.
I had tried something like:
#!/usr/bin/perl -w
# pipe1 - bidirectional communication using two pipe pairs
# designed for the socketpair-challenged
use IO::Handle;
pipe(READER,WRITER);
my $response = undef;
# Parent
my $pid = fork;
if ($pid) {
close WRITER;
for ($count = 1; $count < 8; $count++) {
unless (not defined(READER)) {
$line = <READER>;
}
if ($line) {
chomp($line);
print "Parent just read this:
`$line'\n";
if ($line =~ /N|Y/i) {
$response = $line;
last;
}
} else {
print "Parent didn't see anything from
child\n";
}
sleep 3;
}
if (not $response) {
kill 9,$pid;
} else {
print "Saw response: $response\n";
}
} else {
close READER;
my $count = 0;
ASK:
print "Do another Tape (y/n):\n";
my $response = <STDIN>;
print WRITER $response;
if ($response !~ /Y|N/i and $count < 3) {
$count++;
goto ASK;
}
exit;
}
Instead of looping in the parent and checking if something in in the
READER, it stops dead until the user types something. I would be
happy enough just to check if $response had something in the parent,
but the parent does not know about the child's $response. It seems
simple, but I am going coco trying to figure this out. There are a
lot too simple examples on forks out there. I have not found one that
shows what I want to do.
David
------------------------------
Date: 31 Oct 2002 10:10:02 -0800
From: david.shapiro@bti.com (David E. Shapiro)
Subject: Re: How to pass control character to a telnet session
Message-Id: <2c75e852.0210311010.3e8b4522@posting.google.com>
It might be way off base, but add \r to it: "\c]\r"
David
pv79@ddsl.net (Prashant Varghese) wrote in message news:<5ff7e2e0.0210302035.78e35979@posting.google.com>...
> Dear Chris,
> How can i find a solution for this problem of using ^] ?
> man perlop will detail you abt how to repesent control character under
> Quote and Quote-like Operators section.
> If thats not true then how do i use it?Do you have any suggestions?
>
> Thanks and Regards,
> Prashant
>
> news@roaima.freeserve.co.uk wrote in message news:<tplopa.6uh.ln@moldev.cmagroup.co.uk>...
> > Prashant Varghese <pv79@ddsl.net> wrote:
> > > has anyone tried passing control character over telnet session to a
> > > remote host.
>
> > > I've been trying to find a way to pass '^]' to terminate the telnet
> > > session in the following manner.
>
> > > $r->print ("\c]");
>
> > > Please tell me if its correct and why it is not working out?
> >
> > I don't know what your $r object is supposed to be, so I can only guess
> > at a possible answer.
> >
> > 1. When you type ^] in a telnet client, it and the following text is
> > grabbed and interpreted by that local client. None of it gets
> > anywhere near the remote host. This means that you can't send a
> > ^] to a remote host using something like Net::Telnet and expect
> > it to work in the same manner. (Net::Telnet has other mechanisms
> > for ending a session.)
> >
> > 2. Are you sure that you should represent ^] by the sequence of
> > characters "\c]"? This doesn't feel right to me
> >
> > Chris
------------------------------
Date: 31 Oct 2002 18:43:32 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: How to pass control character to a telnet session
Message-Id: <u9d6pqfnzf.fsf@wcl-l.bham.ac.uk>
[ I've rearranged this back into order ]
david.shapiro@bti.com (David E. Shapiro) top-posts:
>
> pv79@ddsl.net (Prashant Varghese) wrote in message news:<5ff7e2e0.0210302035.78e35979@posting.google.com>...
> >
> > news@roaima.freeserve.co.uk wrote in message news:<tplopa.6uh.ln@moldev.cmagroup.co.uk>...
> > > Prashant Varghese <pv79@ddsl.net> wrote:
> > > > I've been trying to find a way to pass '^]' to terminate the telnet
> > > > session...
> > > 1. When you type ^] in a telnet client, it and the following text is
> > > grabbed and interpreted by that local client. None of it gets
> > > anywhere near the remote host. This means that you can't send a
> > > ^] to a remote host using something like Net::Telnet and expect
> > > it to work in the same manner. (Net::Telnet has other mechanisms
> > > for ending a session.)
> > How can i find a solution for this problem of using ^] ?
It is impossible to find a solution for an imaginary problem that you
only believe exists because you misunderstood something else.
> It might be way off base, but add \r to it: "\c]\r"
You are way off base.
People refrained from top-posting and actually tried to put their
responses in context (as I have done) they'd not only avoid looking
rude/ignorant but they'd also stand a better chance of actually
comprehending what was said to them.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 31 Oct 2002 18:58:49 +0100
From: "Stefan" <someone@somewhere.nl>
Subject: Re: how to share socket handle across related process
Message-Id: <3dc17004$0$84938$e4fe514c@dreader4.news.xs4all.nl>
"Murtaza Nooruddin" <noorix@yahoo.com> schreef in bericht
news:apr086$48rpl$1@ID-165850.news.dfncis.de...
> I am having a hard time sharing a socket handle between parent and child
> process.
> The Parent is a listening socket, and accepts a new connection, and I must
> give this newly connected socket handle to the child process. Sharing it
in
> shared memory does work, IPC::Shareable says that it can't share GLOB
> variables. I believe there is a way using /proc filesystem under linux,
but
> not sure how.
>
> Pleae help.
>
I presume you want to write a non-blocking TCP server. So in your main
program you got
my $socket = IO::Socket::INET->new( ... )
and after that in an (endless) loop
my $connection = $socket->accept();
so that when you fork() a child process you can
in the main process
- close the connection
- continue the accept-loop
in the child process
- close the socket
- do whatever you like with the connection
- close the connection
- exit
This is possible becaurse "File descriptors (and sometimes locks on those
descriptors) are shared, while everything else is copied". See the
description of fork() for more details.
All this with the usual error checking, child reaping, etc, of course.
Get more information using the command "perldoc perlipc" or on the net at
http://www.perldoc.com/perl5.8.0/pod/perlipc.html#Sockets--Client-Server-Com
munication (www.perldoc.com | Perl Manpage | perlipc). You'll find some
good examples there.
Good luck
Stefan
------------------------------
Date: Thu, 31 Oct 2002 16:11:58 GMT
From: "robertbu" <robert.bunney@hotmail.com>
Subject: Re: log files for previous month
Message-Id: <iDcw9.40746$iV1.2290@nwrddc02.gnilink.net>
I'm new to perl, so the test program below is probably not
"good perl," but it provides you a starting point.
== Rob ==
use Time::Local;
use warnings;
%hshMonths = ("Jan" => 1,
"Feb" => 2,
"March" => 3,
"April" => 4,
"May" => 5,
"June" => 6,
"July" => 7,
"Aug" => 8,
"Sept" => 9,
"Oct" => 10,
"Nov" => 11,
"Dec" => 12
);
$SecondsInSevenDays = 7*24*60*60;
@arNow = localtime time;
$timeNow = timelocal(0,0,0,$arNow[3],$arNow[4]+1,$arNow[5]+1900);
while (<DATA>)
{
if (/.*\[(\d+)\/([^\/]+)\/(\d+)/) #Parse out day, month, and year
{
$timeLog = timelocal(0,0,0,$1, $hshMonths{$2}, $3);
if (($timeNow - $timeLog) < $SecondsInSevenDays) #Less than 7 days?
{
print "Yes: $_\n";
}
else
{
print "No: $_\n";
}
}
}
__DATA__
255.255.255.255 - - [30/Oct/2002:23:49:11 +0000] "GET /path/to/file
HTTP/1.0" \200 7377
255.255.255.255 - - [29/Oct/2002:23:49:11 +0000] "GET /path/to/file
HTTP/1.0" \200 7377
255.255.255.255 - - [28/Oct/2002:23:49:11 +0000] "GET /path/to/file
HTTP/1.0" \200 7377
255.255.255.255 - - [27/Oct/2002:23:49:11 +0000] "GET /path/to/file
HTTP/1.0" \200 7377
255.255.255.255 - - [26/Oct/2002:23:49:11 +0000] "GET /path/to/file
HTTP/1.0" \200 7377
255.255.255.255 - - [25/Oct/2002:23:49:11 +0000] "GET /path/to/file
HTTP/1.0" \200 7377
255.255.255.255 - - [24/Oct/2002:23:49:11 +0000] "GET /path/to/file
HTTP/1.0" \200 7377
255.255.255.255 - - [23/Oct/2002:23:49:11 +0000] "GET /path/to/file
HTTP/1.0" \200 7377
255.255.255.255 - - [22Oct/2002:23:49:11 +0000] "GET /path/to/file HTTP/1.0"
\200 7377
255.255.255.255 - - [21/Oct/2002:23:49:11 +0000] "GET /path/to/file
HTTP/1.0" \200 7377
------------------------------
Date: Thu, 31 Oct 2002 07:19:10 -0700
From: Ron Reidy <rereidy@indra.com>
Subject: Re: perl error with oracle
Message-Id: <3DC13BDE.87756AEB@indra.com>
Jerry Preston wrote:
>
> Hi!
>
> I just setup a new server with solaris 8 and installed perl5.6.1 and all
>
> seems to be working great except that I get the following error:
>
> DBD::Oracle initialisation failed: Can't locate auto/DBD/Oracle/ORA_OCI.al
>
> in @INC (@INC contains:
>
> /export/home/kthmgr/lib/perl5/site_perl/5.6.0/sun4-solaris
>
> /usr/local/lib/perl5/5.6.1/sun4-solaris /usr/local/lib/perl5/5.6.1
>
> /usr/local/lib/perl5/site_perl/5.6.1/sun4-solaris
>
> /usr/local/lib/perl5/site_perl/5.6.1 /usr/local/lib/perl5/site_perl .) at
>
> /usr/local/lib/perl5/site_perl/5.6.1/sun4-solaris/DBD/Oracle.pm line 48
>
> at /var/apache/cgi-bin/DM4/fo_fails_only.cgi line 31
>
> Any ideas what is wrong? How to fix?
>
> Thanks,
>
> Jerry
Did you install the Oracle client? What is the output of make? Did you
read the README files? Did you install DBI first? etc., etc. ...
--
Ron Reidy
Oracle DBA
------------------------------
Date: Thu, 31 Oct 2002 14:33:32 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: perl error with oracle
Message-Id: <3dc13ec8.1336848897@news.cis.dfn.de>
On Thu, 31 Oct 2002 07:31:30 -0600, "Jerry Preston"
<g-preston1@ti.com> wrote:
>I just setup a new server with solaris 8 and installed perl5.6.1 and all
>seems to be working great except that I get the following error:
>DBD::Oracle initialisation failed: Can't locate auto/DBD/Oracle/ORA_OCI.al
>in @INC
Install DBD::Oracle.You probably need to reinstall DBI as
well. You may need to set the ORACLE_HOME environment
variable. It is very likely that you also need to set up
Oracle itself or at least a client.
--
Regards, Helgi Briem
helgi AT decode DOT is
A: Top posting
Q: What is the most irritating thing on Usenet?
- "Gordon" on apihna
------------------------------
Date: Thu, 31 Oct 2002 11:29:46 -0600
From: "Jerry Preston" <g-preston1@ti.com>
Subject: Re: perl error with oracle
Message-Id: <aprpa7$kpn$1@tilde.itg.ti.com>
Ron,
How do I install the oracle client? Where do I find it?
Thanks,
Jerry
"Ron Reidy" <rereidy@indra.com> wrote in message
news:3DC13BDE.87756AEB@indra.com...
> Jerry Preston wrote:
> >
> > Hi!
> >
> > I just setup a new server with solaris 8 and installed perl5.6.1 and all
> >
> > seems to be working great except that I get the following error:
> >
> > DBD::Oracle initialisation failed: Can't locate
auto/DBD/Oracle/ORA_OCI.al
> >
> > in @INC (@INC contains:
> >
> > /export/home/kthmgr/lib/perl5/site_perl/5.6.0/sun4-solaris
> >
> > /usr/local/lib/perl5/5.6.1/sun4-solaris /usr/local/lib/perl5/5.6.1
> >
> > /usr/local/lib/perl5/site_perl/5.6.1/sun4-solaris
> >
> > /usr/local/lib/perl5/site_perl/5.6.1 /usr/local/lib/perl5/site_perl .)
at
> >
> > /usr/local/lib/perl5/site_perl/5.6.1/sun4-solaris/DBD/Oracle.pm line 48
> >
> > at /var/apache/cgi-bin/DM4/fo_fails_only.cgi line 31
> >
> > Any ideas what is wrong? How to fix?
> >
> > Thanks,
> >
> > Jerry
> Did you install the Oracle client? What is the output of make? Did you
> read the README files? Did you install DBI first? etc., etc. ...
> --
> Ron Reidy
> Oracle DBA
------------------------------
Date: Thu, 31 Oct 2002 11:32:04 -0600
From: "Jerry Preston" <g-preston1@ti.com>
Subject: Re: perl error with oracle
Message-Id: <aprpeh$l9d$1@tilde.itg.ti.com>
How do I setup the Oracle Client? Where do I find it?
Thanks,
Jerry
"Ron Reidy" <rereidy@indra.com> wrote in message
news:3DC13BDE.87756AEB@indra.com...
> Jerry Preston wrote:
> >
> > Hi!
> >
> > I just setup a new server with solaris 8 and installed perl5.6.1 and all
> >
> > seems to be working great except that I get the following error:
> >
> > DBD::Oracle initialisation failed: Can't locate
auto/DBD/Oracle/ORA_OCI.al
> >
> > in @INC (@INC contains:
> >
> > /export/home/kthmgr/lib/perl5/site_perl/5.6.0/sun4-solaris
> >
> > /usr/local/lib/perl5/5.6.1/sun4-solaris /usr/local/lib/perl5/5.6.1
> >
> > /usr/local/lib/perl5/site_perl/5.6.1/sun4-solaris
> >
> > /usr/local/lib/perl5/site_perl/5.6.1 /usr/local/lib/perl5/site_perl .)
at
> >
> > /usr/local/lib/perl5/site_perl/5.6.1/sun4-solaris/DBD/Oracle.pm line 48
> >
> > at /var/apache/cgi-bin/DM4/fo_fails_only.cgi line 31
> >
> > Any ideas what is wrong? How to fix?
> >
> > Thanks,
> >
> > Jerry
> Did you install the Oracle client? What is the output of make? Did you
> read the README files? Did you install DBI first? etc., etc. ...
> --
> Ron Reidy
> Oracle DBA
------------------------------
Date: Thu, 31 Oct 2002 08:22:50 -0600
From: "Andrew Hutchinson" <andrew.hutchinson@vanderbilt.edu>
Subject: Pulling MAC address on win32
Message-Id: <aprege$hr6$1@news.vanderbilt.edu>
Does anybody know a clean way to get a list of the MAC Addresses on a win32
machine (2000 or XP) cleanly? I wrote a routine that backticks `ipconfig
/all` and then uses regexes to parse out the MACs, but I'd rather do it w/o
spawning an external process. Any ideas?
Thanks
Andrew Hutchinson
Vanderbilt University Medical Center
------------------------------
Date: Thu, 31 Oct 2002 08:17:21 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Regex Pattern Evaluation
Message-Id: <slrnas2erg.1r5.tadmc@magna.augustmail.com>
Phileas Fog <phileasfog@hotmail.com> wrote:
> I'm trying to find a way to do a an eval of the substitution pattern in a
> regex in a simple way.
> As you can see I would like to get the pattern to do an eval of the
> substitution before substituting...
--------------------------------
#!/usr/bin/perl
use warnings;
use strict;
my %MACROS = (
"#macro", '"<macro>$1</macro>"', # added double quotes for 2nd eval
);
my $data = "#macro(Hello World)";
print "before: $data\n";
$data =~ s/#macro\((.+?)\)/ $MACROS{'#macro'} /gee;
print "after: $data\n";
--------------------------------
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 31 Oct 2002 16:40:16 +0100
From: "Phileas Fog" <phileasfog@hotmail.com>
Subject: Re: Regex Pattern Evaluation
Message-Id: <apris6$4ausj$1@ID-13188.news.dfncis.de>
"Tad McClellan" <tadmc@augustmail.com> wrote in message
> my %MACROS = (
> "#macro", '"<macro>$1</macro>"', # added double quotes for 2nd eval
Ha ! Right ! Thanks for reminder, I forgot this one and I tried to do a
double eval which of course could not work in my case.
Many thanks.
------------------------------
Date: Thu, 31 Oct 2002 09:07:16 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: Roger Shrubber <roger256shrubber@hotmail.com>
Subject: Re: Regexp to match a C-style string
Message-Id: <Pine.A41.3.96.1021031090442.100678A-100000@cortez.sss.rpi.edu>
[posted & mailed]
On 31 Oct 2002, Roger Shrubber wrote:
>I need to create a text file format which holds strings. The strings can
>legally contain any ASCII character, so they must be encoded in some way.
>C-style would be most convenient. Some example records might be:
You can find the regex in the FAQ:
perldoc -q comment
shows a regex with this chunk in it:
"(\\.|[^"\\])*"
You can also write that as
"[^"\\]*(?:\\.[^"\\]*)*"
--
Jeff "japhy" Pinyan RPI Acacia Brother #734 2002 Acacia Senior Dean
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
Date: Thu, 31 Oct 2002 14:20:37 GMT
From: Garry Williams <garry@ifr.zvolve.net>
Subject: Re: Regexp to match a C-style string
Message-Id: <slrnas2ep5.9h7.garry@zfw.zvolve.net>
On 31 Oct 2002 00:28:33 -0800, Roger Shrubber
<roger256shrubber@hotmail.com> wrote:
> I need to create a text file format which holds strings. The strings can
> legally contain any ASCII character, so they must be encoded in some way.
> C-style would be most convenient. Some example records might be:
>
> ITEM foo="a string" bar="a string containing \"quotes\""
> ITEM baz="a string ending with a slosh: \\"
> ITEM qux="a string ending with a slosh and a quote: \\\""
>
> Anyone know of a regexp that can find the limits of a string, and won't be
> tripped up by combinations of escaped quotes and escaped sloshes?
This is a FAQ.
See perldoc -q delimit
"How can I split a [character] delimited string except when inside
[character]? (Comma-separated files)"
--
Garry Williams
------------------------------
Date: Thu, 31 Oct 2002 19:18:23 +0100
From: ZZT <a@b.c>
Subject: telnet in perl
Message-Id: <aprs5f$1ij$1@news1.wdf.sap-ag.de>
Hello,
how can I simulate a telnet session to a specific port in perl and get
the "console" responce back to a variable/array, send keys etc. simple
as possible?
thanks a lot
------------------------------
Date: 31 Oct 2002 08:15:55 -0800
From: leaffoot@hotmail.com (Leaffoot)
Subject: Re: Why is this an infine loop???
Message-Id: <d7bd06a3.0210310815.18393741@posting.google.com>
"El Senor" <ilovebritishbeef@yahoo.com> wrote in message news:<GV4w9.5030$V15.499265@newsread2.prod.itd.earthlink.net>...
> The following code is supposed to get several HTML pages and crudely examine
> which page has more HTML tags.
>
> I have examined the code VERY carefully but I cannot understand why it
> results in an infinite loop. For some reason the /g modifyer in the while
> loop is not working - the regular expression matches the same html tag over
> and over again, like it begins from the beginning each time.
>
> Can anyone tell me why the /g is not working so that the code results in an
> infinite loop?
>
> Thanks,
> -Mike
<snip>
> $num_tags++ while( $current_website->{html} =~ /<.*?>/gs );
My guess is, it's this line. I think your intention is to increment
$num_tags for each match, but if there is a match, it will continue to
match forever. Change your "while" to an "if" and increment through
the lines on the website.
Becka
------------------------------
Date: 31 Oct 2002 08:47:27 -0800
From: hap@mikomi.org (Adam Hapworth)
Subject: Re: Why is this an infine loop???
Message-Id: <a6cb04db.0210310847.43e5acae@posting.google.com>
I beleive that this may be your problem
$num_tags++ while( $current_website->{html} =~ /<.*?>/gs );
that while will never be false because once $current_website->{html}
is true it will go back and check that same $current_website to see if
it is a true and cause your loop. maybe a proper while block doing
some more testing on you string would work better.
Adam
"El Senor" <ilovebritishbeef@yahoo.com> wrote in message news:<GV4w9.5030$V15.499265@newsread2.prod.itd.earthlink.net>...
> The following code is supposed to get several HTML pages and crudely examine
> which page has more HTML tags.
>
> I have examined the code VERY carefully but I cannot understand why it
> results in an infinite loop. For some reason the /g modifyer in the while
> loop is not working - the regular expression matches the same html tag over
> and over again, like it begins from the beginning each time.
>
> Can anyone tell me why the /g is not working so that the code results in an
> infinite loop?
>
> Thanks,
> -Mike
>
>
> # q1.pl
> # Given URLs specified on the command line, retrieves their web pages and
> # displays the url of the web page with the most HTML tags. An HTML tag is
> # defined as any text beginning with "<" and ending with ">". If no
> websites
> # are specified, defaults to comparing "www.google.com" and "www.yahoo.com".
>
>
> use strict;
> use LWP::Simple;
>
> # Obtain the websites we want to compare from the user. If no websites
> # specified, use yahoo and google.
> my @websites;
>
> if( @ARGV <= 0 ) {
> push( @websites, { url => $_ } ) foreach
> ("http://www.google.com", "http://www.yahoo.com");
> }
> else {
> push( @websites, { url => $_ } ) foreach @ARGV;
> }
>
>
> # Retrieve HTML for each web page using LWP::Simple's get(). HTML stored in
> # the list of hashes under key {html}.
> foreach my $current_website (@websites) {
> $current_website->{html} = LWP::Simple::get( $current_website->{url} ) or
> die("\nCould not retrieve requested website: $current_website->{url}\n");
> }
>
>
> # Count number of HTML tags for each web page. An HTML tag is defined as
> the
> # smallest possible block of text beginning with "<" and ending with ">".
> my $num_tags;
>
> foreach my $current_website (@websites) {
> $num_tags = 0;
> #######################################
> # Here is the infinite while() loop: WHY??
> # if I change it to $temp = $current_website->{html} and
> # then use $temp in the while condition, it works perfectly.
> # But what is wrong with the way I have it here?
> ###########################################
> #
> $num_tags++ while( $current_website->{html} =~ /<.*?>/gs );
> $current_website->{num_tags} = $num_tags;
> }
>
>
> # Find the website with the most HTML tags and display it.
> @websites = reverse sort { $a->{num_tags} <=> $b->{num_tags} }@websites;
> print "\n$websites[0]->{url} has more tags than ",
> join( ", ", map { $_->{url} } @websites[1..$#websites] ), ".\n";
------------------------------
Date: Thu, 31 Oct 2002 18:01:04 GMT
From: "El Senor" <ilovebritishbeef@yahoo.com>
Subject: Re: Why is this an infine loop???
Message-Id: <Adew9.5667$V15.575079@newsread2.prod.itd.earthlink.net>
"Adam Hapworth" <hap@mikomi.org> wrote:
> $num_tags++ while( $current_website->{html} =~ /<.*?>/gs );
>
> that while will never be false because once $current_website->{html}
> is true it will go back and check that same $current_website to see if
> it is a true and cause your loop. maybe a proper while block doing
> some more testing on you string would work better.
Are you sure you know what the "/g" option for regular expressions does?
It's supposed to begin searching after the last match and return false when
there are no matches left (ie, it autoiterates through the text). If I am
confused about what "/g" means please let me know.
Also, can you explain why the following results in an infinite loop:
while( $current_website->{html} =~ /<.*?>/gs ) {
$num_tags++;
}
But this does not result in an infinite loop and properly counts the
number of HTML tags:
my $temp = $current_website->{html};
while( $temp =~ /<.*?>/gs ) {
$num_tags++;
}
Thanks,
-Mike
------------------------------
Date: 31 Oct 2002 18:27:40 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Why is this an infine loop???
Message-Id: <u9iszifopv.fsf@wcl-l.bham.ac.uk>
"El Senor" <ilovebritishbeef@yahoo.com> writes:
> "Adam Hapworth" <hap@mikomi.org> wrote:
> > $num_tags++ while( $current_website->{html} =~ /<.*?>/gs );
> >
> > that while will never be false because once $current_website->{html}
> > is true it will go back and check that same $current_website to see if
> > it is a true and cause your loop. maybe a proper while block doing
> > some more testing on you string would work better.
>
> Are you sure you know what the "/g" option for regular expressions does?
I'm sure he doesn't.
> Also, can you explain why the following results in an infinite loop:
> while( $current_website->{html} =~ /<.*?>/gs ) {
> $num_tags++;
> }
>
> But this does not result in an infinite loop and properly counts the
> number of HTML tags:
> my $temp = $current_website->{html};
> while( $temp =~ /<.*?>/gs ) {
> $num_tags++;
> }
Since you have found something that appears to be a bug in Perl you
should try to generate a _minimal_ but _complete_ (strict, warning
free) script that other people could run and that you have found will
actually reproduce the symptoms on your system. Post it _unaltered_
together with at least some version information.
For example the following script does _not_ reproduce the problem on
5.6.1 or 5.8.0 on Linux.
#!/usr/bin/perl
use strict;
use warnings;
my $current_website = { html => "xxx <one> sd\nasd <two> xxx" };
my $num_tags = 0;
while ( $current_website->{html} =~ /<.*?>/gs ) {
$num_tags++;
}
print "$num_tags\n";
__END__
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 31 Oct 2002 08:20:49 -0800
From: leaffoot@hotmail.com (Leaffoot)
Subject: windows/unix filename woes
Message-Id: <d7bd06a3.0210310820.732ace75@posting.google.com>
Hi,
I have a short script on a windows machine that creates files on a
unix machine. I know there is a long filenames problem between
windows and unix, and I have attempted to shorten names to rule that
out as a possibility. However, I still get 2 junk files for every
good file I create. Does anyone know how I can avoid this? Here is
the code.
#!C:/Perl
# script to practice copy, move and delete on unix from windows
use strict;
my $maulpath = "\\\\MYUNIXMACHINE\\testbka\\";
my $filestr = "${maulpath}U123456.txt";
open(SINGLEFILE, ">$filestr") || die "Can't open $filestr!\n";
print SINGLEFILE "THis is a test.\n" x 50;
close(SINGLEFILE);
That's it. Thanks in advance for advice.
Becka Louden
------------------------------
Date: Thu, 31 Oct 2002 16:47:01 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: windows/unix filename woes
Message-Id: <3dc15b7c.1344197173@news.cis.dfn.de>
On 31 Oct 2002 08:20:49 -0800, leaffoot@hotmail.com
(Leaffoot) wrote:
>Hi,
>
>I have a short script on a windows machine that creates files on a
>unix machine. I know there is a long filenames problem between
>windows and unix, and I have attempted to shorten names to rule that
>out as a possibility. However, I still get 2 junk files for every
>good file I create. Does anyone know how I can avoid this? Here is
>the code.
>
>#!C:/Perl
># script to practice copy, move and delete on unix from windows
>use strict;
Don't use backslashes. There is no need for them on
Windows (use normal slashes) and Unix does not understand
them at all. Also, don't use double quotes unless you need
interpolation.
>my $maulpath = "\\\\MYUNIXMACHINE\\testbka\\";
my $maulpath = '//MYUNIXMACHINE/testbka';
>my $filestr = "${maulpath}U123456.txt";
Now I use double strings to interpolate, because that's
what I want here:
my $filestr = "$maulpath/U123456.txt";
This is fine but I hate the use of ||. Why not use
the clearer 'or' instead and as an added bonus,
no more need for parentheses. Why $filestr? Why
not $filename? Any particular reason?
open SINGLEFILE "> $filestr"
or die "Can't open $filestr!\n";
>open(SINGLEFILE, ">$filestr") || die "Can't open $filestr!\n";
>print SINGLEFILE "THis is a test.\n" x 50;
I like to put an error warning in when closing filehandles
that have been opened for writing, because occasionally
they fail (disk full usually).
>close(SINGLEFILE);
So, to sum up:
#!perl
use warnings;
use strict;
my $maulpath = '//MYUNIXMACHINE/testbka';
my $filestr = "$maulpath/U123456.txt";
open SINGLEFILE "> $filestr"
or die "Can't open $filestr!\n";
print SINGLEFILE "This is a test.\n" x 50;
close SINGLEFILE or die "Can't close $filestr:$!\n";
--
Regards, Helgi Briem
helgi AT decode DOT is
A: Top posting
Q: What is the most irritating thing on Usenet?
- "Gordon" on apihna
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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 V10 Issue 4052
***************************************