[24284] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6475 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 27 09:06:55 2004

Date: Tue, 27 Apr 2004 06:05:08 -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 Apr 2004     Volume: 10 Number: 6475

Today's topics:
        A1 Triple Gold Star for Robin <jds@nospantrumpetweb.co.uk>
    Re: convert graphic file to x,y coordinates (Mike Solomon)
    Re: Difficult regular expression problem! <noreply@gunnar.cc>
    Re: Difficult regular expression problem! (Anno Siegel)
    Re: free source blogger (works) <gnari@simnet.is>
    Re: free source blogger (works) (Anno Siegel)
    Re: free source guestbook (finished) (Anno Siegel)
    Re: How can I create a PDF page with only Images (EPS & <Eric@nospam.com>
        How to use PDF::API2 Perl Module for placing a Banner (Aqua)
    Re: How to use PDF::API2 Perl Module for placing a Bann (Aandi Inston)
    Re: Ignore errors inserting dup records? <tore@aursand.no>
    Re: Ignore errors inserting dup records? <tore@aursand.no>
    Re: output to STDOUT to a file <Joe.Smith@inwap.com>
    Re: PAR, pp and script packing <Joe.Smith@inwap.com>
    Re: perl -d interfering with program execution? <Joe.Smith@inwap.com>
        Posting Guidelines for comp.lang.perl.misc ($Revision:  tadmc@augustmail.com
    Re: RegExp poser: matching two substrings (Anno Siegel)
    Re: sending data from one program to a perl prog <Joe.Smith@inwap.com>
        Setting up initial @INC when configuring Perl 5.8.4 (Horst Fickenscher)
        variable scope and use strict <PerlGuRu2b@bobotheclown.org>
    Re: variable scope and use strict <tore@aursand.no>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 27 Apr 2004 12:15:16 +0100
From: "Julia deSilva" <jds@nospantrumpetweb.co.uk>
Subject: A1 Triple Gold Star for Robin
Message-Id: <pdrjc.930$n6.423@pathologist.blueyonder.net>

Many Congratulations to Robin.

How does this guy (or gal) do it, I mean, how is it possible to take such
stick, stay cool and come back for more. Many others have got themselves
into similar situations in this NG and have ended up taking offence, being
rude, and then getting plonked, or worse.

What a guy ! <sigh>




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

Date: 27 Apr 2004 01:33:24 -0700
From: mike_solomon@lineone.net (Mike Solomon)
Subject: Re: convert graphic file to x,y coordinates
Message-Id: <56568be5.0404270033.76b53e3a@posting.google.com>

mike_solomon@lineone.net (Mike Solomon) wrote in message news:<56568be5.0404260151.603d47bf@posting.google.com>...
> I need to take a graphics file and then get the xy coordinates from it
> and insert them into a database
> 
> so far the best way I have come up with is to use paint to get the
> cordinates and manually record them in a spreadsheet
> 
> Is there any way I can use perl to read the graphics file and get the
> co-ordinates
> 
> I am probably being optimistic but doing it manually is driving me mad
> :)

Thanks for the replies 

The files are either be jpeg or png

I will try image magic and keep my fingers crossed

The image is a stand map - basically black outlined rectangles on a
white background

I need to get the co-ordinates to pass them to a flash program and
also so I can create a printable stand map

I can't just store the image in the database as I need the
co-ordinates


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

Date: Tue, 27 Apr 2004 10:25:44 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Difficult regular expression problem!
Message-Id: <c6l5k1$cqvks$1@ID-184292.news.uni-berlin.de>

Fritz Bayer wrote:
> Gunnar Hjalmarsson wrote:
>> Fritz Bayer wrote:
>>> "This is an example, which hopefully helps me and you to solve
>>> my problem. I would buy a used computer for 50 Dollars but I
>>> wouldn' buy it for 1000 Dollars. I definitely would by an
>>> apartment for 3000 Dollars or a Miro for 1500 Dollars but not
>>> for 5000000 Dollars. For 50 Dollars you can hire me as a perl
>>> programmer - but I guess I'm not worth the Dollar:)"

<snip>

>>> I would like the following result:
>>> 
>>> 50;computer;
>>> 1000;;
>>> 3000;apartment;
>>> 1500;Miro;
>>> 5000000;;
>>> 50;;
>> 
>> As I indicated in my previous reply, I believe that you'd better 
>> capture respective pattern in two steps. This would do it:
>> 
>>     while (/(.*?)(\d+)\s+Dollar?/igs) {
>>         print "$2;",
>>               $1 =~ /(computer|apartment|miro|somethingelsemissing)/i,
>>               ";\n";
>>     }
> 
> Ok, I get the point and you a right - that would work, so it's a 
> solution. Thanks!
> 
> Just one more thing. Haven't you forgotten to print out $1 and how 
> come that you can append the regex using a comma (,)?

The above code prints the specified result. Didn't you try it?

Your questions indicate that you should study perldoc for a couple of
reasons.

1. The print() function "prints a string or a list of strings", in
this case a (comma separated) list. See "perldoc -f print".

2. One of the elements in the list that is passed to print() is the
return value (in list context) from the second pattern match, i.e. the
captured word. Read about the m// operator in "perldoc perlop".

I could have assigned what's captured from the pattern matches to 
variables first, so this does the same thing:

     while (/(.*?)(\d+)\s+Dollar?/igs) {
         my $amount = $2;
         my ($word) =
           $1 =~ /(computer|apartment|miro|somethingelsemissing)/i;
         $word ||= '';
         print "$amount;$word;\n";
     }

HTH

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



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

Date: 27 Apr 2004 09:10:19 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Difficult regular expression problem!
Message-Id: <c6l81r$23m$1@mamenchi.zrz.TU-Berlin.DE>

Glenn Jackman  <xx087@freenet.carleton.ca> wrote in comp.lang.perl.misc:
> Fritz Bayer <fritz-bayer@web.de> wrote:

[...]

> >  For example:
> >  
> >  "This is an example, which hopefully helps me and you to solve my
> >  problem. I would buy a used computer for 50 Dollars but I wouldn' buy
> >  it for 1000 Dollars. I definitely would by an apartment for 3000
> >  Dollars or a Miro for 1500 Dollars but not for 5000000 Dollars. For 50
> >  Dollars you can hire me as a perl programmer - but I guess I'm not
> >  worth the Dollar:)"
> >  
> >  Here the regex, which of course is not working (just to give you an
> >  idea):
> >  /.*?(computer|apartment|miro|somethingelsemissing).*?(\d+)\s+Dollars?/
> >  print ($1 . ";" . $2 . ";\n")/gies
> >  
> >  I would like the following result:
> >  
> >  50;computer;
> >  1000;;
> >  3000;apartment;
> >  1500;Miro;
> >  5000000;;
> >  50;;
> 
> I don't think regular expressions can do it.

They can, but it's not necessarily the best way to do it.  Here is
one way:

    my $pattern = qr/\d+/;
    my $context = qr/computer|apartment|miro|somethingelsemissing/i;

    while ( $sentence =~ /(?:($context).*?($pattern))|($pattern)/gs ) {
        my $amount = $2 || $3;
        my $article = $1 || '';
        print "$amount;$article;\n";
    }

The loop body could be re-written to be executed in the replacement
part of a s///e, but that's too horrible to write down.

Anno


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

Date: Tue, 27 Apr 2004 08:43:08 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: free source blogger (works)
Message-Id: <c6l6c4$6od$1@news.simnet.is>

"Robin" <robin @ infusedlight.net> wrote in message
news:c6kqp5$18ko$1@news.f.de.plusline.net...
> can someone identify themselves as the hacker who posted that image on my
> blog?

Sorry, I thought it was clear.

> Thanks, and yes, the auth needs a lot of work, I realize.

indeed.

gnari






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

Date: 27 Apr 2004 11:03:46 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: free source blogger (works)
Message-Id: <c6lemi$23m$3@mamenchi.zrz.TU-Berlin.DE>

Uri Guttman  <uri.guttman@fmr.com> wrote in comp.lang.perl.misc:
> >>>>> "R" == Robin  <robin @ infusedlight.net> writes:

> 	winblows runs but it doesn't work. hell, it has no spec at all
> 	so it will never 'work'.

Careful there...  Perl doesn't have specs either :)

Anno


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

Date: 27 Apr 2004 12:21:03 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: free source guestbook (finished)
Message-Id: <c6lj7f$23m$4@mamenchi.zrz.TU-Berlin.DE>

John W. Krahn <krahnj@acm.org> wrote in comp.lang.perl.misc:

> Actually the OP wasn't doing a global replace.  He was using /g on the
> match operator in a boolean context which makes no sense at all.  :-)

 ...except when you're looping over it.  It definitely didn't make
sense the way the OP used it.

Anno


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

Date: Tue, 27 Apr 2004 11:34:55 +0100
From: Eric <Eric@nospam.com>
Subject: Re: How can I create a PDF page with only Images (EPS & TIFF)
Message-Id: <VGqjc.31$7k3.8@newsfe3-win.server.ntli.net>

Aqua wrote:

> > The simple way is to make a document with all the images included and
> > then run out the PS and use GS to make the PDF.
> > 
> > The document that you use depends on your skill. Either use Quark or
> > Pagemaker with some scripting to include the images into your document.
> 
> I dont have Quark, but I have PM. Though I am familar with PM
> scripting, I can give it a try.

Off you go then.

> > Or you could use LaTeX: create a galley using perl and then runout.
> > Or you could write manual PostScript using Perl. This would require some
> > work, but then it would be quite portable.
> 
> I am conversant with perl but I am not familar with Latex. But I can
> try if it works. Appreciate any pointers.

For your purposes the LaTeX that you would need would be very simple. Make 
a galley with lines of the form: 
%%
\EBox{}{/mnt/bert/12341.eps}%
\EBox{}{/mnt/bert/12342.eps}%
\EBox{}{/mnt/bert/12343.eps}%
\EBox{}{/mnt/fred/12341.eps}%
\EBox{}{/mnt/fred/12342.eps}%
\EBox{}{/mnt/fred/12343.eps}%
%%EOF

Then include it in a document like:
%&latex
\usepackage{graphicx}
\def\EBox#1#2{% 1:twiddles 2:path
        \hspace*{0bp}%
        \includegraphics[keepaspectratio,height=100bp,width=100bp,#1]{#2}%
        \hspace*{0bp}%
        }
\begin{document}
\include{galley.tex}
\end{document}
%%EOF

The output might be a bit higlty but it would show them. You might like to 
twiddle \EBox to suit your purposes.

Or you can use some more cleverness:
\def\MkEPSPath#1#2{/mnt/#1/#2}
 ...
\EBox{}{\MkEPSPath{fred}{12345.eps}}

Then you can change the definition of MkEPSPath and all your paths change. 
Then you can generate your galley on one platform and run TeX on another. I 
used to generate on unix and run TeX on  a Mac.

Eric.



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

Date: 27 Apr 2004 03:35:23 -0700
From: junk@dlink.org (Aqua)
Subject: How to use PDF::API2 Perl Module for placing a Banner
Message-Id: <55d7995c.0404270235.67dd5876@posting.google.com>

Group,

Could someone point me to a tutorial for PDF::API2 usage? (or samples
etc) Really I dont know how to start.

Basically I wanted to place a small banner (another PDF) in each page
of original PDF. How to do this?

Thanks for your time

Dominic


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

Date: Tue, 27 Apr 2004 13:00:32 GMT
From: quite@dial.pipex.con (Aandi Inston)
Subject: Re: How to use PDF::API2 Perl Module for placing a Banner
Message-Id: <408e58f5.1091820394@reading.news.pipex.net>

junk@dlink.org (Aqua) wrote:

>Group,
>
>Could someone point me to a tutorial for PDF::API2 usage? (or samples
>etc) Really I dont know how to start.

If you want to use any software that edits PDFs, a basic working
knowledge of the PDF format is a must. All editors are shaped and
constrained by what PDF is, and how it works, and it will be a real
struggle without that basic knowledge.

Read the PDF Reference, at least the first five chapters.
>
>Basically I wanted to place a small banner (another PDF) in each page
>of original PDF. How to do this?

See if the API talks about "form XObjects". If it does, you may be on
to something. 
----------------------------------------
Aandi Inston  quite@dial.pipex.com http://www.quite.com
Please support usenet! Post replies and follow-ups, don't e-mail them.



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

Date: Tue, 27 Apr 2004 11:42:28 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: Ignore errors inserting dup records?
Message-Id: <pan.2004.04.27.09.19.40.266147@aursand.no>

On Mon, 26 Apr 2004 20:47:33 -0700, pt wrote:
>>> Given this table, I run this :
>>> INSERT INTO T (v) VALUES ("The" , "walrus" , "was" , "Paul") ;
>>> 
>>> The insertion of "walrus" will fail because it already exists, and "v"
>>> is indexed/no_dups.  I want the SQL to insert records for "The",
>>> "was", and "Paul", and not error when in sees "walrus" already present
>>> at record #4.

>> No, it won't. It will fail because you are trying to insert 4 column
>> values into a table which has oonly 1 column!

> You noticed that SQL isn't my strong suite.  Are you saying the only way
> to insert 4 rows is to execute 4 individual SQL statements? Sounds like
> a lot of overhead.  Is there another way?  What if I have not 4, but
> 40,000 records I want to insert?

You could take a look at my example; I think it's the fastest way to solve
multi-inserts, though there are other (though slower options);

  my $sth = $dbh->prepare( ... );
  while ( ... ) {
      $sth->execute( ... );
  }
  $sth->finish();

The example above prepares the SQL statement only once (which saves some
time) and then inserts the data via the execute statement using binded
variables.  Take a look at the DBI documentation for more information.

The solution above is still a lot slower than multi-line inserts, though,
so if you need full speed you should stick with that.


-- 
Tore Aursand <tore@aursand.no>
"First, God created idiots. That was just for practice. Then He created
 school boards." (Mark Twain)


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

Date: Tue, 27 Apr 2004 13:31:30 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: Ignore errors inserting dup records?
Message-Id: <pan.2004.04.27.09.57.36.990117@aursand.no>

On Tue, 27 Apr 2004 11:42:28 +0200, Tore Aursand wrote:
> You could take a look at my example; I think it's the fastest way to
> solve multi-inserts, though there are other (though slower options);
> 
>   my $sth = $dbh->prepare( ... );
>   while ( ... ) {
>       $sth->execute( ... );
>   }
>   $sth->finish();

I see that I could be mistaken here; When I refer to "my example" above, I
do _not_ mean the example in the same post (ie. the code above), but the
example I gave in another post;

  <pan.2004.04.26.22.03.22.916075@aursand.no>


-- 
Tore Aursand <tore@aursand.no>
"Have you ever had a dream, Neo, that you were so sure was real?  What
 if you were unable to wake from that dream? How would you know the
 difference between the dream world and the real world?" (Morpheus, The
 Matrix)


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

Date: Tue, 27 Apr 2004 09:42:49 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: output to STDOUT to a file
Message-Id: <tWpjc.47648$aQ6.3675007@attbi_s51>

joe shaboo wrote:

> I'm trying to output the STDOUT to a file which is the same as the
> file I'm reading.

C:\>  perl -pi.bak -e "s/foo/bar/g" file1.txt file2.txt
unix% perl -pi     -e 's/foo/bar/g' file1 file2

Or open the file for read+write, read entire file, seek() to the
beginning, write new data, truncate, close.

	-Joe


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

Date: Tue, 27 Apr 2004 09:55:04 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: PAR, pp and script packing
Message-Id: <Y5qjc.46894$w96.4307397@attbi_s54>

Asier wrote:

> But it is in this point where my mind gets confused. What can i do, if
> i want to distribute my applicattion, accross any *linux* box, with
> the modules i have downloaded and installed in my box?

If you're going to include a compiled binary, you'll have to warn the
end users that "this will only run on Linux systems with glib-1.2"
or "glib2-2.2" or "glibc-2.3.2".  That's just one of the things that
frustrate binary compatibility across Linux distributions.

Maximum portability = compile on target machine.
	-Joe


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

Date: Tue, 27 Apr 2004 10:22:33 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: perl -d interfering with program execution?
Message-Id: <Jvqjc.30748$YP5.2376084@attbi_s02>

Pat Deegan wrote:

>     Guessing start of match, REx `^_<' against
>     `/usr/lib/perl5/5.8.3/utf8.pm'... String not equal...
>     Match rejected by optimizer

Just a wild guess: Does putting in a dummy block to get utf8 loaded before
the regexp make any difference?

     { use utf8; }	# Pre-load the utf8 module just in case
     /^dbi:(\w*?)(?:\((.*?)\))?:(.*)/i


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

Date: Tue, 27 Apr 2004 02:22:16 -0500
From: tadmc@augustmail.com
Subject: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.5 $)
Message-Id: <0OudnWSOWIG1lxPdRVn-vA@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.5 $)
    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://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
        "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: 27 Apr 2004 09:30:40 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: RegExp poser: matching two substrings
Message-Id: <c6l980$23m$2@mamenchi.zrz.TU-Berlin.DE>

Malcolm Dew-Jones <yf110@vtn1.victoria.tc.ca> wrote in comp.lang.perl.misc:
> Stuart Moore (stjm2@cam.ac.uk.remove) wrote:
> : I've been working on a uni project where you have to work out how 
> : similar two strings are, and I was wondering if it could be done somehow 
> : in a regular expression (or two...). This isn't part of my project, 
> : there are far more sensible ways of doing it, this is just for fun.
> 
> : Suppose you have two strings, $s and $t. You want to find the substrings 
> : of $s and $t that have the highest score attached, where you have +1 for 
> : each pair of letters that match, and -1 for each that don't.
> 
> : So, $s='MEAT', $t='ATE' has a score of 2 because you match the 2 'AT' 
> : substrings.
> : $s='ABCDE' $t='ABFDE' has a score of 3 - it's still worthwhile taking 
> : the -1 on the middle letter, because there's +2 on either side.
> 
> : Any thoughts? Feel free to assume $s and $t are alphabetic/alphanumeric.
> 
> : Finding matching substrings of length $n is easy, using
> : "$s:$t" =~ /([^:]{$n}).*:.*$1/;
> : (untested) but I got no further...
> 
> : Stuart
> 
> I would not use regexp.
> 
> I would split the strings into character arrays, and then use the diff 
> module with each character treated as a "line".

A different, and presumably faster, way to find the score of matching
and non-matching characters in two strings $a, $b is

    my $score;
    $score = tr/\0// - tr/\0//c for $a ^ $b;

No guarantees for multi-byte characters, though.

Anno


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

Date: Tue, 27 Apr 2004 10:10:28 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: sending data from one program to a perl prog
Message-Id: <okqjc.47042$w96.4315353@attbi_s54>

Gunnar Hjalmarsson wrote:

> Gunnar Hjalmarsson wrote:
> 
>>
>>     my $msg;
>>     my $maxsize = 131072;
>>     unless ($ENV{CONTENT_LENGTH} > $maxsize) {
>>         $msg = do {local $/; <STDIN>};
> 
> 
> I'd better add that such a check of message size does not always work. 
> For instance, the sendmail configuration on my own brand new server is 
> so 'secure' so that no %ENV variable at all is present when a process is 
> run as the mail program. Perl's stat() function, i.e.
> (stat STDIN)[7], does not contain the size either...
> 
> Oh, well.

What about something like
     my $bytes_read = read STDIN,$msg,$maxsize;
     unless eof(STDIN) { return 'error'};


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

Date: 27 Apr 2004 00:59:54 -0700
From: horst.fickenscher@sealsystems.de (Horst Fickenscher)
Subject: Setting up initial @INC when configuring Perl 5.8.4
Message-Id: <33fd36b9.0404262359.51712f07@posting.google.com>

Using the following settings to configure Perl (aix5)

 ../perl-5.8.4/Configure \
    -des \
    -Dmksymlinks \
    -Dcc=gcc \
    -Dprefix=$PREFIX \
    -Dprivlib=$PREFIX/lib_$OS \
    -Darchlib=$PREFIX/lib_$OS/$OS \
    -Dsitelib=$PREFIX/lib_$OS/site \
    -Dsitearch=$PREFIX/lib_$OS/site/$OS \
    -Dinc_version_list=none \
    -Dsite_lib_stem=none \
    -Dusemymalloc

After running make

 ./perl -V

gives

  @INC:
    /usr/local/perl/lib_aix5/aix5
    /usr/local/perl/lib_aix5
    /usr/local/perl/lib_aix5/site/aix5
    /usr/local/perl/lib_aix5/site
    /usr/local/perl/lib_aix5/site
    .

i.e. the value passed for sitelib shows up twice. While this is not
harmful, does anybody know how to avoid this behaviour?

Thanks

-- 
Horst


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

Date: Tue, 27 Apr 2004 12:46:17 GMT
From: Rocky <PerlGuRu2b@bobotheclown.org>
Subject: variable scope and use strict
Message-Id: <pan.2004.04.27.12.43.01.8345@bobotheclown.org>

I am trying to use strict all the time now.  I have a problem with the
following code.  When I use strict the value of $highest won't leave the
foreach construct.  I know this is by design but I cannot figure out how
make that variable available outside the loop.  Any advice?

Also if someone could tell me where to find perldoc regarding "use
strict;" or scoping in general I would appreciate it.


#!/usr/bin/perl
my $number = 1;
my $dir = "/etc/backup";
opendir DIR1, $dir;
my @files = readdir(DIR1);
closedir DIR1;
foreach my $filename (@files)
    {
        push(@filenum, $1)  if ($filename =~ /^CUX(\d+)\.txt$/);
        #my $highest = (sort { $a <=> $b } @filenum)[-1];
     }
        $highest = (sort { $a <=> $b } @filenum)[-1];
        $final = $highest + $number;
print "CUX00" . "$final" . ".txt\n";




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

Date: Tue, 27 Apr 2004 15:00:50 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: variable scope and use strict
Message-Id: <pan.2004.04.27.13.00.28.146703@aursand.no>

On Tue, 27 Apr 2004 12:46:17 +0000, Rocky wrote:
> I am trying to use strict all the time now.

But you don't.  Your code doesn't use strict at all.  It doesn't use
warnings, either;

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

> I have a problem with the following code.  When I use strict the value
> of $highest won't leave the foreach construct.  I know this is by design
> but I cannot figure out how make that variable available outside the
> loop.  Any advice?
> 
> my $dir = "/etc/backup";

Needless use of double quotes;

  my $dir = '/etc/backup';

> opendir DIR1, $dir;

Always check if 'open()' and 'opendir()' succeeds;

  opendir( DIR1, $dir ) or die "$!\n";

Eventually;

  if ( opendir(DIR1, $dir) ) {
      closedir( DIR1 );
  }
  else {
      # Something bad happened; Error message in $!
  }

> my @files = readdir(DIR1);
> closedir DIR1;
> foreach my $filename (@files) {
>         push(@filenum, $1)  if ($filename =~ /^CUX(\d+)\.txt$/); #my
>         $highest = (sort { $a <=> $b } @filenum)[-1];
>      }
>         $highest = (sort { $a <=> $b } @filenum)[-1]; $final = $highest
>         + $number;
> print "CUX00" . "$final" . ".txt\n";

You could always make sure that you have the correct set of files when you
first read them in with 'readdir';

  my @files = grep { /^CUX\d+\.txt$/ } readdir( DIR1 );

It seems to be that you're trying to find the filename which have the
highest number.  This could be done like this;

  opendir( DIR1, $dir ) or die "$!\n";
  my @files = sort { $a <=> $b } grep { /^CUX\d+\.txt$/ } readdir( DIR1 );
  closedir( DIR1 );

  print 'Highest valued filename: ' . $files[-1] . "\n";

> Also if someone could tell me where to find perldoc regarding "use
> strict;" or scoping in general I would appreciate it.

I guess 'perldoc strict' would get you going.


-- 
Tore Aursand <tore@aursand.no>
"War is too serious a matter to entrust to military men." (Georges
 Clemenceau)


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

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


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