[28773] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 17 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 12 09:05:48 2007

Date: Fri, 12 Jan 2007 06:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 12 Jan 2007     Volume: 11 Number: 17

Today's topics:
        A question about socket programming <kevinmiter@gmail.com>
    Re: A question about socket programming <tfeserver@gmail.com>
    Re: array searching <jurgenex@hotmail.com>
    Re: DB_File tie error <paul.marquess@btinternet.com>
        link text in sendMail <jacqueline.penny@btopenworld.com>
    Re: Perl free e-books <moya0901@126.com>
    Re: Perl free e-books <moya0901@126.com>
        Posting Guidelines for comp.lang.perl.misc ($Revision:  tadmc@augustmail.com
        qr and subroutines <alt.testing@N0SP4M.gmail.com>
    Re: qr and subroutines <rs@474.at>
        This is strange!!! What happens in here??? <Remus.SEPP@t-mobile.co.uk>
    Re: This is strange!!! What happens in here??? anno4000@radom.zrz.tu-berlin.de
    Re: This is strange!!! What happens in here??? (hymie!)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 12 Jan 2007 05:49:47 -0800
From: "firenet" <kevinmiter@gmail.com>
Subject: A question about socket programming
Message-Id: <1168609787.738937.56110@l53g2000cwa.googlegroups.com>

My code is like this:

while( 1 )
{
    my $i = 0;
    my $buffer;
    my $from_who = recv( UDP_IN, $buffer, 10, 0 );
    if ( $from_who )
    {
        my ( $the_port, $the_ip ) = sockaddr_in( $from_who );
        warn 'Received from ', inet_ntoa( $the_ip ), ": $buffer\n";
        $i=$i+1;
        print $i."\n";
        $data=$data.$buffer;
    }
    else
    {
        warn "Problem with recv: $!\n";
    }
}

I supposed when i recv a package, $i can increase.But the output is
like this:
Received from 127.0.0.1: bsfsafsfsf
1
Received from 127.0.0.1: sfssfs:w
1
So we can find that the $i increase only one time,where may the problem
be?3ks



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

Date: 12 Jan 2007 06:04:27 -0800
From: "tfe" <tfeserver@gmail.com>
Subject: Re: A question about socket programming
Message-Id: <1168610667.291429.226030@q2g2000cwa.googlegroups.com>


firenet ha escrito:

> My code is like this:
>
> while( 1 )
> {
>     my $i = 0;
>     my $buffer;
>     my $from_who = recv( UDP_IN, $buffer, 10, 0 );
>     if ( $from_who )
>     {
>         my ( $the_port, $the_ip ) = sockaddr_in( $from_who );
>         warn 'Received from ', inet_ntoa( $the_ip ), ": $buffer\n";
>         $i=$i+1;
>         print $i."\n";
>         $data=$data.$buffer;
>     }
>     else
>     {
>         warn "Problem with recv: $!\n";
>     }
> }
>
> I supposed when i recv a package, $i can increase.But the output is
> like this:
> Received from 127.0.0.1: bsfsafsfsf
> 1
> Received from 127.0.0.1: sfssfs:w
> 1
> So we can find that the $i increase only one time,where may the problem
> be?3ks

the initialisation of $i is inside the loop. On each loop, $i will be
renewed.
Put the line my $i=1 before the while() if you want it to be increased.

-- 

tfe
http://tfeserver.be



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

Date: Fri, 12 Jan 2007 10:58:51 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: array searching
Message-Id: <LRJph.7263$GL.1425@trndny06>

jimcanon@gmail.com wrote:
> This is my first question. [...]

But it has been asked before.

> want to compare the numbers after : in @jn to the numbers after job in
> @job1 and @job2.
[...]
> I want to put what is missing in @jn compared to @job1 and @job2 in
> @jobMissing :
> I want to put what is missing in @job1 and @job2 compared to @jn in
> @jnMissing :

perldoc -q intersection:
  "How do I compute the difference of two arrays?  How do I compute the 
intersection of two arrays?"

jue 




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

Date: Fri, 12 Jan 2007 13:43:59 +0000
From: Paul Marquess <paul.marquess@btinternet.com>
Subject: Re: DB_File tie error
Message-Id: <45a7909f$0$22614$4d4eb98e@read.news.uk.uu.net>

Janna wrote:

> I copied my program to another file and drastically edited it to about
> 75 lines (from over 1000) that duplicate the problem.  I also added
> Xho's suggested warnings.  Here's the complete code now (sorry for the
> length):
> 
> #!/usr/bin/perl
> 
> use strict;
> use warnings;
> use Fcntl;
> use DB_File;
> 
> my $expweight = 0;      # Will hold the user's expression weight
> my $litweight=1;        # Will hold the user's literature (>1 hit)
> weight
> my $conweight=0;        # Will hold the user's conservation weight#
> 
> LIT BLOCK
> unless ($litweight == 0) {
> use strict;
> use warnings;
> 
> #Open the BTREE with the publications
> my $dbloc = '/data3/mcleod.3/aldi/janna/candid/BUILD2/humanpubs.db';
> $DB_BTREE->{'flags'} = R_DUP;
> my %pubhash;$DB_BTREE->{'flags'} = R_DUP;
> my $pubdb = tie %pubhash, "DB_File", $dbloc, O_RDWR|O_CREAT, 0640,
> $DB_BTREE or die "Cannot open $dbloc: $!\n";
> 
> #Open the BTREE with totalpubs
> my $totalloc = '/data3/mcleod.3/aldi/janna/candid/BUILD2/totalpubs.db';
> $DB_BTREE->{'flags'} = R_DUP;
> my %totalpubhash;
> my $totalpubdb = tie %totalpubhash, "DB_File", $totalloc,
> O_RDWR|O_CREAT, 0640, $DB_BTREE or die "Cannot open $totalloc: $!\n";
> 
> undef $pubdb;
> untie %pubhash;
> undef $totalpubdb;
> untie %totalpubhash;
> }
> 
> # CON BLOCK
> unless ($conweight == 0) {
> 
> #Load BTREE of Homologene data.
> my $dbloc = '/data3/mcleod.3/aldi/janna/candid/BUILD2/humanhomol.db';
> my %homolhash;
> my $homoldb = tie %homolhash, "DB_File", $dbloc, O_RDWR|O_CREAT, 0640,
> $DB_BTREE or die "Cannot open $dbloc: $!\n";
> 
> undef $homoldb;
> untie %homolhash;
> }
> 
> # EXP BLOCK
> unless ($expweight == 0) {
> 
> # Load exphash
> use strict;
> use warnings;
> my $dbloc = "/data3/mcleod.3/aldi/janna/candid/BUILD2/humanexp.db";
> my %exphash;
> my $expdb = tie %exphash, "DB_File", $dbloc, O_RDWR|O_CREAT, 0640,
> $DB_BTREE or do {
>          warn "-e ", -e $dbloc, " -f ", -f $dbloc;
>          warn "@{[stat $dbloc]}";
>          die "Cannot open this file $dbloc: $!\n";
>    };
> 
> undef $expdb;
> untie %exphash;
> } #unless
> 
> exit;
> 
> 
> As I said before, it requires $expweight AND $litweight to be nonzero
> in order to reproduce the error.  If $expweight is nonzero and
> $litweight and $conweight are both 0, the error does not occur.
> Likewise, if $litweight and $conweight are nonzero, but $expweight is
> 0, the error does not occur.
> 
> When I run the program as above ($expweight and $litweight = 1), this
> is what I get as the output:
> -e 1 -f 1 at ./gutless.pl line 704.
> 2067 7372805 33188 1 1067 1067 0 87662592 1168557177 1168538256
> 1168538256 4096 171392 at ./gutless.pl line 705.
> Cannot open this file
> /data3/mcleod.3/aldi/janna/candid/BUILD2/humanexp.db: No such file or
> directory

You sometimes set this before opening a database

    $DB_BTREE->{'flags'} = R_DUP;

The problem with that is $DB_BTREE is a global data structure, so once set
it will remain set till the program terminates or something else changes
it. You don't change it.

So if your LIT block sets it, it will still remain set when the CON block is
executed. But if the LIT block isn't executed, the CON block will be
executed without R_DUP. This is a bad idea. You should reset
$DB_BTREE->{'flags'} after each tie.

Paul


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

Date: 12 Jan 2007 05:43:26 -0800
From: "Jaks" <jacqueline.penny@btopenworld.com>
Subject: link text in sendMail
Message-Id: <1168609406.887676.33730@l53g2000cwa.googlegroups.com>

I have the following code in a sub sendMail

$link1 =
"mailto:jacqueline.penny@btopenworld.com?subject=Account&body=Please%20set%20my%20address%20to%20$address1";

$link2 =
"mailto:jacqueline.penny@btopenworld.com?subject=Account&body=Please%20set%20my%20address%20to%20$address2";

print MAIL "
I would like $link1 to be my primary address

I would like $link2to be my primary address";

close (MAIL);

In the generated email the following text is displayed

I would like
mailto:jacqueline.penny@btopenworld.com?subject=Account&body=Please%20set%20my%20address%20to%20Banbridge
to be my primary address.

How do I get the link text to be displayed as the address ie

I would like Banbridge to be my primary address.


Any help would be much appreciated.

JP



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

Date: Fri, 12 Jan 2007 20:22:08 +0800
From: "Shuo Shi" <moya0901@126.com>
Subject: Re: Perl free e-books
Message-Id: <eo7tq4$8ca$1@az33news01.freescale.net>

I just wanna make the format of my message as "Times New Roman", not the 
default format of Plain Text file.

-- 
Thanks & Regards,
Shuo
"John Bokma" <john@castleamber.com> wrote in message 
news:Xns98B697AC952Ecastleamber@130.133.1.4...
> "Shuo Shi" <moya0901@126.com> wrote:
>
>> Yes, it is
>
> Another top post. Please google for top post and learn why it's not a good
> way to reply.
>
>> just what I want to read the hard copies of books, so I
>> should buy the books from bookstore, however, I am in China, I cannot
>> find any good book about Perl,
>
> I have given you several tips on *free* documentation you can read. You're
> having a non-problem.
>
>> whatever is from bookstore or online
>> shop. Frankly speaking, Perl is not very popular and welcomed by
>> programmers in China, all books in bookstore's shelves are about C++,
>> Java, VB.net etc--- no good books are available to see. If you don't
>> believe it, you can come to China to see what happens to Perl here?
>
> I live in Mexico, and can't hardly read Spanish, so I understand that part
> of the story. I solved it by doing some Perl work in exchange for book(s)
> for people with a very small budget, TANSTAAFL, and it makes me happy. I
> got Higher Order Perl that way (which you can also download for free by
> the way).
>
>> So I need your help to get online free book which owns PDF format, and
>> then print it book.
>
> Like others said, the format doesn't matter, PDF, CHM, plain text.
> Perl comes with excellent documentation, you can download PDF versions
> from: http://perldoc.perl.org/perl.html Just pick what you want to learn.
>
> Or you can keep asking for a certain book from Wrox press. But I doubt
> anyone here is going to send it to you by email. In my opinion if you want
> to become a programmer you must be able to solve such a task yourself, or
> stand above it, and go with the standard documentation. I have read a few
> of those documents myself, and while they are together not an easy to read
> book (several authors, etc), the info is there, and more.
>
> -- 
> John                Experienced Perl programmer: http://castleamber.com/
>
>          Perl help, tutorials, and examples: http://johnbokma.com/perl/ 




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

Date: Fri, 12 Jan 2007 20:55:11 +0800
From: "Shuo Shi" <moya0901@126.com>
Subject: Re: Perl free e-books
Message-Id: <eo7vok$8s1$1@az33news01.freescale.net>

I can find this book, but it is not really free downloaded. You see the 
below content shown in learn.perl.org web page
=====================================================================================================
Beginning Perl
by Simon Cozens, Peter Wainwright. 700 pages. Wrox Press, Inc.. (May 25, 
2000).
Beginning Perl is a different kind of Perl book. It's written particularly 
with the beginning programmer in mind, but it doesn't treat you like an 
idiot, and experienced programmers will not feel patronised. It covers a lot 
of ground, from the very basics of programming, right through to developing 
CGI applications for the web. More importantly, it emphasises good Perl 
practice, and readable and maintainable code.
Buy from: Amazon - Powells - Amazon UK - Bookpool

====================================================================================================

"Uri Guttman" <uri@stemsystems.com> wrote in message 
news:x7zm8pzamj.fsf@mail.sysarch.com...
>>>>>> "SS" == Shuo Shi <moya0901@126.com> writes:
>
>  SS> John,It is very nice of you! I am moving by your
>  SS> kindness. However, I tried to look through the material from your
>  SS> below link, it is still not pdf format, and the pdf book which you
>  SS> refer to is not real what I want, my hope is that I could get a
>  SS> formal pdf book, just like <<Profssional Perl Programming >> which
>  SS> is from Wrox book concern ...... etc.  If you have, would you
>
> go to learn.perl.org and you will find the book beginning perl which is
> totally free, good quality and in pdf format. you can also print the
> perldocs in almost any format you want. look for pod to pdf conversion
> utilities if you must use that. but you can print the perldocs from man
> format, plain text, ps or others. so don't keep whining you must have
> pdf format if you are just going to print the docs. and the docs are
> your best resource for learning perl. there are over 1000 pages of them.
> don't print them all, look in the top level doc called just 'perl' and
> it lists them all by category.
>
> uri
>
> -- 
> Uri Guttman  ------  uri@stemsystems.com  --------  
> http://www.stemsystems.com
> --Perl Consulting, Stem Development, Systems Architecture, Design and 
> Coding-
> Search or Offer Perl Jobs  ----------------------------  
> http://jobs.perl.org 




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

Date: 12 Jan 2007 08:10:24 GMT
From: tadmc@augustmail.com
Subject: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.7 $)
Message-Id: <45a7426f$0$81351$ae4e5890@news.nationwide.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.7 $)
    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.

    The article at:

        http://www.catb.org/~esr/faqs/smart-questions.html

    describes how to get answers from technical people in general.

    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://www.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 that they do 
       know and are being the "bad kind" of Lazy.

    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
        "top-posting", "Jeopardy" (because the answer comes before the
        question), or "TOFU" (Text Over, Fullquote Under).

        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: Fri, 12 Jan 2007 22:31:45 +1100
From: WRX <alt.testing@N0SP4M.gmail.com>
Subject: qr and subroutines
Message-Id: <chpeq2pcmsdvcqg797c8s03n443tftcqcs@4ax.com>

Hi all, 
I am writing a program(code at bottom) to clean up bot posts on a web
forum.
To do this, I need to build various URL's with session id's etc.
First time I have actually used a perl module, and it's all really
smooth sailing and good fun.

However, I'm really stuck on WHY, I have has to write some code in a
particular way to achieve something.

In order to follow the methodology of re-using code, I want a
subroutine that I can pass a "regex", in order to build URL's from a
base URL.

Here it is.

my $input_url = 'http://xyz.com.au/forum/index.php';
my $test_url = &build_url( \'admin/index.php?admin=22&sid=' );


sub build_url {
 my $tmp_regex =  shift;
 my $tmp_url   =  $input_url;
    $tmp_url   =~ s/index\.php/$$tmp_regex/;
    $tmp_url   .= $s_id;
} 

Ok, so I have created a hard reference to a string (remembers the
"Camel Book" saying one day you might need to). I then dereference it
in the actual regex function itself, and I get what I want. BUT, it
seems a bogus way to do it, and it's not even a regex I'm passing,
which is going to cost me flexibility down the road.

What I wanted to do was something like this.


my $input_url = 'http://xyz.com.au/forum/index.php';
my $test_url = &build_url( qr|index.php/admin/index.php?admin=22&sid=|
);

sub build_url {
 my $tmp_regex =  shift;
 my $tmp_url   =  $input_url;
    $tmp_url   =~ s/index\.php/$tmp_regex/;
    $tmp_url   .= $s_id;
}

BUT, I get the "regex reference" being dereferenced and expressed as
the regex, including status of switches etc. As follows:

http://xyz.com.au/forum/(?-xism:admin/index.php?admin=22&sid=)21292773ce2e5de93dea126ac35784df

(so, probably I need to build the regex reference beforehand, and I'm
then writing more code which is kind of self defeating, unless the
subroutine was like 20 lines long - but it's not) 


 ...AND, what I REALLY wanted to do, was pass the ENTIRE "Regex" to the
function if one dirty big long swoop, somehow.
 
my $input_url = 'http://xyz.com.au/forum/index.php';
my $test_url = &build_url(
s/index\.php/index.php/admin/index.php?admin=22&sid=/ )

sub build_url {
 my $tmp_regex =  shift;
 my $tmp_url   =  $input_url;
 $tmp_url   =~ $tmp_regex;
 $tmp_url   .= $s_id;
}

Obviously not correct, but why can't I do something like this? 
OR can I? Is there a way?  
Thanks people in advance.




#!/usr/bin/perl

use strict;
use warnings;

use WWW::Mechanize;
my $mech = WWW::Mechanize->new( autocheck => 1 );

use WWW::Mechanize::Frames;
my $mech_f = WWW::Mechanize::Frames->new();

my $input_url = 'http://xyz.com.au/forum/index.php';
my $name = 'username';
my $password = 'password';
my $button = 'login';

$mech->get( $input_url );

&authenticate;

my $raw_mech = $mech->content;

my $s_id = $raw_mech;
   $s_id =~ tr/\n/ /;
   $s_id =~ s/^.*admin\/index\.php\?sid=([0-9a-z]*)">.*$/$1/;

my $login_url =  $input_url;
   $login_url =~ s/index\.php/admin\/index\.php\?sid=/;
   $login_url .= $s_id;

my $logout_url =  $input_url;
   $logout_url =~ s/index\.php/login\.php\?logout=true&sid=/;
   $logout_url .= $s_id; 

$mech->get( $login_url );

### Forum asks for authentication again to get into admin panel ###
&authenticate;

my $admin_url =  $input_url;
   $admin_url =~ s/index\.php/admin\/index\.php\?admin=1&sid=/;
   $admin_url .= $s_id;

### admin panel is frames  :( ###
$mech_f->get( $admin_url );
my @frames = $mech_f->get_frames();

$raw_mech = "";
$raw_mech = $mech->content;

### JUST TESTING RIGHT HERE ###
my $test_url = &build_url( \'admin/index.php?admin=22&sid=' );
print "$test_url\n";

#print $frames[0]->content;
#print $frames[1]->content;

&logout;
exit 0;


#==================================================================#

sub authenticate {
 $mech->set_fields( $name => '' );
 $mech->set_fields( $password => '' );
 $mech->click;
}

sub build_url {
 my $tmp_regex =  shift;
 my $tmp_url   =  $input_url;
    $tmp_url   =~ s/index\.php/$$tmp_regex/;
    $tmp_url   .= $s_id;
} 

sub logout {
 $mech->get( $logout_url );
}




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

Date: Fri, 12 Jan 2007 14:18:24 +0100
From: Robert 'phaylon' Sedlacek <rs@474.at>
Subject: Re: qr and subroutines
Message-Id: <45a78aa1$0$5716$9b4e6d93@newsspool3.arcor-online.net>

WRX wrote:

> In order to follow the methodology of re-using code, I want a
> subroutine that I can pass a "regex", in order to build URL's from a
> base URL.
> 
> Here it is.
> 
> my $input_url = 'http://xyz.com.au/forum/index.php';
> my $test_url = &build_url( \'admin/index.php?admin=22&sid=' );
> 
> 
> sub build_url {
>  my $tmp_regex =  shift;
>  my $tmp_url   =  $input_url;
>     $tmp_url   =~ s/index\.php/$$tmp_regex/;
>     $tmp_url   .= $s_id;
> } 

Wait a second. First, don't use & in front of build_url unless you
really know what it is doing. Second: Your $tmp_regex is not a regex,
it's a string. Third: In your function you don't use $tmp_regex as
regex, but as substitute.

> Ok, so I have created a hard reference to a string (remembers the
> "Camel Book" saying one day you might need to). I then dereference it
> in the actual regex function itself, and I get what I want. BUT, it
> seems a bogus way to do it, and it's not even a regex I'm passing,
> which is going to cost me flexibility down the road.
> 
> What I wanted to do was something like this.
> 
> 
> my $input_url = 'http://xyz.com.au/forum/index.php';
> my $test_url = &build_url( qr|index.php/admin/index.php?admin=22&sid=|
> );
> 
> sub build_url {
>  my $tmp_regex =  shift;
>  my $tmp_url   =  $input_url;
>     $tmp_url   =~ s/index\.php/$tmp_regex/;
>     $tmp_url   .= $s_id;
> }
> 
> BUT, I get the "regex reference" being dereferenced and expressed as
> the regex, including status of switches etc. As follows:
> 
> http://xyz.com.au/forum/(?-xism:admin/index.php?admin=22&sid=)21292773ce2e5de93dea126ac35784df

Why do you even think you want a regular expression in the second part
of a s///?

> ...AND, what I REALLY wanted to do, was pass the ENTIRE "Regex" to the
> function if one dirty big long swoop, somehow.
>  
> my $input_url = 'http://xyz.com.au/forum/index.php';
> my $test_url = &build_url(
> s/index\.php/index.php/admin/index.php?admin=22&sid=/ )
> 
> sub build_url {
>  my $tmp_regex =  shift;
>  my $tmp_url   =  $input_url;
>  $tmp_url   =~ $tmp_regex;
>  $tmp_url   .= $s_id;
> }
> 
> Obviously not correct, but why can't I do something like this? 
> OR can I? Is there a way?  
> Thanks people in advance.

The solutions:
- Use a regex where you want a regex, use a string where you want a
  string.
- You can pass more than one argument.


<untested>

  my $search  = qr/index\.php/;
  my $replace = 'admin/index.php?admin=22&sid=';

  my $new_uri
    = rework_uri('http://example.com/index.php', $search, $replace);

  sub rework_uri {
    my ($uri, $search, $replace) = @_;
    $uri =~ s/$search/$replace/;
    $uri .= $sid;
    return $uri;
  }

</untested>


-- 
# Robert 'phaylon' Sedlacek
# Perl 5/Catalyst Developer in Hamburg, Germany
{ EMail => ' rs@474.at ', Web => ' http://474.at ' }


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

Date: 12 Jan 2007 03:11:09 -0800
From: "trxrse" <Remus.SEPP@t-mobile.co.uk>
Subject: This is strange!!! What happens in here???
Message-Id: <1168600269.621823.205550@q2g2000cwa.googlegroups.com>

I have a piece of code and I really don't understand what's
happening...

The code:

#! /bin/perl
# Forking out a series of processes which may take
# a while to run. System waits for any SIGCHILD signal to be
# received back so that it can get the faster ones
# finalised quickly! Once a SIGCHILD signal is received back
# it accounts for it in an array

use strict;
use warnings;
use POSIX ":sys_wait_h";


my @waitlist = (20,10,35);
$SIG{CHLD} = \&REAPER;
my $start = localtime();
print "Started $start\n";
my $parent = $$;
my $child=0;
my @kids=();
my $waitedpid;
my $gotone;
my $finished_child;
my $pid;
my $child_pid;

foreach $child (@waitlist) {
	unless ($pid = fork()) {
			# Child process
			sleep $child;
			print "I am the kid # $child and I am completed\n";
			exit();
	}
	# Parent process - loop to start others
	push @kids, $pid;
}
print "The kids array\n";
foreach (@kids){
	print $_,"\n";
}

print "Parent continues now...\n";
# Parent - wait for returned data
while (&sum_pids > 0) {
	print "sum_pids=",&sum_pids,"\n";
	while (! $gotone){
		sleep 1;
		print "Slept 1\n";
	}
	$gotone=0;
	print "finished_child=$finished_child","\n";
	foreach (@kids){
		if ($finished_child=$_){
			print "\$finished_child=",$finished_child,"\n";
			print "\$_=",$_,"\n";
			print "I am the parent and process $_ finished!!!\n";
			$_=0;
		}
	}
}

print "And in the end sum_pids=",&sum_pids,"\n";
print "Completed!!!\n";


sub REAPER {
	if (($finished_child = waitpid(-1, &WNOHANG)) > 0){
		$gotone = 1;
	}
	# $SIG{CHLD} =\&REAPER;
}


sub sum_pids{
	my $temp;

	foreach $child_pid (@kids){
		$temp+=$child_pid;
	}
	$temp;
}




The output:
Started Fri Jan 12 11:03:53 2007
I am the kid # 10 and I am completed
The kids array
5332
5333
5335
Parent continues now...
sum_pids=16000
Slept 1
Slept 1
Slept 1
Slept 1
Slept 1
Slept 1
Slept 1
Slept 1
Slept 1
Slept 1
finished_child=5333
$finished_child=5332
$_=5332
I am the parent and process 5332 finished!!!
$finished_child=5333
$_=5333
I am the parent and process 5333 finished!!!
$finished_child=5335
$_=5335
I am the parent and process 5335 finished!!!
And in the end sum_pids=0
Completed!!!
I am the kid # 20 and I am completed
I am the kid # 35 and I am completed



The questions: How is it possible to display only once
"finished_child=5333" and then to display $finished_child three times?
That would mean that it's catching only one SIGCHLD but somehow it's
executing that "if ($finished_child) three times. How come?


Thanks
trxrse



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

Date: 12 Jan 2007 12:23:27 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: This is strange!!! What happens in here???
Message-Id: <50pctvF1gucb2U1@mid.dfncis.de>

trxrse <Remus.SEPP@t-mobile.co.uk> wrote in comp.lang.perl.misc:
> I have a piece of code and I really don't understand what's
> happening...

Nor do I, finding your code a bit hard to follow.  I noticed

    if ($finished_child=$_){

in your code.  That should almost certainly be "$finished_child == $_".

> The code:

[snipped]

Anno

-- 
$anagram = 'Knuth heals rare project'; # by Abigail
push @{ $pos{ $_}}, $pos ++ for split //, lc $anagram;
print "print +(split //, '$anagram')[ $_]\n" for
join ', ', map shift @$_, @pos{ split //, lc "Just another Perl hacker"};


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

Date: Fri, 12 Jan 2007 07:30:43 -0600
From: hymie_@_lactose.homelinux.net (hymie!)
Subject: Re: This is strange!!! What happens in here???
Message-Id: <ae2dnS1g0cQeEDrYnZ2dnUVZ_ompnZ2d@comcast.com>

In our last episode, the evil Dr. Lacto had captured our hero,
  "trxrse" <Remus.SEPP@t-mobile.co.uk>, who said:
>I have a piece of code and I really don't understand what's
>happening...

Found it.

>print "Parent continues now...\n";
># Parent - wait for returned data
>while (&sum_pids > 0) {
>	print "sum_pids=",&sum_pids,"\n";
>	while (! $gotone){
>		sleep 1;
>		print "Slept 1\n";
>	}
>	$gotone=0;
>	print "finished_child=$finished_child","\n";
>	foreach (@kids){
                                 vvvvv
>		if ($finished_child=$_){
                                 ^^^^^
>			print "\$finished_child=",$finished_child,"\n";
>			print "\$_=",$_,"\n";
>			print "I am the parent and process $_ finished!!!\n";
>			$_=0;
>		}
>	}
>}

As soon as you finish your first child, you declare them all finished.
Thus the while loop only runs once.

hymie!        http://www.smart.net/~hymowitz        hymie@lactose.homelinux.net
===============================================================================
When speaking to a Bear of Very Little Brain, remember that long words may
Bother him.                                                  -- Winnie the Pooh
===============================================================================


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

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


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