[22824] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5045 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 27 09:06:04 2003

Date: Tue, 27 May 2003 06:05:09 -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, 27 May 2003     Volume: 10 Number: 5045

Today's topics:
    Re: An error in my solution code (Anno Siegel)
        converting string of [01] to (binary) number <scare.crow@oz.land>
    Re: converting string of [01] to (binary) number <abigail@abigail.nl>
    Re: Display form data in a html format. <REMOVEsdnCAPS@comcast.net>
    Re: drop down selection from flatfile <ron@savage.net.au>
    Re: html tables <ron@savage.net.au>
    Re: html tables <ron@savage.net.au>
    Re: Net::AIM help! news@roaima.freeserve.co.uk
        Posting Guidelines for comp.lang.perl.misc ($Revision:  tadmc@augustmail.com
        Reading Function Keys in a GUI Loft  window (fernjilly)
        scope of variable (fatted)
    Re: scope of variable <bernard.el-hagin@DODGE_THISlido-tech.net>
    Re: scope of variable <REMOVEsdnCAPS@comcast.net>
    Re: scope of variable <abigail@abigail.nl>
        shellwords.pl is not Shell compatible <occitan@esperanto.org>
        Sorting hash <noreply@gunnar.cc>
    Re: Sorting hash <tassilo.parseval@rwth-aachen.de>
    Re: Spawning self - a better way? <tp601553@cia.gov>
    Re: sprintf question (Gilgames)
        string search problem (Marco)
    Re: string search problem <allanon@hotmail.com>
    Re: string search problem (Anno Siegel)
        turning off output buffer does not work (andipfaff)
    Re: turning off output buffer does not work <steve@uptime.orgNo.ukSpam>
    Re: turning off output buffer does not work <see_signature.usenet@tinita.de>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 27 May 2003 12:42:35 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: An error in my solution code
Message-Id: <bavmfr$9hs$1@mamenchi.zrz.TU-Berlin.DE>

David K. Wall <usenet@dwall.fastmail.fm> wrote in comp.lang.perl.misc:

[calculating the arithmetic mean]
 
> If I recall correctly from a numerical methods class I took a long time 
> ago, if some of the numbers are fractions and some are large, they 
> should be sorted from smallest to largest (in absolute value) before 
> accumulating the sum so as to avoid rounding errors due to machine 
> representation.  (Someone please correct me if my memory is faulty)

This is true for sums in general.  With mean calculations the individual
values usually don't vary wildly (if they do, their mean value is
meaningless (pun unintended)).

A numerically stable way of calculating the mean m[n] of x[1] ... x[n]
is to set m[0] = 0 and recursively calculate

     m[i+1] = m[i] + (x[i+1] - m[i])/(i+1)

This way each step is a (small) correction to the last value.

There is a similar formula for the variance (and probably for higher
statistical momenta), though these calculate intermediate values that
require post-processing.

The Module Statistics::Descriptive incorporates this wisdom.

Anno


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

Date: Tue, 27 May 2003 13:39:32 +0200
From: Eric Moors <scare.crow@oz.land>
Subject: converting string of [01] to (binary) number
Message-Id: <pan.2003.05.27.13.39.31.604104.14972@oz.land>

I'm trying to split a string of n*8 characters
in their hexadecimal counterparts. A small example:

As input I have the ascii string:

"0000_0000_0011_0000_1010_1100"

and I want to convert this to the ascii string:

00
30
AC

So I first split the string in n byte parts,
But how can I convert each part to a number?
The code below works, but I cannot help thinking there
must be an easier way. (It's more C'ish than perl'ish)
I looked into (un)pack, but couldn't get any lifesign
out of that.

@bytes = /([01]{8})/g;
foreach (@bytes) {
	my @a = split(//, $_);
	$number = 0;
	$i = 7;
	foreach (@a) {
		$number |= ($_ << $i);
		$i--;
	}
	printf("%02X : %02X\n", $address / 8, $number);
	$address += 8;
}

Eric


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

Date: 27 May 2003 12:08:19 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: converting string of [01] to (binary) number
Message-Id: <slrnbd6l9f.co.abigail@alexandra.abigail.nl>

Eric Moors (scare.crow@oz.land) wrote on MMMDLVI September MCMXCIII in
<URL:news:pan.2003.05.27.13.39.31.604104.14972@oz.land>:
::  I'm trying to split a string of n*8 characters
::  in their hexadecimal counterparts. A small example:
::  
::  As input I have the ascii string:
::  
::  "0000_0000_0011_0000_1010_1100"
::  
::  and I want to convert this to the ascii string:
::  
::  00
::  30
::  AC

One way of doing it is:

    $_ = "0000_0000_0011_0000_1010_1100";
    y/_//d;   # Delete all underscores.
    printf "%02x\n" => oct "0b$_" for /.{8}/g'

The last line should be explained right to left.
The regex is list context is going to split the string consisting
of 0's and 1's into groups of eight characters. Each group is
forces to be interpreted as a binary number, and then printed
as a hex number.



Abigail
-- 
map{${+chr}=chr}map{$_=>$_^ord$"}$=+$]..3*$=/2;        
print "$J$u$s$t $a$n$o$t$h$e$r $P$e$r$l $H$a$c$k$e$r\n";


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

Date: Tue, 27 May 2003 05:08:49 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Display form data in a html format.
Message-Id: <Xns93883E5325380sdn.comcast@216.166.71.239>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

techadmin@shaw.ca (Steve) wrote in news:2e27f51a.0305261950.1b083a87
@posting.google.com:

> I have a web page, an html form, which when I receive in my e-mail
> client is all text, in fact all the fileds are displyed not just the
> ones filled. I would like to have the entire html page sent through
> the email so when printed it will look exactly like the page that was
> filled out. The forms, when first created worked perfectly, now that
> we are using them and had to make a few changes, moved the filed from
> a UNIX server to NT server, they do not e-mail the same way. I
> remember the person who created tham saying that all they had to was "
> encase them in 'Brackets'or 'Parenthases' or something of that nature
> alhtough I am not sure what to put in brackets? I manot sure if they
> meant the code in the forms.pl file or the code in the html file. can
> anyone help.
> 
> Can anyome help

Perhaps you should ask in an HTML or email newsgroup.  I don't see anything 
applicable to Perl above.

- -- 
Eric
$_ =  reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBPtM45mPeouIeTNHoEQK9NQCdHRiIN5tQDLSSMQr4uzwxBtRSLNcAoNXc
kS+u7dZlw9+e0eMQC9zE1CGB
=VHnB
-----END PGP SIGNATURE-----


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

Date: Tue, 27 May 2003 20:22:01 +1000
From: "Ron Savage" <ron@savage.net.au>
Subject: Re: drop down selection from flatfile
Message-Id: <bave6q$2cja$1@arachne.labyrinth.net.au>

Hi Peter

See below.

"Bob Walton" <bwalton@rochester.rr.com> wrote in message
news:3ED28DCD.9090108@rochester.rr.com...
> Peter Feldmann wrote:

[snip]

> Well, first of all, when writing a CGI program, you should:
>
>     use CGI;

Beside Bob's fine advice, why don't you put your strings into a database
table, and use a module like DBIx::HTML::PopupRadio to convert the table
into either a Popup menu or a Radio button set?

CPAN is your friend. If you can't find an appropriate module here:
http://search.cpan.org/
or
http://theoryx5.uwinnipeg.ca/mod_perl/cpan-search?request=search
then, as a last resport, try
http://savage.net.au/Perl-modules.html




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

Date: Tue, 27 May 2003 20:10:59 +1000
From: "Ron Savage" <ron@savage.net.au>
Subject: Re: html tables
Message-Id: <bavdi5$2c6d$1@arachne.labyrinth.net.au>

Hi Matija

See below.

"Matija Papec" <mpapec@yahoo.com> wrote in message
news:4ti1dvs7nor9ktcsrd3sgh6r1ftsnmv695@4ax.com...
> X-Ftn-To: Andras Malatinszky
>
> Andras Malatinszky <nobody@dev.null> wrote:
> >>     $1 =~ /$filter/ ? '' : $1;
> >>   }iges;
> >>
> >> Is there more efficiant way to do the same thing and using perl
only?(don't
> >> like idea of capturing $1 and doing substitution with same content)
> >
> >
> >Would
> >
> >$simpletable=~s[<tr.+?$filter.+?</tr>][]iges;
> >
> >work?
>
> Not quite; it would always start matching from first '<tr' in
$simpletable.
>
> >There are modules on CPAN for parsing HTML, and I've often seen the
> >advice here to use those modules rather than roll your own.
>
> I'm not in position to use additional modules, but I'll take a look at
CPAN.
> Do you have some favorite module?
>
>
> -- 
> Matija




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

Date: Tue, 27 May 2003 20:14:24 +1000
From: "Ron Savage" <ron@savage.net.au>
Subject: Re: html tables
Message-Id: <bavdoi$2cag$1@arachne.labyrinth.net.au>

Hi Matija

Ignore previous post - that was just Outlook Express and its
auto-post-before-I-finished-typing option :-(.

See below.

"Matija Papec" <mpapec@yahoo.com> wrote in message
news:4ti1dvs7nor9ktcsrd3sgh6r1ftsnmv695@4ax.com...
> X-Ftn-To: Andras Malatinszky
>
> Andras Malatinszky <nobody@dev.null> wrote:
> >>     $1 =~ /$filter/ ? '' : $1;
> >>   }iges;
> >>
> >> Is there more efficiant way to do the same thing and using perl
only?(don't
> >> like idea of capturing $1 and doing substitution with same content)
> >
> >
> >Would
> >
> >$simpletable=~s[<tr.+?$filter.+?</tr>][]iges;
> >
> >work?
>
> Not quite; it would always start matching from first '<tr' in
$simpletable.
>
> >There are modules on CPAN for parsing HTML, and I've often seen the
> >advice here to use those modules rather than roll your own.
>
> I'm not in position to use additional modules, but I'll take a look at
CPAN.
> Do you have some favorite module?

HTML::TreeBuilder is a fine module.

Tested data and code:
-----><8-----
<html>
 <head>
  <title>Tutorial for HTML::TreeBuilder</title>
 </head>
 <body>
  <h1 align = 'center'>Tutorial for HTML::TreeBuilder</h1>

  <table align = 'center' border = '1'>
   <tr>
    <th>Outer table has 1 row with 2 columns</th>
    <td>
     <table border = '1'>
      <tr>
       <th colspan = '2'>Inner table has 3 rows with 2 columns</th>
      </tr>
      <tr>
       <th>Row Two/Column One</th><td>Row Two/Column Two</td>
      </tr>
      <tr>
       <th>Row Three/Column One</th><td>Row Three/Column Two</td>
      </tr>
     </table>
    </td>
   </tr>
  </table>
 </body>
</html>
-----><8-----

-----><8-----
#!/usr/bin/perl
#
# Name:
# test-html-treebuilder.pl.
#
# Author:
# Ron Savage
# http://savage.net.au/index.html.

use strict;
use warnings;

use HTML::TreeBuilder;

# -----------------------------------------------

sub find_nested_content
{
 my($root) = @_;

 print "Looking for nested content. \n";
 print "\n";

 my($first_tr, $last_tr);

 for ($root -> look_down(
 sub
 {
  # Find the 1st & last <tr>s, so we can report them.

  return 0 if ($_[0] -> tag() ne 'tr');

  (! $first_tr) && ($first_tr = $_[0]);

  $last_tr = $_[0];

  return 0;
 }))
 {
 }

 print "Text of 1st tr in nested table:  ", $first_tr -> as_text(), ". \n"
if ($first_tr);
 print "\n";
 print "Text of last tr in nested table: ", $last_tr -> as_text(), ". \n" if
($last_tr);
 print "\n";

} # End of find_nested_content.

# -----------------------------------------------

sub find_nested_table
{
 my($root) = @_;

 print "Looking for nested table. \n";
 print "\n";

 # Find the 1st <table>, because I know it contains a <td>.

 my($nested_table);

 $root -> look_down(_tag => 'table',
 sub
 {
  # Find the 1st <td>, because I know it contains the nested <table>.

  $nested_table = $_[0] -> look_down(_tag => 'td',
  sub
  {
   # Find the nested <table>.

   return $_[0] -> look_down(_tag => 'table');
  });

  return $nested_table;
 });

 if ($nested_table)
 {
  print "Found nested table. \n";
 }
 else
 {
  print "Did not find nested table. \n";
 }

 print "\n";

 $nested_table;

} # End of find_nested_table.

# -----------------------------------------------

my($file_name) = '/temp/test-html-treebuilder.html';
my($root)  = HTML::TreeBuilder -> new();

$root -> parse_file($file_name) || die("Can't parse $file_name");

my($nested_table) = find_nested_table($root);

find_nested_content($nested_table) if ($nested_table);

$root -> delete();
-----><8-----




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

Date: Fri, 23 May 2003 10:51:00 +0100
From: news@roaima.freeserve.co.uk
Subject: Re: Net::AIM help!
Message-Id: <a2mbq-v2f.ln1@moldev.cmagroup.co.uk>

In comp.lang.perl.misc Richard Mahoney <rm.mymail@nospamherentlworld.com> wrote:
> I'm having trouble sending an instant message with the Perl module Net::AIM.
> I can connect to the service but it will not send a message???

>   use Net::AIM;
>   $aim = new Net::AIM;
>   $conn = $aim->newconn(Screenname   => 'AIMScreenname',
>                         Password     => 'Password');
>   $aim->start; // Connects fine

Now put this in here:
	warn "Started AIM loop; ready to send\n";

>   $aim->send_im('AnotherScreenname', 'Message'); // Doesn't work??

And put this in here:
	warn "Sent message\n";
	sleep 5;


You'll see from this that the documentation is correct: aim->start starts
an (almost) *infinite* loop of do_one_loop(). I'm not entirely sure
why you'd want to use this method (perhaps it's a thread-safe loop?),
but I'm pretty certain it's not what you want.

Try this instead:
	$aim = new Net::AIM;
	$conn = $aim->newconn (...);

	foreach my $i (0..14) {	# Empirical 15s delay
	    $aim->do_one_loop || last;
	    sleep 1;
	}

	$aim->send_im (...);
	sleep 2;
		
		

Regards,
Chris
-- 
@s=split(//,"Je,\nhn ersloak rcet thuarP");$k=$l=@s;for(;$k;$k--){$i=($i+1)%$l
until$s[$i];$c=$s[$i];print$c;undef$s[$i];$i=($i+(ord$c))%$l}


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

Date: Tue, 27 May 2003 02:24:56 -0500
From: tadmc@augustmail.com
Subject: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.4 $)
Message-Id: <v4mdnQ8PqKJVj06jXTWcpQ@august.net>

Outline
   Before posting to comp.lang.perl.misc
      Must
       - Check the Perl Frequently Asked Questions (FAQ)
       - Check the other standard Perl docs (*.pod)
      Really Really Should
       - Lurk for a while before posting
       - Search a Usenet archive
      If You Like
       - Check Other Resources
   Posting to comp.lang.perl.misc
      Is there a better place to ask your question?
       - Question should be about Perl, not about the application area
      How to participate (post) in the clpmisc community
       - Carefully choose the contents of your Subject header
       - Use an effective followup style
       - Speak Perl rather than English, when possible
       - Ask perl to help you
       - Do not re-type Perl code
       - Provide enough information
       - Do not provide too much information
       - Do not post binaries, HTML, or MIME
      Social faux pas to avoid
       - Asking a Frequently Asked Question
       - Asking a question easily answered by a cursory doc search
       - Asking for emailed answers
       - Beware of saying "doesn't work"
       - Sending a "stealth" Cc copy
      Be extra cautious when you get upset
       - Count to ten before composing a followup when you are upset
       - Count to ten after composing and before posting when you are upset
-----------------------------------------------------------------

Posting Guidelines for comp.lang.perl.misc ($Revision: 1.4 $)
    This newsgroup, commonly called clpmisc, is a technical newsgroup
    intended to be used for discussion of Perl related issues (except job
    postings), whether it be comments or questions.

    As you would expect, clpmisc discussions are usually very technical in
    nature and there are conventions for conduct in technical newsgroups
    going somewhat beyond those in non-technical newsgroups.

    This article describes things that you should, and should not, do to
    increase your chances of getting an answer to your Perl question. It is
    available in POD, HTML and plain text formats at:

     http://mail.augustmail.com/~tadmc/clpmisc.shtml

    For more information about netiquette in general, see the "Netiquette
    Guidelines" at:

     http://andrew2.andrew.cmu.edu/rfc/rfc1855.html

    A note to newsgroup "regulars":

       Do not use these guidelines as a "license to flame" or other
       meanness. It is possible that a poster is unaware of things
       discussed here.  Give them the benefit of the doubt, and just
       help them learn how to post, rather than assume 

    A note about technical terms used here:

       In this document, we use words like "must" and "should" as
       they're used in technical conversation (such as you will
       encounter in this newsgroup). When we say that you *must* do
       something, we mean that if you don't do that something, then
       it's unlikely that you will benefit much from this group.
       We're not bossing you around; we're making the point without
       lots of words.

    Do *NOT* send email to the maintainer of these guidelines. It will be
    discarded unread. The guidelines belong to the newsgroup so all
    discussion should appear in the newsgroup. I am just the secretary that
    writes down the consensus of the group.

Before posting to comp.lang.perl.misc
  Must
    This section describes things that you *must* do before posting to
    clpmisc, in order to maximize your chances of getting meaningful replies
    to your inquiry and to avoid getting flamed for being lazy and trying to
    have others do your work.

    The perl distribution includes documentation that is copied to your hard
    drive when you install perl. Also installed is a program for looking
    things up in that (and other) documentation named 'perldoc'.

    You should either find out where the docs got installed on your system,
    or use perldoc to find them for you. Type "perldoc perldoc" to learn how
    to use perldoc itself. Type "perldoc perl" to start reading Perl's
    standard documentation.

    Check the Perl Frequently Asked Questions (FAQ)
        Checking the FAQ before posting is required in Big 8 newsgroups in
        general, there is nothing clpmisc-specific about this requirement.
        You are expected to do this in nearly all newsgroups.

        You can use the "-q" switch with perldoc to do a word search of the
        questions in the Perl FAQs.

    Check the other standard Perl docs (*.pod)
        The perl distribution comes with much more documentation than is
        available for most other newsgroups, so in clpmisc you should also
        see if you can find an answer in the other (non-FAQ) standard docs
        before posting.

    It is *not* required, or even expected, that you actually *read* all of
    Perl's standard docs, only that you spend a few minutes searching them
    before posting.

    Try doing a word-search in the standard docs for some words/phrases
    taken from your problem statement or from your very carefully worded
    "Subject:" header.

  Really Really Should
    This section describes things that you *really should* do before posting
    to clpmisc.

    Lurk for a while before posting
        This is very important and expected in all newsgroups. Lurking means
        to monitor a newsgroup for a period to become familiar with local
        customs. Each newsgroup has specific customs and rituals. Knowing
        these before you participate will help avoid embarrassing social
        situations. Consider yourself to be a foreigner at first!

    Search a Usenet archive
        There are tens of thousands of Perl programmers. It is very likely
        that your question has already been asked (and answered). See if you
        can find where it has already been answered.

        One such searchable archive is:

         http://groups.google.com/advanced_group_search

  If You Like
    This section describes things that you *can* do before posting to
    clpmisc.

    Check Other Resources
        You may want to check in books or on web sites to see if you can
        find the answer to your question.

        But you need to consider the source of such information: there are a
        lot of very poor Perl books and web sites, and several good ones
        too, of course.

Posting to comp.lang.perl.misc
    There can be 200 messages in clpmisc in a single day. Nobody is going to
    read every article. They must decide somehow which articles they are
    going to read, and which they will skip.

    Your post is in competition with 199 other posts. You need to "win"
    before a person who can help you will even read your question.

    These sections describe how you can help keep your article from being
    one of the "skipped" ones.

  Is there a better place to ask your question?
    Question should be about Perl, not about the application area
        It can be difficult to separate out where your problem really is,
        but you should make a conscious effort to post to the most
        applicable newsgroup. That is, after all, where you are the most
        likely to find the people who know how to answer your question.

        Being able to "partition" a problem is an essential skill for
        effectively troubleshooting programming problems. If you don't get
        that right, you end up looking for answers in the wrong places.

        It should be understood that you may not know that the root of your
        problem is not Perl-related (the two most frequent ones are CGI and
        Operating System related), so off-topic postings will happen from
        time to time. Be gracious when someone helps you find a better place
        to ask your question by pointing you to a more applicable newsgroup.

  How to participate (post) in the clpmisc community
    Carefully choose the contents of your Subject header
        You have 40 precious characters of Subject to win out and be one of
        the posts that gets read. Don't waste them. Take care while
        composing them, they are the key that opens the door to getting an
        answer.

        Spend them indicating what aspect of Perl others will find if they
        should decide to read your article.

        Do not spend them indicating "experience level" (guru, newbie...).

        Do not spend them pleading (please read, urgent, help!...).

        Do not spend them on non-Subjects (Perl question, one-word
        Subject...)

        For more information on choosing a Subject see "Choosing Good
        Subject Lines":

         http://www.cpan.org/authors/id/D/DM/DMR/subjects.post

        Part of the beauty of newsgroup dynamics, is that you can contribute
        to the community with your very first post! If your choice of
        Subject leads a fellow Perler to find the thread you are starting,
        then even asking a question helps us all.

    Use an effective followup style
        When composing a followup, quote only enough text to establish the
        context for the comments that you will add. Always indicate who
        wrote the quoted material. Never quote an entire article. Never
        quote a .signature (unless that is what you are commenting on).

        Intersperse your comments *following* each section of quoted text to
        which they relate. Unappreciated followup styles are referred to as
        "Jeopardy" (because the answer comes before the question), or
        "TOFU".

        Reversing the chronology of the dialog makes it much harder to
        understand (some folks won't even read it if written in that style).
        For more information on quoting style, see:

         http://web.presby.edu/~nnqadmin/nnq/nquote.html

    Speak Perl rather than English, when possible
        Perl is much more precise than natural language. Saying it in Perl
        instead will avoid misunderstanding your question or problem.

        Do not say: I have variable with "foo\tbar" in it.

        Instead say: I have $var = "foo\tbar", or I have $var = 'foo\tbar',
        or I have $var = <DATA> (and show the data line).

    Ask perl to help you
        You can ask perl itself to help you find common programming mistakes
        by doing two things: enable warnings (perldoc warnings) and enable
        "strict"ures (perldoc strict).

        You should not bother the hundreds/thousands of readers of the
        newsgroup without first seeing if a machine can help you find your
        problem. It is demeaning to be asked to do the work of a machine. It
        will annoy the readers of your article.

        You can look up any of the messages that perl might issue to find
        out what the message means and how to resolve the potential mistake
        (perldoc perldiag). If you would like perl to look them up for you,
        you can put "use diagnostics;" near the top of your program.

    Do not re-type Perl code
        Use copy/paste or your editor's "import" function rather than
        attempting to type in your code. If you make a typo you will get
        followups about your typos instead of about the question you are
        trying to get answered.

    Provide enough information
        If you do the things in this item, you will have an Extremely Good
        chance of getting people to try and help you with your problem!
        These features are a really big bonus toward your question winning
        out over all of the other posts that you are competing with.

        First make a short (less than 20-30 lines) and *complete* program
        that illustrates the problem you are having. People should be able
        to run your program by copy/pasting the code from your article. (You
        will find that doing this step very often reveals your problem
        directly. Leading to an answer much more quickly and reliably than
        posting to Usenet.)

        Describe *precisely* the input to your program. Also provide example
        input data for your program. If you need to show file input, use the
        __DATA__ token (perldata.pod) to provide the file contents inside of
        your Perl program.

        Show the output (including the verbatim text of any messages) of
        your program.

        Describe how you want the output to be different from what you are
        getting.

        If you have no idea at all of how to code up your situation, be sure
        to at least describe the 2 things that you *do* know: input and
        desired output.

    Do not provide too much information
        Do not just post your entire program for debugging. Most especially
        do not post someone *else's* entire program.

    Do not post binaries, HTML, or MIME
        clpmisc is a text only newsgroup. If you have images or binaries
        that explain your question, put them in a publically accessible
        place (like a Web server) and provide a pointer to that location. If
        you include code, cut and paste it directly in the message body.
        Don't attach anything to the message. Don't post vcards or HTML.
        Many people (and even some Usenet servers) will automatically filter
        out such messages. Many people will not be able to easily read your
        post. Plain text is something everyone can read.

  Social faux pas to avoid
    The first two below are symptoms of lots of FAQ asking here in clpmisc.
    It happens so often that folks will assume that it is happening yet
    again. If you have looked but not found, or found but didn't understand
    the docs, say so in your article.

    Asking a Frequently Asked Question
        It should be understood that you may have missed the applicable FAQ
        when you checked, which is not a big deal. But if the Frequently
        Asked Question is worded similar to your question, folks will assume
        that you did not look at all. Don't become indignant at pointers to
        the FAQ, particularly if it solves your problem.

    Asking a question easily answered by a cursory doc search
        If folks think you have not even tried the obvious step of reading
        the docs applicable to your problem, they are likely to become
        annoyed.

        If you are flamed for not checking when you *did* check, then just
        shrug it off (and take the answer that you got).

    Asking for emailed answers
        Emailed answers benefit one person. Posted answers benefit the
        entire community. If folks can take the time to answer your
        question, then you can take the time to go get the answer in the
        same place where you asked the question.

        It is OK to ask for a *copy* of the answer to be emailed, but many
        will ignore such requests anyway. If you munge your address, you
        should never expect (or ask) to get email in response to a Usenet
        post.

        Ask the question here, get the answer here (maybe).

    Beware of saying "doesn't work"
        This is a "red flag" phrase. If you find yourself writing that,
        pause and see if you can't describe what is not working without
        saying "doesn't work". That is, describe how it is not what you
        want.

    Sending a "stealth" Cc copy
        A "stealth Cc" is when you both email and post a reply without
        indicating *in the body* that you are doing so.

  Be extra cautious when you get upset
    Count to ten before composing a followup when you are upset
        This is recommended in all Usenet newsgroups. Here in clpmisc, most
        flaming sub-threads are not about any feature of Perl at all! They
        are most often for what was seen as a breach of netiquette. If you
        have lurked for a bit, then you will know what is expected and won't
        make such posts in the first place.

        But if you get upset, wait a while before writing your followup. I
        recommend waiting at least 30 minutes.

    Count to ten after composing and before posting when you are upset
        After you have written your followup, wait *another* 30 minutes
        before committing yourself by posting it. You cannot take it back
        once it has been said.

AUTHOR
    Tad McClellan <tadmc@augustmail.com> and many others on the
    comp.lang.perl.misc newsgroup.



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

Date: 27 May 2003 02:57:52 -0700
From: jill.tayamen@onsemi.com (fernjilly)
Subject: Reading Function Keys in a GUI Loft  window
Message-Id: <e618034e.0305270157.527e36c5@posting.google.com>

I have a UI created in GUI Loft which is design to provide inputs to 
a tester machine. My UI communicates with the tester machine thru its 
own program (a dos shell)thru Piping. One functionality of the Dos 
shell is being able to use the function keys. I have no problem in 
passing the value of the function key to the dos shell when imbedded 
in a button. Now I would like to read the keyboard stroke instead of 
the button being pressed. So for example my user would press F1 from 
the keyboard within the UI, it will be able to recognize that F1 was 
pressed. Thanks in advance!


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

Date: 27 May 2003 02:16:58 -0700
From: fatted@yahoo.com (fatted)
Subject: scope of variable
Message-Id: <4eb7646d.0305270116.665b04ab@posting.google.com>

Consider code:

use warnings;
use strict;

open(OUT,'>>','program.log');

while(1)
{
        sleep(3);
        print OUT "Hello\n";
}

With the strict pragma, the filehandle OUT is not available in the
while block, but opening a filehandle in the while loop, will result
in a call to open every 3 seconds. Any idea's? I thought I might be
able to globally define the file handle using:

our *OUT; 

before the open call, but the compiler didn't like that :)


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

Date: Tue, 27 May 2003 09:22:53 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: scope of variable
Message-Id: <Xns938873665DB6Aelhber1lidotechnet@62.89.127.66>

fatted wrote:

> Consider code:
> 
> use warnings;
> use strict;
> 
> open(OUT,'>>','program.log');


You should always make sure open() was successful:


open (OUT, '>> program.log') or die $!;


> while(1)
> {
>         sleep(3);
>         print OUT "Hello\n";
> }
> 
> With the strict pragma, the filehandle OUT is not available in the
> while block


You must be doing something else wrong, because the code above does exactly 
what you want.


-- 
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'



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

Date: Tue, 27 May 2003 04:58:12 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: scope of variable
Message-Id: <Xns93883C864B86Dsdn.comcast@216.166.71.239>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

fatted@yahoo.com (fatted) wrote in 
news:4eb7646d.0305270116.665b04ab@posting.google.com:

> Consider code:
> 
> use warnings;
> use strict;
> 
> open(OUT,'>>','program.log');
> 
> while(1)
> {
>         sleep(3);
>         print OUT "Hello\n";
> }
> 
> With the strict pragma, the filehandle OUT is not available in the
> while block,

Sure it is.


> but opening a filehandle in the while loop, will result
> in a call to open every 3 seconds. Any idea's? I thought I might be
> able to globally define the file handle using:
> 
> our *OUT; 
> 
> before the open call, but the compiler didn't like that :)

You could do

    local *OUT;

 ...but your problem is elsewhere.

- -- 
Eric
$_ =  reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBPtM2aWPeouIeTNHoEQKXxACg38oYlNAcru4rXogpuqEx+8P4Q+IAoKn3
wrbDWiic4NqNPx09AyseS2F+
=uWDz
-----END PGP SIGNATURE-----


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

Date: 27 May 2003 12:10:49 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: scope of variable
Message-Id: <slrnbd6le9.co.abigail@alexandra.abigail.nl>

fatted (fatted@yahoo.com) wrote on MMMDLVI September MCMXCIII in
<URL:news:4eb7646d.0305270116.665b04ab@posting.google.com>:
//  Consider code:
//  
//  use warnings;
//  use strict;
//  
//  open(OUT,'>>','program.log');
//  
//  while(1)
//  {
//          sleep(3);
//          print OUT "Hello\n";
//  }
//  
//  With the strict pragma, the filehandle OUT is not available in the
//  while block,

Please show us the compile time error you are getting, because it
seems you have stumbled upon a bug in Perl.


Abigail
-- 
$_ = "\x3C\x3C\x45\x4F\x54" and s/<<EOT/<<EOT/e and print;
Just another Perl Hacker
EOT


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

Date: Tue, 27 May 2003 10:31:51 +0200
From: Daniel Pfeiffer <occitan@esperanto.org>
To: perlbug@perl.org
Subject: shellwords.pl is not Shell compatible
Message-Id: <20030527103151.31905ebd.occitan@esperanto.org>

Hi,

Perl still contains a Perl 4 library, that purports to emulate the way the =
Shell parses a command.  But it can't handle backquotes or variable interpo=
lation.  And it gets backslash wrong.

Perl make <http://dapfy.bei.t-online.de/make.pl/> now contains a similar fu=
nction shellparse, which corrects these bugs.  Welcome to use it as you ple=
ase, if you give me the credit.

coralament / best Gr=F6tens / liebe Gr=FC=DFe / best regards / elkorajn sal=
utojn
Daniel Pfeiffer

-- GPL 3: take the wind out of Palladium's sails! --
 ------
  -- My other stuff here too, sawfish, make.pl...: --
   ------
    -- http://dapfy.bei.t-online.de/ --


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

Date: Tue, 27 May 2003 11:07:25 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Sorting hash
Message-Id: <bavafl$3tkgm$1@ID-184292.news.dfncis.de>

I'm sorting the keys of a hash by (part of) the hash values like this:

     @sortedkeys = sort {
         ($hash{$b} =~ /^([\d.-]+)\|/)[0]
                        <=>
         ($hash{$a} =~ /^([\d.-]+)\|/)[0]
     } keys %hash;

The portion of a hash value before the '|' character is a floating 
number that may be negative.

This is about what happens if two values would be identical. Basically 
I don't care in _which_ order the corresponding keys are stored in the 
array, but the sort will be done many times, and I want the keys to be 
stored in _the same_ order each time as long as the hash isn't changed.

My question is: Can I trust that the keys will appear in @sortedkeys 
in _the same_ order, even if there would be occurrences of identical 
hash values, or do I need to add another sort criterion to be sure?

/ Gunnar

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



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

Date: 27 May 2003 11:56:21 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Sorting hash
Message-Id: <bavjp5$a91$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Gunnar Hjalmarsson:

> I'm sorting the keys of a hash by (part of) the hash values like this:
> 
>      @sortedkeys = sort {
>          ($hash{$b} =~ /^([\d.-]+)\|/)[0]
>                         <=>
>          ($hash{$a} =~ /^([\d.-]+)\|/)[0]
>      } keys %hash;
> 
> The portion of a hash value before the '|' character is a floating 
> number that may be negative.
> 
> This is about what happens if two values would be identical. Basically 
> I don't care in _which_ order the corresponding keys are stored in the 
> array, but the sort will be done many times, and I want the keys to be 
> stored in _the same_ order each time as long as the hash isn't changed.
> 
> My question is: Can I trust that the keys will appear in @sortedkeys 
> in _the same_ order, even if there would be occurrences of identical 
> hash values, or do I need to add another sort criterion to be sure?

If I understand you correctly, you want a stable sort-algorithm. With
Perl5.8.0 you can explicitely say

    use sort 'stable';  # currently the same as '_mergesort'

The sort() of older perls is an unstable quicksort. Not sure which sort
method is the default for 5.8.0. But for this version you can always
explicitely specify which you want.

Also see 'perldoc sort' (without the -f).

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Tue, 27 May 2003 11:09:49 GMT
From: Tweetie Pooh <tp601553@cia.gov>
Subject: Re: Spawning self - a better way?
Message-Id: <Xns93887BBCBEFBTweetiePooh@62.253.162.105>

efflandt@xnet.com (David Efflandt) honoured comp.lang.perl.misc on Fri 23 May 
2003 10:47:44p with news:slrnbct5o0.gkq.efflandt@typhoon.xnet.com:

> See 'perldoc perlipc' which has examples of client/server scripts 
> including servers that spawn a child to handle each connection, then the 
> parent immediately goes back to waiting for the next new connection. 

Reading this now.  Used the camel, advanced perl and perl cookbook for my 
code help.  I got the parent to start the kiddies but had problems when a 
child died.  A reaper script would close the zombie child but not then return 
to the parent loop.  No reaper would leave zombies floating around.

 
> Although, it sounds like you want a parent client that forks a child 
> client for each of a list of connections.  There is no reason I can think 
> of to use system() for that.
> 
That's what I want.  Due to connection problems coming in I now want a parent 
that will spawn a kiddie to connect to the remote system and process data.  
The kiddie should be "self sufficient" ie once started it will keep itself 
going.  The parent literally is there just to start off the kiddies.  The 
kiddies all output to the same local port where another program awaits.

> There is also an example of forking and daemonizing a child (disassociated
> it from its parent) so it can go off and do its own thing.  I use that for
> a Perl daemon that forks into the background and uses LWP to monitor the
> dynamic WAN IP of my router (and reports to syslogd to log occasional
> status or if anything changes, along with updating DNS).  Although, I only
> do it for a single process, it could just as easily be done for a list of
> children.
> 

Will play with that today.

Ta for your help


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

Date: 27 May 2003 12:48:21 GMT
From: gilgames@aol.coma (Gilgames)
Subject: Re: sprintf question
Message-Id: <20030527084821.08559.00000326@mb-m24.aol.com>

I always use the foolproof

 $form = "%0" . $DIGITS" . "d";
 sprintf($form,$number_unpadded);

<<

i have numbers and want to pad them with a given number
of leading zeros instead of whitespaces. but i don't want to
hardcode them so the number is given by a variable:

my $number_padded = sprintf "%0$DIGIGSd", $number_unpadded;

but perl complains about undefined $DIGITSd so i tried
some things and got it working with "%0DIGITS\d". but
this isnt really correct i think (httpd gives some warnings
about unrecognized escapes '\d')

so can you plz help me out...

 ...rene
>>


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

Date: 27 May 2003 02:59:10 -0700
From: ver_for@yahoo.it (Marco)
Subject: string search problem
Message-Id: <da63f24c.0305270159.18aece5d@posting.google.com>

Hi,

I have a script that search some certain keywords in a file.
The test to know if the keyword is present is the following one:

if ($ligne=~ m/$keyword/gsi & $keyword_dans_ce_fichier==0)

With this, if one of the keywords is "tur". The answer will positive
if the word "turnover" is present in the file.

How can I modify it in order to detect only the words that fits
completely with the keywords

Thanks for your answers

Marco


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

Date: Tue, 27 May 2003 11:28:29 +0100
From: "Allanon" <allanon@hotmail.com>
Subject: Re: string search problem
Message-Id: <bavekh$175i@newton.cc.rl.ac.uk>


"Marco" <ver_for@yahoo.it> wrote in message
news:da63f24c.0305270159.18aece5d@posting.google.com...
> Hi,
>
> I have a script that search some certain keywords in a file.
> The test to know if the keyword is present is the following one:
>
> if ($ligne=~ m/$keyword/gsi & $keyword_dans_ce_fichier==0)
>
> With this, if one of the keywords is "tur". The answer will positive
> if the word "turnover" is present in the file.

if ($ligne=~ m/\b$keyword\b/gsi & $keyword_dans_ce_fichier==0)

Allanon




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

Date: 27 May 2003 12:56:36 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: string search problem
Message-Id: <bavna4$9hs$3@mamenchi.zrz.TU-Berlin.DE>

Allanon <allanon@hotmail.com> wrote in comp.lang.perl.misc:
> 
> "Marco" <ver_for@yahoo.it> wrote in message
> news:da63f24c.0305270159.18aece5d@posting.google.com...
> > Hi,
> >
> > I have a script that search some certain keywords in a file.
> > The test to know if the keyword is present is the following one:
> >
> > if ($ligne=~ m/$keyword/gsi & $keyword_dans_ce_fichier==0)
> >
> > With this, if one of the keywords is "tur". The answer will positive
> > if the word "turnover" is present in the file.
> 
> if ($ligne=~ m/\b$keyword\b/gsi & $keyword_dans_ce_fichier==0)
                                  ^
The "&" operation performs a bit-wise logical and of its arguments.  Ii
think you (and the OP) want "&&".

Anno



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

Date: 27 May 2003 03:20:08 -0700
From: andreaspfaff@hotmail.com (andipfaff)
Subject: turning off output buffer does not work
Message-Id: <e4d62a06.0305270220.6db68b2e@posting.google.com>

Hi there

I have writen a small script to test my homepage. Therefore I tried to
turn off output buffering, but that does not work as described on
various websites:

#!/usr/bin/perl
# Turn all buffering off.
$| = 0;
print "Content-type: text/html\n\n";
print "One<br>";
sleep(3);
print "Two";

After three seconds I will get the entire website. I have tried
different methods like:
$| = 0;
select((select(STDOUT), $| = 1)[0]);
but none of them worked! I sthat because I have a Windows-Environment?
ActivState Perl and IIS?

thanks in advance
Andi


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

Date: Tue, 27 May 2003 13:12:31 +0100
From: Stephen Hildrey <steve@uptime.orgNo.ukSpam>
Subject: Re: turning off output buffer does not work
Message-Id: <1054037551.48507.0@dyke.uk.clara.net>

In article <e4d62a06.0305270220.6db68b2e@posting.google.com>, andipfaff wrote:
> Hi there
> 
> I have writen a small script to test my homepage. Therefore I tried to
> turn off output buffering, but that does not work as described on
> various websites:
> 
> #!/usr/bin/perl
> # Turn all buffering off.
> $| = 0;

$| should not be thought of as 'buffering', it should be thought of as
'auto flush'.  If $| is set to zero, buffering is *on*; if it is
non-zero, a flush is forced immediately after every write to the
currently selected output channel - i.e. buffering is *off*.

See perlvar.

So, rather than $| = 0, you could just use $| = 1.

Regards,
Steve


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

Date: 27 May 2003 12:25:56 GMT
From: Tina Mueller <see_signature.usenet@tinita.de>
Subject: Re: turning off output buffer does not work
Message-Id: <bavlgk$46sb4$1@ID-24002.news.dfncis.de>

andipfaff wrote:

> #!/usr/bin/perl
> # Turn all buffering off.
> $| = 0;

have you tried "$| = 1"?
additionally this depends (AFAIK) on the webserver; some
might buffer regardless of what perl does.

hth, tina
-- 
http://www.tinita.de/     \  enter__| |__the___ _ _ ___
     -- NOTE --            \     / _` / _ \/ _ \ '_(_-< of
I'm moving my domain, so    \    \ _,_\ __/\ __/_| /__/ perception
at the moment you can reach me at: tina {at} perlquotes . de


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

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


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