[29572] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 816 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Sep 2 16:09:41 2007

Date: Sun, 2 Sep 2007 13:09:06 -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           Sun, 2 Sep 2007     Volume: 11 Number: 816

Today's topics:
    Re: =encoding <thepoet_nospam@arcor.de>
    Re: FAQ 4.32 How do I strip blank space from the beginn <bik.mido@tiscalinet.it>
    Re: FAQ 4.32 How do I strip blank space from the beginn <bik.mido@tiscalinet.it>
    Re: FAQ 4.32 How do I strip blank space from the beginn <stoupa@practisoft.cz>
    Re: FAQ 4.32 How do I strip blank space from the beginn <mark.clementsREMOVETHIS@wanadoo.fr>
        How to generate http error in script <stoupa@practisoft.cz>
    Re: How to generate http error in script <noreply@gunnar.cc>
    Re: Searching in a line <tadmc@seesig.invalid>
    Re: Searching in a line <jurgenex@hotmail.com>
    Re: Searching in a line <RedGrittyBrick@SpamWeary.foo>
        Spell checking an html file with aspell or ispell <bill@ts1000.us>
        web programming in perl <spam@nospam.net>
    Re: web programming in perl <noreply@gunnar.cc>
        Win32::GUI Text File not getting updated <steven.stone4@btopenworld.com>
    Re: Win32::GUI Text File not getting updated <remay.uk@googlemail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 02 Sep 2007 13:19:16 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: =encoding
Message-Id: <46da9c01$0$4520$9b4e6d93@newsspool3.arcor-online.net>

Ben Bullock wrote:
> There seems to be a discrepancy between the documentation for perlpod and
> its behaviour.
> 
> http://perldoc.perl.org/perlpod.html says
> 
>     =encoding encodingname
> 
>     This command is used for declaring the encoding of a document. Most
>     users won’t need this; but if your encoding isn’t US-ASCII or Latin-1,
>     then put a =encoding encodingname command early in the document so
>     that pod formatters will know how to decode the document. For
>     encodingname, use a name recognized by the Encode::Supported module.
>     Examples:
> 
>     =encoding utf8
> 
>     =encoding koi8-r
> 
>     =encoding ShiftJIS
> 
>     =encoding big5
> 
> However, perldoc says
> 
> ./mymodule.pm:1: Unknown command paragraph "=encoding utf8"
> 
> pod2html produced a similar message.
> 
> It doesn't depend on the location of the =encoding since I tried putting
> it in various positions.
> 
> Can anyone explain this?

It seems that perlpod is too new and doesn't fit the shipped
versions of Pod::Text and (if already using the new Pod::Text
package) Pod::Simple on your system. However, it seems that
this is an issue with the locally installed versions of perlpod
as well, as my local 5.8.8 build also mentions the =encoding
directive but can't handle it.

I just checked with an older bleadperl from November 2006, this
one already has up-to-date versions of the Pod:: packages that
can handle =encoding just fine.

So you can either wait for Perl 5.10 being released or install
the newer Pod:: modules from CPAN.

-Chris


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

Date: Sun, 02 Sep 2007 15:40:04 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: FAQ 4.32 How do I strip blank space from the beginning/end of a string?
Message-Id: <n74ld3930ru4ehds8b0t7gavbejlummokh@4ax.com>

On Sat, 1 Sep 2007 21:42:57 +0000 (UTC), dkcombs@panix.com (David
Combs) wrote:

>I'm wondering how many perl programmers have always-include
>libraries of useful functions, one of them being "trim".
>
>So, have a poll, and decide based on that.

First of all, please quote some context... inter alia this is a very
old thread... it would help. Coming to your question, it depends:
people use CPAN and own modules all the time, and not only for very
complex stuff that would require thousands of lines of code, but even
simpler things. One example that springs to mind is given by
List::Util's functions: I'm increasingly willing to to use the module
even if I just need one or two of them in one or two places in a tiny
script, and I'm not concerned with "efficiency". Similarly with e.g.
File::Basename. But as far as the hypothetical trim() function goes:
well, for one thing I've not needed it that often, and no, I wouldn't
probably use a library for it but stick to a plain

  s/^\s+//, s/\s+$// for $string;  # instead


My two eurocents,
Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Sun, 02 Sep 2007 15:41:09 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: FAQ 4.32 How do I strip blank space from the beginning/end of a string?
Message-Id: <hafld3derni01amkbcd2veatijs7siuj6e@4ax.com>

On Sun, 2 Sep 2007 04:44:25 +0200, "Petr Vileta"
<stoupa@practisoft.cz> wrote:

>Yes, you are right sherm ;-) But, frankly speaking, the trim() is the 
>function which absent in Perl. Everytime I write script for string 
>manupulation and I plan to write more then 50 lines I write this

I don't want to distrust you, but I'm astonished... I just happen not
to need this kinda things so often.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Sun, 2 Sep 2007 17:42:03 +0200
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: Re: FAQ 4.32 How do I strip blank space from the beginning/end of a string?
Message-Id: <fbemqh$rjs$1@ns.felk.cvut.cz>

Michele Dondi wrote:
> On Sun, 2 Sep 2007 04:44:25 +0200, "Petr Vileta"
> <stoupa@practisoft.cz> wrote:
>
>> Yes, you are right sherm ;-) But, frankly speaking, the trim() is the
>> function which absent in Perl. Everytime I write script for string
>> manupulation and I plan to write more then 50 lines I write this
>
> I don't want to distrust you, but I'm astonished... I just happen not
> to need this kinda things so often.
>
>
> Michele
Characteristic case is web form and putting fields to database. For example 
user name, address or phone number. Many users type some like
" John    Doe"
"Victory str.   60,   London  "
"+420 220 130 150"
Before I put these data to database I want to "normalise" it for future 
comparing for duplicity.

    " John    Doe"
and
    "John Doe"
is not the same for computer but is the same for human. So I must replace 
all "more spaces" with "single space", and remove leading and trailing 
spaces. Phone number must be a number not a string, so
    "+420 220 130 150"
must be translated to
    "420220130150"

-- 

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail 
from another non-spammer site please.)




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

Date: Sun, 02 Sep 2007 09:08:49 +0200
From: Mark Clements <mark.clementsREMOVETHIS@wanadoo.fr>
Subject: Re: FAQ 4.32 How do I strip blank space from the beginning/end of a string?
Message-Id: <46da6181$0$25940$ba4acef3@news.orange.fr>

David Combs wrote:
> I'm wondering how many perl programmers have always-include
> libraries of useful functions, one of them being "trim".

I almost always use String::Strip for that.


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

Date: Sun, 2 Sep 2007 17:54:47 +0200
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: How to generate http error in script
Message-Id: <fbemqi$rjs$2@ns.felk.cvut.cz>

I wrote script where some login is needed and I want to generate standard 
http error when login data is wrong. The script below work on MS-IIS but 
fail on Apache. What is the right way?

#!/usr/bin/perl
use strict;
use warnings;
use CGI qw(:cgi);
my $user = param('user');
if($user ne 'test') {&unauth; exit;}
# do something

sub unauth
{
print "HTTP/1.1 401 Unauthorized\n",
 "Connection: close\n",
 "Content-Type: text/html; charset=utf-8\n\n",
 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n",
 "<HTML><HEAD><TITLE>401 Unauthorized access</TITLE></HEAD><BODY>\n",
 "<h1>401 Unauthorized access</h1>\n</body></html>";
}

-- 

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail 
from another non-spammer site please.)




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

Date: Sun, 02 Sep 2007 19:57:29 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How to generate http error in script
Message-Id: <5k0bsgF1it7qU1@mid.individual.net>

Petr Vileta wrote:
> I wrote script where some login is needed and I want to generate 
> standard http error when login data is wrong. The script below work on 
> MS-IIS but fail on Apache. What is the right way?

<snip>

Instead of

> print "HTTP/1.1 401 Unauthorized\n",

I'd just do:

     print "Status: 401 Unauthorized\n",

The web server is supposed to turn the CGI header "Status" into the 
proper HTTP syntax.

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


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

Date: Sun, 2 Sep 2007 06:43:18 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Searching in a line
Message-Id: <slrnfdl8em.1f5.tadmc@tadmc30.sbcglobal.net>

Petr Vileta <stoupa@practisoft.cz> wrote:

> When you use "use strict" then you must use "my", "our" or "local" variable 
                                     ^^^^                     ^^^^^
> declaration.


That is wrong in multiple ways.

"local" does not help with strict's checks.

"use vars" does help with strict's checks.

You are NOT required to use any declaration at all under strict,
you can simply use fully-qualified names instead:

   $main::foo    # instead of $foo


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Sun, 02 Sep 2007 11:58:05 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Searching in a line
Message-Id: <hzxCi.2090$es2.258@trndny09>

lerameur wrote:
[...]
> I tried using
> use strict;
> use warnings;
>
> with the above program and it do not work.

"It does not work" it the worst possible problem description. Do you also go 
to the doctor and just say "It hurts, please make it stop" without 
explaining any symptoms or details? I strongly suggest you read 
http://www.catb.org/~esr/faqs/smart-questions.html.

Proposal for a better question:

==========
When I'm adding
    use strict;
    use warnings;
to the above program then I am getting these error messages:
    Global symbol "$line" requires explicit package name at C:\tmp\t.pl line 
6.
    Global symbol "$line" requires explicit package name at C:\tmp\t.pl line 
7.
    Global symbol "@items" requires explicit package name at C:\tmp\t.pl 
line 8.
    [and several more like this]
I checked perldoc and Google, but couldn't find an explanation. What do I 
need to do to make the program strict and warnings compliant?

-OR-

I checked perldoc and Google, but I still don't understand these error 
messages, could someone please explain?

-OR-

I checked perldoc and found this explanation
[Quote of text]
but I don't understand it. Could someone please explain?

-OR-
I don't understand these error messages and don't know where to start 
looking for an explanation, could someone please post a pointer?

===========

Do you see the difference between your posting and the my suggestions above?


Then people would have pointed you to "perldoc perldiag" which has 
explanations of all perl messages where it says

    Global symbol "%s" requires explicit package name
        (F) You've said "use strict vars", which indicates that all
        variables must either be lexically scoped (using "my"), declared
        beforehand using "our", or explicitly qualified to say which package
        the global variable is in (using "::").

or to "perldoc strict" where it says

    "strict vars"
          This generates a compile-time error if you access a variable that
          wasn't declared via "our" or "use vars", localized via "my()", or
          wasn't fully qualified. [...] See the my entry in the perlfunc
          manpage and the local entry in the perlfunc manpage.

              use strict 'vars';
              $X::foo = 1;         # ok, fully qualified
              my $foo = 10;        # ok, my() var

jue 




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

Date: Sun, 02 Sep 2007 16:48:29 +0100
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.foo>
Subject: Re: Searching in a line
Message-Id: <w-KdnYsrienRRkfbRVnyhQA@bt.com>

xhoster@gmail.com wrote:
> "Jürgen Exner" <jurgenex@hotmail.com> wrote:
>> Benoit Lefebvre wrote:
>>> Here is how I'd do it..
>>>
>>> #!/usr/bin/perl
>>> @list = `cat file.txt | grep beth`;
>> Useless use of cat
> 
> It isn't useless.  By doing it that way, it becomes trivially easy
> change cat into gzcat if you want to.  Making things trivially easy
> for me in the future is quite useful.
> 

If you start with
  `cat file.txt | sed -e'' | awk '' | perl -p -e '' | tr a a |grep beth`
it becomes trivially easy to insert a sed/awk/perl/tr command if you 
want to.

I'm not sure I like the direction you're headed. :-)


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

Date: Sun, 02 Sep 2007 05:58:13 -0700
From:  Bill H <bill@ts1000.us>
Subject: Spell checking an html file with aspell or ispell
Message-Id: <1188737893.030414.23680@r34g2000hsd.googlegroups.com>

Can someone point me to some docs, modules etc that will show me how
to spell check an html file using ispell or aspell (have both on the
server) and perl?

Thanks

Bill H



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

Date: Sun, 02 Sep 2007 21:48:02 +0200
From: Tom Forsmo <spam@nospam.net>
Subject: web programming in perl
Message-Id: <46db139e$1@news.broadpark.no>

Hi

I have been out of the perl web programming sphere for a long time, so I 
have a couple of quick question just to point me in the right direction.

- is perl used as much for web programming compared to f.ex php, ruby, java?
- what are the primary forums for dicussing perl web programming these days?
- what are the most used web frameworks for perl? I have found out about 
Catalyst, and it seems to be used on some known sites

links to articles discussing modern perl programming techniques and 
frameworks would also be appreciated.

regards

tom


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

Date: Sun, 02 Sep 2007 22:05:27 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: web programming in perl
Message-Id: <5k0jceF1kelaU1@mid.individual.net>

Tom Forsmo wrote:
> 
> - what are the primary forums for dicussing perl web programming these 
> days?

I don't know. I do know that it's not this group...  And the dedicated 
group "comp.infosystems.www.authoring.cgi" has been out of order for 
almost a year now.

> - what are the most used web frameworks for perl? I have found out about 
> Catalyst, and it seems to be used on some known sites

The "CGI/Web Programming and Administration" links at 
http://www.perl.org/app.html should be of interest to you.

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


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

Date: Sat, 01 Sep 2007 23:24:38 -0700
From:  steve <steven.stone4@btopenworld.com>
Subject: Win32::GUI Text File not getting updated
Message-Id: <1188714278.746372.228820@r29g2000hsg.googlegroups.com>

Hi,
  I'm trying to learn a few things with the Win32::GUI side of things
and sockets.
I created a very simple receiver socket script and a sender script
which work in as much that I can send different 'messages' between
them :-)

Then I tried the same using a Win32::GUI setup, simple window with a
textfield where the messages should appear as I send them, but nothing
happens until I exit the window (with an Exit Button) at which point
all the messages appear in the textfield.

The applications is obviously stuck in some loop somewhere that is
preventing the update of the textfield, but I cant figure it out :-(

Here is my code for both send and receiver.....

Sender##############################################################
use IO::Socket;
my $sock = new IO::Socket::INET (
	PeerAddr => 'localhost',
    PeerPort => '7070',
    Proto => 'tcp',
);
die "Could not create socket: $!\n" unless $sock;
print "sending 1st...";
print $sock "1,c:\\temp\\test.txt\n";
sleep(5);
print "sending 2nd...";
print $sock "3,c:\\temp\\test_2.txt\n";
sleep(5);
print "sending 3rd...";
print $sock "4";
close($sock);

Receiver##############################################################
#!/usr/local/bin/perl -w

use strict;
use IO::Socket;
use Switch;
use warnings;
use Win32::GUI;
use Win32();
use Win32::GUI::Loft::Design;

eval {
	main();
	};
sleep(10);

Win32::GUI::MessageBox(0, "Error: $@", "hello Demo") if($@);

sub main {
	my $fileWindow = "receiver.gld";           #You created this using
The GUI Loft

	my $objDesign = Win32::GUI::Loft::Design->newLoad($fileWindow) or
                        die("Could not open window file
($fileWindow)");

	$objDesign->buildWindow() or die("Could not build window
($fileWindow)");

	$Win32::GUI::Loft::window{Rx_Window}->Show();
my $sock = new IO::Socket::INET (
                              LocalHost => 'localhost',
                              LocalPort => '7070',
                              Proto => 'tcp',
                              Listen => 1,
                              Reuse => 1,
                              );
die "Could not create socket: $!\n" unless $sock;
my $new_sock = $sock->accept();
	Win32::GUI::DoEvents();
	Win32::GUI::Dialog();

while(<$new_sock>) {
	Win32::GUI::DoEvents();
	RxMsg($_);
}
close($sock);
	return(1);
}

sub RxMsg {
   my @actions = split(/,/);
	switch ($actions[0]) {
    	case 1 {defined(my $win = $Win32::GUI::Loft::window{Rx_Window})
or return(1);
			$win->RxTextfield->Append("action 1\r\n");
			chomp($actions[1]);
			$win->RxTextfield->Append("$actions[1]\r\n");
            open ACTION, "< $actions[1]" or die "cant open file : $!";
            while (my $line = <ACTION> ) {
				$win->RxTextfield->Append("$line\r\n");
           }
        }
        case 2 {defined(my $win =
$Win32::GUI::Loft::window{Rx_Window}) or return(1);
			$win->RxTextfield->Append("action 2\r\n");
        }
        case 3 {defined(my $win =
$Win32::GUI::Loft::window{Rx_Window}) or return(1);
			$win->RxTextfield->Append("action 3\r\n");
 			chomp($actions[1]);
			$win->RxTextfield->Append("$actions[1]\r\n");
            open ACTION, "< $actions[1]" or die "cant open file : $!";
            while (my $line = <ACTION> ) {
				$win->RxTextfield->Append("$line\r\n");
            }
       }
        else {defined(my $win = $Win32::GUI::Loft::window{Rx_Window})
or return(1);
			$win->RxTextfield->Append("action unknown\r\n");
        }
    }
	return(1);
}

sub ::ExitBtn_Click { defined(my $win =
$Win32::GUI::Loft::window{Rx_Window}) or return(1);

	#Just exit
	return(-1);
	}



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

Date: Sun, 02 Sep 2007 09:41:10 -0000
From:  Robert May <remay.uk@googlemail.com>
Subject: Re: Win32::GUI Text File not getting updated
Message-Id: <1188726070.289513.28750@k79g2000hse.googlegroups.com>

On Sep 2, 7:24 am, steve <steven.sto...@btopenworld.com> wrote:

> I created a very simple receiver socket script and a sender script
> which work in as much that I can send different 'messages' between
> them :-)
>
> Then I tried the same using a Win32::GUI setup, simple window with a
> textfield where the messages should appear as I send them, but nothing
> happens until I exit the window (with an Exit Button) at which point
> all the messages appear in the textfield.
>
> The applications is obviously stuck in some loop somewhere that is
> preventing the update of the textfield, but I cant figure it out :-(

[snip code]

>         Win32::GUI::Dialog();

Try removing that line from your receiver - it won't return until you
close your window.  Win32::GUI::DoEvents() is the 'non-blocking'
equivalent.

Regards,
Rob.




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

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


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