[23809] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 6012 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 29 19:56:20 2004

Date: Thu, 29 Jan 2004 16:55:43 -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, 29 Jan 2004     Volume: 10 Number: 6012

Today's topics:
        HTTP::Daemon <oeschey@web.de>
    Re: HTTP::Daemon <usenet@morrow.me.uk>
    Re: HTTP::Daemon <gnari@simnet.is>
    Re: HTTP::Daemon <oeschey@web.de>
    Re: HTTP::Daemon <gnari@simnet.is>
        HTTP::Request format. <no-mail-here@black.hole.com>
    Re: HTTP::Request format. <usenet@morrow.me.uk>
        IMAP::Admin Module <akilaj@yahoo.com>
    Re: IMAP::Admin Module <usenet@morrow.me.uk>
    Re: IMAP::Admin Module <akilaj@yahoo.com>
    Re: IMAP::Admin Module <usenet@morrow.me.uk>
    Re: Including a source <noreply@gunnar.cc>
    Re: Including a source <gnari@simnet.is>
    Re: Including a source <usenet@morrow.me.uk>
    Re: Including a source <raisin@delete-this-trash.mts.net>
        index returns 0 for NULL substring (Bill)
    Re: index returns 0 for NULL substring <nobull@mail.com>
    Re: index returns 0 for NULL substring <ittyspam@yahoo.com>
        insert random blank every few chars <jidanni@jidanni.org>
    Re: insert random blank every few chars <pinyaj@rpi.edu>
    Re: insert random blank every few chars <trammell+usenet@hypersloth.invalid>
    Re: insert random blank every few chars <ittyspam@yahoo.com>
    Re: insert random blank every few chars <xx087@freenet.carleton.ca>
    Re: insert random blank every few chars (dan baker)
    Re: insert random blank every few chars <jidanni@jidanni.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Mon, 26 Jan 2004 23:34:15 +0100
From: Lars Oeschey <oeschey@web.de>
Subject: HTTP::Daemon
Message-Id: <9q4b10hrd0r7qcgacmooq4tbu02hk00fjf@4ax.com>

Hi,

I have a bit of a problem with the behaviour of HTTP::Daemon 

my code looks like this:

------------------------------------------------------------
my $http = HTTP::Daemon->new ( LocalPort => 82);
print $http->url;
while (my $connect = $http->accept) {
                        $request=$connect->get_request;
                        if ($request->method eq "GET") {

$connect->send_response($html);
					}
				elsif ($request->method eq "POST") {
				
				$connect->send_response($working);
				&Action;
				$connect->send_response($done);
			}
         }
         $connect->close;
         undef $connect;

sub Action {
	print "Gruss von der Sub!\n";
	sleep 20;
}
---------------------------------------------------------------

$html, $working and $done are html pages as string. $html displays a
button with method "post". The first page with the button gets
displayed fine, when I click on the button, there's a 20sec delay, and
then $working and $done get displayed at once. Is there a way to have
the delay actually happen between $working and $done? Is this some
buffering problem? Another Question: On every page I get a status line
displayed:
Date: Mon, 26 Jan 2004 21:30:25 GMT Server: libwww-perl-daemon/1.25 

how can I switch that off?

Lars




------------------------------

Date: Mon, 26 Jan 2004 22:36:49 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: HTTP::Daemon
Message-Id: <bv44q1$n8u$1@wisteria.csv.warwick.ac.uk>


Lars Oeschey <oeschey@web.de> wrote:
> Hi,
> 
> I have a bit of a problem with the behaviour of HTTP::Daemon 
> 
> $html, $working and $done are html pages as string. $html displays a
> button with method "post". The first page with the button gets
> displayed fine, when I click on the button, there's a 20sec delay, and
> then $working and $done get displayed at once. Is there a way to have
> the delay actually happen between $working and $done? Is this some
> buffering problem?

The solution to this problem is called 'server push'. I don't know if
HTTP::Daemon implements this.

Ben

-- 
   If you put all the prophets,   |   You'd have so much more reason
   Mystics and saints             |   Than ever was born
   In one room together,          |   Out of all of the conflicts of time.
ben@morrow.me.uk |----------------+---------------| The Levellers, 'Believers'


------------------------------

Date: Mon, 26 Jan 2004 22:59:00 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: HTTP::Daemon
Message-Id: <bv4698$k82$1@news.simnet.is>

"Lars Oeschey" <oeschey@web.de> wrote in message
news:9q4b10hrd0r7qcgacmooq4tbu02hk00fjf@4ax.com...
> Hi,
>
> I have a bit of a problem with the behaviour of HTTP::Daemon

[snipped daemon that tries to sleep in the middle of the request]

you have to realize how HTTP works.

the browser sends a request, that is a specially formatted text
message, to a port on the server.
the server, in this case your script,  reads the request, processes
it and send back on the still open connection, a response.
the response also has a special format
the browser now displays the response.

your sleep just delays the moment that the browser can display
the response.

as we are talking HTML here, maybe a <META http-equiv="refresh">
tag would do the trick for you?


> ...  Another Question: On every page I get a status line
> displayed:
> Date: Mon, 26 Jan 2004 21:30:25 GMT Server: libwww-perl-daemon/1.25
>

here we come to the format of the response.
the response starts with a number of header lines separated from the
response body by an empty line. the Daemon tries to create a valid header
by inserting headerlines like Date: and Server: , but probably something
you do causes an empty line to be emitted before that.
the browser interprets these headers as part of the body.

hope this helps

gnari






------------------------------

Date: Tue, 27 Jan 2004 20:43:34 +0100
From: Lars Oeschey <oeschey@web.de>
Subject: Re: HTTP::Daemon
Message-Id: <bofd10hqf5nqsr0gkc78s7dj80nrmqe4it@4ax.com>

On Mon, 26 Jan 2004 22:59:00 -0000, "gnari" <gnari@simnet.is> wrote:

>as we are talking HTML here, maybe a <META http-equiv="refresh">
>tag would do the trick for you?

hm, I changed $working to:

$working="<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01
Transitional//EN'>
<html>
<head>
<title>Bremsenpr&uuml;fstand I/EF-53</title>
<META http-equiv='refresh'>
<meta http-equiv='Content-Type' content='text/html;
charset=iso-8859-1'>
</head>
<BODY bgcolor='#999999'>
<p align='center'><font size='+1' face='Verdana, Arial, Helvetica,
sans-serif'>Die Daten werden geholt...</font> 
</p>
</BODY>
</html>";

didn't help though...

>here we come to the format of the response.
>the response starts with a number of header lines separated from the
>response body by an empty line. the Daemon tries to create a valid header
>by inserting headerlines like Date: and Server: , but probably something
>you do causes an empty line to be emitted before that.
>the browser interprets these headers as part of the body.

As you can see above, I don't use anything unusal, at least I don't
see it...

Lars


------------------------------

Date: Tue, 27 Jan 2004 20:24:13 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: HTTP::Daemon
Message-Id: <bv6hj0$tb5$1@news.simnet.is>

"Lars Oeschey" <oeschey@web.de> wrote in message
news:bofd10hqf5nqsr0gkc78s7dj80nrmqe4it@4ax.com...
> On Mon, 26 Jan 2004 22:59:00 -0000, "gnari" <gnari@simnet.is> wrote:
>
> >as we are talking HTML here, maybe a <META http-equiv="refresh">
> >tag would do the trick for you?
>
> hm, I changed $working to:
>
> ...
> <META http-equiv='refresh'>

sorry, I assumed you would look up the syntax of the META:
<META http-equiv='refresh' content='20;URL='>

google is your friend, and much faster that these newsgroups.

gnari






------------------------------

Date: Thu, 29 Jan 2004 17:58:29 +0000
From: Danny Woods <no-mail-here@black.hole.com>
Subject: HTTP::Request format.
Message-Id: <bvbhk6$3uq$1@phys-pa.scotland.net>

Hi all,

I have a script that listens on a socket, reads some XML from an 
external entity, slaps a POST header on it, and POSTs it off to a Web 
server for processing. So, using HTTP::Request::Common, it's a simple 
matter of:

$request = POST("http://www.no-server-here.com/cgi-bin/script.cgi");
$request->header("Content-Length", length($xml));
$request->content($xml);

When sent, this looks something like:

POST http://www.no-server-here.com/cgi-bin/script.cgi
Content-Length: [some-number]

<some-xml..../>

But I have a client who (for some reason) wants:

POST /cgi-bin/script.cgi HTTP/1.0
Host: www.no-server-here.com
Content-Length: [some-number]

<some-xml..../>

?

The RFC states (at 
http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5) that 
requests start with a request line, which has a format of:

Method SP Request-URI SP HTTP-Version CRLF

The format for a Request-URI seems to be leaning towards the absolute 
format produced by HTTP::Request, but the other format with the Host 
header is still valid. In any case, the protocol and version don't 
appear to be optional, and yet are missed out by HTTP::Request.

Is there any way that I'm missing to hammer the request string into 
shape, or so I have to resort to sockets and hand made requests?


Many thanks,

Danny.


------------------------------

Date: Thu, 29 Jan 2004 19:09:09 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: HTTP::Request format.
Message-Id: <bvblol$cgq$1@wisteria.csv.warwick.ac.uk>


Danny Woods <no-mail-here@black.hole.com> wrote:
> $request = POST("http://www.no-server-here.com/cgi-bin/script.cgi");
> $request->header("Content-Length", length($xml));
> $request->content($xml);
> 
> When sent, this looks something like:
> 
> POST http://www.no-server-here.com/cgi-bin/script.cgi
> Content-Length: [some-number]
> 
> <some-xml..../>
> 
> But I have a client who (for some reason) wants:
> 
> POST /cgi-bin/script.cgi HTTP/1.0
> Host: www.no-server-here.com
> Content-Length: [some-number]
> 
> <some-xml..../>
> 
> ?
> 
> The RFC states (at 
> http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5) that 
> requests start with a request line, which has a format of:
> 
> Method SP Request-URI SP HTTP-Version CRLF
> 
> The format for a Request-URI seems to be leaning towards the absolute 
> format produced by HTTP::Request, but the other format with the Host 
> header is still valid. In any case, the protocol and version don't 
> appear to be optional, and yet are missed out by HTTP::Request.

This is Not Good... :)

The protocol is absolutely not optional, and can be put in with

$request->protocol("HTTP/1.0");

The Host: header is required for HTTP/1.1 and recommended for
HTTP/1.0, even if the request-URI is absolute. You can put this in
with 

$request->header(host => $request->uri->host);

The server ought to accept a request in this format, i.e.

POST http://www.no-server-here.com/cgi-bin/script.cgi HTTP/1.0
Host: www.no-server-here.com
Content-Length: ...

, but if it really won't then you can make the request-URI relative
with

$request->uri($request->uri->path);

(obviously you must do this *after* you set the Host: header from the
URI :).

Note that if you use LWP::UserAgent to send the request it does all
this for you.

Ben

-- 
$.=1;*g=sub{print@_};sub r($$\$){my($w,$x,$y)=@_;for(keys%$x){/main/&&next;*p=$
$x{$_};/(\w)::$/&&(r($w.$1,$x.$_,$y),next);$y eq\$p&&&g("$w$_")}};sub t{for(@_)
{$f&&($_||&g(" "));$f=1;r"","::",$_;$_&&&g(chr(0012))}};t    # ben@morrow.me.uk
$J::u::s::t, $a::n::o::t::h::e::r, $P::e::r::l, $h::a::c::k::e::r, $.


------------------------------

Date: Thu, 22 Jan 2004 09:59:25 -0800
From: Akila <akilaj@yahoo.com>
Subject: IMAP::Admin Module
Message-Id: <40100F7D.1070801@yahoo.com>

Hello all,

I am looking for a module that can manipulate a users's mail spool (as 
root).  The IMAP::Admin Module only has functions to create a mailbox, 
set acls, etc but no functions to read/edit the mailspool.  Does anyone 
know of any other modules so that I can read a user's mail spool, as 
root, and also list, delete messages?

Thanks,
Akila



------------------------------

Date: Thu, 22 Jan 2004 18:04:06 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: IMAP::Admin Module
Message-Id: <bup3am$5re$2@wisteria.csv.warwick.ac.uk>


Akila <akilaj@yahoo.com> wrote:
> I am looking for a module that can manipulate a users's mail spool (as 
> root).  The IMAP::Admin Module only has functions to create a mailbox, 
> set acls, etc but no functions to read/edit the mailspool.  Does anyone 
> know of any other modules so that I can read a user's mail spool, as 
> root, and also list, delete messages?

Mail::IMAPClient? Or are you trying to edit the spool directly, rather
than via an IMAP server?

Ben

-- 
And if you wanna make sense / Whatcha looking at me for?          (Fiona Apple)
                            * ben@morrow.me.uk *


------------------------------

Date: Thu, 22 Jan 2004 15:19:32 -0800
From: Akila <akilaj@yahoo.com>
Subject: Re: IMAP::Admin Module
Message-Id: <40105A84.3080406@yahoo.com>

I would like to use a Perl module to edit the spool directly on the 
server.  Mail::IMAPClient requires userid and password of the user.  I 
want a module that takes the root login and can edit users's mail spool.

Thanks,
Akila

Ben Morrow wrote:

>Akila <akilaj@yahoo.com> wrote:
>  
>
>>I am looking for a module that can manipulate a users's mail spool (as 
>>root).  The IMAP::Admin Module only has functions to create a mailbox, 
>>set acls, etc but no functions to read/edit the mailspool.  Does anyone 
>>know of any other modules so that I can read a user's mail spool, as 
>>root, and also list, delete messages?
>>    
>>
>
>Mail::IMAPClient? Or are you trying to edit the spool directly, rather
>than via an IMAP server?
>
>Ben
>
>  
>



------------------------------

Date: Fri, 23 Jan 2004 00:49:10 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: IMAP::Admin Module
Message-Id: <bupr26$mlc$1@wisteria.csv.warwick.ac.uk>


Akila <akilaj@yahoo.com> wrote:
> Ben Morrow wrote:
> >Akila <akilaj@yahoo.com> wrote:
> >>
> >>I am looking for a module that can manipulate a users's mail spool (as 
> >>root).  The IMAP::Admin Module only has functions to create a mailbox, 
> >>set acls, etc but no functions to read/edit the mailspool.  Does anyone 
> >>know of any other modules so that I can read a user's mail spool, as 
> >>root, and also list, delete messages?
> >
> >Mail::IMAPClient? Or are you trying to edit the spool directly, rather
> >than via an IMAP server?
>
> I would like to use a Perl module to edit the spool directly on the 
> server.  Mail::IMAPClient requires userid and password of the user.  I 
> want a module that takes the root login and can edit users's mail spool.

I see. I would suggest you look at Mail::Box.

Ben

-- 
"If a book is worth reading when you are six,                * ben@morrow.me.uk
it is worth reading when you are sixty." - C.S.Lewis


------------------------------

Date: Sat, 24 Jan 2004 22:59:46 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Including a source
Message-Id: <buuq60$m66rk$1@ID-184292.news.uni-berlin.de>

Mark J Fenbers wrote:
> Currently, I want to include a small amount of Perl code from a
> file into my main code.

You probably want to _require_ the file:

     http://www.perldoc.com/perl5.8.0/pod/func/require.html

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



------------------------------

Date: Sat, 24 Jan 2004 22:10:13 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: Including a source
Message-Id: <buuqln$p6b$1@news.simnet.is>

"Mark J Fenbers" <Mark.Fenbers@noaa.gov> wrote in message
news:4012E7FA.D17041CD@noaa.gov...
[snipped HTML formatted message]

please post in plain text.

you might want to try
    require 'something.pl';

if you are using strict, as you should, then you need
to qualify fully qualify variables set in the include,
or use the 'package' keyword

simplest form, but not necessarily the best, is to this
in the include file to set variable:
    $main::x='somevalue';

other method is to use a package:
the include file could be:
    package incl;
    use vars 'foo';
    $foo='bar';
in main:
    use strict;
    require 'include.pl';
    print "$incl::foo\n";

gnari




------------------------------

Date: Sat, 24 Jan 2004 23:08:22 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Including a source
Message-Id: <buutt6$20f$1@wisteria.csv.warwick.ac.uk>


DON'T post HTML here.

Mark J Fenbers <Mark.Fenbers@noaa.gov> wrote:
> Currently, I want to include a small amount of Perl code from a file
> into my main code.  In bash or Korn shell, I can use a dot (.) or
> the word "source" to include some scripting code from a file.  How
> do I do this in Perl?  I couldn't find it in any of my 5 Perl books,
> but maybe I don't know what term to search for.
> 
> My intent is simple: I want to be able to include variables into my
> code whose values are dynamic or contextual, and external to my
> project.  A sample of such file contents might be:
> 
> disclaimer = "These forecasts are based on 12Z data only.\nPlease
> try later for updates.\n";
> floodstage = 42.5;
> petsz = "HGIRP";

These should have $s on the front.

There are a number of alternatives. The simplest is to 'do' the file:
this has a similar effect to simply cutting-and-pasting the
code. There is one principal difference, however: 'my' variables
declared in one file will not be visible in the other. Since you
should be using strictures, this will cause you problems.

There are two ways round this. You can eval the contents of the file
instead of do-ing it:

{
    open my $CONFIG, "</path/to/config" or die "can't read config: $!";
    local $/;
    eval <$CONFIG> or die "can't eval config: $@";
}

; note that the last expression in 'config' must be true, or the eval
will fail. It is customary to put a

1;

as the last line, just to make sure of this. Alternatively you can use
'our' variables. It's probably best if you learn about packages
(perldoc perlmod) before you try this, and put all the config
variables in a different package. Something like:

---config
package Local::Config;

our $disclaimer = "....";
our $floodstage = 42.5;

1;

---main program
#!/usr/bin/perl

 ...

do 'config' or die "can't read config: " . ($@ || $!);

print $Local::Config::disclaimer;

__END__

If you use require instead of do perl will search for the file in
@INC. You can write the values back out to one of these files using
Data::Dumper or Data::Dump.

OTOH, you may be better off not trying to use Perl in your config
file; the module Config::IniFiles from CPAN is one alternative that is
fairly easy to use.

So: read perldoc -f do, perldoc -f require, and perldoc perlmod.

Ben

-- 
   If you put all the prophets,   |   You'd have so much more reason
   Mystics and saints             |   Than ever was born
   In one room together,          |   Out of all of the conflicts of time.
ben@morrow.me.uk |----------------+---------------| The Levellers, 'Believers'


------------------------------

Date: Sun, 25 Jan 2004 10:06:38 -0600
From: Web Surfer <raisin@delete-this-trash.mts.net>
Subject: Re: Including a source
Message-Id: <MPG.1a7da585ae5fcd0798978c@news.mts.net>

[This followup was posted to comp.lang.perl.misc]

In article <4012E7FA.D17041CD@noaa.gov>, Mark.Fenbers@noaa.gov says...
> I am learning Perl.  Pretty cool!
> 
> Currently, I want to include a small amount of Perl code from a file into my
> main code.  In bash or Korn shell, I can use a dot (.) or the word "source" to
> include some scripting code from a file.  How do I do this in Perl?  I couldn't
> find it in any of my 5 Perl books, but maybe I don't know what term to search
> for.
> 
> My intent is simple:  I want to be able to include variables into my code whose
> values are dynamic or contextual, and external to my project.  A sample of such
> file contents might be:
> 
> disclaimer = "These forecasts are based on 12Z data only.\nPlease try later for
> updates.\n";
> floodstage = 42.5;
> petsz = "HGIRP";
> 
> And so in my may code after including this, I can do a test:
> 
> if ($currentstage > $floodstage) { ... }
> 
> Any ideas?
> 
> Mark


Yiu could use the "rwquire" statement as follows :

require "include.pl";

Check your documentation for further details
(eg. perldoc -f require)


------------------------------

Date: 23 Jan 2004 10:21:01 -0800
From: fult01@yahoo.com (Bill)
Subject: index returns 0 for NULL substring
Message-Id: <3968b6b.0401231021.6a71a8e4@posting.google.com>

#!/usr/local/bin/perl 
# try.pl

use strict;

my $string = 'ABC';
my $substr = '';
my $rval = index($string,$substr);

print "-> $rval\n";

__END__

$ try.pl
-> 0

Why does this happen?  It seems that index() should return -1.

$ perldoc -f index
     index STR,SUBSTR,POSITION
     index STR,SUBSTR
             The index function searches for one string within
             another, but without the wildcard-like behavior of a
             full regular-expression pattern match.  It returns
             the position of the first occurrence of SUBSTR in
             STR at or after POSITION.  If POSITION is omitted,
             starts searching from the beginning of the string.
             The return value is based at "0" (or whatever you've
             set the "$[" variable to--but don't do that).  If
             the substring is not found, returns one less than
             the base, ordinarily "-1".


------------------------------

Date: 23 Jan 2004 18:30:23 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: index returns 0 for NULL substring
Message-Id: <u9hdym8qm8.fsf@wcl-l.bham.ac.uk>

fult01@yahoo.com (Bill) writes:
> my $string = 'ABC';
> my $substr = '';
> my $rval = index($string,$substr);

> -> 0

> Why does this happen?  It seems that index() should return -1.

Can you explain why you would expect that?

When you look for nothing you'll always find it immediately.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


------------------------------

Date: Fri, 23 Jan 2004 13:33:01 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: index returns 0 for NULL substring
Message-Id: <20040123132958.L15931@dishwasher.cs.rpi.edu>

On Fri, 23 Jan 2004, Bill wrote:

> #!/usr/local/bin/perl
> # try.pl
>
> use strict;
>
> my $string = 'ABC';
> my $substr = '';
> my $rval = index($string,$substr);
>
> print "-> $rval\n";
>
> __END__
>
> $ try.pl
> -> 0
>
> Why does this happen?  It seems that index() should return -1.
>

It happened because the null string IS found within that string.  It's
found within every string.  It's found before and after every character in
every string.  It is therefore found at position 0, position 1, position
2, etc....

Basically, you're asking perl "What is the first location in which the
next 0 characters are equal to this string of 0 characters?"  Obviously,
that will be vacuuously true at every position in the string.


Paul Lalli


------------------------------

Date: Fri, 23 Jan 2004 02:38:26 +0800
From: Dan Jacobson <jidanni@jidanni.org>
Subject: insert random blank every few chars
Message-Id: <87wu7jg76l.fsf@jidanni.org>

How can I introduce a random blank every few chars?
I want to chop a string into words oh, 3 to 9 chars long.
echo fknfgkljstfklmzkbmsfb|perl -e ...
fkn fgkljst fklmzk bmsfb
[workaround for morse code practice
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=222128 ]


------------------------------

Date: Thu, 22 Jan 2004 14:07:19 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: Dan Jacobson <jidanni@jidanni.org>
Subject: Re: insert random blank every few chars
Message-Id: <Pine.SGI.3.96.1040122135938.58921A-100000@vcmr-64.server.rpi.edu>

[posted & mailed]

On Fri, 23 Jan 2004, Dan Jacobson wrote:

>How can I introduce a random blank every few chars?
>I want to chop a string into words oh, 3 to 9 chars long.
>echo fknfgkljstfklmzkbmsfb|perl -e ...
>fkn fgkljst fklmzk bmsfb

The primary problem with what you're asking is that you need to make sure
all the resulting chunks are the proper length.  For instance,

  abcdefghijklmno => abcdef ghijk lmn o

has a chunk of 6, then 5, then 3, but then we're left with ONE character.

-- 
Jeff Pinyan            RPI Acacia Brother #734            2003 Rush Chairman
"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, 22 Jan 2004 19:19:05 +0000 (UTC)
From: "John J. Trammell" <trammell+usenet@hypersloth.invalid>
Subject: Re: insert random blank every few chars
Message-Id: <slrnc108h9.ill.trammell+usenet@hypersloth.el-swifto.com.invalid>

On Fri, 23 Jan 2004 02:38:26 +0800, Dan Jacobson <jidanni@jidanni.org> wrote:
> How can I introduce a random blank every few chars?
> I want to chop a string into words oh, 3 to 9 chars long.
> echo fknfgkljstfklmzkbmsfb|perl -e ...
> fkn fgkljst fklmzk bmsfb
> [workaround for morse code practice
> http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=222128 ]
> 

My humble solution:

#!/usr/bin/perl
use strict;
use warnings;

print addspaces($_) while <DATA>;

sub addspaces {
    my ($loc,$str,@int) = (0,$_[0],3,4,5,6,7,8,9);
    {
        $loc += $int[ rand(@int) ];
        last unless $loc < length($str);
        substr($str,$loc++,0) = " ";
        redo;
    }
    return $str;
}

__DATA__
alkalalsdfadsfahsdfjasdfhlasjkf
vxmznvcbxcmvbnxcmvbxcvb



------------------------------

Date: Thu, 22 Jan 2004 14:22:26 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: insert random blank every few chars
Message-Id: <20040122140906.G15931@dishwasher.cs.rpi.edu>

On Fri, 23 Jan 2004, Dan Jacobson wrote:
>
> How can I introduce a random blank every few chars?
> I want to chop a string into words oh, 3 to 9 chars long.
> echo fknfgkljstfklmzkbmsfb|perl -e ...
> fkn fgkljst fklmzk bmsfb
> [workaround for morse code practice
> http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=222128 ]


#!/usr/bin/perl
use warnings;
use strict;

my $string = $ARGV[0];

my $pos = 0;
while ($pos < length($string)){
    $pos += int(rand 6) + 3;
    last if $pos >= length($string);
    $string = substr($string, 0, $pos) . " " . substr($string, $pos);
}

print "$string\n";


That could probably be shortened up a bit, but it's a good start.

Paul Lalli


------------------------------

Date: 22 Jan 2004 19:30:34 GMT
From: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: insert random blank every few chars
Message-Id: <slrnc1096q.so9.xx087@smeagol.ncf.ca>

Dan Jacobson <jidanni@jidanni.org> wrote:
>  How can I introduce a random blank every few chars?
>  I want to chop a string into words oh, 3 to 9 chars long.
>  echo fknfgkljstfklmzkbmsfb|perl -e ...
>  fkn fgkljst fklmzk bmsfb

    echo qwersdafdrqwerasdvcxvasdfqeasdfaxcv | perl -ne '
        while ($_) {
            my $len = 3 + int rand 7;
            print substr($_, 0, $len), " ";
            substr($_, 0, $len) = "";
        }
        print "\n";
    '


------------------------------

Date: 22 Jan 2004 15:55:40 -0800
From: botfood@yahoo.com (dan baker)
Subject: Re: insert random blank every few chars
Message-Id: <13685ef8.0401221555.3fa607fc@posting.google.com>

Dan Jacobson <jidanni@jidanni.org> wrote in message news:<87wu7jg76l.fsf@jidanni.org>...
> How can I introduce a random blank every few chars?
> ---------------

gee, are you sure you arent trying to develop another tactic to
obsfucate words for sending SPAM ?

d


------------------------------

Date: Fri, 23 Jan 2004 14:25:10 +0800
From: Dan Jacobson <jidanni@jidanni.org>
Subject: Re: insert random blank every few chars
Message-Id: <87oesvb2rd.fsf@jidanni.org>

Jeff> has a chunk of 6, then 5, then 3, but then we're left with ONE character.

No big deal at the end of a lengthy Morse code practice session.

For stream of input with no newlines, (cwgen|tr -d ' '), my stab at it is:

$low  = 3;
$high = 9;
while (1) {
    {
        for ( 1 .. $low + int( rand( $high - $low + 1 ) ) ) {
            print getc || exit;
        }
        print " "
    }
}


------------------------------

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 V10 Issue 6012
***************************************


home help back first fref pref prev next nref lref last post