[28291] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9655 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 28 00:05:54 2006

Date: Sun, 27 Aug 2006 21:05:05 -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, 27 Aug 2006     Volume: 10 Number: 9655

Today's topics:
        A Sort Optimization Technique: decorate-sort-dedecorate <xahlee@gmail.com>
    Re: A Sort Optimization Technique: decorate-sort-dedeco <tcole6@gmail.com>
        Allowing threading with CGI <youknows@gmail.com>
    Re: Allowing threading with CGI <noreply@gunnar.cc>
    Re: Allowing threading with CGI <youknows@gmail.com>
    Re: Beginner: read $array with line breaks line by line <tadmc@augustmail.com>
    Re: Beginner: read $array with line breaks line by line <tadmc@augustmail.com>
    Re: Beginner: read $array with line breaks line by line <mstep@t-online.de>
    Re: Beginner: read $array with line breaks line by line <tadmc@augustmail.com>
    Re: Calling another cgi program using CGI.pm <youknows@gmail.com>
    Re: Out of memory! When running perl script on windows <youknows@gmail.com>
        pack problem? <zhushenli@gmail.com>
    Re: pack problem? <DJStunks@gmail.com>
    Re: page reload question <youknows@gmail.com>
    Re: Perl's GUI <bik.mido@tiscalinet.it>
    Re: Splitting a string to access a multilevel hash <w.c.humann@arcor.de>
        TCP Port checking script <nospam@nospam.net>
        Threading - share <mumebuhi@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 27 Aug 2006 15:51:32 -0700
From: "xahlee@gmail.com" <xahlee@gmail.com>
Subject: A Sort Optimization Technique: decorate-sort-dedecorate
Message-Id: <1156719092.603277.57390@b28g2000cwb.googlegroups.com>

Last year, i've posted a tutorial and commentary about Python and
Perl's sort function. (http://xahlee.org/perl-python/sort_list.html)

In that article, i discussed a technique known among juvenile Perlers
as the Schwartzian Transform, which also manifests in Python as its
=E2=80=9Ckey=E2=80=9D optional parameter.

Here, i give a more detailed account on why and how of this construct.

----

Language and Sort Optimization: decorate-sort-dedecorate

There are many algorithms for sorting. Each language can chose which to
use. See wikipedia for a detailed list and explanation:
Sorting_algorithm=E2=86=97 .

However, does not matter which algorithm is used, ultimately it will
need the order-deciding function on the items to be sorted. Suppose
your items are (a,b,c,d,...), and your order-deciding function is F.
Various algorithms will try to minimize the number of times F is
called, but nevertheless, F will be applied to a particular element in
the list multiple times. For example, F(a,b) may be called to see which
of =E2=80=9Ca=E2=80=9D or =E2=80=9Cb=E2=80=9D comes first. Then, later the =
algorithm might need
to call F(m,a), or F(a,z). The point here is that, F will be called
many times on arbitrary two items in your list, even if one of the
element has been compared to others before.

Now suppose, you are sorting some polygons in 3D space, or personal
records by the person's address's distance from a location, or sorting
matrixes by their eigen-values in some math application, or ordering
files by number of occurrences of some text in the file.

In general, when you define your decision function F(x,y), you will
need to extract some property from the elements to be sorted. For
example, when sorting points in space by a criterion of distance, one
will need to compute the distance for the point. When sorting personal
records from database by the person's location, the decision function
will need to retrieve the person's address from the database, then find
the coordinate of that address, that compute the distance from there to
a given coordinate. In sorting matrixes in math by eigen-values, the
order-decision will first compute the eigen-value of the matrix. A
common theme from all of the above is that they all need to do some
non-trivial computation on each element.

As we can see, the order-decision function F may need to do some
expensive computation on each element first, and this is almost always
the case when sorting elements other than simple numbers. Also, we know
that a sorting algorithm will need to call F(x,y) many times, even if
one of x or y has been compared to others before. So, this may result
high inefficiency. For example, you need to order people by their
location to your home. So when F(Mary,Jane) is called, Mary's address
is first retrieved from a database across a network, the coordinate of
her address is looked up in another database. Then the distance to your
home are computed using spherical geometry. The exact same thing is
done for Jane. But later on, it may call F(Mary,Chrissy),
F(Mary,Jonesy), F(Mary,Pansy) and so on, and the entire record
retrieval for Mary is repeated many times.

One solution, is to do the expensive extraction one time for each
element, then associate that with the corresponding elements. Suppose
this expensive extraction function is called gist(). So, you create a
new list ([Mary,gist(Mary)], [Jane,gist(Jane)], [John,gist(John)],
[Jenny,gist(Jenny)], ...) and sort this list instead, when done, remove
associated gist. This technique is sometimes called
decorate-sort-dedecorate.

In Perl programing, this decorate-sort-dedecorate technique is sillily
known as Schwartzian Transform as we have demonstrated previously. In
Python, they tried to incorporate this technique into the language, by
adding the =E2=80=9Ckey=E2=80=9D optional parameter, which is our gist() fu=
nction.

----------
This post is archived at:
http://xahlee.org/perl-python/sort_list.html

I would be interested in comments about how Common Lisp, Scheme, and
Haskell deal with the decorate-sort-dedecorate technique. In
particular, does it manifest in the language itself? If not, how does
one usually do it in the code? (note: please reply to approprate groups
if it is of no general interest. Thanks) (am also interested on how
Perl6 or Python3000 does this, if there are major changes to their sort
function)

Thanks.

  Xah
  xah@xahlee.org
=E2=88=91 http://xahlee.org/



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

Date: 27 Aug 2006 17:06:42 -0700
From: "Tom Cole" <tcole6@gmail.com>
Subject: Re: A Sort Optimization Technique: decorate-sort-dedecorate
Message-Id: <1156723602.192984.49610@m79g2000cwm.googlegroups.com>

Well you cross-posted this enough, including a Java group, and didn't
even ask about us... What a pity.

In Java, classes can implement the Comparable interface. This interface
contains only one method, a compareTo(Object o) method, and it is
defined to return a value < 0 if the Object is considered less than the
one being passed as an argument, it returns a value > 0 if considered
greater than, and 0 if they are considered equal.

The object implementing this interface can use any of the variables
available to it (AKA address, zip code, longitude, latitude, first
name, whatever) to return this -1, 0 or 1. This is slightly different
than what you mention as we don't have to "decorate" the object. These
are all variables that already exist in the Object, and if fact make it
what it is. So, of course, there is no need to un-decorate at the end.

There are several built-in objects and methods available to sort
Objects that are Comparable, even full Arrays of them.



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

Date: 27 Aug 2006 18:38:18 -0700
From: "alpha_beta_release" <youknows@gmail.com>
Subject: Allowing threading with CGI
Message-Id: <1156729098.562522.229200@74g2000cwt.googlegroups.com>

Hi,

I'm doing CGI, and plan to use threads.pm for CGI application. I ran a
test, but unfortunately, my http server (Apache) won't allow multiple
threads ran within a CGI script. But the script works OK if not as CGI
and as local running script. Any suggestion? Is this normal or just my
fault somewhere?

p/s This not to run multiple users simultenously (as using mod_perl or
something) but allow a user to run multiple threads (optimization)

thanks.



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

Date: Mon, 28 Aug 2006 03:49:00 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Allowing threading with CGI
Message-Id: <4lf0cuF1jtqcU1@individual.net>

alpha_beta_release wrote:
> I'm doing CGI, and plan to use threads.pm for CGI application. I ran a
> test, but unfortunately, my http server (Apache) won't allow multiple
> threads ran within a CGI script. But the script works OK if not as CGI
> and as local running script. Any suggestion? Is this normal or just my
> fault somewhere?
> 
> p/s This not to run multiple users simultenously (as using mod_perl or
> something) but allow a user to run multiple threads (optimization)

Depending on which platform you are on, fork() may be a better solution. 
The Parallel::ForkManager module facilitates the use of multiple processes.

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


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

Date: 27 Aug 2006 19:36:29 -0700
From: "alpha_beta_release" <youknows@gmail.com>
Subject: Re: Allowing threading with CGI
Message-Id: <1156732589.115427.3840@i42g2000cwa.googlegroups.com>

It doesn't work either. I modify this code from the example given.

[code]------------------------------
#!c:/perl/bin/perl -Tw

use strict;
use Parallel::ForkManager;
use CGI;
use CGI::Carp 'fatalsToBrowser';

  my $max_procs = 5;
  my @names = qw( Fred Jim Lily Steve Jessica Bob Dave Christine Rico
Sara );

  my $pm =  new Parallel::ForkManager($max_procs);
  $pm->run_on_finish(
    sub {
        my ($pid, $exit_code, $ident) = @_;
    }
  );

  $pm->run_on_start(
    sub {
        my ($pid,$ident)=@_;
    }
  );

  $pm->run_on_wait(
    sub {},
    0.5
  );

  foreach my $child ( 0 .. $#names ) {
    my $pid = $pm->start($names[$child]) and next;
   # $pm->finish($child);
  }

  my $page = new CGI;
  print $page->header,
        $page->start_html,
        'xxxxxx',
        $page->end_html;

[/code]----------------------------

None of error messages, except system error :(

Is this (might be) because the system won't allow anonymous to run
threads and eat system resources?

p/s : Anyway i'm still try to make it work using this module. thanks
for the reference.

Gunnar Hjalmarsson wrote:
> alpha_beta_release wrote:
> > I'm doing CGI, and plan to use threads.pm for CGI application. I ran a
> > test, but unfortunately, my http server (Apache) won't allow multiple
> > threads ran within a CGI script. But the script works OK if not as CGI
> > and as local running script. Any suggestion? Is this normal or just my
> > fault somewhere?
> >
> > p/s This not to run multiple users simultenously (as using mod_perl or
> > something) but allow a user to run multiple threads (optimization)
>
> Depending on which platform you are on, fork() may be a better solution.
> The Parallel::ForkManager module facilitates the use of multiple processes.
>
> --
> Gunnar Hjalmarsson
> Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Sun, 27 Aug 2006 10:49:47 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Beginner: read $array with line breaks line by line
Message-Id: <slrnef3for.1hn.tadmc@magna.augustmail.com>

Marek Stepanek <mstep@t-online.de> wrote:

> for a series (?) letter (=the same letter with many different addresses).
        ^^^^^^^^^^^^^^^^^


I think the term you are looking for is "mail merge".


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


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

Date: Sun, 27 Aug 2006 14:48:09 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Beginner: read $array with line breaks line by line
Message-Id: <slrnef3tnp.2vp.tadmc@magna.augustmail.com>

Marek Stepanek <mstep@t-online.de> wrote:

>     $e =~ s!<span\s+class="comp2">([^<]+)</span>!"Competition: " . $1 .
> "\n\n"!ge;


The replacement string part of s/// is "double quotish" so you
get backslash escapes (\n) and interpolation ($1) for free.

No need for the eval (e) modifier:

     $e =~ s!<span\s+class="comp2">([^<]+)</span>!Competition: $1\n\n!g;


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


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

Date: Sun, 27 Aug 2006 22:58:23 +0200
From: Marek Stepanek <mstep@t-online.de>
Subject: Re: Beginner: read $array with line breaks line by line
Message-Id: <C117D40F.2B71E%mstep@t-online.de>

On 27.08.2006 21:48, in article slrnef3tnp.2vp.tadmc@magna.augustmail.com,
"Tad McClellan" <tadmc@augustmail.com> wrote:

> $e =~ s!<span\s+class="comp2">([^<]+)</span>!Competition: $1\n\n!g;

Thank you all for all the answers! I get only the competitions, and here and
there some email-addresses into my out-file. But tomorrow I will probably
find the mistake(s) myself. (I am online only the evening). I am learning
enormously with all your hints. Until now my script looks like follows:

#! /usr/bin/perl

use strict;
use warnings;
use HTML::Entities;

$/ = undef;

my (@competitions, @complete_address);

while (<>)
  {
    foreach my $entry (m"<dd>(.+?)</dd>"g)
      {
        push (@complete_address, $entry);
      }
  }
    
foreach my $e (@complete_address)
  {
    $e =~ s!<span\s+class="comp2">([^<]+)</span>!Competition: $1\n\n!g;
    $e =~ s!<br />!\n!g;
    $e =~ s!<[^>]+>!!g;
    push (@competitions, $e);
  }

my $out_file1 = 'letter_comp_addr_01.adr';
open OUT1, "> $out_file1" or die "Connot create your out_file: $!";
my $out_file2 = 'letter_comp_addr_02.adr';
open OUT2, ">> $out_file2" or die "Connot create your out_file: $!";

print OUT1 join ("\n\n", @competitions);
print OUT1 "\n\n";

my ($competition, $email, $first_name, $last_name, $gender, $phone);
foreach my $addr (@competitions)
  {
    foreach (split(/\n/, $addr))
      {
        ($competition) = $1 if m/^Competition:\s+(.+)/;
        s/^(International|National) Competition\s*$//i;
        ($gender, $first_name, $last_name) = $_ =~
/^(Mr\.?|Mrs\.?\s+)?([A-Z][a-z]+(?:\s+[A-Z][a-z]+\.?)?)\s+([A-Z][a-z]+(?:[-A
-Z][a-z]+)?)\s*$/; # this regex needs some refinement ... in work ...
# need some ideas for address and phone numbers again ... in work ...
        if ($gender)
          {
            if ( $gender =~ m/Mrs\.?/ )
              {
                $gender = "w";
              }
              elsif ( $gender =~ m/Mr\.?/ )
              {
                $gender = "m";
              }
              else
              {
                $gender = "u";
              }
            }
        ($email) = $_ =~ m"((&#\d+;)+)";
        $email = decode_entities($email) if $email;
      }
      if ($competition)
        {
          print OUT2 "\\addrentry\n";
          print OUT2 "\t{$first_name}\n" if $first_name;
          print OUT2 "\t{$last_name}\n" if $last_name;
          print OUT2 "\t{$competition}\n";
          print OUT2 "\t{$gender}\n" if $gender;
          print OUT2 "\t{$email}\n" if $email;
        }
  }

close OUT1;
close OUT2;



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

Date: Sun, 27 Aug 2006 17:21:25 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Beginner: read $array with line breaks line by line
Message-Id: <slrnef46n5.5rp.tadmc@magna.augustmail.com>

Marek Stepanek <mstep@t-online.de> wrote:

>     foreach my $entry (m"<dd>(.+?)</dd>"g)
>       {
>         push (@complete_address, $entry);
>       }


You can replace that whole foreach loop with:

   push @complete_address, m"<dd>(.+?)</dd>"g;

There is no need to put them in one-at-a-time.



> open OUT1, "> $out_file1" or die "Connot create your out_file: $!";


The error message should contain the name of the file:

  open OUT1, '>', $out_file1 or die "Connot create your file '$out_file' $!";


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


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

Date: 27 Aug 2006 18:00:02 -0700
From: "alpha_beta_release" <youknows@gmail.com>
Subject: Re: Calling another cgi program using CGI.pm
Message-Id: <1156726802.092865.145460@i3g2000cwc.googlegroups.com>

i think your script flow is not quite correct.

Test the param first,
if it exist then process the param, and if valid go to the next page.
else show the form. (again if invalid)

And also do remember, use session to keep track of the logged-in user.

#!/usr/bin/perl -Tw
use CGI;

$cgi=new CGI;
if($cgi->param("username") eq "user1") {
       print
$cgi->redirect(-uri=>"http://localhost/cgi-bin/index2.pl",-status=>301);
#                                                            ^ what's
status for?
       exit;
}
print $cgi->header,
         $cgi->start_html,
         $cgi->start_form,
         "Username ",
          $cgi->textfield(-name=>'username',-default=>'user1'),
         "Password ",
         $cgi->textfield(-name=>'password',-default=>'pass1'),
         $cgi->submit(-name=>'login',-value=>'Login');
         $cgi->endform;

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

dmedhora@gmail.com wrote:
> Hi and Thanks for your replies,
> I did what you said but I'm getting this message:-
>
> Status: 301 Location: http://localhost/cgi-bin/index2.pl
>
> as soon as i press the submit button.
>
> Note I tried using the function oriented as well as the OO styles.
> Here is my very basic index.pl and index2.pl
> ( The main page and the called page )
>
> index.pl
> ======
> #!/usr/bin/perl
> use CGI;
> $cgi=new CGI;
> print $cgi->header,
>         $cgi->start_html,
>         $cgi->start_form,
>         "Username ",
> $cgi->textfield(-name=>'username',-default=>'user1'),
>         "Password ",
> $cgi->textfield(-name=>'password',-default=>'pass1'),
>         $cgi->submit(-name=>'login',-value=>'Login');
>         if($cgi->param("username") eq "user1")
>         {
>                 #As per your suggestion
>                 print
> $cgi->redirect(-uri=>"http://localhost/cgi-bin/index2.pl",-status=>301);
>         }
>         $cgi->endform;
>
> index2.pl
> =======
> #!/usr/bin/perl
> use CGI qw/:all/;
> print   header,
>         start_html('My Title'),
>         start_form,
>         "To be continued...",p;
> print endform;
>
> Thanks!:)
>
> alpha_beta_release wrote:
> > or use CGI.pm,
> >
> > -----------------------------
> > use CGI;
> >
> > my $page = new CGI;
> >
> > # assuming validate_ok() is the function to validate your user
> >
> > if (validate_ok($page->param('user'), $page->param('password')) {
> >    print $page->redirect(
> > 'http://tosomewhere.cgi?user='.$page->param('user'));
> > }
> >
> > # else, print login form
> >
> > -----------------------------
> >
> > Tad McClellan wrote:
> > > [ Please do not top-post! }
> > >
> > >
> > > dmedhora@gmail.com <dmedhora@gmail.com> wrote:
> > >
> > > > Lets say if the index.pl program above validates the user/password
> > > > successfully then  how do I continue to another html page?
> > > > say, continue.pl
> > >
> > >
> > > If continue.pl accepts GET requests, you can issue a "redirect":
> > >
> > >    print "Location: http://www.yoursite.com/cgi-bin/continue.pl\n\n";
> > >
> > > or some such.
> > >
> > >
> > >
> > > [ snip TOFU]
> > >
> > > --
> > >     Tad McClellan                          SGML consulting
> > >     tadmc@augustmail.com                   Perl programming
> > >     Fort Worth, Texas



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

Date: 27 Aug 2006 18:50:57 -0700
From: "alpha_beta_release" <youknows@gmail.com>
Subject: Re: Out of memory! When running perl script on windows
Message-Id: <1156729857.331674.83700@i3g2000cwc.googlegroups.com>

Hi
i used to do scripting for Bioinformatics and still doing it. Most of
the task is to swallow a huge chunk of text, parse it, then tranfer or
convert into another form (SQL database, other text format etc...). I
had met this kind of problem several times.

Normally what i do is :
1- check for infinite loop, which caused by
    + unchanged variable values (missing $i++ etc.)
    + never fulfilled condition  (-1 > 0 etc.)
2- undef not-used variable in the middle of script (sometimes these
variables hold huge   data from file, and used only before parsing). So
undef after parsing, and before doing other task, to save memory.
3- optimize (reading file chunk-by-chunk can save memory than slurping
a whole file etc.)

etc.




Peter J. Holzer wrote:
> On 2006-08-27 15:30, felad <felad@walla.co.il> wrote:
> > I have found that every single loop the commit memory grow by 6000 K so
> > I guess this is why the program crash
> > But I really can't find that cause of it, most of my variable are local
> > and I can't find any infinite loop
> >
> > Any ideas ?
>
> First, check that you aren't creating cyclic data structures: The perl
> garbage collector cannot free cyclic data structures. If you really need
> them, use weak references or destroy them explicitely after you are done
> with them.
>
> Second, lexical variables aren't freed immediately after they go out of
> scope but only after the function returns. So if you create large
> temporary variables, use them inside functions, not in the main program.
>
> Third, modules which may be helpful: Devel::Cycle, Devel::Leak.
>
> Fourth, perl has quite a bit overhead for each object: If you must keep
> lots of data in memory, try to keep few large objects instead of many
> little ones.
>
> 	hp
>
> --
>    _  | Peter J. Holzer    | > Wieso sollte man etwas erfinden was nicht
> |_|_) | Sysadmin WSR       | > ist?
> | |   | hjp@hjp.at         | Was sonst w=E4re der Sinn des Erfindens?
> __/   | http://www.hjp.at/ |	-- P. Einstein u. V. Gringmuth in desd



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

Date: 27 Aug 2006 20:17:21 -0700
From: "Davy" <zhushenli@gmail.com>
Subject: pack problem?
Message-Id: <1156735041.597411.219500@i42g2000cwa.googlegroups.com>

Hi all,

I want to write a dec data to bin data translator.
But I found the $dec_pack in the program don't print "A signed integer
value" as the pack manual said. Why? Thanks!

#------------------------------------------------
use strict;
use warnings;


my $dec = 1234;
my $bin;

$bin = dec2bin($dec);

print 'bin is ',$bin,"\n";

sub dec2bin {
    my $dec_shift = shift;
    print 'dec_shift is ',$dec_shift, "\n";

    my $dec_pack = pack("i", $dec_shift);
    print 'dec_pack ',$dec_pack, "\n";

    return unpack('B32', $dec_pack);
}
#----------------------------------------------------

Best regards,
Davy



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

Date: 27 Aug 2006 20:29:09 -0700
From: "DJ Stunks" <DJStunks@gmail.com>
Subject: Re: pack problem?
Message-Id: <1156735748.992715.88410@75g2000cwc.googlegroups.com>


Davy wrote:
> I want to write a dec data to bin data translator.

it has already been written for you.

  perldoc -f sprintf

-jp



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

Date: 27 Aug 2006 20:10:44 -0700
From: "alpha_beta_release" <youknows@gmail.com>
Subject: Re: page reload question
Message-Id: <1156734644.222954.136470@b28g2000cwb.googlegroups.com>

hi

pass the deleted file as parameter, then process it according to the
parameter

[code]----------------------------------------
my $page = new CGI;

my $content;
if($page->param('file')) {
      $content = .....create processed form / something....;
}

#
my $jscript =<<SCRIPT;
function doRefresh(deletedfilename){
   location.replace("/cgi-bin/page.cgi?file="+deletedfilename);
}
SCRIPT

print $page->header,
       $page->start_html,
       $jscript,
       $content,
       $page->end_html,

[/code]----------------------------------------

Matt Garrish wrote:
> pleaseexplaintome@yahoo.com wrote:
>
> > Hi, I have a perl/cgi script that includes dynamically created
> > checkboxes and file names.  When a given checkbox is checked I move the
> > related file.  how do I redisplay the page without the checkbox and
> > file name.  In other words, I want to reload the page just as if the
> > user has entered for the 1st time.
> >
> > i've tried variations of:
> >
> > <form action="/cgi-bin/page.cgi" method="post" onsubmit="doRefresh()">
> >
> > function doRefresh(){
> >    location.replace("/cgi-bin/page.cgi");
> >    //location.reload("/cgi-bin/page.cgi");
> >    //location.reload("");
> > }
> >
>
> This doesn't make any sense at all. If you're posting back the form to
> move the files, why don't you remove the checkboxes from the page you
> return in response? You're trying to intercept the post action and
> instead reload the page, which means the form the user is submitting
> will never get processed.
> 
> Matt



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

Date: 27 Aug 2006 20:19:36 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Perl's GUI
Message-Id: <d7o3f25kukj6tsihku7l09uf6a10i185gb@4ax.com>

On Sun, 27 Aug 2006 13:02:13 GMT, zentara <zentara@highstream.net>
wrote:

>A few other comparisons bewtween Tk and Gtk2 (and WxWidgets built on
>Gtk2).

On an OT basis and on behalf of a friend of mine[*]: he's been having
difficulties using threads with Tk. I don't have experience with
either so I couldn't really help him, but from posts both here and on
PM I already knew about the possible issues, so I just reminded him of
good ol' fork(). Now the question is: is Gtk2 thread safe? Which
toolkit is, if any?


[*] Really!


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: Mon, 28 Aug 2006 09:49:40 +0800
From: "wolfram.humann" <w.c.humann@arcor.de>
Subject: Re: Splitting a string to access a multilevel hash
Message-Id: <44f24bb9$0$20031$9b4e6d93@newsspool4.arcor-online.net>

Brian McCauley wrote:
> wolfram.humann wrote:
> 
>> So I think I will stick to my original idea, stuff it into a sub like this:
>>
>> sub resolve
>> {
>> 	my ($tmp, $path) = @_;
>> 	$tmp = $tmp->{$_} for split '\.', $path;
>> 	return $tmp;
>> }
> 
> Sooner or later you'll probably wish you'd written that as an lvalue
> sub
> 
> sub resolve : lvalue
> {
>  	my $tmp = \shift;
>  	$tmp = \$$tmp->{$_} for split '\.', shift;
>         $$tmp;
> }
> 

Hey, I haven't read perlsub in a while -- I didn't even know about these. But I'm slightly concerned 
to use something with a fat warning "Lvalue subroutines are EXPERIMENTAL". Always fearing that 
someone might decide that it was not such a good idea after all and remove them altogether...

Thanks for the hint!


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

Date: Fri, 25 Aug 2006 18:44:34 +1000
From: darkmoo <nospam@nospam.net>
Subject: TCP Port checking script
Message-Id: <pan.2006.08.25.08.44.34.94000@nospam.net>

I have borrowed a script that checks to see if a tcp port is openned.   If
not I want it to restart a service.   I can stop the service but not sure
how to check the running state of the service before starting it.  I've
dont something simple like sleep but I get am error. SIGALARM or something
like that. 

Thanks for the help (: 


#!/usr/bin/perl -w
#
# Author: Ralf Schwarz <ralf@schwarz.ath.cx>
#         February 20th 2006
#
# returns 0 if host is listening on specified tcp port
#

use strict;
use Socket;

# set time until connection attempt times out
my $timeout = 3;

if ($#ARGV != 1) {
  print "usage: is_tcp_port_listening hostname portnumber\n";
  exit 2;
}

my $hostname = $ARGV[0];
my $portnumber = $ARGV[1];
my $host = shift || $hostname;
my $port = shift || $portnumber;
my $proto = getprotobyname('tcp');
my $iaddr = inet_aton($host);
my $paddr = sockaddr_in($port, $iaddr);

socket(SOCKET, PF_INET, SOCK_STREAM, $proto) || die "socket: $!";

eval {
  local $SIG{ALRM} = sub { die "timeout" };
  alarm($timeout);
  connect(SOCKET, $paddr) || error();
  alarm(0);
};

if ($@) {
  close SOCKET || die "close: $!";
  print "$hostname is NOT listening on tcp port $portnumber.\n";
  system("net","stop","SSH Tunnel");
  sleep 5;
  system("net","start","SSH Tunnel");
  exit 1;
}
else {
  close SOCKET || die "close: $!";
  print "$hostname is listening on tcp port $portnumber.\n";
  exit 0;
}




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

Date: 27 Aug 2006 12:15:18 -0700
From: "mumebuhi" <mumebuhi@gmail.com>
Subject: Threading - share
Message-Id: <1156706118.045849.116710@b28g2000cwb.googlegroups.com>

I am trying to understand the differences among these constructs:

# 1
my $p : shared;
$p->{'_name'} = "My Name";

# 2
my $p : shared = &share({});
$p->{'_name'} = "My Name";

Do 1 and 2 achieve the same thing?

# 3
my %p : shared;
$p{'_name'} = "My Name";

Is it fair to say that 3 is the simpler form compared to 1 and 2?

Thank you.

Buhi



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

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


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