[19315] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1510 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 13 14:10:32 2001

Date: Mon, 13 Aug 2001 11:10:17 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <997726216-v10-i1510@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 13 Aug 2001     Volume: 10 Number: 1510

Today's topics:
    Re: Self-Searchable Perl documention - Extremely Useful (John Holdsworth)
    Re: small CGI.pm hack, code review request <gnarinn@hotmail.com>
    Re: string extraction <ren@tivoli.com>
        Txt file contents, numbers and commas <paanwa@hotmail.com>
    Re: Txt file contents, numbers and commas <christoph.neubauer@siemens.at>
    Re: Txt file contents, numbers and commas (Rafael Garcia-Suarez)
    Re: Txt file contents, numbers and commas (Tad McClellan)
    Re: URL Encode <jtjohnston@courrier.usherb.ca>
    Re: URL Encode <ilya@martynov.org>
    Re: URL Encode <cberry@cinenet.net>
        VSlickEd + Emacs ??? <bill02115@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 13 Aug 2001 10:24:57 -0700
From: coldwave@bigfoot.com (John Holdsworth)
Subject: Re: Self-Searchable Perl documention - Extremely Useful!
Message-Id: <2a46b11e.0108130924.172890a4@posting.google.com>

David Coppit <newspost@coppit.org> wrote in message news:<3B77D6C0.8020400@coppit.org>...
> John Holdsworth wrote:
> 
> > David Coppit <newspost@coppit.org> wrote in message news:<3B65AF04.2050906@coppit.org>...
> >
>  
> >>The main reason I ask is that I'm interested in techniques for building 
> >>web-based interfaces to Perl programs, and most Windows folks don't have 
> >>web servers running on their machines.
> > 
> > David,
> > 
> > You got me thinking here and I've published a short example
> > perl application with a browser interface (a version of du).
> > This could be a .html file but a ".hta" removes the IE-ness.
> > 
> > http://www.openpsp.org/source/util/du.hta.gz
> 
> 
> Hi John,
> 
> I couldn't get it to work with IE 5.5a. (It was also funny that I 
> couldn't drop a .hta file on the IE window, but it would open it from 
> your website okay...) Basically I'd get a single form entry in a window 
> with a generic icon and no menus. Then I hit enter and ZoneAlarm told me 
> it wanted network access (too bad it triggers that), but then nothing 
> else happened.

Hi David,

I don't know whats happening here with the zones on IE5.5a perhaps
things have changed since 5.01. A ".hta" file is a "HTML Application"
according to microsoft and looses all the menus giving an application
marked up in HTML in effect. I forgot to mention this! Its described
here:

http://msdn.microsoft.com/library/default.asp?url=/workshop/author/hta/overview/htaoverview.asp


> By the way, another thought occurs to me. How about encapsulating all 
> this in a class derived from CGI? The basic idea would be that I could 
> take an existing CGI app, change "use CGI" to "use IECGI", drop the code 
> into an .hta file, and BOOM! an instant local HTML interface to a Perl 
> program. Drool....

Drool indeed. This is how I found my way to these "active documents".
I have been mucking about with perl web servers since I read an
article on "tinyhttpd.pl" in Byte. I use a class PSP::Socket.pm
which could perhaps be in CGI as CGI::Socket which is a subclass of
IO::Socket::INET and does pretty much what you suggest. To write
an application you just subclass it an override its "main()" function
or define a main::main() then code as you would a CGI script.

http://www.openpsp.org/source/PSP/Socket.pm
(ropey pod documentation at the end)

> I assume debuggin Perlscript is a pain. If so, people used to debugging 
> CGI apps can develop using a standard web server, then move everything 
> over to IECGI...

Yup debugging inside IE is no party. All you get to do is call alert()
which pops up a dialog or put in a stack of "warn" calls and redirect
STDERR into a file to ponder when things go wrong. Rather than use a 
standard Web Server I develop scripts using a PSP::Socket.pm and run
it from the command line viz:

#!/usr/bin/perl -w

use CGI qw(:all);
use PSP::Socket;
use strict;


PSP::Socket->new( LocalPort=>9090 )->run( my $state = {} );

sub main {
    my ($socket, $state, $env) = @_;
    my $cgi = CGI->new();
    CGI->nph(1);

    print header(), h1( "Hello World!" );
}

PSP::Socket and an example called "example.pl" are in the OpenPSP
Web Server download http://www.openpsp.org/download.html. There
a few other goodies in this server as well such as compiled CGI
(use URLs such as /ecgi/script.cgi instead of /cgi-bin/script.cgi)


john


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

Date: Mon, 13 Aug 2001 17:02:31 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: small CGI.pm hack, code review request
Message-Id: <997722151.877113582566381.gnarinn@hotmail.com>

In article <tneauhre8vs8e4@corp.supernews.com>,
Stephen Deken <shutupsteve@awdang.no.thanks.com> wrote:

>MIME-Version: 1.0
>Content-Type: text/plain; charset="iso-8859-1"
>Content-Transfer-Encoding: quoted-printable

try to avoid the quoted-printable when posting plain text to newsgroups.

>In my original post, I asked if there was any method provided by CGI.pm =
>to add or remove cookies from the internal data structure, so I could =
>'fake' the cookies for the newly logged in and newly logged out pages.  =
>Since then I've read the sources and discovered that there isn't, so I =
>hacked it up to make my own.
>
>Basically, what I need to do is this.  Within the lifetime of a single =
>HTTP / CGI request, I need to be able to set a cookie and then read its =
>value later on.  Essentially I need to do this:

this is strange. usually you read the cookies into your data structure
at the start of the request, then you send the header (optionally with
cookies) , and then the body of the result page. any cookie dependent
code in that last phase should not be reading the cookies again, but 
should use your data structure

>
>  use CGI ':cookie';
>  my $cookie =3D cookie( -name=3D>'a_cookie', -value=3D>'this is the =
>value' );
>  print "Set-cookie: $cookie\n";
>  print "Content-type: text/html\n\n";

why not let CGI do the header (including cookies) for you?

gnari


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

Date: 13 Aug 2001 10:36:24 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: string extraction
Message-Id: <m366bs9dl3.fsf@dhcp9-161.support.tivoli.com>

On Sun, 12 Aug 2001, krahnj@acm.org wrote:

> David Combs wrote:
>> 
[snip]
>> Sure looks strange, that idiom (which, like most,
>> I've never seen before).
>> 
>> ie, that " = () = ".   VERY strange-looking.
> 
> It's the same as:
> 
> $number_xxx_found = @array = $string =~ m!xxx!g;
> 
> where @array = $string =~ m!xxx!g fills @array with all the matches
> from $string and then $number_xxx_found = @array puts the number of
> elements from @array into $number_xxx_found. The only difference is
> that perl allows us to use () instead of @array to achieve the same
> effect without declaring and extra variable (since we only need the
> number and not the list itself.)

There is one more subtlety hiding here, and it is mentioned in
perlop(1) under Assignment Operators:

       Similarly, a list assignment in list context produces the
       list of lvalues assigned to, and a list assignment in
       scalar context returns the number of elements produced by
       the expression on the right hand side of the assignment.

This can be surprising when you do something like:

  my $count = ($a, $b) = (1, 2, 3);

Some might expect $count to be 2, but it is 3.  This naturally extends
to create the above idiom.  It sure is a funny way to write "list",
but since Perl doesn't have a list(), only a scalar(), "() =" has to
serve.

-- 
Ren Maddox
ren@tivoli.com


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

Date: Mon, 13 Aug 2001 11:39:21 -0400
From: "PaAnWa" <paanwa@hotmail.com>
Subject: Txt file contents, numbers and commas
Message-Id: <tnft5c7mmci5a7@corp.supernews.com>

I would like to be able to read a txt file containing a number and display
the number with proper comma formatting.  For example, if the file contains
the number 2345, I would like "2,345" displayed; similarly, if the file
contains the number 345987, I would like "345,987" displayed.

Here is the code I am currently using:

#!/usr/bin/perl

use CGI qw(:standard);

$file=param('file')

#######################################################################
# Read the current file #
#######################################################################

open(COUNT,$file);
$total=<COUNT>;
close(COUNT);

#######################################################################
# Update the count file #
#######################################################################

$total++;               # Add 1 to the number
open(COUNT,">$file");
print COUNT $total;     # Replace old count with new count
close(COUNT);

#######################################################################
# Print Section #
#######################################################################

print header;

print $total;

exit;




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

Date: Mon, 13 Aug 2001 17:53:37 +0200
From: Christoph Neubauer <christoph.neubauer@siemens.at>
Subject: Re: Txt file contents, numbers and commas
Message-Id: <3B77F7FF.6814D245@siemens.at>



PaAnWa wrote:

> I would like to be able to read a txt file containing a number and display
> the number with proper comma formatting.  For example, if the file contains
> the number 2345, I would like "2,345" displayed; similarly, if the file
> contains the number 345987, I would like "345,987" displayed.
>

<snip>

see perldoc -f printf
      perldoc -f sprintf

hth

CN



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

Date: 13 Aug 2001 15:55:47 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Txt file contents, numbers and commas
Message-Id: <slrn9nfue7.o54.rgarciasuarez@rafael.kazibao.net>

PaAnWa wrote in comp.lang.perl.misc:
} I would like to be able to read a txt file containing a number and display
} the number with proper comma formatting.  For example, if the file contains
} the number 2345, I would like "2,345" displayed; similarly, if the file
} contains the number 345987, I would like "345,987" displayed.

This is a FAQ ; "perldoc -q commas" gives you the appropriate entry
in perlfaq5 : "How can I output my numbers with commas added?"

} Here is the code I am currently using:
} 
} #!/usr/bin/perl
} 
} use CGI qw(:standard);
} 
} $file=param('file')
} 
} #######################################################################
} # Read the current file #
} #######################################################################
} 
} open(COUNT,$file);

Besides the fact that you're not using "strict" and "warnings", you
should never use open() without checking its return value.

Here's what can happen : this first open() fails because of exhaustion
of system resources ; $total is then an empty string. Once incremented,
$total == 1. But the 2d open() may succeed. So you will write '1' in the
file, erasing the previous value.

This kind of thing actually happens. That's why (once again) you should
never use a system call without checking its return value.

} $total=<COUNT>;
} close(COUNT);
} 
} #######################################################################
} # Update the count file #
} #######################################################################
} 
} $total++;               # Add 1 to the number
} open(COUNT,">$file");
} print COUNT $total;     # Replace old count with new count
} close(COUNT);
} 
} #######################################################################
} # Print Section #
} #######################################################################
} 
} print header;
} 
} print $total;
} 
} exit;

-- 
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
perl -sleprint -- -_='Just another Perl hacker,'


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

Date: Mon, 13 Aug 2001 11:47:00 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Txt file contents, numbers and commas
Message-Id: <slrn9nftjk.57t.tadmc@tadmc26.august.net>

Christoph Neubauer <christoph.neubauer@siemens.at> wrote:
>
>
>PaAnWa wrote:
>
>> I would like to be able to read a txt file containing a number and display
>> the number with proper comma formatting.  For example, if the file contains
>> the number 2345, I would like "2,345" displayed; similarly, if the file
>> contains the number 345987, I would like "345,987" displayed.
>>
>
><snip>
>
>see perldoc -f printf
>      perldoc -f sprintf


Why see those? They do not address the question that was asked.


   perldoc -q comma

Now _that_ addresses the question that was asked.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Mon, 13 Aug 2001 17:34:18 GMT
From: jtjohnston <jtjohnston@courrier.usherb.ca>
Subject: Re: URL Encode
Message-Id: <3B78100C.51D4FCD@courrier.usherb.ca>

> use URI::Escape
>

Please, do you have an example?

Much thanks,

john




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

Date: 13 Aug 2001 21:50:12 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: URL Encode
Message-Id: <873d6vn92j.fsf@abra.ru>


>> use URI::Escape

j> Please, do you have an example?

Did you tried to read documentation (perldoc URI::Escape)? This module
is very simple and IMHO it is obvious how to use it once you have read
its docs. I'll give example this time but please try first to read
docs.

    use URI::Escape;

    $message = "what a nice day it's going to be!"
    $message = uri_escape($message);
    http://www.nowhere.com/something.cgi?$message

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Date: Mon, 13 Aug 2001 17:58:07 -0000
From: Craig Berry <cberry@cinenet.net>
Subject: Re: URL Encode
Message-Id: <Xns90FC6F91B5A94cberrycinenetnet1@207.126.101.92>

jtjohnston <jtjohnston@courrier.usherb.ca> wrote in 
news:3B78100C.51D4FCD@courrier.usherb.ca:

>> use URI::Escape
> 
> Please, do you have an example?

>perl -MURI::Escape -e "print uri_escape('%percent space')"
%25percent%20space

-- 
Craig Berry <http://www.cinenet.net/~cberry/>
"That which is now known, was once only imagined." - William Blake



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

Date: 13 Aug 2001 13:10:09 -0400
From: bill <bill02115@hotmail.com>
Subject: VSlickEd + Emacs ???
Message-Id: <9l91lh$j3k$1@panix3.panix.com>





This is a question for Emacs veterans that have succeeded in working
with Visual SlickEdit.

Emacs has served me well for 15+ years.  I like the fact that I can
navigate comfortably from the keyboard without ever having to use the
mouse.

Now I'm test driving Visual SlickEdit, which claims to have a GNU
Emacs emulation mode.  I'm very unhappy with this software, because
its Emacs emulation pretty awful, and contrary to real Emacs, there
seems to be nothing the user can do to adjust the interface to suit
his preferences.  I'm making so many mistakes as I write my source
code that my programming has become two steps forward and one step
back, or maybe the other way around.

Can the user do anything to improve the quality of the Emacs emulation
in Visual SlickEdit?

Thanks!

Bill

P.S. For example, in "real Emacs" one selects a region by setting the
mark (C-SPC) and moving the point (cursor) to some other location.
The selected region is that between the mark and the point.  To an
Emacs veteran, this maneuver becomes practically hardwired in the
brain.  To approximate it with Visual SlickEdit, one places the cursor
at the beginning of the region of interest.  Then one presses the
Shift key, and *while pressing the Shift key* move the cursor to the
other end of the region.  Any movement of the cursor that happens
while the Shift key is not pressed effectively destroys the selection
(which is a royal pain).  Moreover, to expand the selection one
screenful Emacs-style, one would need to continue pressing the Shift
key while hitting C-V, which is a pain, but it doesn't work anyway
(C-V advances one screenful fine if Shift is not pressed.)  (In
contrast, with real Emacs, the selected region is, by definition,
whatever lies between the mark and the point/cursor, and one can move
the cursor anywhere in the buffer using the usual cursor movement
commands and keys, including C-V)







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

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 1510
***************************************


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