[22502] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4723 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 18 06:07:34 2003

Date: Tue, 18 Mar 2003 03:05:07 -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           Tue, 18 Mar 2003     Volume: 10 Number: 4723

Today's topics:
    Re: 'Wraping' die() (Anno Siegel)
    Re: Can I use session Variables in Perl <ynykon@lvivmedia.lviv.net>
    Re: CGI: how to clear form? <josef.moellers@fujitsu-siemens.com>
    Re: Determining String Membership <noreply@gunnar.cc>
    Re: Determining String Membership <goldbb2@earthlink.net>
    Re: Determining String Membership <nobody@dev.null>
    Re: Determining String Membership <noreply@gunnar.cc>
    Re: Determining String Membership (Anno Siegel)
    Re: Determining String Membership (Anno Siegel)
    Re: new Perl feature request: call into shared libs <para@tampabay.rr.com>
    Re: OLE Clipboard DisplayAlerts CLSID ProgID <wallus@results-hannover.de>
        Posting Guidelines for comp.lang.perl.misc ($Revision:  tadmc@augustmail.com
    Re: regex help <bwalton@rochester.rr.com>
    Re: regex help (Tad McClellan)
    Re: regex help <tore@aursand.no>
    Re: regex help (david)
    Re: splitting an array into two arrays <wksmith@optonline.net>
        use of uninitialized value (david)
    Re: use of uninitialized value (Anno Siegel)
    Re: Where to find DBD::CSV help? <happier_tj@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 18 Mar 2003 09:34:19 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: 'Wraping' die()
Message-Id: <b56p6r$81l$1@mamenchi.zrz.TU-Berlin.DE>

James Willmore <jwillmore@cyberia.com> wrote in comp.lang.perl.misc:
> > It sounds like you want to print an error message, and then die again,
> > or am I mistaken?
> > 
> > Your form is at least correct to override the sig handler.
> 
> I was afraid this would happen .... I sometimes have trouble putting
> into words what I'm thinking, so bear with me.
> 
> I wanted to have a signal handler in the package that would be used
> when errors occur within the package.  I would use Carp, but the
> requirements for the script that is soon to become a package don't
> allow me to use 'English' error messages.  Instead, if the script ends
> without error, a '0' is returned.  If there's an error, a '40' is
> returned.  I'd much rather use Carp and be done with it, but you know
> what they say about requirements :)
> 
> The real crux of the issue is when you use the package from within a
> script that already has a signal handler.  The package overrides the
> script's signal handler.  If I put the package's signal handler in a
> closure, the script's signal handler overrides the package's.
> 
> I guess the real question is ..... 
> Can two signal handlers co-exsist?

Yes, in a way.  You can save the previous handler when you install
yours and call the old one when yours is called.

Basically, there are two ways of doing this:  You can do your own
handling first and then &goto the previous handler, or you can call
the previous handler first (as a sub) and then do your own processing.
The first solution is preferable because it calls the old handler in
the same caller() context it would have been called without intervention.

However, since you want to die() in your handler, that isn't possible
here.  You must call a possible previous handler first:

    {
        my $old_handler;
        sub handler {
            &old_handler if ref $old_handler eq 'CODE';
            # your own processing here
        }
        sub install_handler {
            my( $sig, $handler) = @_;
            $old_handler = $SIG{ $sig};
            $SIG{ $sig} = $handler;
        }
    }

(Code untested)

The other question is if you actually want to preserve a previous
handler.  If *it* dies (which isn't unlikely) , your processing will
never happen.  If you want your processing to happen under all
circumstances and exclusively, unceremoniously overwrite the old handler.

You should also look into the possibility of overriding die() in
your package.

Anno


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

Date: Tue, 18 Mar 2003 10:44:56 +0200
From: Yurij Nykon <ynykon@lvivmedia.lviv.net>
Subject: Re: Can I use session Variables in Perl
Message-Id: <3E76DC88.4090605@lvivmedia.lviv.net>

Tore Aursand wrote:
> On Mon, 17 Mar 2003 17:56:47 +0200, Yurij Nykon wrote:
> 
>>what I need is to use some Session variables on my web-Project.
> 
> 
> Go to http://www.cpan.org/ and search for 'session'.
> 
> 

How can I install module CGI:Session on Windows OS?
Is this modul intended only for Apache Servers?

Thanx in anvance



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

Date: Tue, 18 Mar 2003 08:36:38 +0100
From: Josef =?iso-8859-1?Q?M=F6llers?= <josef.moellers@fujitsu-siemens.com>
Subject: Re: CGI: how to clear form?
Message-Id: <3E76CC86.9FA0F8D1@fujitsu-siemens.com>

Benjamin Goldberg wrote:
> =

> Josef M=F6llers wrote:
> [snip]
> > Unfortunately it doesn't seem to work. I just tried using the "Simple=

> > Script" example (the "eenie meenie minie moe" form) from the CGI
> > manpage and inserted
> >
> > my $query =3D new CGI;
> > $query->delete_all();
> >
> > right at the top but the reply page generated (the one with the
> > response below the ruler) still has the name in the entry field.
> >
> > Even if I change the
> >         textfield('name')
> > to any of
> >         textfield('name', "XXX")
> > or
> >         textfield(-name=3D>'name', -default=3D>'XXX',)
> >
> > it is still initialized with the value I inserted before.
> =

> This is because when you do textfield('name'), it is using the special
> internal $CGI::Q object, rather than your 'my $query' object.
> =

> Change your line at the top to:
> =

>    my $query =3D $CGI::Q ||=3D new CGI;
>    $query->delete_all();
> =

> And all should be well.

Tanks to both of you (Sharon and Benjamin). I've recoded the lot (sounds
impressing, but I was in the early stages, only about 40 LOC so far)
with object references:
my $query =3D new CGI;
=2E..
$query->delete_all()
=2E..
$query->textfield(...)

and now I can set it up as desired.

Josef
-- =

Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett


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

Date: Tue, 18 Mar 2003 03:12:04 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Determining String Membership
Message-Id: <b55viv$25uflm$1@ID-184292.news.dfncis.de>

Tad McClellan wrote:
> rymoore <member26707@dbforums.com> wrote:
>>I have an array of server names that is read in from a config file.
> 
>>I then need to search through a file and keep any lines that have these
>>server names in them.
> 
>    "How do I efficiently match many regular expressions at once?"

Is that method more efficient than the index() function?

/ Gunnar

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



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

Date: Mon, 17 Mar 2003 21:39:57 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Determining String Membership
Message-Id: <3E7686FD.3069F860@earthlink.net>

rymoore wrote:
> 
> I have a PERL dilema.
> 
> I have an array of server names that is read in from a config file.
> So I end up with an array like this.
> 
> @SERVERS = ("fred","barney","wilma");
> 
> I then need to search through a file and keep any lines that have
> these server names in them.
> 
> while(<FILE>) {
>            if (current line contains one of the server names) {
>                          print the line;
> }
> 
> I'm certain there is an simple way to do this but I can't put my
> thumb on it.

my $server_re = join("|", @SERVERS);
while( <FILE> ) {
   print if /$server_re/o;
}
__END__


-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: Tue, 18 Mar 2003 03:16:21 GMT
From: Andras Malatinszky <nobody@dev.null>
Subject: Re: Determining String Membership
Message-Id: <3E768F18.6060003@dev.null>



Gunnar Hjalmarsson wrote:

> Tad McClellan wrote:
> 
>> rymoore <member26707@dbforums.com> wrote:
>>
>>> I have an array of server names that is read in from a config file.
>>
>>
>>> I then need to search through a file and keep any lines that have these
>>> server names in them.
>>
>>
>>    "How do I efficiently match many regular expressions at once?"
> 
> 
> Is that method more efficient than the index() function?
> 
> / Gunnar
> 
More germanely, is the OP, who has demonstrated a considerable lack of cluefulness about Perl resources, going to realize that you are referring to a FAQ, and know that he can find the answer by visiting http://www.perl.com/pub/q/faqs?



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

Date: Tue, 18 Mar 2003 11:18:04 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Determining String Membership
Message-Id: <b56s42$268mkp$1@ID-184292.news.dfncis.de>

Andras Malatinszky wrote:
> Gunnar Hjalmarsson wrote:
>> Tad McClellan wrote:
>>>    "How do I efficiently match many regular expressions at once?"
>>
>> Is that method more efficient than the index() function?
> 
> More germanely, is the OP, who has demonstrated a considerable lack of 
> cluefulness about Perl resources, going to realize that you are 
> referring to a FAQ, and know that he can find the answer by visiting 
> http://www.perl.com/pub/q/faqs?

Sure, it's a standard problem, the FAQ and docs provides adequate help, 
and the OP should be so advised. That's one thing.

But irrespective of that, since all the suggestions but mine include the 
use of regexp patterns, I'd be interested in comments on which of regexp 
patterns and the index() function is the most efficient approach in this 
particular case.

/ Gunnar

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



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

Date: 18 Mar 2003 10:36:03 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Determining String Membership
Message-Id: <b56sqj$9u1$1@mamenchi.zrz.TU-Berlin.DE>

Walter Roberson <roberson@ibd.nrc-cnrc.gc.ca> wrote in comp.lang.perl.misc:
> In article <2653596.1047941479@dbforums.com>,
> rymoore  <member26707@dbforums.com> wrote:
> :I have an array of server names that is read in from a config file.
> :So I end up with an array like this.
> 
> :@SERVERS = ("fred","barney","wilma");
> 
> :I then need to search through a file and keep any lines that have these
> :server names in them.
> 
> :while(<FILE>) {
> :           if (current line contains one of the server names) {
> :                         print the line;
> :}
> 
> one approach:
> 
> $pattern = join '|', @SERVERS;

Make that

    $pattern = join '|', map quotemeta, @SERVERS;

> 
> print (($_ =~ m/$pattern/o) ? $_ : '') foreach <FILE>;

That calls print with an empty string for each non-match.  Also,
"foreach <FILE>" reads the whole file into memory.  Both are
unnecessary:

    /$pattern/o and print while <FILE>;

Anno


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

Date: 18 Mar 2003 10:50:52 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Determining String Membership
Message-Id: <b56tmc$9u1$2@mamenchi.zrz.TU-Berlin.DE>

Gunnar Hjalmarsson  <noreply@gunnar.cc> wrote in comp.lang.perl.misc:
> Andras Malatinszky wrote:
> > Gunnar Hjalmarsson wrote:
> >> Tad McClellan wrote:
> >>>    "How do I efficiently match many regular expressions at once?"
> >>
> >> Is that method more efficient than the index() function?
> > 
> > More germanely, is the OP, who has demonstrated a considerable lack of 
> > cluefulness about Perl resources, going to realize that you are 
> > referring to a FAQ, and know that he can find the answer by visiting 
> > http://www.perl.com/pub/q/faqs?
> 
> Sure, it's a standard problem, the FAQ and docs provides adequate help, 
> and the OP should be so advised. That's one thing.
> 
> But irrespective of that, since all the suggestions but mine include the 
> use of regexp patterns, I'd be interested in comments on which of regexp 
> patterns and the index() function is the most efficient approach in this 
> particular case.

I suspect neither, once you allow the hash approach to the contest.

Anno


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

Date: Tue, 18 Mar 2003 05:37:40 GMT
From: "Matt Taylor" <para@tampabay.rr.com>
Subject: Re: new Perl feature request: call into shared libs
Message-Id: <Egyda.84612$lW3.3144455@twister.tampabay.rr.com>

"Ilya Zakharevich" <nospam-abuse@ilyaz.org> wrote in message
news:b55jlj$30cn$1@agate.berkeley.edu...
> [A complimentary Cc of this posting was sent to
> Matt Taylor
> <para@tampabay.rr.com>], who wrote in article
<v9gca.58137$lW3.2011891@twister.tampabay.rr.com>:
> > > > > Actually, one could also duplicate the last min(3, num_params)
> > > > > arguments in EAX, EDX, ECX.  This way the same code could call
> > > > > __regparam__(3) functions too.
> > >
> > > > Why not have the calling convention used as a parameter?
> > >
> > > What for - if one can avoid it?
> >
> > The premise is not valid. That is, you can't avoid it.
>
> See above recipe; which translates the calling convention into
> reordering of arguments.

Convention is more than reordering of arguments.

> > > > I don't see why you would try to satisfy all schemes with one
> > > > function.
> > >
> > > Why not - if this is easy to do?  Change 3 to 6 above, and duplicate
> > > the last 6 arguments in 6 standard registers; then providing arguments
> > > to the wrapper function in a "correct" order will satisfy any "input"
> > > calling convention.
> >
> > Last I checked GCC did not support __regparm__(6) on x86. That was GCC
2.x.
> > It may be supported in GCC 3.x, but I doubt it. Most industrial-strength
> > compilers do not support more than 3 registers for a register call
scheme
> > for 2 reasons:
>
> When I checked it circa 10 years ago, Watcom allowed (more or less?)
> arbitrary calling conventions (by #pragmas).

And still does. It's not heavily used anymore, though.

> > 1. eax, ecx, and edx are typically not preserved
> > 2. More than 3 often results in register spill anyway since esp never
gets
> > used for computation except in lame hand-coded assembly. (Unreal
Tournament
> > actually did this.)
>
> I was planning to do this last week; turned out that I could simplify
> the algorithm so that even gcc 2.8.1 could fit everything into
> registers - without any assembler.  Deep sigh...
>
> > Also, you can't simply "duplicate" parameters and expect it to work.
They
> > exist in one place, and it's either in a register or on the stack.
>
> ???  Since the callee does not care about extra values on stack, and
> extra values in registers, your arguments is not only wrong, it also
> makes no sense.  ;-) To call a function which expects the argument A
> on stack, and B in %esi, you call the interface as

This is not always true. In "standard" Windows convention, the callee cleans
the stack. The asm code I posted worked regardless of callee or caller
cleaning the stack.

>   my $n_a = 0; # place holder
>   call_params($function, $A, $B, ($n_a) x 5);
>
> (here I assume that the 6th argument from the end is duplicated in
> %esi).  Rearranging $A, $B, and $n_a, one can satisfy all the input
> calling conventions (which preserve a given register, e.g., %ebp).

If the first argument went in esi, this would not work. The function would
see the second argument as A, the third as B, etc. I've never seen arguments
passed -both- on the stack and in a register on x86. They are mutually
exclusive. You have to know which parameters go where or you screw up the
stack.

Since you don't mind forcing the user to describe the calling convention,
you can still do it the x86_context way. The user has to know where
everything goes, though. You could further wrap a specific convention so
that it sets up the regs appropriately and then passes the remaining
parameters on the stack. You still need to worry about how structures and
real numbers are passed, and offhand I do know very little about conventions
for either.

-Matt




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

Date: Tue, 18 Mar 2003 09:17:24 +0100
From: Harald wallus <wallus@results-hannover.de>
Subject: Re: OLE Clipboard DisplayAlerts CLSID ProgID
Message-Id: <lik65b.6nq.ln@mail.results-hannover.de>

Chris Lowth wrote:
> Harald wallus wrote:
> 
> 
>>Dears,
>>
>>since two month I working with the OLE Module and Excel. And it works
>>fine. But there is one problem and I have one more question.
>>Cut out from program:
>>   $Win32::OLE::Warn = 3;    # die on errors...
>>   my $Excel = Win32::OLE->GetActiveObject('Excel.Application')
>>     || Win32::OLE->new('Excel.Application', 'Quit');
>>   $Allset = $Excel->Workbooks->Open($tplf); # open Excel file
>>   $AllSheetset = $Allset->Worksheets($usesheet);
>>
>>   $Bookset = $Excel->Workbooks->Open($fullname); # open Excel file
>>   $Sheetset = $Bookset->Worksheets($usesheet);
>>   $Sheetset->Activate();   #Rows("4:4").Select ;Selection.Copy
>>   $Sheetset->Rows("10:10")->Select();
>>   $Sheetset->Rows("10:10")->Copy();   $AllSheetset->Activate();
>>   $AllSheetset->Range("$outline")->Select();#outline is +=1 for each
>>Sheetset.
>>   $AllSheetset->Paste();
>>   $Sheetset->Activate();
>>    ##Excel->Workbooks(2)->Application->DisplayAlerts=>"False";
>>   $Bookset->Close;
>>   undef $Bookset;
>>Yes, it copies lines from one workbook (Sheetset)  to another one
>>(AllSheetset).
>>The problem:
>>After I close the the Sheetset to open the next one, I got a Alert
>>message from clippboard: If I want save the content of the clipboard.
>>When I look at VBA,it is possible to switch off this alert:
>>    Application.DisplayAlerts="False"
>>But this is not an Excel-method, isn't it?
>>The commented line in my program above does not work.
>>How can I set this DisplayAlert?
>>Now my question:
>>I think above I have to call the method Win32::OLE->GetActiveObject
>>with the clipboard to use it.
>>When I use OLE-Browser I see some more Object, which I like to use.
>>How could I retrieve the prog ID for the GetActiveObject-method
>>or how I can determine the classID.
>>I read that to register an Application is to do with
>>regedt32 /i   <dll-name of application>.
>>Is there somewhere a more detial explanation of this stuff?
>>
>>Thanx.
> 
> 
> Not sure about quenching the warning, but I suspect your logic is flawed. 
> The windows clipboard is a global resource, and your code could be broken 
> by the user interacting with another program while your script is running, 
> thus replacing the clipboard contents at the crucial moment. You have built 
> a "race condition" exploit into your software.
> 
> I would suggest finding another way to do it without the clipboard.
> 
> Chris
Thats right,
till the program runs, no one is allowed to use Excel. But this is a 
problem in Excel itself and occurs in the same way if I use VBA. E.G. 
you run a macro which needs more time, if you then click into excel the 
macro goes wrong.
This problem is pointed out from microsoft too.
But I found some things to the CLSID-Problem:
In registry:
HKEY_CLASSES_ROOT\CSLID\{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} we have a 
name Standard, in which is definded the ProgID.
The Number in {}-brackets is the CLSID
This key have a subnode called ProgID, in which once again the ProgID is 
called.
But the problem with the clipboard  I don't have solved.

Harald



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

Date: Tue, 18 Mar 2003 02:22:04 -0600
From: tadmc@augustmail.com
Subject: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.4 $)
Message-Id: <n_KcnWYEF7qxSuujXTWc3Q@august.net>

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

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

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

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

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

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

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

    A note to newsgroup "regulars":

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

    A note about technical terms used here:

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

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

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

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

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

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

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

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

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

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

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

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

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

        One such searchable archive is:

         http://groups.google.com/advanced_group_search

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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



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

Date: Tue, 18 Mar 2003 02:54:49 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: regex help
Message-Id: <3E7689EF.4050205@rochester.rr.com>

david wrote:

> I am trying to hammer out a regex to search to the value S/N: (\w+)
> that could happen anywhere in field 7 of my data. My original data
> file has fields seperated by commas, EXCEPT for field 7, which is
> seperated by spaces from what I can tell. There can be many different
> values in this field, but what I am interested in is anything matching
> {S/N:\s(\w+)}. Any suggestions on making this a workable regex?


What is it about that regex which you think is not workable?  It looks 
it would do the job you describe just fine.


> 
> 
> So it looks something like this:
> 
> dlepage,engineering,mn,field4,field5,field6, some random S/N: A12345
> data,field8
> 
> while ( <FILE> ) {
>         # Split fields by comma


You might want a chomp; in here if you don't what the newline to become 
part of the last field.


>         my @fields = split ( /,/ );
>         # Grab token serial number from Comments field
>         if ( $fields[7] =~ m{^\$\$S\/N:(\w+)} ) {

6----------------------^

The seventh field is subscript 6, assuming you didn't muck with $[ .  I 
don't know why the regex here is anchored, has a leading $$ in it, and 
is missing the space character between the : and the first \w .  The 
regex you had above should match your example data no problem.


>                 my $tok = '$$' . $1 . '$$';
>                 my $subtok = $1;
 ...

-- 
Bob Walton



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

Date: Mon, 17 Mar 2003 20:56:52 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: regex help
Message-Id: <slrnb7d2nk.5ag.tadmc@magna.augustmail.com>

david <dwlepage@yahoo.com> wrote:

> I am trying to hammer out a regex to search to the value S/N: (\w+)
                                                               ^
                                                               ^
There is a space there...


>         if ( $fields[7] =~ m{^\$\$S\/N:(\w+)} ) {
                                        ^^
                                        ^^

 ...your pattern does not allow a space there.


Why is the anchor in the pattern?

Why are the dollar signs in the pattern?

Your word description did not say anything about dollar signs,
nor where in the string the S/N was supposed to occur.


Please consider posting a complete program that illustrates your
problem, as suggested in the Posting Guidelines.


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


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

Date: Tue, 18 Mar 2003 06:13:36 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: regex help
Message-Id: <pan.2003.03.18.04.44.02.378585@aursand.no>

On Mon, 17 Mar 2003 17:23:57 -0800, david wrote:
> while ( <FILE> ) {
>         # Split fields by comma
>         my @fields = split ( /,/ );
>         # Grab token serial number from Comments field
>         if ( $fields[7] =~ m{^\$\$S\/N:(\w+)} ) {
>                 my $tok = '$$' . $1 . '$$';
>                 my $subtok = $1;

Your regular expression doesn't allow whitespace after 'S/N:', so it won't
match.  In addition, what are those $ characters doing there?

  while ( <FILE> ) {
      chomp;
      my @fields = split( /\Q,\E/ );
      if ( $fields[7] =~ m,^S/N: (\w+), ) {
          # voilá
      }
  }


-- 
Tore Aursand <tore@aursand.no>


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

Date: 17 Mar 2003 22:10:49 -0800
From: dwlepage@yahoo.com (david)
Subject: Re: regex help
Message-Id: <b09a22ae.0303172210.30ddc6b8@posting.google.com>

tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnb7d2nk.5ag.tadmc@magna.augustmail.com>...
> david <dwlepage@yahoo.com> wrote:
> 
> > I am trying to hammer out a regex to search to the value S/N: (\w+)
>                                                                ^
>                                                                ^
> There is a space there...
> 
> 
> >         if ( $fields[7] =~ m{^\$\$S\/N:(\w+)} ) {
>                                         ^^
>                                         ^^
> 
> ...your pattern does not allow a space there.
> 
> 
> Why is the anchor in the pattern?
> 
> Why are the dollar signs in the pattern?
> 
> Your word description did not say anything about dollar signs,
> nor where in the string the S/N was supposed to occur.
> 
> 
> Please consider posting a complete program that illustrates your
> problem, as suggested in the Posting Guidelines.

That was a silly question. Removing the anchor and making the regex:
m/S\/N:\s(\w+)/ seems to work when S/N: is anywhere in the field. That
was the other part of the problem. I was thinking AWK and starting
counting from 1..
 Thanks for the suggestions.


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

Date: Tue, 18 Mar 2003 03:59:33 GMT
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: splitting an array into two arrays
Message-Id: <FQwda.122871$b8.18229536@news4.srv.hcvlny.cv.net>


"David K. Wall" <usenet@dwall.fastmail.fm> wrote in message
news:Xns9341A8D9D9D59dkwwashere@216.168.3.30...
> Bill Smith <wksmith@optonline.net> wrote on 17 Mar 2003:
>
> > "David K. Wall" <usenet@dwall.fastmail.fm> wrote in message
> > news:Xns93417A4BC8BE4dkwwashere@216.168.3.30...
> >>
> >> The purpose of this snippet of code is to split an array into
halves.
> > If
> >> there are an odd number of elements, the first array should be the
> >> largest, e.g.; an array with 9 elements should be split into arrays
> > with 5
> >> and 4 elements.
> >>
> >> my @full_array = 1..9;
> >> my @second = @full_array;
> >> ###my @first = splice @second, 0, int(scalar(@second)/2 + 0.8);
> >> my @first = splice @second, 0, ceil(@second/2);
> >
> > Your approach is not correct for an even number of elements.
> > The function ceil (available in the POSIX module) always does the
> > 'rounding' correctly.  For details on the difference,
> > refer to perldoc -f int .
>
> Sure it is.  While it's not the most elegant approach possible**, it
> produces correct results.  Run it and see, or just look below.
>
> ** (I only picked 0.8 because I was in a hurry and didn't want to
worry
> about how the computer represented the number.  Any x where
> 0.5 <= x < 1.0 would work, since 0.5 has an exact representation in
> binary.)
>
>
> Let n be a positive integer.
>
> Array with even length of 2n
> splice() will return int( 2n/2 + 0.8 ) = int( n + 0.8 ) = n elements
>
> Array with odd length of 2n+1
> splice will return int( (2n+1)/2 + 0.8 ) = int(n + 0.5 + 0.8)
>     = int(n + 1.3) = n+1 elements
>
> Just what I wanted.
>
Sorry for the criticism, I must have read the document for int with
my eyeballs out of calibration.  I still prefer ceil because it does
exactly
what you want in any numerical representation without the bias term.

Bill




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

Date: 18 Mar 2003 00:42:49 -0800
From: dwlepage@yahoo.com (david)
Subject: use of uninitialized value
Message-Id: <b09a22ae.0303180042.12ce1839@posting.google.com>

I am continuously getting a message "Use of uninitialized value in
pattern match (m//) at test.pl line 15, <FILE> line 2130." This
happens for every line parsed by my script. I have tried this on
several deffernt data files and the strange this is that it doesn't
happen when I parse against all of them, only some. I have looked at
older postings and searched around and it appears it must have
something to do with the way I am using the m/ operator in my if
block. The script does appear to run normally, but if I am doing
something that is deprecated or not a good practice, could someone
please point it out?
Here is what I have:

#!/usr/bin/perl -w
use strict;

my (%records, @import);

open (FILE, "<Newimport") || die "Couldn't open file; $!\n";
open (OUT, ">output.dat") || die "Couldn't create file; $!\n";
open (REJECTS, ">rejects.dat") || die "$!\n";
open (NEWOUT, ">newout.dat") || die "Couldn't create; $!\n";

while ( <FILE> ) {
        # Split fields by comma
          my @fields = split ( /,/ );
        # Grab token serial number from Comments field if exists
                if (!($fields[8] =~ m/S\/N:\s(\w+)/ )) {
                        print REJECTS;
                }
                elsif ($_ =~ m/37\,00000000/) {
                        print REJECTS;
                }
                else
                {
                        my $tok = '$$' . $1 . '$$';

                                # Create lexical var in token for LDIF
                                (my $subtok = $tok) =~ s/\$\$//g;

                                # Create lexical var in User for LDIF
                                (my $user = $fields[2]) =~ s/\$\$//g;
      
                                # Create lexical var in Comments for
LDIF
                                (my $comment = $fields[8]) =~
s/\$\$//g;

                                  #Switch fields                      
                                                                  
print $comment;
                 ( $fields[2], $tok ) = ( $tok, $fields[2] );

                 # Push records back into 5.2 import file
                   push (@import, join (',', @fields));

                 #  Hash for token and username
                   $records{$subtok} = $user;

# Print out ldif
print NEWOUT <<LDIF;
dn: UserId=$user
Number: $subtok
Comment: $comment
LDIF

        }
}
#while ( ($key,$value ) = each %records ) {
#        print OUT "$key --> $value\n"
#}

print OUT @import;
 
close(FILE);
close (OUT);
close (NEWOUT);

thanks for the help.


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

Date: 18 Mar 2003 09:04:20 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: use of uninitialized value
Message-Id: <b56nek$6h5$1@mamenchi.zrz.TU-Berlin.DE>

david <dwlepage@yahoo.com> wrote in comp.lang.perl.misc:
> I am continuously getting a message "Use of uninitialized value in
> pattern match (m//) at test.pl line 15, <FILE> line 2130." This

Line s 13-15 are

           my @fields = split ( /,/ );
         # Grab token serial number from Comments field if exists
                 if (!($fields[8] =~ m/S\/N:\s(\w+)/ )) {

You would have done us all a favor if you had identified the critical
line instead of letting everyone count.

Obviously, $fields[8] is undefined because some input lines don't
have enough comma-delimited fields.

> happens for every line parsed by my script. I have tried this on
> several deffernt data files and the strange this is that it doesn't
> happen when I parse against all of them, only some.

Some have eight or more fields per line, others don't.

>                                                      I have looked at
> older postings and searched around and it appears it must have

You should have looked at the error message and your script.

[...]

Anno


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

Date: Tue, 18 Mar 2003 13:36:02 +0800
From: "James Hou" <happier_tj@hotmail.com>
Subject: Re: Where to find DBD::CSV help?
Message-Id: <b56b99$2m7s$1@mail.cn99.com>

oh,Thank  you for your kindly help!

James hou


"Tore Aursand" <tore@aursand.no>
??????:pan.2003.03.17.14.00.11.532268@aursand.no...
> On Mon, 17 Mar 2003 18:01:12 +0800, James Hou wrote:
> > I searched the document about DBD::CSV in www.cpan.org, but I found it
> > is too simple. I don't know how can I open a CSV file and retire data
> > form it.
>
> That is actually explained with a few examples in the DBD::CSV
> documentation, so I expect that you didn't read it good enough;
>
>   my $dbh = DBI->connect('DBI:CSV:csv_sep_char=,');
>   $dbh->{'csv_tables'}->{'users'} = { 'file' => 'users.csv' };
>   my $stUsers = $dbh->prepare('SELECT * FROM user');
>
>
> --
> Tore Aursand <tore@aursand.no>




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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 4723
***************************************


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