[23778] in Perl-Users-Digest
Perl-Users Digest, Issue: 5982 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Dec 27 00:05:55 2003
Date: Fri, 26 Dec 2003 21:05:05 -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 Fri, 26 Dec 2003 Volume: 10 Number: 5982
Today's topics:
Re: Binary program? <gnari@simnet.is>
Re: effecient software engineering (Aaron)
how to put file(s) from a webform (on windows) to (Jonay Herrera)
Re: how to put file(s) from a webform (on windows) <gnari@simnet.is>
Re: how to put file(s) from a webform (on windows) <noreply@gunnar.cc>
I don't know what's wrong here ! <groleau@freeshell.org>
Re: I don't know what's wrong here ! <gnari@simnet.is>
Re: I don't know what's wrong here ! <krahnj@acm.org>
Re: I don't know what's wrong here ! <noreply@gunnar.cc>
Re: I don't know what's wrong here ! <groleau@freeshell.org>
Re: I don't know what's wrong here ! <groleau@freeshell.org>
Re: I don't know what's wrong here ! <groleau@freeshell.org>
Re: isql in perl (mike)
Re: isql in perl <ndronen@io.frii.com>
Re: looping every x seconds <joecool118@nospam.hotmail.com>
Re: matching balanced parens (ivo welch)
Newbie problems with > in a string <albert.browne@ntlworld.com>
Re: Newbie problems with > in a string <noreply@gunnar.cc>
Re: Newbie problems with > in a string (Tad McClellan)
Re: why this code shots up memory usage <bik.mido@tiscalinet.it>
Re: why this code shots up memory usage (Jay Tilton)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 26 Dec 2003 12:23:28 -0000
From: "Ragnar Hafstað" <gnari@simnet.is>
Subject: Re: Binary program?
Message-Id: <bsh98e$ejp$1@news.simnet.is>
"Just in" <goth1938@hotmail.com> wrote in message
news:bsgnct$fd4$1@news01.intel.com...
> Theres this old Apollo Unix station that runs a cronjob that actually does
> something, that I'm supposed to help identify.
>
> What the cronjob calls is what I assume to be a Perl program, because the
> first line has the path perl on it with old shebang hash in front of it.
>
> What miffs me is what follows after it - binary characters without any EOL
> termination.
>
> I assume this is encrypted, or even compiled. But I'm not so sure how perl
> is interpreting the binary.
>
> I know it would help if I posted an example, but I can't as it is
> confidential information to my company.
can you show us the crontab line?
surely you can show us the first line of the script and next 10 bytes or so.
gnari
------------------------------
Date: 26 Dec 2003 07:45:16 -0800
From: afriedman111@hotmail.com (Aaron)
Subject: Re: effecient software engineering
Message-Id: <a038b5c9.0312260745.283b0192@posting.google.com>
James Willmore <jwillmore@remove.adelphia.net> wrote in message news:<20031224095543.0c57e9be.jwillmore@remove.adelphia.net>...
> On 23 Dec 2003 23:08:14 -0800
> afriedman111@hotmail.com (Aaron) wrote:
>
> > I read that scripting is very useful in software engineering. I
> > picked up some video game programming books and they mention that
> > scripting can be used to seperate the code that is likely to change
> > from the core game engine.
> >
> > I have heard that Perl is widely used in the game programming
> > industry. Can perl scripting used for this? If not, what is it used
> > for? If it is used for this, how does Perl communicate with the
> > main game engine? Can some one explain how this works? For example:
> > are there two executables that run and communicate back and forth,
> > or is there only one executable? Is there a Perl interpreter that
> > reads in scripts into your main program?
>
> What *exactly* are you looking to do? Are you just trying to get a
> feel for the capabilities of Perl? If that's the case, go to
> http://www.perl.com/ and start reading :-)
>
> You *may* want to read perlembed (if you have Perl installed, then
> just type 'perldoc perlembed' at the command line to get this document
> - if not, visit http://perldoc.com). This may be what you're after.
> It's a way to embed Perl code in your C application - if I understand
> your post. This also *assumes* that you know C :-) You could also
> check out SWIG (http://www.swig.org/), which will also allow you to
> "connect" Perl code with a C/C++ application.
>
> If this isn't anything you're looking for, post with more specifics
> :-)
>
> HTH
>
> --
> Jim
>
> Copyright notice: all code written by the author in this post is
> released under the GPL. http://www.gnu.org/licenses/gpl.txt
> for more information.
>
> a fortune quote ...
> Speak softly and carry a +6 two-handed sword.
Thanks man, the swig documentation is very helpful. I guess my post
wasn't really descriptive of what I needed. I am looking to connect
Perl to C++. I talked to someone who programs for a gaming company
and he told me, "It's good to know perl scripting." I've been going
from book and website to website looking for appropriate uses of perl
in the game coding buisness. I haven't really come across anything
that relates to perl. The closest thing I found was a description of
how scripting, in general, can be useful. It read, for example, if
you want to change a bitmap in the game, instead of having a
programmer go in and change the name of the bmp file in the code, you
can have a script do this and save the programmer some time. It's an
effective way to seperate code that changes alot from the complicated
logic that makes up the game engine. It also modularizes the code.
Then I found an example of a very basic scripting engine that
implements a few functions of 80x86 assembly language (along with some
functions that imported other functions written in the main game
engine) and uses it to program a "Ponglike" game. The example went
from the design of the scripting language to the implementation of a
compiler for the scripting language. My original question was, "can a
perl script be used to write code that works like this engine?" I
know it is a fundamental question.
I read some on the swig and I'm going to go browsing through some
stuff on www.perl.com. As soon as I get to my home computer I will
check out the perlembed. Thank you very much for responding to my
message!
Aaron
------------------------------
Date: 26 Dec 2003 04:38:33 -0800
From: jonay.herrera@pandora.be (Jonay Herrera)
Subject: how to put file(s) from a webform (on windows) to a unix/linux machine ?
Message-Id: <41934070.0312260438.341563da@posting.google.com>
Hello,
I have question:
How I can put file(s) from windows ( throught a webform) to
Unix/linux machine (webserver) ?
why ?
to do with the asked file some other operations on linux or
unix (also perlscripts )and give the output back to my
webbrowser ...
thanks,
jonay herrera
------------------------------
Date: Fri, 26 Dec 2003 13:13:13 -0000
From: "Ragnar Hafstað" <gnari@simnet.is>
Subject: Re: how to put file(s) from a webform (on windows) to a unix/linux machine ?
Message-Id: <bshc5o$eol$1@news.simnet.is>
"Jonay Herrera" <jonay.herrera@pandora.be> wrote in message
news:41934070.0312260438.341563da@posting.google.com...
> Hello,
>
> I have question:
>
> How I can put file(s) from windows ( throught a webform) to
> Unix/linux machine (webserver) ?
you use a html form input type 'file'
look at the CGI module.
there are better newsgroups for your question, like comp.infosystem.www.*
come back here when you have a Perl question.
gnari
------------------------------
Date: Fri, 26 Dec 2003 22:58:47 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: how to put file(s) from a webform (on windows) to a unix/linux machine ?
Message-Id: <bsib2a$cs6o7$1@ID-184292.news.uni-berlin.de>
Ragnar Hafstað wrote:
> Jonay Herrera wrote:
>> How I can put file(s) from windows ( throught a webform) to
>> Unix/linux machine (webserver) ?
>
> you use a html form input type 'file'
> look at the CGI module.
This script:
http://groups.google.com/groups?selm=bqpqmd%24262n27%241%40ID-184292.news.uni-berlin.de
might help you get started. It's supposed to be invoked from this
form:
<form method="post" enctype="multipart/form-data"
action="/cgi-bin/upload.pl">
<input type="file" name="myfile">
<input type="submit">
</form>
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Fri, 26 Dec 2003 17:44:00 -0500
From: Wes Groleau <groleau@freeshell.org>
Subject: I don't know what's wrong here !
Message-Id: <N8GdnUlDLKMsJHGi4p2dnA@gbronline.com>
I have a script to process a certain file format.
It was working at one time, but it doesn't now.
Obviously I changed something important, but
I have no memory of doing so, nor can I see anything wrong.
The input format: Each line has up to four parts:
Level, ID, Tag, and Text; separated by white space.
White space is optional _before_ the level.
ID is optional; if present, it is the second part.
It is printable characters, starting and ending
with '@'
Tag is always there. It is a single "word" of
letters, no white space. For simplicity, I am
going for any non-whitespace characters.
Text is optional and is everything after the
tag.
Here is what is not working:
@lines = <STDIN>; # Read all lines into array @lines
foreach (@lines) # Each line is placed into predefined scalar $_
{
# Get rid of CR/LF chars for originating platform.
# (So this platform's style can be put back on later.)
chomp;
s/[\r\n]//;
($Level, $ID, $Tag, $XRef, $Text, $Comment) = ("", "", "", "", "", "");
# Get the component parts of the line.
# Can UTF-8 input break this regexp???
#($Level, $ID, $Tag, $XRef, $Text, $Comment) =
# --- ----- --- ----- -- --
#/^\s*(\d+)\s+(@\S+@)?\s*(\S+)s+(@\S+@)?\s+(.*)?({{.*}})?/;
# 1 2 3 4 5 6
# Let's just use four (standard GEDCOM) for now.
# 1 2 3 4
/^\s*(\d+)\s+(@\S+@)?\s*(\S+)\s+(.*)/;
# Get level of subrecord
if ( ! defined ( $1 ) )
{
$Level = 0;
$LineEOL = "NO LEVEL: $_\n";
}
else
{
$Level = $1;
}
print $Level . "\n"; # This part (Level) seems to work
# Save the label (if specified)
if ( ! defined ( $2 ) )
{
$ID = "";
}
else
{
$ID = $2;
}
print $ID . "\n";
# Uppercase the tag
if ( ! defined ( $3 ) )
{
$Tag = "";
$LineEOL = "NO TAG: $_\n";
}
else
{
$Tag = $3;
}
print $Tag . "\n"; # When input line is "0 HEAD" this should be "HEAD"
# but it is blank instead and the diagnostic "NO TAG"
# is added.
# Save everything else
if ( ! defined ( $4 ) )
{
$Text = "";
}
else
{
$Text = $4;
}
print $Text . "\n";
----------
In the form above, ID and Text are unknown, since the script
wants to open and write to a file with name derived from $Tag.
So it blows up on the first line "0 HEAD"
--
Wes Groleau
"Lewis's case for the existence of God is fallacious."
"You mean like circular reasoning?"
"He believes in God. Therefore, he's fallacious."
------------------------------
Date: Fri, 26 Dec 2003 23:43:15 -0000
From: "Ragnar Hafstað" <gnari@simnet.is>
Subject: Re: I don't know what's wrong here !
Message-Id: <bsih3a$g3t$1@news.simnet.is>
"Wes Groleau" <groleau@freeshell.org> wrote in message
news:N8GdnUlDLKMsJHGi4p2dnA@gbronline.com...
>
snipped verbose description of problem
in case like this you should make a short script only containing the part
that seems to be failing
and usually the problem will become clear
> /^\s*(\d+)\s+(@\S+@)?\s*(\S+)\s+(.*)/;
look at this a bit:
(your input is '0 HEAD')
^\s* zero or more whitespace. ok
(\d+) one ore more digits. ok matches '0', the rest is ' HEAD'
\s+ one or more ws. matches ' ', rest is 'HEAD'
(@\S+@)? maches ''
\s* matches ''
(\S+) matches 'HEAD' rest is ''
\s+ does not match . oooooops
(.*)/;
maybe your previous input contained space at the end of the '0 HEAD' line
gnari
------------------------------
Date: Sat, 27 Dec 2003 00:51:38 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: I don't know what's wrong here !
Message-Id: <3FECD770.39106E3E@acm.org>
Wes Groleau wrote:
>
> I have a script to process a certain file format.
> It was working at one time, but it doesn't now.
> Obviously I changed something important, but
> I have no memory of doing so, nor can I see anything wrong.
>
> The input format: Each line has up to four parts:
> Level, ID, Tag, and Text; separated by white space.
>
> White space is optional _before_ the level.
>
> ID is optional; if present, it is the second part.
> It is printable characters, starting and ending
> with '@'
>
> Tag is always there. It is a single "word" of
> letters, no white space. For simplicity, I am
> going for any non-whitespace characters.
>
> Text is optional and is everything after the
> tag.
>
> Here is what is not working:
use warnings;
use strict;
> @lines = <STDIN>; # Read all lines into array @lines
> foreach (@lines) # Each line is placed into predefined scalar $_
> {
Do you really need to slurp the entire input into an array?
> # Get rid of CR/LF chars for originating platform.
> # (So this platform's style can be put back on later.)
> chomp;
> s/[\r\n]//;
chomp() removes the contents of $/ from the end of $_. s/[\r\n]//
removes the FIRST occurrence of either \r or \n from $_. If you want to
remove any trailing whitespace including \r and \n then:
s/\s+\Z//;
> ($Level, $ID, $Tag, $XRef, $Text, $Comment) = ("", "", "", "", "", "");
>
> # Get the component parts of the line.
> # Can UTF-8 input break this regexp???
> #($Level, $ID, $Tag, $XRef, $Text, $Comment) =
> # --- ----- --- ----- -- --
> #/^\s*(\d+)\s+(@\S+@)?\s*(\S+)s+(@\S+@)?\s+(.*)?({{.*}})?/;
> # 1 2 3 4 5 6
>
> # Let's just use four (standard GEDCOM) for now.
> # 1 2 3 4
> /^\s*(\d+)\s+(@\S+@)?\s*(\S+)\s+(.*)/;
Why not just assign directly to your variables? That way you can
eliminate all the following else clauses. Also, the @ characters have
to be escaped or perl will try to interpolate them as arrays.
my ( $Level, $ID, $Tag, $Text ) =
/^\s*(\d+)\s*(\@\S+\@)?\s*(\S+)\s*(.*)/;
# Get level of subrecord
if ( not defined $Level )
{
$Level = 0;
$LineEOL = "NO LEVEL: $_\n";
}
print "$Level\n"; # This part (Level) seems to work
# Save the label (if specified)
if ( not defined $ID )
{
$ID = '';
}
print "$ID\n";
# Uppercase the tag
if ( not defined $Tag )
{
$Tag = '';
$LineEOL = "NO TAG: $_\n";
}
print "$Tag\n"; # When input line is "0 HEAD" this should be "HEAD"
# but it is blank instead and the diagnostic "NO TAG"
# is added.
# Save everything else
if ( not defined $Text )
{
$Text = '';
}
print "$Text\n";
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sat, 27 Dec 2003 01:59:18 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: I don't know what's wrong here !
Message-Id: <bsill8$dhpdb$1@ID-184292.news.uni-berlin.de>
Wes Groleau wrote:
>
> Text is optional and is everything after the tag.
That condition is not reflected in this regex, which requires one or
more whitespace characters after Tag, or else it won't capture the
data as expected:
> /^\s*(\d+)\s+(@\S+@)?\s*(\S+)\s+(.*)/;
---------------------------------^^^
It's better written as:
/^\s*(\d+)\s+(@\S+@)?\s*(\S+)(?:\s+(.+))?/;
---------------------------------^^^-------^^
Other comments:
You should declare your variables and run your script with strictures
and warnings enabled.
use strict;
use warnings;
> Here is what is not working:
That's a pointless description of your problem, isn't it? You'd better
explain what you expect the script to output, what it actually
outputs, and which error and warning messages you receive (if any).
> @lines = <STDIN>; # Read all lines into array @lines
Are you really using the STDIN filehandle for reading the file? Since
STDIN is a special filehandle, you should use some other name.
Basically I think your code can be shortened to:
while (<FILE>) {
chomp;
my ($Level, $ID, $Tag, $Text) =
/^\s*(\d+)\s+(@\S+@)?\s*(\S+)(?:\s+(.+))?/;
$Level ||= 0;
$ID ||= '';
$Text ||= '';
print "$Level\n$ID\n$Tag\n$Text\n";
}
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Fri, 26 Dec 2003 23:22:45 -0500
From: Wes Groleau <groleau@freeshell.org>
Subject: Re: I don't know what's wrong here !
Message-Id: <zLOdneKKDZmLlHCiRVn-jw@gbronline.com>
"Ragnar Hafsta��������������������" wrote:
>> /^\s*(\d+)\s+(@\S+@)?\s*(\S+)\s+(.*)/;
>
> look at this a bit:
> (your input is '0 HEAD')
> ^\s* zero or more whitespace. ok
> (\d+) one ore more digits. ok matches '0', the rest is ' HEAD'
> \s+ one or more ws. matches ' ', rest is 'HEAD'
> (@\S+@)? maches ''
> \s* matches ''
> (\S+) matches 'HEAD' rest is ''
> \s+ does not match . oooooops
> (.*)/;
>
> maybe your previous input contained space at the end of the '0 HEAD' line
OK, I see that. Thanks. Maybe there was a space.
However, if the regexp doesn't match, why was
it able to get the $Level and leave the other
parts undefined?
--
Wes Groleau
Alive and Well
http://freepages.religions.rootsweb.com/~wgroleau/
------------------------------
Date: Fri, 26 Dec 2003 23:30:02 -0500
From: Wes Groleau <groleau@freeshell.org>
Subject: Re: I don't know what's wrong here !
Message-Id: <dpudnSl9vthQl3CiRVn-hQ@gbronline.com>
John W. Krahn wrote:
> Do you really need to slurp the entire input into an array?
Not really. I have used foreach (<>) before
I got this from someone else, and just kept that part.
But the original regexp didn't work. I made it work
but now I've broken it again.
> chomp() removes the contents of $/ from the end of $_. s/[\r\n]//
> removes the FIRST occurrence of either \r or \n from $_. If you want to
> remove any trailing whitespace including \r and \n then:
>
> s/\s+\Z//;
OK, thanks. That wasn't a problem in this particular
environment, but it's nice to know.
>> # 1 2 3 4
>> /^\s*(\d+)\s+(@\S+@)?\s*(\S+)\s+(.*)/;
>
> Why not just assign directly to your variables? That way you can
> eliminate all the following else clauses. Also, the @ characters have
> to be escaped or perl will try to interpolate them as arrays.
>
> my ( $Level, $ID, $Tag, $Text ) =
> /^\s*(\d+)\s*(\@\S+\@)?\s*(\S+)\s*(.*)/;
That was tried, but there was some problem I don't remember.
However, the '@' has always worked OK. But escaping them
won't hurt--I remember the error messages from that in other
contexts.
So you have helped me quite a bit (thanks), but I still
don't understand how the regexp as written was able to
define the $Level but not the $Tag
--
Wes Groleau
-----------
Daily Hoax: http://www.snopes2.com/cgi-bin/random/random.asp
------------------------------
Date: Fri, 26 Dec 2003 23:48:24 -0500
From: Wes Groleau <groleau@freeshell.org>
Subject: Re: I don't know what's wrong here !
Message-Id: <i5idnYjYjdCEknCiRVn-sw@gbronline.com>
Gunnar Hjalmarsson wrote:
>> Text is optional and is everything after the tag.
>
> That condition is not reflected in this regex, which requires one or
> more whitespace characters after Tag, or else it won't capture the
> data as expected:
>
>> /^\s*(\d+)\s+(@\S+@)?\s*(\S+)\s+(.*)/;
>
> ---------------------------------^^^
Sorry, I was unclear. The only way to determine
the end of the Tag is by whitespace. But as someone
else pointed out, if there is no text, then there may
be a line-end instead of white space. Perhaps this
is what you are saying?
> It's better written as:
>
> /^\s*(\d+)\s+(@\S+@)?\s*(\S+)(?:\s+(.+))?/;
> ---------------------------------^^^-------^^
So here, $4 matches the _inner_ parentheses?
I don't know what ?: means in this context.
> That's a pointless description of your problem, isn't it? You'd better
> explain what you expect the script to output, what it actually
> outputs, and which error and warning messages you receive (if any).
Well, I explained that $1 or $Level gets defined,
$2 ($ID) and $4 ($Text) do not (but weren't expected to
on the first line), and $3 ($Tag) did not which was a
surprise and prevented reading any other lines.
After finding the fatal error of $Tag undefined,
it seemed pointless to quote the remaining two pages
of the script.
>> @lines = <STDIN>; # Read all lines into array @lines
>
> Are you really using the STDIN filehandle for reading the file? Since
> STDIN is a special filehandle, you should use some other name.
Yes, I pipe cat (file) into the script. I figured
I should get the output right before improving the UI.
> Basically I think your code can be shortened to:
>
> while (<FILE>) {
> chomp;
Oh, I definitely need to convert line ends on files
from other platforms. (Mac/Win/Unix) But as John
pointed out, I did it wrong.
> my ($Level, $ID, $Tag, $Text) =
> /^\s*(\d+)\s+(@\S+@)?\s*(\S+)(?:\s+(.+))?/;
I'll give this a try, along with the other two guys' suggestions.
> $Level ||= 0;
> $ID ||= '';
> $Text ||= '';
> print "$Level\n$ID\n$Tag\n$Text\n";
OK, but I definitely want to keep the error reporting
if Level or Tag is missing.
Thanks to all three responders for the additional understanding.
For the curious, what I am doing is reformatting a GEDCOM
file, AND splitting it into multiple files. Have to
open a new file every time a Level = 0 line comes in,
with the filename determined by parts of the line.
But all of that is later in the script, and is meaningless
if Tag is undefined or missing.
I will experiment with what you three guys have offered,
and I appreciate it very much. Thanks.
--
Wes Groleau
Nobody believes a theoretical analysis -- except the guy who did it.
Everybody believes an experimental analysis -- except the guy who did it.
-- Unknown
------------------------------
Date: 26 Dec 2003 18:35:50 -0800
From: s99999999s2003@yahoo.com (mike)
Subject: Re: isql in perl
Message-Id: <dfd17ef4.0312261835.6bb48d41@posting.google.com>
Gregory Toomey <nospam@bigpond.com> wrote in message news:<1080562.d8XGKOZNtQ@gregs-web-hosting-and-pickle-farming>...
> It was a dark and stormy night, and mike managed to scribble:
>
> > hi
> >
> > i have a code like this
> >
> > open ISQL, "| isql -U $user -S $server " or die "Failed to open: $!";
> > print ISQL << "EOF";
> > select count(*) from table
> > go
> > quit
> > EOF
> >
> > this code is suppose to get the count from a table in my database.
> > how can i assign this count to a perl variable??
> > thanks...
>
> Use Perl dbi instead http://dbi.perl.org/
>
> gtoomey
hi
i do not have the facility(compiler) to compile DBI module on my Solaris machine
so that's why i have to use the isql client for access to database...
cheers
------------------------------
Date: 27 Dec 2003 02:50:20 GMT
From: Nicholas Dronen <ndronen@io.frii.com>
Subject: Re: isql in perl
Message-Id: <3fecf36c$0$204$75868355@news.frii.net>
mike <s99999999s2003@yahoo.com> wrote:
[ snip ]
m> open ISQL, "| isql -U $user -S $server " or die "Failed to open: $!";
m> print ISQL << "EOF";
m> select count(*) from table
m> go
m> quit
m> EOF
m> this code is suppose to get the count from a table in my database.
m> how can i assign this count to a perl variable??
You can always read
$ perldoc -q pipe
but I'd just install gcc from
http://www.sunfreeware.com/
and install and use DBI as the other poster suggested.
Regards,
Nicholas
--
"Why shouldn't I top-post?" http://www.aglami.com/tpfaq.html
"Meanings are another story." http://www.ifas.org/wa/glossolalia.html
------------------------------
Date: Fri, 26 Dec 2003 23:32:43 GMT
From: Joe <joecool118@nospam.hotmail.com>
Subject: Re: looping every x seconds
Message-Id: <9sgpuv86dari97hafjksdbpolu7ufjca86@4ax.com>
On Wed, 10 Sep 2003 14:17:32 GMT, merlyn@stonehenge.com (Randal L.
Schwartz) wrote:
>>>>>> "kernal32" == kernal32 <surakshan@removethisYahooRemove.com> writes:
>
>kernal32> I'm using sleep 5 to wait 5 second before executing some
>kernal32> code.
>
>kernal32> my question is, how can I keep the rest of the program
>kernal32> running whilst the loop continues in pararel
>
>A simple way is to insert a check into your main loop:
>
>my $next_time = time + 5;
>while (1) {
> if (time > $next_time) {
> ... do your once every five seconds thing here ..
> $next_time = time + 5;
> }
> ... rest of code ...
>}
>
>If other things are event-driven, consider POE, found in the CPAN,
>and described at http://poe.perl.org/.
>
>print "Just another Perl hacker,"
2 cents...
Run "modulus"...
example.
###########################
use Time::Local; #Epoch Declares
my $stime = time();
my $often = 25; #number of secs
while (1)
{
if(!($stime % $often))
{
print "Hello.. I should print this every "$often\" secs\n";
}
$stime = time();
sleep 1;
}
exit;
###########################
------------------------------
Date: 26 Dec 2003 16:04:45 -0800
From: ivo.welch@anderson.ucla.edu (ivo welch)
Subject: Re: matching balanced parens
Message-Id: <5159bba2.0312261604.12435480@posting.google.com>
thanks, gunnar. you made more headway than I did. (Now at least I
know how to use the code from the perlfaq6! this would make a good
example to include.) Alas, my need is to be able to parse reasonable
latex source code, where these parens can be nested in many possible
ways. A genuine matching counter would definitely be nice to have as
a feature in regex like expressions. I still wonder if this is
possible.
if not, what is the recommended way? Splitting all characters into a
perl array seems wasteful. Working character by character with
substr($t, $c, 1) to do paren counting also somehow seems contrary to
the spirit of perl.
Regards,
/iaw
------------------------------
Date: Fri, 26 Dec 2003 18:37:39 -0000
From: "Albert Browne" <albert.browne@ntlworld.com>
Subject: Newbie problems with > in a string
Message-Id: <ff%Gb.10938$FN.9315@newsfep4-winn.server.ntli.net>
I am using the code below in part of a subroutine. It displays ok later in
the routine within a <TEXTAREA> block.
But when I try to use $Meta elsewhere the string appears to be empty.
Further investigation shows the string is ok until it gets to the >
in the string. The string looks like this and does in the TEXTAREA
block<META NAME=\"AUTHOR\" CONTENT=\"AAA\"> which is correct.
I have tried printing the string a bit at a time it is ok until it gets to
the >. The string then appears to be empty. What am I missing?
Regards
Albert
$title = $query->param("Title");
if ($title ne "") {$Meta = "<META NAME=\"AUTHOR\" CONTENT=\"$title\">\n"} ;
$Owner = $query->param("Owner");
if ($Author ne "") {$Meta .= "<META NAME=\"AUTHOR\" CONTENT=\"$Owner\">\n"}
;
--
albert.browne@ntlworld.com
http://www.allroadsleadhere.co.uk
------------------------------
Date: Fri, 26 Dec 2003 21:56:42 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Newbie problems with > in a string
Message-Id: <bsi7dh$cv8n1$1@ID-184292.news.uni-berlin.de>
Albert Browne wrote:
> I am using the code below in part of a subroutine. It displays ok
> later in the routine within a <TEXTAREA> block.
> But when I try to use $Meta elsewhere the string appears to be
> empty. Further investigation shows the string is ok until it gets
> to the > in the string. The string looks like this and does in
> the TEXTAREA block<META NAME=\"AUTHOR\" CONTENT=\"AAA\"> which is
> correct.
> I have tried printing the string a bit at a time it is ok until it
> gets to the >. The string then appears to be empty. What am I
> missing?
$Meta contains HTML code. When displaying HTML source code as CGI
output, it should better be encoded first. This is an easy way to do
that:
use HTML::Entities;
my $Meta_display = encode_entities($Meta);
See also the documentation of HTML::Entities:
http://www.perldoc.com/perl5.8.0/lib/HTML/Entities.html
It should be noted that your problem appears to be a CGI problem
rather than a Perl problem. A more appropriate group to discuss CGI is
comp.infosystems.www.authoring.cgi (ciwac).
If the above does not help, you'd better post to ciwac a small but
complete program that people can run and that illustrates the problem.
The code you posted here was confusing, and did not serve that
purpose.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Fri, 26 Dec 2003 15:51:49 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Newbie problems with > in a string
Message-Id: <slrnbupbbl.d5f.tadmc@magna.augustmail.com>
Albert Browne <albert.browne@ntlworld.com> wrote:
> What am I missing?
A short and complete program that we can run that illustrates
the problem that you need to solve.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 27 Dec 2003 17:52:01 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: why this code shots up memory usage
Message-Id: <a2kouv0cveskrker0sh3g43tqr7k3iqk6i@4ax.com>
On Thu, 25 Dec 2003 01:05:31 +0530, "Madhur" <a_madhur@vsnl.net>
wrote:
>Hello
>The following code snippet, shots the memory usage to full and
>results in Out of Memory error.
>The substitution seems to be the culprit. But why it happens. I
>am running W2K, Perl 5.6.
>
>@input=<MYFILE>;
>$i=0;
>while($i<=@input)
>{
>
> $input[$i]=~s/^[0-9]+://;
> print("$input[$i]");
> $i++;
>}
>close(MYFILE);
s/^\d+://,print while <MYFILE>;
Michele
--
# This prints: Just another Perl hacker,
seek DATA,15,0 and print q... <DATA>;
__END__
------------------------------
Date: Fri, 26 Dec 2003 18:33:40 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: why this code shots up memory usage
Message-Id: <3fec749d.574770708@news.erols.com>
"Madhur" <a_madhur@vsnl.net> wrote:
: Jay Tilton <tiltonj@erols.com> wrote in message
: news:3feb17a4.485419583@news.erols.com...
: > while ( <MYFILE> ) {
: > s/^\d+://;
: > print;
: > }
: > close MYFILE;
:
: Could you please explain me,this. what does while(<MYFILE>)
: means.
This is explained in the "I/O Operators" subsection of perlop. The
"while(<MYFILE>) { ... }" construct reads single records from the MYFILE
filehandle into the $_ scalar until all records have been read.
: One more think, this is the code from the faq:
: Stringification also destroys arrays.
:
: @lines = `command`;
: print "@lines"; # WRONG - extra blanks
: print @lines; # right
:
: Does it mean that value of @lines is changed.
No. Stringification does not change the array in any way. It does change
the arguments given to a function, operator, or subroutine. For example:
foo( "@array" );
is equivalently written as:
foo( join($", @array) );
That passes a single string to the foo() subroutine. It is very different
from:
foo( @array )
which will pass a list containing the individual values from @array to the
foo() subroutine.
: Will the @lines contain now 2 elements 'command' and ' '.
No, but you misunderstand what the statement "@lines = `command`;" does.
The backticks are not normal quotes. They invoke an external command and
capture its output. See " qx/STRING/ " in the "Quote and Quote-like
Operators" subsection of perlop.
------------------------------
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 5982
***************************************