[24467] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6650 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 4 06:05:55 2004

Date: Fri, 4 Jun 2004 03:05:05 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 4 Jun 2004     Volume: 10 Number: 6650

Today's topics:
        Configuring serial port <nospam@nospam.com>
    Re: Configuring serial port <lord-jacob@comcast.net>
    Re: Configuring serial port (Anno Siegel)
    Re: Escaping single quotes with sql <irving@maine.edu>
    Re: how can a Perl script for Win32 tell if it's runnin <MrReallyVeryNice.NOVIRUS@NoSpam.yahoo.com>
    Re: how can a Perl script for Win32 tell if it's runnin <jack_challen@ocsl.co.uk>
    Re: Kill a system process within the script (Anno Siegel)
    Re: On "for (@foo)" <pb2@aracnet.com>
    Re: On "for (@foo)" <usenet@morrow.me.uk>
        opening multiple pipes (justme)
    Re: opening multiple pipes <invalid-email@rochester.rr.com>
    Re: opening multiple pipes <usenet@morrow.me.uk>
    Re: perl and serail port an win maschine <kalinaubears@iinet.net.au>
        Posting Guidelines for comp.lang.perl.misc ($Revision:  tadmc@augustmail.com
    Re: regexp <Joe.Smith@inwap.com>
    Re: Regexp: Lazy match workaround? (R. Rajesh Jeba Anbiah)
    Re: Regexp: Lazy match workaround? (Anno Siegel)
    Re: sorting and resorting hash (Andrea Spitaleri)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 04 Jun 2004 00:29:09 -0500
From: Mike Kelly <nospam@nospam.com>
Subject: Configuring serial port
Message-Id: <mr10c0tg70mkrr9frqng322j32bhjrh6l6@4ax.com>

I hadn't thought of using perl for this, but I saw a mention on a web
site that someone used a trivial little perl program to set the
parameters on a serial port for barcode scanner input...

What I need to do is set the baud rate, parity, and start and stop
bits so I can talk to a change machine, which is a pretty primitive
device, and wants 9600,7,e,1

Frankly, I don't care whether I use perl or not, but in an hour of
googling and searching various linux sites I haven't come across the
right combination of terms to find an appropriate command line... so ,
whether it's perl or something else... if you can point me in the
right direction, I'd appreciate it.




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

Date: Fri, 04 Jun 2004 05:49:05 GMT
From: Jacob Heider <lord-jacob@comcast.net>
Subject: Re: Configuring serial port
Message-Id: <724ce4f991e6716a77f7bb3796b63331@news.teranews.com>

On Fri, 04 Jun 2004 00:29:09 -0500, a posting issued forth from Mike Kelly...
> I hadn't thought of using perl for this, but I saw a mention on a web
> site that someone used a trivial little perl program to set the
> parameters on a serial port for barcode scanner input...
> 
> What I need to do is set the baud rate, parity, and start and stop
> bits so I can talk to a change machine, which is a pretty primitive
> device, and wants 9600,7,e,1
> 
> Frankly, I don't care whether I use perl or not, but in an hour of
> googling and searching various linux sites I haven't come across the
> right combination of terms to find an appropriate command line... so ,
> whether it's perl or something else... if you can point me in the
> right direction, I'd appreciate it.
> 
> 

This isn't a perl answer, but the canonical way to deal with the serial
port under linux is 'setserial'. If it's not installed (I don't know
what you're running), you should be able to find it.

GL
Jacob


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

Date: 4 Jun 2004 08:47:39 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Configuring serial port
Message-Id: <c9pcvb$2h2$2@mamenchi.zrz.TU-Berlin.DE>

Mike Kelly  <nospam@nospam.com> wrote in comp.lang.perl.misc:
> I hadn't thought of using perl for this, but I saw a mention on a web
> site that someone used a trivial little perl program to set the
> parameters on a serial port for barcode scanner input...
> 
> What I need to do is set the baud rate, parity, and start and stop
> bits so I can talk to a change machine, which is a pretty primitive
> device, and wants 9600,7,e,1
> 
> Frankly, I don't care whether I use perl or not, but in an hour of
> googling and searching various linux sites I haven't come across the
> right combination of terms to find an appropriate command line... so ,
> whether it's perl or something else... if you can point me in the
> right direction, I'd appreciate it.

By a remarkable coincidence just last week I happened to set a serial
port to 9600,7,e,1 to communicate with a barcode scanner.

I used POSIX::Termios.  The code is on a machine I can't reach at the
moment.  If you have problems applying Termios, mail me or post again.

Anno


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

Date: Thursday , 03 Jun 2004 21:30:46 EST
From: "David Irving" <irving@maine.edu>
Subject: Re: Escaping single quotes with sql
Message-Id: <c9ojdd$kbp$1@murdoch.unet.maine.edu>

This is what I do:

$myvariable =~ /\\\'/\\\'\\\'/g;



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

Date: Thu, 3 Jun 2004 17:31:21 -0700
From: "MrReallyVeryNice" <MrReallyVeryNice.NOVIRUS@NoSpam.yahoo.com>
Subject: Re: how can a Perl script for Win32 tell if it's running as an admin?
Message-Id: <BfmdnS2-sKAxUCLd4p2dnA@comcast.com>

In addition to the suggestions provided above, you might also consider this
post:

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&frame=right&th=bc17797480
3e52b3&seekm=muadnaaNJo41huvdRVn-sA%40comcast.com#link2

Let us know if that solves your problem.
MrReallyVeryNice




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

Date: Fri, 04 Jun 2004 10:07:22 +0100
From: Jack Challen <jack_challen@ocsl.co.uk>
Subject: Re: how can a Perl script for Win32 tell if it's running as an admin?
Message-Id: <qZWvc.1$0Q2.388@psinet-eu-nl>

Bennett Haselton wrote:
> I went to
> http://cpan.uwinnipeg.ca/dist/Win32/
> to do a search to see if anything had been created more recently, but
> the search bar wouldn't let me search just within that module.

Hmm... oddness
I went to http://search.cpan.org/~nwclark/perl-5.8.4/win32/ext/Win32/Win32.pm

and used my browser's "find in this page" option to look for "admin".
This found me Win32::IsAdminUser()

> Are you aware of some function in that module that does what I need,
> and you were trying to lead me there without spoonfeeding me :) or
> were you just giving me a suggestion as the first place to look? 

Sorry, had assumed zero effort on your part, and was trying to lead you to 
the answer, so your assumption was correct :)

cheers
jack


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

Date: 4 Jun 2004 09:01:30 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Kill a system process within the script
Message-Id: <c9pdpa$2h2$3@mamenchi.zrz.TU-Berlin.DE>

Mav <mluvw47@yahoo.com> wrote in comp.lang.perl.misc:
> Hi, all
>   I am trying to lanuch a command on my perl script using system call,
> I wonder is that a way when someone hit Ctrl-Y, it will kill my
> script,and also  kill that system call process as well.
> 
> My script:
> 
> ...
> @args = ("doing something take a long time");
> 
> if (system(@args)==0) {
>    print "ok";
> } else
>    print "something wrong";

I don't know what Ctrl-Y does in your system.  An INT signal (as
created by Ctrl-C per default on Unix) is already treated the way
you want.

Anno


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

Date: 3 Jun 2004 23:37:08 GMT
From: P Buder <pb2@aracnet.com>
Subject: Re: On "for (@foo)"
Message-Id: <c9ocn40aar@enews1.newsguy.com>

Paul Lalli <ittyspam@yahoo.com> writes:

>  I'm just not convinced there's any variation of a C-style for
>loop that cannot be emulated with a Perl-style foreach loop.

My usual use for a C style loop is when I want to know where the loop
exited.
                                                                                
for $i(0..4)
    {
    last if # some condition, let's say $i==2 just before loop exit.
    }
# Here $i is undef which isn't what I want.
                                                                                
Compared to C style
                                                                                
for($i=0; $i<=4; $i++)
    {
    last if # some condition, let's say $i==2 just before loop exit.
    }
# Here $i == 2 which is what I want.
                                                                                
Of course you could assign $i's value to something else in the
first chunk but that seems messier.



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

Date: Fri, 4 Jun 2004 03:22:07 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: On "for (@foo)"
Message-Id: <c9opsv$i6f$2@wisteria.csv.warwick.ac.uk>

[your newsreader seems to be putting 80 spaces on every blank line,
which is unnecessary to say the least...]

Quoth P Buder <pb2@aracnet.com>:
> Paul Lalli <ittyspam@yahoo.com> writes:
> 
> >  I'm just not convinced there's any variation of a C-style for
> >loop that cannot be emulated with a Perl-style foreach loop.
> 
> My usual use for a C style loop is when I want to know where the loop
> exited.
>
> for $i(0..4)
>     {
>     last if # some condition, let's say $i==2 just before loop exit.
>     }
> # Here $i is undef which isn't what I want.
>
> Compared to C style
>
> for($i=0; $i<=4; $i++)
>     {
>     last if # some condition, let's say $i==2 just before loop exit.
>     }
> # Here $i == 2 which is what I want.

Neither of these work under 'use strict'. In the case of the C-style
loop

for (my $i = 0; $i <= 4; $i++) {

the variable is scoped to all iterations as one scope rather than each
iter separately; it still isn't visible outside. If you want it to be,
you lose the only minor advantage a C-style for has over the equivalent
while---that it introduces this extra scope---so you should use while
instead:

my $i = 0;
while ($i <= 4) {
    ...
    last if ...;
}
continue { $i++ }

Ben

-- 
Musica Dei donum optimi, trahit homines, trahit deos.    |
Musica truces molit animos, tristesque mentes erigit.    |   ben@morrow.me.uk
Musica vel ipsas arbores et horridas movet feras.        |


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

Date: 3 Jun 2004 19:15:06 -0700
From: eight02645999@yahoo.com (justme)
Subject: opening multiple pipes
Message-Id: <c0837966.0406031815.46e4e52d@posting.google.com>

hi

in unix, we can use pipes such as 
#ls -ltr |grep "txt" | wc -l 

I have looked at IPC::Open2 and IPC::Open3 but haven't a clue how to do it...
Is IPC::Open2 and IPC::Open3 the correct modules to use for this kind of multiple
pipes? Would appreciate an example on the above can be implemented in perl..
thanks very much


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

Date: Fri, 04 Jun 2004 03:10:13 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: opening multiple pipes
Message-Id: <40BFE803.5050905@rochester.rr.com>

justme wrote:

> hi
> 
> in unix, we can use pipes such as 
> #ls -ltr |grep "txt" | wc -l 
> 
> I have looked at IPC::Open2 and IPC::Open3 but haven't a clue how to do it...
> Is IPC::Open2 and IPC::Open3 the correct modules to use for this kind of multiple
> pipes? Would appreciate an example on the above can be implemented in perl..
> thanks very much
> 


You don't need open2 or open3 to do a one-directional pipe.  Try [untested]:


open PIPE,'ls -ltr |grep "txt" | wc -l|' or
     die "Couldn't open pipe, $!";
while(<PIPE>){print}
close PIPE;

-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl



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

Date: Fri, 4 Jun 2004 03:13:33 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: opening multiple pipes
Message-Id: <c9opcs$i6f$1@wisteria.csv.warwick.ac.uk>


Quoth eight02645999@yahoo.com (justme):
> 
> in unix, we can use pipes such as 
> #ls -ltr |grep "txt" | wc -l 
> 
> I have looked at IPC::Open2 and IPC::Open3 but haven't a clue how to do it...
> Is IPC::Open2 and IPC::Open3 the correct modules to use for this kind of multiple
> pipes? Would appreciate an example on the above can be implemented in perl..

There are many ways to do this in perl. The simplest is to use perl's
magic open and the shell:

open my $WC, 'ls -ltr | grep "txt" | wc -l |'
    or die "can't open pipe: $!";

$WC is now opened for reading from the pipeline. Obviously you can go
the other way:

open my $GZIP, '| gzip > out.gz' or die ....;

and get a FH open for writing.

IPC::Open{2,3} are for when you need both ends of the program: say
you've opened something like bc and you are sending questions and
getting responses (the fact that I can't actually think of a useful
example that wouldn't be better done 'neat' in Perl shows how seldom you
need to do this... :). You need to be very careful about deadlocks: read
the docs.

Ben

-- 
It will be seen that the Erwhonians are a meek and long-suffering people,
easily led by the nose, and quick to offer up common sense at the shrine of
logic, when a philosopher convinces them that their institutions are not based 
on the strictest morality.  [Samuel Butler, paraphrased]       ben@morrow.me.uk


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

Date: Fri, 04 Jun 2004 19:05:01 +1000
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: perl and serail port an win maschine
Message-Id: <40c03c69$0$8098$5a62ac22@freenews.iinet.net.au>

Xaver Biton wrote:
> HI,
> 
> I'd like to use perl to comunicate via serial port with a ISDN telephon 
> switschboard, I'm running XP Professional and perl 5.8 activestate, but 
> the maschine on  which  the final progam should run is a win 2000 pro.
> 
> I searched the active state directory an I found a Device-SerialPort 
> modul, but when I try to install it I recieve a message error from the 
> ppm program which say :
> Error: PPD for "Device-SerialPort.pm" could not be found.
> 
> I never had this problem befor. what's that?


Perhaps you specified "Device-SerialPort.pm" where you should have 
specified "Device-SerialPort.ppd" or just "Device-SerialPort". (I'm no 
expert on ppm.)

> 
> I then serached the web for the module, and I found also somes, but 
> having a look in the example I saw that these modules were for perl 
> 5.0.., my question is if is possible to install such modules on perl 5.8.
> 

Probably ok to install them on perl 5.8. "ppm" should refuse to install 
anything that's not satisfactory with an error message about "no 
suitable target installation found".
Where you see code that contains "require 5.006;" that means it needs to 
be run on perl 5.6 (or later). "require 5.008;" means that it needs to 
be run on perl 5.8 (or later).

> or there's another maybe beter to communicate with a serial port?
> 

On windows I would expect that Win32::SerialPort would be the best choice.

Cheers;
Rob


-- 
To reply by email u have to take out the u in kalinaubears.



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

Date: Fri, 04 Jun 2004 02:23:49 -0500
From: tadmc@augustmail.com
Subject: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.5 $)
Message-Id: <KbadnUKqhr8Yvl3dRVn-hw@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: Fri, 04 Jun 2004 09:02:16 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: regexp
Message-Id: <sUWvc.5893$%F2.9@attbi_s04>

Wojtek Michalik wrote:

> perl -pi -e 's#(banana\n\t)(apple)#$1\.\/$2#g' with modifiers like m s ms 

That won't work because using -p reads the file one line at a time.
This means that is stops at each \n.  The first time through, $_ will
have "banana\n" and the second time $_ will have "\tapple\n".
In neither case will \n and \t be consecutive characters.

Since the pattern you're looking for spans lines, you'll need to
slurp the entire file into a scalar variable before looking for it.

Use the command
   perldoc perlvar
and look for the section on $INPUT_RECORD_SEPARATOR for an example
for using slurp mode.
	-Joe


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

Date: 3 Jun 2004 22:08:38 -0700
From: ng4rrjanbiah@rediffmail.com (R. Rajesh Jeba Anbiah)
Subject: Re: Regexp: Lazy match workaround?
Message-Id: <abc4d8b8.0406032108.baf38ff@posting.google.com>

Brian McCauley <nobull@mail.com> wrote in message news:<u94qpsg9dc.fsf@wcl-l.bham.ac.uk>...
> ng4rrjanbiah@rediffmail.com (R. Rajesh Jeba Anbiah) writes:

   <snip>

   Many thanks to all the experts who answered in this thread. My
original code was in PHP with PCRE. I'd thought I will get more help
in regular expression in a Perl group, and so posted here. Sorry to
bug you all.

> 
> Here's what I constructed from your description.
> 
> my $str = <<EOT;
> n2 = new something(){
> with n2{
> __add (a);
> __add (d);
> }
> 
> 
> 
> n3 = new somethinge_else(){
> with n3{
> __add (x);
> __add (y);
> }
> 
> EOT
> 
> print join ', ', map "'$_'",
>      $str =~ /(\w+) = new (.*?)\(\).*?(__add \((.*?)\).+?)+.*?\}/is;
> print "\n";
> __END__
> > 
> >   In this string OP wants matches like n2, something, a, d  and n3,
> > something_else, x, y
> > 
> > Mine and OP's regex pattern matches n2, something, a and then n3,
> > something_else, x (ommitting d and y)
> 
> No they don't.  Your pattern finds:
> 
>   'n2', 'something', '__add (a);', 'a'

   Yes, that is my problem. I couldn't get it to match the next '__add
(d);', and 'd'
 
> Random shot in the dark: You want to be able to capture any number of
> __add() lines.  This is most simply done with two m// operators.  One
> to caputure everyting within the {...} and an other to capture the
> argument of each __add within that.
> 
> while ($str =~ /(\w+) = new (.*?)\(\)(.*?)\}/isg ) {
>     my @match = ($1,$2);
>     push @match, $3 =~ /__add \((.*?)\)/ig;
>     print join ', ', map "'$_'", @match;
>     print "\n";
> }
> 
> This gives:
> 
> 'n2', 'something', 'a', 'd'
> 'n3', 'somethinge_else', 'x', 'y'

   Yes, I understand, you're suggesting to use two patterns.
 
> I'm sure one could do it all in a single m// using (?{}) but that would
> make for hard to read/maintain code.

   Yes, that is what I was trying. I couldn't understand why a single
pattern didn't catch up all __add (). In the string __add () appears
two times, but my pattern didn't catch it.
  /(\w+) = new (.*?)\(\).*?(__add \((.*?)\).+?)+.*?\}/is
                           ^^^^^^^^^^^^^^^^^^^^
   As you see, I have used (__add \((.*?)\).+?)+  I have also tried
(__add \((.*?)\).+?)* and (__add \((.*?)\).+?)*?  It catches up only
if we used in a separate expression, but if we use it in
  /(\w+) = new (.*?)\(\).*?(__add \((.*?)\).+?)+.*?\}/is
                           ^^^^^^^^^^^^^^^^^^^^
   it doesn't work. I'm much puzzled here with this behavior.

   Many thanks for all your patience.


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

Date: 4 Jun 2004 08:33:45 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Regexp: Lazy match workaround?
Message-Id: <c9pc59$2h2$1@mamenchi.zrz.TU-Berlin.DE>

R. Rajesh Jeba Anbiah <ng4rrjanbiah@rediffmail.com> wrote in comp.lang.perl.misc:
> Brian McCauley <nobull@mail.com> wrote in message
> news:<u94qpsg9dc.fsf@wcl-l.bham.ac.uk>...

[...]

>    Yes, I understand, you're suggesting to use two patterns.
>  
> > I'm sure one could do it all in a single m// using (?{}) but that would
> > make for hard to read/maintain code.
> 
>    Yes, that is what I was trying. I couldn't understand why a single
> pattern didn't catch up all __add (). In the string __add () appears
> two times, but my pattern didn't catch it.
>   /(\w+) = new (.*?)\(\).*?(__add \((.*?)\).+?)+.*?\}/is
>                            ^^^^^^^^^^^^^^^^^^^^
>    As you see, I have used (__add \((.*?)\).+?)+  I have also tried
> (__add \((.*?)\).+?)* and (__add \((.*?)\).+?)*?  It catches up only
> if we used in a separate expression, but if we use it in
>   /(\w+) = new (.*?)\(\).*?(__add \((.*?)\).+?)+.*?\}/is
>                            ^^^^^^^^^^^^^^^^^^^^
>    it doesn't work. I'm much puzzled here with this behavior.

That's because the same pair of capturing parentheses matches both
occurrences of "__add ()".  In effect only the second match is captured.
In isolation this may be clearer:

    $_ = 'xxAxxB';
    no warnings 'uninitialized';
    print "match: \$1: |$1|, \$2: |$2|\n" if /(xx.)+/;
    print "match: \$1: |$1|, \$2: |$2|\n" if /(xx.)(xx.)/;

Anno


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

Date: 4 Jun 2004 02:17:52 -0700
From: spiritelllo@interfree.it (Andrea Spitaleri)
Subject: Re: sorting and resorting hash
Message-Id: <4de1519a.0406040117.2d9ae6be@posting.google.com>

Thanks for helping me! :-)
andrea


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

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


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