[31319] in Perl-Users-Digest
Perl-Users Digest, Issue: 2564 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 20 21:09:46 2009
Date: Thu, 20 Aug 2009 18:09:12 -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 Thu, 20 Aug 2009 Volume: 11 Number: 2564
Today's topics:
Re: Detecting non-printing characters(?) <ldolan@thinkinghatbigpond.net.au>
Re: Error uninitialized value (Jens Thoms Toerring)
Re: search for hex characters in a binary file and remo sln@netherlands.com
Re: search for hex characters in a binary file and remo sln@netherlands.com
Re: trapping errors using $! sln@netherlands.com
Re: Why doesn't this work? HerbF@earthlink.net
Re: Why doesn't this work? HerbF@earthlink.net
Re: Why doesn't this work? <glennj@ncf.ca>
Re: Why doesn't this work? <uri@StemSystems.com>
Re: Why doesn't this work? HerbF@earthlink.net
Re: Why doesn't this work? HerbF@earthlink.net
Re: Why doesn't this work? <jurgenex@hotmail.com>
Re: Why doesn't this work? <jurgenex@hotmail.com>
Re: Why doesn't this work? HerbF@earthlink.net
Re: Why doesn't this work? HerbF@earthlink.net
Re: Why doesn't this work? <jurgenex@hotmail.com>
Re: Why doesn't this work? HerbF@earthlink.net
Re: Why doesn't this work? <nat.k@gm.ml>
Re: Why doesn't this work? <nat.k@gm.ml>
Re: Why doesn't this work? <tadmc@seesig.invalid>
Re: Why doesn't this work? <tadmc@seesig.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 20 Aug 2009 23:58:01 GMT
From: "Peter Jamieson" <ldolan@thinkinghatbigpond.net.au>
Subject: Re: Detecting non-printing characters(?)
Message-Id: <dqljm.13085$ze1.5161@news-server.bigpond.net.au>
Thx Ben, Jürgen and sln for your kind assistance!
I will further investigate your suggestions....cheers, Peter
------------------------------
Date: 20 Aug 2009 23:40:40 GMT
From: jt@toerring.de (Jens Thoms Toerring)
Subject: Re: Error uninitialized value
Message-Id: <7f657oF2jnn36U1@mid.uni-berlin.de>
Keith Thompson <kst-u@mib.org> wrote:
> jt@toerring.de (Jens Thoms Toerring) writes:
> Or write it all in a single line:
> >
> > $Year = param("Year") || $local_year;
> >
> > This deals with the case that param("Year") is not defined as well
> > as that it's an empty string.
> But be careful; this will set $Year to $local_year if param("Year")
> is either undef, the empty string, or 0. That shouldn't cause any
> visible problems for a year number (unless you're dealing with very
> old events or using 2-digit years), but it could bite you for values
> that could legitimately be 0.
Thanks, good point! Hadn't considered it to be a possiblilty.
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
------------------------------
Date: Thu, 20 Aug 2009 13:32:09 -0700
From: sln@netherlands.com
Subject: Re: search for hex characters in a binary file and remove them
Message-Id: <bnbr859l1nf392qpj1l6hs0u79k8qbmk7c@4ax.com>
On Thu, 20 Aug 2009 14:11:27 +0200, Josef Moellers <josef.moellers@ts.fujitsu.com> wrote:
>venkateshwar D wrote:
>> Hi All,
>>
>> I need to look for a sequence of hex characters in a binary file and
>> remove them. the binary file has 00 00 02 02 01 00 sequence somewhere
>> in the file.
>
>I've done this a couple of times in order to find some embedded files in
>some documents (most often to find images in xls, doc, ppt, ...),
>although I usually discard whatever is not of interest to me.
>
>You have to read the file byte-by-byte and check for the header:
>(Untested Code follows!)
>
>my $special = pack('C*', 0x00, 0x00, 0x02, 0x02, 0x01, 0x00);
Why would you have to read the file a byte at a time and check
for the header? You store binary (byte) data in a buffer then use 'eq'
as if it is a character, but you won't trust a regular expression which
would do the same thing.
The file could be slurped into a buffer then checked with a regular expression
or it could be read in a chunk at a time, checked, then the chunk rolled out
of the buffer minus the width of the sequence plus 18 bytes. The next chunk
is appended, then the process repeats until its found.
I put up an example how to do this.
The proof that this works is using the same method you use but
instead of read 1, is it 'eq', etc.., uses a regular expression
on a chunk of bytes.
Perl defaults to bytes in regex, it will upgrade the context to
utf8 if anything in the expression forces it to. In this case it
doesen't, the sequence is byte context (ie: less than 0x100).
The file is opened in binary mode, its byte context.
-sln
use strict;
use warnings;
my $special = pack('C*', 0x00, 0x00, 0x02, 0x02, 0x01, 0x00);
my $bytes = '';
for (1 .. 12_000) {
if ($_ == 6000) {
$bytes .= $special;
} else {
$bytes .= chr(int(rand(256)) & 0xff);
}
}
print "buf len = ".length($bytes)."\n";
my $posn = 0;
if ($bytes =~ s/($special)(.{18})/$posn = pos($bytes); ''/es) {
print "Found special at position ".$posn.": ".ordsplit($1)."\n";
print "Next 18 bytes : ".ordsplit($2)."\n";
print "Special + 18 bytes, removed!\n";
}
print "buf len = ".length($bytes)."\n";
sub ordsplit
{
my $string = shift;
my $buf = '';
for (map {ord $_} split //, $string) {
$buf.= sprintf ("%02x ",$_);
}
return $buf;
}
__END__
buf len = 12005
Found special at position 5999: 00 00 02 02 01 00
Next 18 bytes : de b9 70 b9 4b b9 4c 9f 1d f3 de 33 52 00 26 a7
50 41
Special + 18 bytes, removed!
buf len = 11981
------------------------------
Date: Thu, 20 Aug 2009 13:37:53 -0700
From: sln@netherlands.com
Subject: Re: search for hex characters in a binary file and remove them
Message-Id: <pmcr85pdi9htbh8begqabut7slv42v65u1@4ax.com>
On Tue, 18 Aug 2009 07:14:34 -0700 (PDT), venkateshwar D <venkateshwar1981@gmail.com> wrote:
>Hi All,
>
>I need to look for a sequence of hex characters in a binary file and
>remove them. the binary file has 00 00 02 02 01 00 sequence somewhere
>in the file.
>The script should open the file and look for this sequence 00 00 02 02
>01 00 <18 variable bytes> and remove the 18 + 6 = 24 bytes from the
>file.can someone please help. I can open the binary file and buffer
>byte by byte but since the pattern can be anywhere in the file i dont
>know how to proceed
>
>regards
>venkat
Here's the same example in binary mode (ie: the dummy file
is random binary, with the binary sequence embedded).
If this doesen't work for you, something else is wrong.
-sln
-------------------------
use strict;
use warnings;
my $sequence = "\x{00}\x{00}\x{02}\x{02}\x{01}\x{00}";
# or = pack('C*', 0x00, 0x00, 0x02, 0x02, 0x01, 0x00);
# Create dummy random binary file with embeded sequence
# ##
open my $ftest, '>:raw', 'dummy.bin' or die "can't create dummy.bin: $!";
for (1 .. 12_000) {
if ($_ == 2000) {
print $ftest $sequence;
} else {
print $ftest chr(int(rand(256)) & 0xff);
}
}
close $ftest;
# Read in binary, look for sequence, remove then write to file
# ##
open my $fin, '<:raw', 'dummy.bin' or die "can't open input file: $!";
open my $fout, '>:raw', 'dummy_o.bin' or die "can't open output file: $!";
my ($chunksize, $found) = (1024,0);
{
local $/ = \$chunksize;
my ($keep, $buf, $data) = (50,'','');
while (defined ($data = <$fin>)) {
$buf .= $data;
if (!$found) {
if ($buf =~ s/($sequence)(.{18})//s) {
print "Found sequence: ".ordsplit($1)."\n";
print "Next 18 bytes : ".ordsplit($2)."\n";
print "Sequence + 18 bytes, removed!\n";
$found = 1;
}
}
print $fout substr( $buf, 0, -$keep, "");
}
print $fout $buf;
}
if (!$found) {
print "Did not match sequence: '\$sequence.{18}'\n";
}
close $fout;
close $fin;
## End of program
exit 0;
sub ordsplit
{
my $string = shift;
my $buf = '';
for (map {ord $_} split //, $string) {
$buf.= sprintf ("%02x ",$_);
}
return $buf;
}
__END__
Found sequence: 00 00 02 02 01 00
Next 18 bytes : 25 6f e4 7e 6e fb fe 1e 47 af e6 2e 50 3f 31 54
dd 51
Sequence + 18 bytes, removed!
------------------------------
Date: Thu, 20 Aug 2009 14:46:49 -0700
From: sln@netherlands.com
Subject: Re: trapping errors using $!
Message-Id: <otfr85l8j0dl78manl7on40kkblqsf464g@4ax.com>
On Thu, 20 Aug 2009 12:54:13 +0100, "John" <john1949@yahoo.com> wrote:
>Hi
>
>This part of code is in a web service so there is no output to screen.
>I've turned off printing to standard error.
>
>open STDERR,'>/dev/null';
>
>....
>read (STDIN,$request,$length);
>if ($1 > 0) {$response=$error1};
>
>Would the above condition trap any error?
>
>Regards
>John
>
>
Assuming you meant
$cnt = read ($handle, $buffer, $length);
if (!defined ($cnt) ) {
print "Error reading from file: $!\n";
}
But, and I don't know if this is true, from some module
I looked at, dated a few years ago, it mentioned defined isin't
always an error check on some platforms.
Quote:
" read is supposed to return undef on error, but on some platforms it
seems to just return 0 and set $!"
Then he does some wrapper read sub.
The jist boils down to this:
{
local $!;
$cnt = read ($handle, $buffer, $length);
if (!$cnt && $! ) {
print "Error reading from file: $!\n";
}
}
This would seem to cover both
($cnt as undefined or $cnt is zero) and $! is not empty
Not sure about this.
Usually just a
defined(read($fh,$buf,$length)) or croak "Read caused an error: $!";
will do ok.
-sln
------------------------------
Date: Thu, 20 Aug 2009 13:22:30 -0700
From: HerbF@earthlink.net
Subject: Re: Why doesn't this work?
Message-Id: <17ar85hfs2kkacrrb204ekg7gbh2ht37gb@4ax.com>
Keith Thompson wrote:
>HerbF@earthlink.net writes:
>> Glenn Jackman wrote:
>>>At 2009-08-20 02:08PM, "HerbF@earthlink.net" wrote:
>>>> Noob here.
>>>>
>>>> I'm trying to write a simple routine to print a character every second. I
>>>> have:
>>>>
>>>> foreach (1..5) {
>>>> print "*";
>>>> sleep 1;
>>>> }
>>>>
>>>> When I run it, it waits for the full 5 seconds to tick by, and then prints
>>>> the string '*****'. Why doesn't it print an asterisk every second until
>>>> finished?
>>>
>>>Your output is buffered. Set $|=1 first.
>>
>> Tried that, but it made no difference.
>
>It worked for me.
>
>Here's my program:
>====================
>#!/usr/bin/perl
>
>use strict;
>use warnings;
>
>$| = 1;
>
>foreach (1..5) {
> print "*";
> sleep 1;
>}
>print "\n";
>====================
Here's mine:
#!/usr/bin/perl
use warnings;
use strict;
$|=1;
foreach (1..5) {
print "*";
sleep 1;
}
It looks familiar, no? Waits 5 secs and then prints.
>
>With the "$| = 1" commented out, it waits 5 seconds and then prints
>"*****". With the line in place, it prints a '*' character every
>second.
>
>Maybe it's related to the environment in which you're running the
>script, but it works for me under Ubuntu, Cygwin, and Windows
>(ActiveState Perl).
I'm using Windows, but Perl installed on the [remote] server is using
Unix.
Herb
------------------------------
Date: Thu, 20 Aug 2009 13:26:02 -0700
From: HerbF@earthlink.net
Subject: Re: Why doesn't this work?
Message-Id: <47cr85lh9bdg61rktk0iq4orki9gequdv5@4ax.com>
Tad J McClellan wrote:
>Nathan Keel <nat.k@gm.ml> wrote:
>> HerbF@earthlink.net wrote:
>>
>>> Noob here.
>>>
>>> I'm trying to write a simple routine to print a character every
>>> second. I have:
>>>
>>> foreach (1..5) {
>>> print "*";
>>> sleep 1;
>>> }
>>>
>>> When I run it, it waits for the full 5 seconds to tick by, and then
>>> prints the string '*****'. Why doesn't it print an asterisk every
>>> second until finished?
>>>
>> Is this on the command line or via a web browser?
>
>Perl does not run in a web browser.
I'm using a browser to launch the script on a web server and output the
print to the browser.
--
Herb
------------------------------
Date: 20 Aug 2009 20:56:22 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: Why doesn't this work?
Message-Id: <slrnh8re3o.rcl.glennj@smeagol.ncf.ca>
At 2009-08-20 04:22PM, "HerbF@earthlink.net" wrote:
> Keith Thompson wrote:
[...]
> >Maybe it's related to the environment in which you're running the
> >script, but it works for me under Ubuntu, Cygwin, and Windows
> >(ActiveState Perl).
>
> I'm using Windows, but Perl installed on the [remote] server is using
> Unix.
See, that's a rather crucial piece of information you didn't give us.
You might want to investigate non-parsed header cgi scripts (for
example, here: http://docstore.mik.ua/orelly/linux/cgi/ch03_03.htm)
--
Glenn Jackman
Write a wise saying and your name will live forever. -- Anonymous
------------------------------
Date: Thu, 20 Aug 2009 16:58:35 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Why doesn't this work?
Message-Id: <8763cinqx0.fsf@quad.sysarch.com>
>>>>> "H" == HerbF <HerbF@earthlink.net> writes:
H> Tad J McClellan wrote:
>> Nathan Keel <nat.k@gm.ml> wrote:
>>> HerbF@earthlink.net wrote:
>>>
>>>> Noob here.
>>>>
>>>> I'm trying to write a simple routine to print a character every
>>>> second. I have:
>>>>
>>>> foreach (1..5) {
>>>> print "*";
>>>> sleep 1;
>>>> }
>>>>
>>>> When I run it, it waits for the full 5 seconds to tick by, and then
>>>> prints the string '*****'. Why doesn't it print an asterisk every
>>>> second until finished?
>>>>
>>> Is this on the command line or via a web browser?
>>
>> Perl does not run in a web browser.
H> I'm using a browser to launch the script on a web server and output the
H> print to the browser.
and that is not running perl in a web browser. and it explains why your
output is delayed - the server is buffering it all until your script
exits. you need to use another technique to force the server to output
as soon as it gets data. and even then the browser can screw it up.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Thu, 20 Aug 2009 14:19:58 -0700
From: HerbF@earthlink.net
Subject: Re: Why doesn't this work?
Message-Id: <bffr85l0f6af3355op9t1b21aojl3mp7r9@4ax.com>
Uri Guttman wrote:
>>>>>> "H" == HerbF <HerbF@earthlink.net> writes:
>
> H> Tad J McClellan wrote:
> >> Nathan Keel <nat.k@gm.ml> wrote:
> >>> HerbF@earthlink.net wrote:
> >>>
> >>>> Noob here.
> >>>>
> >>>> I'm trying to write a simple routine to print a character every
> >>>> second. I have:
> >>>>
> >>>> foreach (1..5) {
> >>>> print "*";
> >>>> sleep 1;
> >>>> }
> >>>>
> >>>> When I run it, it waits for the full 5 seconds to tick by, and then
> >>>> prints the string '*****'. Why doesn't it print an asterisk every
> >>>> second until finished?
> >>>>
> >>> Is this on the command line or via a web browser?
> >>
> >> Perl does not run in a web browser.
>
> H> I'm using a browser to launch the script on a web server and output the
> H> print to the browser.
>
>and that is not running perl in a web browser. and it explains why your
>output is delayed - the server is buffering it all until your script
>exits. you need to use another technique to force the server to output
>as soon as it gets data. and even then the browser can screw it up.
>
Thanks.
--
Herb
------------------------------
Date: Thu, 20 Aug 2009 14:20:34 -0700
From: HerbF@earthlink.net
Subject: Re: Why doesn't this work?
Message-Id: <8gfr85hqk6627l4ub97kn6pakq2f7qp5sd@4ax.com>
Glenn Jackman wrote:
>At 2009-08-20 04:22PM, "HerbF@earthlink.net" wrote:
>> Keith Thompson wrote:
>[...]
>> >Maybe it's related to the environment in which you're running the
>> >script, but it works for me under Ubuntu, Cygwin, and Windows
>> >(ActiveState Perl).
>>
>> I'm using Windows, but Perl installed on the [remote] server is using
>> Unix.
>
>See, that's a rather crucial piece of information you didn't give us.
>
>You might want to investigate non-parsed header cgi scripts (for
>example, here: http://docstore.mik.ua/orelly/linux/cgi/ch03_03.htm)
Thanks.
--
Herb
------------------------------
Date: Thu, 20 Aug 2009 14:23:17 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Why doesn't this work?
Message-Id: <kjfr85tpin7stufn1dskq4bjldrasa4l1h@4ax.com>
HerbF@earthlink.net wrote:
>I'm using Windows, but Perl installed on the [remote] server is using
>Unix.
What server? rsh? Wouldn't you assume, that whatever tool establishes
the remote connection would also include its own buffering?
Check the description of that tool on how to turn of buffering.
jue
------------------------------
Date: Thu, 20 Aug 2009 14:26:29 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Why doesn't this work?
Message-Id: <kmfr851fpiur764qp7a76hslg77lsu8b6u@4ax.com>
HerbF@earthlink.net wrote:
>>Perl does not run in a web browser.
>
>I'm using a browser to launch the script on a web server and output the
>print to the browser.
Duuuuh! Are there any other critical pieces of information that you are
withholding?
Where did you get the idea that CGI and HTTP were sending replies
character by character? Hint: they don't.
jue
------------------------------
Date: Thu, 20 Aug 2009 14:41:07 -0700
From: HerbF@earthlink.net
Subject: Re: Why doesn't this work?
Message-Id: <0mgr85tooa7q96f21dum23m7dvuabaatpa@4ax.com>
Jürgen Exner wrote:
>HerbF@earthlink.net wrote:
>>I'm using Windows, but Perl installed on the [remote] server is using
>>Unix.
>
>What server? rsh? Wouldn't you assume, that whatever tool establishes
>the remote connection would also include its own buffering?
>Check the description of that tool on how to turn of buffering.
>
I assumed nothing, except that I needed to ask a question. Thanks for the
pointer.
--
Herb
------------------------------
Date: Thu, 20 Aug 2009 14:41:47 -0700
From: HerbF@earthlink.net
Subject: Re: Why doesn't this work?
Message-Id: <qngr85p4qtk27t6fatdbf68totbds49r9k@4ax.com>
Jürgen Exner wrote:
>HerbF@earthlink.net wrote:
>>>Perl does not run in a web browser.
>>
>>I'm using a browser to launch the script on a web server and output the
>>print to the browser.
>
>Duuuuh! Are there any other critical pieces of information that you are
>withholding?
>
>Where did you get the idea that CGI and HTTP were sending replies
>character by character? Hint: they don't.
>
That's why I asked. Duh!
H
------------------------------
Date: Thu, 20 Aug 2009 15:11:49 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Why doesn't this work?
Message-Id: <36ir85lgvm1rmcr7acsom1efdi6r36enhs@4ax.com>
HerbF@earthlink.net wrote:
>Jürgen Exner wrote:
>
>>HerbF@earthlink.net wrote:
>>>>Perl does not run in a web browser.
>>>
>>>I'm using a browser to launch the script on a web server and output the
>>>print to the browser.
>>
>>Duuuuh! Are there any other critical pieces of information that you are
>>withholding?
>>
>>Where did you get the idea that CGI and HTTP were sending replies
>>character by character? Hint: they don't.
>>
>That's why I asked. Duh!
Ok, maybe you are not aware of it, but
Perl != (CGI/WWW/HTTP/....)
If you are claiming you are running a specific program, then of course
everyone is assuming you are running it as stated: put the code in a
file and throw it to the interpreter.
If you don't and instead are running it in a non-standard way and in
particular when the output is piped forward half a dozen times through
half a dozen different tools and you happen to have a question about
that very output, then don't you think it would be worth mentioning that
fact instead of leading everyone on a wild-goose chase?
jue
------------------------------
Date: Thu, 20 Aug 2009 16:07:49 -0700
From: HerbF@earthlink.net
Subject: Re: Why doesn't this work?
Message-Id: <9dlr8550bf3tt4150n09fv1fmd7qvlp8h9@4ax.com>
Jürgen Exner wrote:
>HerbF@earthlink.net wrote:
>>Jürgen Exner wrote:
>>
>>>HerbF@earthlink.net wrote:
>>>>>Perl does not run in a web browser.
>>>>
>>>>I'm using a browser to launch the script on a web server and output the
>>>>print to the browser.
>>>
>>>Duuuuh! Are there any other critical pieces of information that you are
>>>withholding?
>>>
>>>Where did you get the idea that CGI and HTTP were sending replies
>>>character by character? Hint: they don't.
>>>
>>That's why I asked. Duh!
>
>Ok, maybe you are not aware of it, but
>
> Perl != (CGI/WWW/HTTP/....)
>
>If you are claiming you are running a specific program, then of course
>everyone is assuming you are running it as stated: put the code in a
>file and throw it to the interpreter.
>
>If you don't and instead are running it in a non-standard way and in
>particular when the output is piped forward half a dozen times through
>half a dozen different tools and you happen to have a question about
>that very output, then don't you think it would be worth mentioning that
>fact instead of leading everyone on a wild-goose chase?
>
Perhaps you didn't see my first post. It began with 'Noob here.' While you
are correct that as much info should be provided, I don't think it's
reasonable to expect a noob to know what to ask or what to provide. That
comes with experience, and unfortunately, we noobs don't have
enough...else we wouldn't be asking questions.
As far as Perl != (CGI/WWW/HTTP/....), to those of us who program strictly
for the internet using Perl, and who have never used Perl for any other
purpose, it most definitely is what CGI, etc., is all about.
All that said, thanks for your comments...except for your resorting to
"Duh!!!" That was uncalled for.
--
Herb
------------------------------
Date: Thu, 20 Aug 2009 16:27:14 -0700
From: Nathan Keel <nat.k@gm.ml>
Subject: Re: Why doesn't this work?
Message-Id: <mZkjm.31$wT4.11@newsfe03.iad>
Tad J McClellan wrote:
> Nathan Keel <nat.k@gm.ml> wrote:
>> HerbF@earthlink.net wrote:
>>
>>> Noob here.
>>>
>>> I'm trying to write a simple routine to print a character every
>>> second. I have:
>>>
>>> foreach (1..5) {
>>> print "*";
>>> sleep 1;
>>> }
>>>
>>> When I run it, it waits for the full 5 seconds to tick by, and then
>>> prints the string '*****'. Why doesn't it print an asterisk every
>>> second until finished?
>>>
>>> Herb
>>
>> Is this on the command line or via a web browser?
>
>
> Perl does not run in a web browser.
>
>
I'd ask you not to be an asshole, but I know that's difficult for you.
It's pretty obvious that I was asking if they were viewing it via a web
browser (as in from a web site, through CGI or otherwise).
------------------------------
Date: Thu, 20 Aug 2009 16:31:03 -0700
From: Nathan Keel <nat.k@gm.ml>
Subject: Re: Why doesn't this work?
Message-Id: <X0ljm.33$wT4.1@newsfe03.iad>
HerbF@earthlink.net wrote:
> Jürgen Exner wrote:
>
>>HerbF@earthlink.net wrote:
>>>Jürgen Exner wrote:
>>>
>>>>HerbF@earthlink.net wrote:
>>>>>>Perl does not run in a web browser.
>>>>>
>>>>>I'm using a browser to launch the script on a web server and output
>>>>>the print to the browser.
>>>>
>>>>Duuuuh! Are there any other critical pieces of information that you
>>>>are withholding?
>>>>
>>>>Where did you get the idea that CGI and HTTP were sending replies
>>>>character by character? Hint: they don't.
>>>>
>>>That's why I asked. Duh!
>>
>>Ok, maybe you are not aware of it, but
>>
>>Perl != (CGI/WWW/HTTP/....)
>>
>>If you are claiming you are running a specific program, then of course
>>everyone is assuming you are running it as stated: put the code in a
>>file and throw it to the interpreter.
>>
>>If you don't and instead are running it in a non-standard way and in
>>particular when the output is piped forward half a dozen times through
>>half a dozen different tools and you happen to have a question about
>>that very output, then don't you think it would be worth mentioning
>>that fact instead of leading everyone on a wild-goose chase?
>>
> Perhaps you didn't see my first post. It began with 'Noob here.' While
> you are correct that as much info should be provided, I don't think
> it's reasonable to expect a noob to know what to ask or what to
> provide. That comes with experience, and unfortunately, we noobs don't
> have enough...else we wouldn't be asking questions.
>
> As far as Perl != (CGI/WWW/HTTP/....), to those of us who program
> strictly for the internet using Perl, and who have never used Perl for
> any other purpose, it most definitely is what CGI, etc., is all about.
>
> All that said, thanks for your comments...except for your resorting to
> "Duh!!!" That was uncalled for.
Some of the regulars here are arrogant assholes and act like you're
intentionally wasting their time because YOU don't know if it's
related. This is why I asked if you were viewing it via a web browser
(i.e., from a CGI script), whereas one prick responded with "Perl
doesn't run in the web browser", and those are the sort of nonsense
replies you can expect sometimes. Ignore the attitudes they give and
just use it as a learning experience. Some of us are respectful enough
to not attack you because you came here asking about something you
don't know. Anyway, that is why you're seeing the issue, since the
output isn't happening until the document is loaded fully.
------------------------------
Date: Thu, 20 Aug 2009 19:58:29 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Why doesn't this work?
Message-Id: <slrnh8rroa.30k.tadmc@tadmc30.sbcglobal.net>
Uri Guttman <uri@StemSystems.com> wrote:
>>>>>> "H" == HerbF <HerbF@earthlink.net> writes:
>
> H> Tad J McClellan wrote:
> >> Nathan Keel <nat.k@gm.ml> wrote:
> >>> HerbF@earthlink.net wrote:
> >>>
> >>>> Noob here.
> >>>>
> >>>> I'm trying to write a simple routine to print a character every
> >>>> second. I have:
> >>>>
> >>>> foreach (1..5) {
> >>>> print "*";
> >>>> sleep 1;
> >>>> }
> >>>>
> >>>> When I run it, it waits for the full 5 seconds to tick by, and then
> >>>> prints the string '*****'. Why doesn't it print an asterisk every
> >>>> second until finished?
> >>>>
> >>> Is this on the command line or via a web browser?
> >>
> >> Perl does not run in a web browser.
>
> H> I'm using a browser to launch the script on a web server and output the
> H> print to the browser.
>
> and that is not running perl in a web browser.
Which is what I guessed the OP had not yet learned, and it is what
my followup was meant to ellicit.
Perl can run in a CGI environment. The output of the Perl program
goes to the web server, which can send it to a browser, or modify
it and then send it to a browser, or drop it on the floor and send
nothing to the browser.
Knowing how your programming environment operates goes a long way
to becoming self-sufficient in your programming.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Thu, 20 Aug 2009 20:04:16 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Why doesn't this work?
Message-Id: <slrnh8rs34.30k.tadmc@tadmc30.sbcglobal.net>
Nathan Keel <nat.k@gm.ml> wrote:
> Tad J McClellan wrote:
>
>> Nathan Keel <nat.k@gm.ml> wrote:
>>> HerbF@earthlink.net wrote:
>>>
>>>> Noob here.
>>>>
>>>> I'm trying to write a simple routine to print a character every
>>>> second. I have:
>>>>
>>>> foreach (1..5) {
>>>> print "*";
>>>> sleep 1;
>>>> }
>>>>
>>>> When I run it, it waits for the full 5 seconds to tick by, and then
^^^^^^
>>>> prints the string '*****'. Why doesn't it print an asterisk every
^^^^^^^^
>>>> second until finished?
>>> Is this on the command line or via a web browser?
Which "this"?
running or printing?
(neither happens in a web browser, both happen in a CGI under the
control of the web server)
>> Perl does not run in a web browser.
>>
>>
>
> I'd ask you not to be an asshole,
And I'd ignore you, as I do not respect you.
I was not being an asshole anyway, I was being an instructor.
It played out pretty much just as I expected, the OP learned a bit
about the environment that he is programming for.
> but I know that's difficult for you.
> It's pretty obvious
^^^^^^^
He said "when I run it", so *that* was what seemed obvious to me.
> that I was asking if they were viewing it via a web
> browser (as in from a web site, through CGI or otherwise).
Neither he nor you said "viewing".
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 V11 Issue 2564
***************************************