[30316] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1559 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 20 09:09:45 2008

Date: Tue, 20 May 2008 06:09:14 -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           Tue, 20 May 2008     Volume: 11 Number: 1559

Today's topics:
    Re: Example for open3 on windows? <ben@morrow.me.uk>
    Re: Example for open3 on windows? <zentara@highstream.net>
    Re: FAQ 2.11 Perl Books <brian.d.foy@gmail.com>
    Re: FAQ 4.41 How can I remove duplicate elements from a <brian.d.foy@gmail.com>
        How to determine if a word has an extended character? ambarish.mitra@gmail.com
    Re: I need ideas on how to sort 350 million lines of da <bugbear@trim_papermule.co.uk_trim>
    Re: Perl equivalent of htmlspecialchars() (Ben Bullock)
    Re: Perl equivalent of htmlspecialchars() <noreply@gunnar.cc>
    Re: Perl equivalent of htmlspecialchars() <yogeshkagrawal@gmail.com>
    Re: Perl equivalent of htmlspecialchars() <tadmc@seesig.invalid>
    Re: Perl equivalent of htmlspecialchars() <noreply@gunnar.cc>
        Regexp: non greedy? <oli.meister@gmail.com>
    Re: Regexp: non greedy? <RedGrittyBrick@SpamWeary.foo>
        select ethernet card for socket? <swest@gmx.de>
    Re: Server-side modules <ben@morrow.me.uk>
    Re: Strawberry <RedGrittyBrick@SpamWeary.foo>
    Re: Strawberry <1usa@llenroc.ude.invalid>
    Re: Tk with Thread <ben@morrow.me.uk>
    Re: Tk with Thread <tadmc@seesig.invalid>
    Re: Tk with Thread <zentara@highstream.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 20 May 2008 11:54:21 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Example for open3 on windows?
Message-Id: <t7nag5-in4.ln1@osiris.mauzo.dyndns.org>


Quoth Manuel.Spam@nurfuerspam.de:
> 
> I tried to forward input, output and error of a command to files using 
> open3 on windows.
> 
> I used the following code:
> 
> open(F_IN, "<$f_in");
> open(F_OUT, ">$f_out");
> open(F_ERR, ">$f_err");
> my $pid = open3(\*F_IN, \*F_OUT, \*F_ERR, "$command");

open3 doesn't work like this: it opens the handles for you.

Under sane versions of windows (Win2k and later) you can use

    system "$command <$f_in >$f_out 2>$f_err";

just as under Unix. Alternatively, you can use IPC::Run, which I would
recommend.

Ben

-- 
Many users now operate their own computers day in and day out on various
applications without ever writing a program. Indeed, many of these users
cannot write new programs for their machines...
    -- F.P. Brooks, 'No Silver Bullet', 1987             [ben@morrow.me.uk]


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

Date: Tue, 20 May 2008 08:45:11 -0400
From: zentara <zentara@highstream.net>
Subject: Re: Example for open3 on windows?
Message-Id: <qmh5341rhe55m979pgp7hugr9oo5t014gn@4ax.com>

On Tue, 20 May 2008 07:33:37 +0200, Manuel Reimer
<mreimer@expires-31-05-2008.news-group.org> wrote:

>Hello,
>
>I tried to forward input, output and error of a command to files using 
>open3 on windows.
>
>I used the following code:
>
>open(F_IN, "<$f_in");
>open(F_OUT, ">$f_out");
>open(F_ERR, ">$f_err");
>my $pid = open3(\*F_IN, \*F_OUT, \*F_ERR, "$command");
>waitpid($pid, 0);
>
>Anything, this code does, is hanging on waitpid.
>
>Does open3 work on windows? If yes: How can I use it to forward all 
>input/output channels to files?
>
>Thanks in advance

open3 uses pipes to open the filehandles, but Win32 dosn't
handle pipes well,

Use IPC::Run  or IPC::Cmd on Win32, it uses sockets instead of pipes,
and win32 can handle it.

See
http://perlmonks.org?node_id=593769

for other ideas.


zentara

-- 
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html


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

Date: Tue, 20 May 2008 12:13:52 +0200
From: brian d  foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 2.11 Perl Books
Message-Id: <200520081213523682%brian.d.foy@gmail.com>

In article <g0qr8h$cte$1@reader2.panix.com>, David Combs
<dkcombs@panix.com> wrote:


> ----
> 
> Well, I've tried.  Breaking into a clique is really hard.
> 

If you want to accuse me of something, just come out and say it. That
you had to invoke some "clique" twice in your *first* message about the
subject.


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

Date: Tue, 20 May 2008 11:56:47 +0200
From: brian d  foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 4.41 How can I remove duplicate elements from a list or array?
Message-Id: <200520081156472175%brian.d.foy@gmail.com>

In article <g0q0580tcc@news4.newsguy.com>, szr <szrRE@szromanMO.comVE>
wrote:

> Point taken, though my goal was to show how to do what was shown at the 
> end of the FAQ with one less line.

Generally I don't golf perlfaq answers, and even take more lines than I
would in my normal programming. Beginners can see more discrete steps,
and advanced people can golf it as much as they like. :)


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

Date: Tue, 20 May 2008 05:54:17 -0700 (PDT)
From: ambarish.mitra@gmail.com
Subject: How to determine if a word has an extended character?
Message-Id: <405f2950-fa4a-4a3e-b5a7-c030a4604b2f@k1g2000prb.googlegroups.com>

I have a file which contains just one word. My task is just to find
out if the word has any extended character. Thats all.

I can use regex, but am not able to find out a regex pattern for
extended character. Any hints?


For example, if the file content is: sample, then the Perl code prints
false; and if the file content is sampl=E9, then the Perl code prints
true.

Thanks.


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

Date: Tue, 20 May 2008 11:42:55 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: I need ideas on how to sort 350 million lines of data
Message-Id: <zPGdnQ0fl9itNq_VnZ2dnUVZ8j6dnZ2d@plusnet>

Ted Zlatanov wrote:
> One simple way, without using databases, is to take smaller pieces (say,
> 10K lines each) and sort them individually by whatever field you need.
> Then you take the top or bottom of each piece, make a new set, and sort
> that set for the final result.  
> 
> If you need to sort the whole list and not just get the max/min, apply
> the same algorithm except you keep each sorted piece open and keep
> taking the smallest/largest element from the top/bottom of the piece
> that contains it.
> 
> For more information and if my explanation doesn't make sense, look up
> the "merge sort" algorithm.

IIRC Linux/Unix sort used quicksort for in RAM
and merge sort (via disc) if the data size exceeds RAM size,
again using quicksort in RAM when the portion to be
merged fit in RAM.

  BugBear


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

Date: Tue, 20 May 2008 07:35:11 +0000 (UTC)
From: benkasminbullock@gmail.com (Ben Bullock)
Subject: Re: Perl equivalent of htmlspecialchars()
Message-Id: <g0tuvf$52t$1@ml.accsnet.ne.jp>

Yogi <yogeshkagrawal@gmail.com> wrote:
> I am looking for perl equivalent of PHP functions htmlspecialchars()

There are lots of ways to do it, try the HTML::Entities module:

http://search.cpan.org/~gaas/HTML-Parser-3.56/lib/HTML/Entities.pm

> and stripslashes() to parse a html page.

stripslashes seems to be something like

s/\\//g;

in Perl.



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

Date: Tue, 20 May 2008 09:39:03 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Perl equivalent of htmlspecialchars()
Message-Id: <69fdkqF322461U1@mid.individual.net>

Yogi wrote:
> I am looking for perl equivalent of PHP functions htmlspecialchars()

That would be CGI.pm's escapeHTML() function.

> and stripslashes()

Don't know about any function. I'd make use of the s/// operator.

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


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

Date: Tue, 20 May 2008 00:51:19 -0700 (PDT)
From: Yogi <yogeshkagrawal@gmail.com>
Subject: Re: Perl equivalent of htmlspecialchars()
Message-Id: <8844b5b4-85bc-4c79-b319-6c1aa420e83d@i36g2000prf.googlegroups.com>

On May 20, 12:35 pm, benkasminbull...@gmail.com (Ben Bullock) wrote:
> Yogi <yogeshkagra...@gmail.com> wrote:
> > I am looking forperlequivalent of PHP functions htmlspecialchars()
>
> There are lots of ways to do it, try the HTML::Entities module:
>
> http://search.cpan.org/~gaas/HTML-Parser-3.56/lib/HTML/Entities.pm
>
> > andstripslashes() to parse a html page.
>
> stripslashesseems to be something like
>
> s/\\//g;
>
> inPerl.

Thanks Ben for your input.  HTML::Entities seems to solve my
puzzle. :)
will use Regex for stripslashes. Thanks again.


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

Date: Tue, 20 May 2008 06:54:22 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Perl equivalent of htmlspecialchars()
Message-Id: <slrng35eve.iu6.tadmc@tadmc30.sbcglobal.net>

Yogi <yogeshkagrawal@gmail.com> wrote:
> On May 20, 12:35 pm, benkasminbull...@gmail.com (Ben Bullock) wrote:


>> stripslashesseems to be something like
>>
>> s/\\//g;


> will use Regex for stripslashes. Thanks again.


Transliteration is more appropriate for operating on characters
(regexes are better for operating on patterns):


   tr/\\//d;


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


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

Date: Tue, 20 May 2008 13:49:03 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Perl equivalent of htmlspecialchars()
Message-Id: <69fs9jF31vakaU1@mid.individual.net>

Tad J McClellan wrote:
> Yogi <yogeshkagrawal@gmail.com> wrote:
>> On May 20, 12:35 pm, benkasminbull...@gmail.com (Ben Bullock) wrote:
>>> 
>>> stripslashesseems to be something like
>>>
>>> s/\\//g;
>> 
>> will use Regex for stripslashes. Thanks again.
> 
> Transliteration is more appropriate for operating on characters
> (regexes are better for operating on patterns):
> 
>    tr/\\//d;

True, but are we really talking about simple character removals here? I 
thought we were rather talking about something like

     s/(^|[^\\])\\(['"\\0])/$1.($2 eq '0' ? "\0" : $2)/eg

http://www.php.net/manual/en/function.stripslashes.php

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


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

Date: Tue, 20 May 2008 03:49:19 -0700 (PDT)
From: Oliver <oli.meister@gmail.com>
Subject: Regexp: non greedy?
Message-Id: <3cfed297-ddee-46e1-bcf0-cc93a4cac9a1@b1g2000hsg.googlegroups.com>

Dear all

I know, that its probably a little boring for the "pro"s to answer
question about regexp...
 ...but, bevor I start to cry I'd like to ask for a helping hand.

I have the following regexp:
$message =~ m/(\:59\:(.+)?(\n\:\d\d\:))/s ;

I am expecting it to grab everything whats between :59: and :70: into
$2.
Unfortunately it does it greedy that for some examples it does not
the  add the first but the last match of :59: and :70:.

What can I do, that it matches the first occurance between :59: and :
70: ?

Regards,
Oliver

Example Data:

a)

:21: Hello World
:23A: 12344523423
:59: I Am a line
I am another line
me too
I could be another but mustn't
:70: ABRV
:71A: kkk

b)

:21: Hello World
:23A: 12344523423
:59: I Am a line
I am another line with a number
:70: ABRV
:71G: kkk
:70: ABRV2
:71H: lll
:70: ABRV3




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

Date: Tue, 20 May 2008 12:01:58 +0100
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.foo>
Subject: Re: Regexp: non greedy?
Message-Id: <4832afa8$0$26092$db0fefd9@news.zen.co.uk>

Oliver wrote:

> I have the following regexp:
> $message =~ m/(\:59\:(.+)?(\n\:\d\d\:))/s ;
> 
> I am expecting it to grab everything whats between :59: and :70: into
> $2.
> Unfortunately it does it greedy that for some examples it does not
> the  add the first but the last match of :59: and :70:.
> 
> What can I do, that it matches the first occurance between :59: and :
> 70: ?
> 
> Regards,
> Oliver
> 
> Example Data:
> 
> [snip, see below]

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

my $x=<<END;
:21: Hello World
:23A: 12344523423
:59: I Am a line
I am another line
me too
I could be another but mustn't
:70: ABRV
:71A: kkk
END

my $y=<<END;
:21: Hello World
:23A: 12344523423
:59: I Am a line
I am another line with a number
:70: ABRV
:71G: kkk
:70: ABRV2
:71H: lll
:70: ABRV3
END

for ($x,$y) {
   if (/:59:(.+?):70:/s) {
     print "\n'$1'\n";
   }
}


-- 
RGB


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

Date: Tue, 20 May 2008 14:31:46 +0200
From: Susanne West <swest@gmx.de>
Subject: select ethernet card for socket?
Message-Id: <a3b32$4832c4af$544b8434$17895@news.hispeed.ch>



how can i select an specific ethernet card for a
socket, when i have multiple ethernet-cards (lan,
wireless) installed?

i have two cards, configured for two different subnets:
   wireless: 192.168.50.x
   lan: 2.1.1.x
and want to open a socket and broadcast to 2.1.1.x but
without touching the wireless-settings. currently, i
do:

----------------------------------------------
my $sendsocket = new IO::Socket::INET(
       LocalHost => '2.1.1.1',
       LocalPort => '6454',
       PeerAddr => '2.255.255.255',
       PeerPort => '6454',
       Proto => 'udp',
       Broadcast => 1
    ) || die "[ERROR CREATING SOCKET] $!\n";
$sendsocket->sockopt(SO_BROADCAST, 1);
----------------------------------------------

which causes the wireless-connection to collapse...
i guess i can do something with 'bind' but can't
figure out how to identify the correct card...


thanks a ton!




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

Date: Tue, 20 May 2008 11:42:35 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Server-side modules
Message-Id: <rhmag5-in4.ln1@osiris.mauzo.dyndns.org>


Quoth hotkitty <stpra123@gmail.com>:
> I am trying to setup a script on my server (godaddy.com, if anyone has
> any experience w/ them) and have been ripping my hair out the past
> couple of days trying to figure it out. My guess is that the problem
> lies in the "Undefined subroutine &utf8::is_utf8 called" but I have no
> idea how to correct it. When I run the script on my local machine
> everything runs perfectly. When I upload it to the server I get the
> following errors (obviously, I;ve cut out a portion that contains some
> of the more sensitive details of my site, but you get the idea):
> 
> Undefined subroutine &utf8::is_utf8 called at /var/chroot/home/
> content/........./html/cgi/modules/lib/Carp/Heavy.pm line 122.

Have you by any chance uploaded Carp/Heavy.pm from 5.8 to a machine
that only has 5.6? That isn't going to work: modules supplied with perl
are not (in general) portable to other versions. If they are, there will
be a version on CPAN, which you should install rather than taking a copy
from your current perl.

Ben

-- 
I touch the fire and it freezes me,                      [ben@morrow.me.uk]
I look into it and it's black.
Why can't I feel? My skin should crack and peel---
I want the fire back...                     BtVS, 'Once More With Feeling'


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

Date: Tue, 20 May 2008 10:51:45 +0100
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.foo>
Subject: Re: Strawberry
Message-Id: <48329f33$0$10629$fa0fcedb@news.zen.co.uk>

sanozuke wrote:
> I put in the command line perl hello.pl and perl perl40.pl and a pop
> up very quicly appear's, just show up and don't gives time to see
> anything.
> What is that is going wrong

Without knowing the contents of the hello.pl or perl40.pl, which you are 
hiding from us, I can only guess.

What is in hello.pl?


-- 
RGB


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

Date: Tue, 20 May 2008 13:00:08 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Strawberry
Message-Id: <Xns9AA45B9291336asu1cornelledu@127.0.0.1>

RedGrittyBrick <RedGrittyBrick@SpamWeary.foo> wrote in
news:48329f33$0$10629$fa0fcedb@news.zen.co.uk: 

> sanozuke wrote:
>> I put in the command line perl hello.pl and perl perl40.pl and a pop
>> up very quicly appear's, just show up and don't gives time to see
>> anything.
>> What is that is going wrong
> 
> Without knowing the contents of the hello.pl or perl40.pl, which you
> are hiding from us, I can only guess.

And my guess is the OP is not running the programs from the cmd shell 
command line but instead typing

perl hello.pl

in Start -> Run

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/


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

Date: Tue, 20 May 2008 11:38:13 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Tk with Thread
Message-Id: <l9mag5-in4.ln1@osiris.mauzo.dyndns.org>


Quoth Joost Diepenmaat <joost@zeekat.nl>:
> Slickuser <slick.users@gmail.com> writes:
> 
>  > Here is a sample code:
> >
> > use strict;
> > use warnings;
> > use Tk;
> > use threads;
> >
> > my $mainWindow = MainWindow->new;
> > my $textBox = $mainWindow->Scrolled("Text", -width=>80, -height=>7, -
> > scrollbars=>"ose", -wrap=>"word")->pack();
> >
<snip>
> > sub excecute
> > {
> > 	my $thr = threads->new(\&click);
> > 	$thr->join;
> > 	$thr->detach;
> > }
> >
> > sub click
> > {
> >
<snip>
> > 		$textBox->insert('end', "$line\n");
<snip>
> 
> You shouldn't expect to be able to close over or otherwise refer to
> objects in multiple threads, unless the docs for those objects
> explictely say you can.

More importantly, in this case, you mustn't access Tk (at all) from more
than one thread, since it isn't threadsafe.

Ben

-- 
For the last month, a large number of PSNs in the Arpa[Inter-]net have been
reporting symptoms of congestion ... These reports have been accompanied by an
increasing number of user complaints ... As of June,... the Arpanet contained
47 nodes and 63 links. [ftp://rtfm.mit.edu/pub/arpaprob.txt] * ben@morrow.me.uk


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

Date: Tue, 20 May 2008 06:50:50 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Tk with Thread
Message-Id: <slrng35eoq.iu6.tadmc@tadmc30.sbcglobal.net>

Slickuser <slick.users@gmail.com> wrote:


> 	while(<FILE>)
> 	{
> 		my $line = $_;
> 		push(@data,$line);
> 	}


You can replace all of that code with:

   my @data = <FILE>;


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


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

Date: Tue, 20 May 2008 08:40:29 -0400
From: zentara <zentara@highstream.net>
Subject: Re: Tk with Thread
Message-Id: <ikh534dvqg1ijsehhfmte11aroeb2qlg3a@4ax.com>

On Mon, 19 May 2008 17:16:44 -0700 (PDT), Slickuser
<slick.users@gmail.com> wrote:

>Here is the update code with the same error.
>
>I would like to be able to move my Tk window when a button is press.
>Currently, it's freeze until it's done parsing.

I get all sorts of errors regarding thread corruption, since you
created your thread after Tk is invoked, and you try to access the
Tk text widget from the thread. Gtk2 will allow you to do that, but Tk
won't. Even Gtk2 needs some precautions.

This is a basic Tk thread script, to show you the ropes.
You can search groups.google.com for "perl Tk threads"
and find all of the many examples that have been posted previously.

#!/usr/bin/perl
use strict;
use warnings;
use Tk;
use threads;
use threads::shared;

my $go:shared = 0;
my $die:shared = 0;
my $count:shared = 0;

# make thread before any Tk is called, 
# usually a sleeping thread
my $thr = threads->new(\&new_thread);

my $mainWindow = MainWindow->new;
my $textBox = $mainWindow->Scrolled("Text", -width=>80, -height=>7, 
      -scrollbars=>"ose", -wrap=>"word")->pack();

$mainWindow->Button(-foreground=>"blue", -text=>"Click", 
                   -command=>\&excecute)->pack();

$mainWindow->Button(-foreground=>"red", -text=>"Stop", 
                   -command=>sub{ $go=0 })->pack();

$mainWindow->Button(-foreground=>"black", -text=>"exit", 
                   -command=>sub{ $die=1;
                                  $thr->join;
                                  exit;
                                   })->pack();

# you must actively read the shared variables with a timer
# filehandles can be shared thru the fileno, 
# search groups.google for examples
my $repeater = $mainWindow->repeat(1000,sub{
            if($go){
              $textBox->insert('end', "$count\n");
	      $textBox->see('end');
	      $textBox->update;
             }
            });


MainLoop;

sub new_thread{

    while(1){
       if($die){return}    #thread can only be joined after it returns
       if( $go == 1){
           if($die){return}    
           
          $count++;           
      
       }else{ select undef,undef,undef,.1}  #sleep awhile
    }
}

sub excecute { $go = 1 }
__END__



 Those are the basics, but search groups.google.com, because
we have answered these questions many times before, with code examples.

zentara


-- 
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html


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

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


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