[23004] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5224 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 15 06:06:03 2003

Date: Tue, 15 Jul 2003 03: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, 15 Jul 2003     Volume: 10 Number: 5224

Today's topics:
    Re: assigning alternativ value if a regular expression  <Rocco.Melzian@TU-Berlin.de>
        calling system command as another user <yukky##@somewhere.com.au>
    Re: calling system command as another user <yukky##@somewhere.com.au>
    Re: calling system command as another user <yukky##@somewhere.com.au>
    Re: calling system command as another user <yukky##@somewhere.com.au>
    Re: combinatorics, scripts for (Chris Charley)
        Designing Interfaces with Perl and Perl APIs <slepetys@homeworks.com.br>
    Re: Help with Fileman V-1, File Manager <angel2@ShirT.com>
        Perl 5.004 bug <moliverius@w-link.net>
    Re: Perl 5.004 bug <mgjv@tradingpost.com.au>
        Posting Guidelines for comp.lang.perl.misc ($Revision:  tadmc@augustmail.com
    Re: Regex question... <bart.lateur@pandora.be>
    Re: safe cgi programming in perl? <me@home.com>
    Re: safe cgi programming in perl? <me@home.com>
    Re: script for unrestricted permutation (Chris Charley)
        sprintf help <moliverius@w-link.net>
    Re: testing for array or scalar in a hash. <bart.lateur@pandora.be>
        text parse (david)
    Re: TOO SLOW:     `echo ${LINE} | sed -n 's/^.* proto / <btd.heck@t-online.de>
    Re: Translation with PERL? <bart.lateur@pandora.be>
        Use module (maybe) w/o dying <jaspax@u.washington.edu>
    Re: Use module (maybe) w/o dying (Sam Holden)
    Re: Win32-OLE where's the info? <spikey-wan@bigfoot.com>
        Win32::OLE, Excel and OLE Automation question (Domenico Discepola)
    Re: Win32::OLE, Excel and OLE Automation question <asu1@c-o-r-n-e-l-l.edu>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 15 Jul 2003 09:45:42 +0200
From: Rocco Melzian <Rocco.Melzian@TU-Berlin.de>
Subject: Re: assigning alternativ value if a regular expression has failed
Message-Id: <bf0b7g$k6f$1@mamenchi.zrz.TU-Berlin.DE>



LaDainian Tomlinson wrote:
> "Rocco Melzian" wrote:
> 
>>I am using regular expressions to filter words and numbers from $_ and
>>assign them to $1 and $2 for further use
>>
>>$_ =~ m/(.*?)(-{0,1}\d+)$/;
> 
> 
> To make things a little simpler, the m// operator operates on $_ by default,
> the 'm' is not required if you are using forward slashes as delimiters, and
> the {0,1} construct is exactly the same as '?' in that context.  So your
> line is equivalent to:
> 
> /(.*?)(-?\d+)$/;
> 
> Check up on perlop under "Regexp Quote-Like Operators" for info on m// and
> perlre for info on regular expressions.
> 
> 
>>How can I assign an alternative value to $1 and $2 if the regular
>>expression failed? (sometimes no there is no input, so I want to record
>>a failure message)
> 
> 
> In scalar context, m// also returns true if the match succeeds and false if
> it doesn't.
> 
> if (/(.*?)(-?\d+)$/){
>     $word = $1;
>     $number = $2;
> } else {
>     print "Match failed.";
> }
> 
> 
>>How cann I check whether a $scalar exists or not? Is there something
>>like the "hash exists-function"? Thanks for helping me.
> 
> 
> You can try defined().  But most of the regexp operators will give you an
> easy way to check if (or how many times) the match succeeded, so you
> shouldn't really need to check whether the $n variables are defined, since
> that may also give you unexpected results based on an earlier match.
> 
> Hope that helps,
> 
Thank you very much. I will work out how I can check the regexp return 
values. Meanwhile I use the if-method. Cheers.

Rocco



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

Date: Tue, 15 Jul 2003 11:37:13 +0800
From: "Gary Perkins" <yukky##@somewhere.com.au>
Subject: calling system command as another user
Message-Id: <3f1376e7$0$95050$c30e37c6@lon-reader.news.telstra.net>

Howdy People,

I am not a Perl guy and have to make some code work.  We have a password
reset facility that is Perl cgi based and simply generates a password,
writes it to an email and the passwd.txt file for the system we run.  This
all works great except we then need to call a command to relod the password
file but as another user.

I have
my $reloadcmd = "su - ariba -c
\"/u01/app/AribaBuyer7/CoreServer/serverMonitor -host buy_test -username
aribasystem -password password -runTask ReloadPasswordFile -partition
wespar\"";

$reloadcmd =~ s/[\n]|[\r]//gi;

system($reloadcmd);


It doesnt appear to work at all.  Have I escaped the quotes incorrectly, I
logged it to a text file and the command is coming out OK....I think?

The actual command that I know works is;
/u01/app/AribaBuyer7/CoreServer/serverMonitor -host buy_test -username
aribasystem -password password -runTask ReloadPasswordFile -partition wespar

Thanks
Gary




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

Date: Tue, 15 Jul 2003 13:41:40 +0800
From: "Gary Perkins" <yukky##@somewhere.com.au>
Subject: Re: calling system command as another user
Message-Id: <3f139411$0$95043$c30e37c6@lon-reader.news.telstra.net>

This works when I run it as a stand alone perl script just not when called
via CGI??

Cheers
Gary
"Gary Perkins" <yukky##@somewhere.com.au> wrote in message
news:3f1376e7$0$95050$c30e37c6@lon-reader.news.telstra.net...
> Howdy People,
>
> I am not a Perl guy and have to make some code work.  We have a password
> reset facility that is Perl cgi based and simply generates a password,
> writes it to an email and the passwd.txt file for the system we run.  This
> all works great except we then need to call a command to relod the
password
> file but as another user.
>
> I have
> my $reloadcmd = "su - ariba -c
> \"/u01/app/AribaBuyer7/CoreServer/serverMonitor -host buy_test -username
> aribasystem -password password -runTask ReloadPasswordFile -partition
> wespar\"";
>
> $reloadcmd =~ s/[\n]|[\r]//gi;
>
> system($reloadcmd);
>
>
> It doesnt appear to work at all.  Have I escaped the quotes incorrectly, I
> logged it to a text file and the command is coming out OK....I think?
>
> The actual command that I know works is;
> /u01/app/AribaBuyer7/CoreServer/serverMonitor -host buy_test -username
> aribasystem -password password -runTask ReloadPasswordFile -partition
wespar
>
> Thanks
> Gary
>
>




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

Date: Tue, 15 Jul 2003 15:14:35 +0800
From: "Gary Perkins" <yukky##@somewhere.com.au>
Subject: Re: calling system command as another user
Message-Id: <3f13a9d8$0$95051$c30e37c6@lon-reader.news.telstra.net>

More info....

This works...system("ls -l >> $logfile");

but this doesnt system("su - username -c \"ls -l >> $logfile\"");

The script is been called from iPlanet and nothing gets logged in the errors
file when it doesnt work, it like the command gets passed over.



Thanks heaps
Gary

"Gary Perkins" <yukky##@somewhere.com.au> wrote in message
news:3f139411$0$95043$c30e37c6@lon-reader.news.telstra.net...
> This works when I run it as a stand alone perl script just not when called
> via CGI??
>
> Cheers
> Gary
> "Gary Perkins" <yukky##@somewhere.com.au> wrote in message
> news:3f1376e7$0$95050$c30e37c6@lon-reader.news.telstra.net...
> > Howdy People,
> >
> > I am not a Perl guy and have to make some code work.  We have a password
> > reset facility that is Perl cgi based and simply generates a password,
> > writes it to an email and the passwd.txt file for the system we run.
This
> > all works great except we then need to call a command to relod the
> password
> > file but as another user.
> >
> > I have
> > my $reloadcmd = "su - ariba -c
> > \"/u01/app/AribaBuyer7/CoreServer/serverMonitor -host buy_test -username
> > aribasystem -password password -runTask ReloadPasswordFile -partition
> > wespar\"";
> >
> > $reloadcmd =~ s/[\n]|[\r]//gi;
> >
> > system($reloadcmd);
> >
> >
> > It doesnt appear to work at all.  Have I escaped the quotes incorrectly,
I
> > logged it to a text file and the command is coming out OK....I think?
> >
> > The actual command that I know works is;
> > /u01/app/AribaBuyer7/CoreServer/serverMonitor -host buy_test -username
> > aribasystem -password password -runTask ReloadPasswordFile -partition
> wespar
> >
> > Thanks
> > Gary
> >
> >
>
>




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

Date: Tue, 15 Jul 2003 15:38:15 +0800
From: "Gary Perkins" <yukky##@somewhere.com.au>
Subject: Re: calling system command as another user
Message-Id: <3f13af64$0$95045$c30e37c6@lon-reader.news.telstra.net>

If I dont use the su- for my command it actually works but doesnt return.
The web page just hangs and eventually times out.

Sorry for the multipart post but I keep trying things.

Cheers
Gary
"Gary Perkins" <yukky##@somewhere.com.au> wrote in message
news:3f13a9d8$0$95051$c30e37c6@lon-reader.news.telstra.net...
> More info....
>
> This works...system("ls -l >> $logfile");
>
> but this doesnt system("su - username -c \"ls -l >> $logfile\"");
>
> The script is been called from iPlanet and nothing gets logged in the
errors
> file when it doesnt work, it like the command gets passed over.
>
>
>
> Thanks heaps
> Gary
>
> "Gary Perkins" <yukky##@somewhere.com.au> wrote in message
> news:3f139411$0$95043$c30e37c6@lon-reader.news.telstra.net...
> > This works when I run it as a stand alone perl script just not when
called
> > via CGI??
> >
> > Cheers
> > Gary
> > "Gary Perkins" <yukky##@somewhere.com.au> wrote in message
> > news:3f1376e7$0$95050$c30e37c6@lon-reader.news.telstra.net...
> > > Howdy People,
> > >
> > > I am not a Perl guy and have to make some code work.  We have a
password
> > > reset facility that is Perl cgi based and simply generates a password,
> > > writes it to an email and the passwd.txt file for the system we run.
> This
> > > all works great except we then need to call a command to relod the
> > password
> > > file but as another user.
> > >
> > > I have
> > > my $reloadcmd = "su - ariba -c
> > > \"/u01/app/AribaBuyer7/CoreServer/serverMonitor -host
buy_test -username
> > > aribasystem -password password -runTask ReloadPasswordFile -partition
> > > wespar\"";
> > >
> > > $reloadcmd =~ s/[\n]|[\r]//gi;
> > >
> > > system($reloadcmd);
> > >
> > >
> > > It doesnt appear to work at all.  Have I escaped the quotes
incorrectly,
> I
> > > logged it to a text file and the command is coming out OK....I think?
> > >
> > > The actual command that I know works is;
> > > /u01/app/AribaBuyer7/CoreServer/serverMonitor -host buy_test -username
> > > aribasystem -password password -runTask ReloadPasswordFile -partition
> > wespar
> > >
> > > Thanks
> > > Gary
> > >
> > >
> >
> >
>
>




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

Date: 14 Jul 2003 15:25:31 -0700
From: charley@pulsenet.com (Chris Charley)
Subject: Re: combinatorics, scripts for
Message-Id: <4f7ed6d.0307141425.7647cfde@posting.google.com>

Harald Weber <weberh@zedat.fu-berlin.de> wrote in message news:<weberh-F72F57.09503314072003@news.fu-berlin.de>...
> Hi !

[snip]

> Maybe youıd like to work out better solutions.
> Iım sure itıs easy for you to write more stylish code, 
> but it shouldnıt be much slower than this one.
> Hopefully this posting is somehow helpful
> (give me a hint: is this too much code for a posting ?!).
>  
> Harald
> 

Hi Harald,

Just a suggestion! I hope I am correct when I say that to have more
useful functions, a good programmer in general will return a array of
numbers, a string or an array of strings. That way, if you only want
to print the results of the permutation method used, you can just
iterate over the returned array - same if you want to do any sort of
manipulation. But when the print operator is inside the function,
thats the only operation being performed. In other words, in this
case, to return an array of all permutations is more flexible. I
learned this point from M-J. Dominus's web site -
http://perl.plover.com/.  :-)

HTH

--
Chris Charley


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

Date: Mon, 14 Jul 2003 22:47:47 -0300
From: "Roberto Slepetys" <slepetys@homeworks.com.br>
Subject: Designing Interfaces with Perl and Perl APIs
Message-Id: <bevlr0$9ci7r$1@ID-193173.news.uni-berlin.de>

Hi,

I am a long date perl programmer, and from time to time, I am having the
same trouble:

- To design interfaces for a self contained application under M$ Windows.

Our solution is to use some Borland Tool and Programer language with
integrated User Interface Tool and API, like Delphi or Java.

But, I really love PERL, and I am looking for some programing API (other
than Tck) that gives me all the simplicity in designing the user interface
of Borland Delphi, with the power and simplicity of Perl, maybe, some
compiler glue that allows me to program the API in Delphi/Pascal, but gives
me the power of perl behind the scenes...

Is this a dream ?

[]s
Slepetys

comp.lang.perl.misc




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

Date: 14 Jul 2003 22:39:46 GMT
From: Angel <angel2@ShirT.com>
Subject: Re: Help with Fileman V-1, File Manager
Message-Id: <Xns93B8BDD89F8F6smakyou33msnhardhitt@129.250.170.82>

It's cgi.

Sorry, I have obviously made an erronous mistake. Please ignore my 
request for help. Thank you.

Angel


Eric Schwartz <emschwar@pobox.com> posted this mush in
news:etoptkcg4p2.fsf@wormtongue.emschwar: 

> Angel <angel2@ShirT.com> writes:
>> I uploaded and changed permissions for the file manager mentioned on
>> the subject line.
> 
> I've never heard of it.  Is it GTK-based?  Qt?  Curses?  *gack* *spit*
> CGI?  How can you expect anyone to comment on something that's
> brand-new to them?  ESR has a fairly helpful page on How To Ask
> Questions the Smart Way at his website:
> 
> <URL:http://www.catb.org/~esr/faqs/smart-questions.html>
> 
> I strongly urge you to read it over.
> 



Remove "ShirT" to reply.
-- 
Archives for the Walrus Contest
http://WeeklyWalrus.com

Weekly Walrus Contest entries and rules
http://web.newsguy.com/evilsideshowbob/index.html


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

Date: Mon, 14 Jul 2003 18:36:09 -0400
From: Matt Oliverius <moliverius@w-link.net>
Subject: Perl 5.004 bug
Message-Id: <vh6lnfsabrd711@corp.supernews.com>

Can someone give me some guidance as to why the following code does not 
work in Perl 5.004, but does work in version 5.6? Note, the output below is 
produced from a cat -n on the actual file so the line numbers are not part 
of the actual program. 

I'm getting syntax errors on line 31 and 34 presumably from the for 
@buckets syntax.  In addition, the sprintf command on line 27 doesn't 
appear to be working correctly.  Is there something wrong with Perl 5.004 
that would prevent the binary conversion?  Can someone help me modify this 
so that it will work with version 5.004.  Thanks a bunch.

Matt



    1   #!/usr/bin/perl
     2  
     3  use warnings;
     4  use strict;
     5  my %hash;
     6  
     7  while (<>){
     8  
     9     my($bucket, $capacity) = (split)[1,2];
    10  
    11     {
    12  
    13     no warnings 'numeric';
    14  
    15        $bucket +=0;
    16     }
    17     push @{$hash{$bucket}{$capacity}}, $_;
    18  }
    19  my @buckets = sort keys %hash;
    20  
    21  PERM:
    22  for(0 .. (1<<@buckets)-1){
    23  
    24  my %caps;
    25  @caps{@buckets} =
    26  ('Half', 'Full')
    27  [sprintf('%0*b', scalar @buckets, $_) =~ /[01]/g];
    28  
    29  defined $hash{$_}{$caps{$_}} or next PERM
    30  
    31     for @buckets;
    32  
    33  print join '', map("$_:$caps{$_}",@buckets), "\n";
    34  print @{ $hash{$_}{$caps{$_}}} for @buckets;
    35  print "\n\n";
    36  }
    37  



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

Date: 15 Jul 2003 02:16:43 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Perl 5.004 bug
Message-Id: <slrnbh6p0d.6sb.mgjv@verbruggen.comdyn.com.au>

On Mon, 14 Jul 2003 18:36:09 -0400,
	Matt Oliverius <moliverius@w-link.net> wrote:
> Can someone give me some guidance as to why the following code does not 
> work in Perl 5.004, but does work in version 5.6? Note, the output below is 
> produced from a cat -n on the actual file so the line numbers are not part 
> of the actual program. 

Which version of 5.004? Which version 5.6?

> I'm getting syntax errors on line 31 and 34 presumably from the for 
> @buckets syntax.  In addition, the sprintf command on line 27 doesn't 
> appear to be working correctly.  Is there something wrong with Perl 5.004 
> that would prevent the binary conversion?  Can someone help me modify this 
> so that it will work with version 5.004.  Thanks a bunch.
> 
> Matt
> 
> 
> 
>     1   #!/usr/bin/perl
>      2  
>      3  use warnings;

This didn't exist in perl 5.004.

>     27  [sprintf('%0*b', scalar @buckets, $_) =~ /[01]/g];

The %b conversion specifier didn't exist in 5.004.

>     29  defined $hash{$_}{$caps{$_}} or next PERM
>     30  
>     31     for @buckets;

Statement modifiers didn't exist in 5.004, before 5.004_05. On
5.004_05 this isn't a syntax error. I'm sure it is on 5.004_04.

If you write code that needs to run on 5.004, make sure to use the
5.004 documentation, and develop against 5.004. Perl is largely
backward compatible, but, of course, it doesn't just work the other
way around.

The perl*delta.pod documents shipped with Perl also can be very
helpful.

$ man perl5005delta
[snip]
       "EXPR foreach EXPR" is supported
[snip]

$ man perl56delta
[snip]
       Binary numbers supported
[snip]
       Pragmata
[snip]
       Lexical warnings pragma, "use warnings;", to control optional warnings.
       See perllexwarn.
[snip]

Martien
-- 
                        | 
Martien Verbruggen      | 
Trading Post Australia  | Curiouser and curiouser, said Alice.
                        | 


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

Date: Tue, 15 Jul 2003 02:22:30 -0500
From: tadmc@augustmail.com
Subject: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.4 $)
Message-Id: <WoSdnddg-NQrNo6iRTvUrg@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, 15 Jul 2003 09:21:14 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Regex question...
Message-Id: <gmh7hvsoj38u136s59j0hlnb65vo7uutf2@4ax.com>

Math55 wrote:

>hi, i have this regex:
>
>
>\.(?!.png|.log)[^.]*$
>
>
>how can i replace the .before png and log with nothing? the problem
>is, the alternation can be longer, like that:
>
>\.(?!.png|.log|.txt|.c|.cpp and so on )[^.]*$

I'm not sure on what you're asking, but this won't work, as you have two
dots in a row, one in front of the lookahead, and one (though unescaped)
inside it. And you don't have a anchor to the end of string.

This, IMO, would look more like it:

	\.(?!(?:png|log|txt|c|cpp)$)[^.]*$


-- 
	Bart.


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

Date: Mon, 14 Jul 2003 23:29:29 -0700
From: Steve <me@home.com>
Subject: Re: safe cgi programming in perl?
Message-Id: <qa77hv8bvta46t3g97svcd9csnb1da1gfs@4ax.com>

Hi Ted,

Thank you for giving me some good suggestions. First off, I removed
the dot when untainting data.

I'm using a combination of Perl commands and backtics.

Perl:
mkdir, open

Shell:
zip, rm, mv, chmod

the problem I was having was in dealing with the cgi program creating
files with owner "apache". So I was having a hard time getting
"unlink" and "rmdir" to work.

But I think I will follow your advice and try moving more of the
backtic commands to perl commands.

Steve

On Mon, 14 Jul 2003 08:52:42 -0500, tadmc@augustmail.com (Tad
McClellan) wrote:

>Steve <me@home.com> wrote:
>
>> My main concern is with untainting data and
>> using backtics for system commands.
>
>> I'm only using mkdir, 
>
>
>Is that the shell's mkdir(1) or Perl's mkdir() function?
>
>
>> open 
>
>
>_That_ must be Perl's open(), I don't think there is a shell "open".
>
>
>> and rm with user input.
>
>
>And that is clearly the shell's rm(1).
>
>
>> most of my commands to create directories, files and to remove files
>> are with backtics,
>
>
>You can do all three of those things in native Perl rather than
>"shelling out" to external programs.
>
>   perldoc -f mkdir
>   perldoc -f open
>   perldoc -f unlink
>
>
>Avoiding a shell goes a long way toward peace of mind, so you
>should avoid it whenever possible.
>
>As an added bonus, you could then move your program unchanged
>to some other operating system.



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

Date: Mon, 14 Jul 2003 23:36:15 -0700
From: Steve <me@home.com>
Subject: Re: safe cgi programming in perl?
Message-Id: <p587hv0s7b0h1dsqnt3p4qunmrnkurohri@4ax.com>

On Mon, 14 Jul 2003 23:29:29 -0700, Steve <me@home.com> wrote:

>Hi Ted,

sorry...of course I meant Tad ;-)


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

Date: 14 Jul 2003 15:51:13 -0700
From: charley@pulsenet.com (Chris Charley)
Subject: Re: script for unrestricted permutation
Message-Id: <4f7ed6d.0307141451.20647ae9@posting.google.com>

charley@pulsenet.com (Chris Charley) wrote in message news:<4f7ed6d.0307070749.7f0bb197@posting.google.com>...
> "John W. Krahn" <krahnj@acm.org> wrote in message news:<3F07BD9F.BAA5B427@acm.org>...
> > "John W. Krahn" wrote:
> >  
> > [snip]
> > 
> > Or a bit simpler.  :-)
> > 
> > my $group = 4;
> > my @elements = qw/ red green blue /;
> > 
> > for ( 0 .. ( @elements ** $group ) - 1 ) {
> >     my @odometer;
> >     do { unshift @odometer, $_ % @elements } while $_ = int( $_ / @elements );
> >     print "@{[ map $elements[$_], (0) x ($group - @odometer), @odometer ]}\n";
> >     }
> > 
> > 
> > 
> > John
> 
[snip]> 
> John, I will look over your code to understand its brevity.

Hi John

I know this is not srictly about Perl and probably an algorithmic
topic.

(After running your code through the debugger!), I finally got what
was happening. The do while loop is a base 10 to base 3 (in this
problem) converter. Can be used to convert between base 10 and any
other base.
Sure is clean once you see it. 3 lines in the for loop. Also found
this same algorithm in my old Discreet Math book (by Kenneth Rosen).
Was in a cs program at college but only completed half the program.
With this algorithm you can also selectively perform 
any of 0 .. (@elements ** $group - 1) permutations - not nesessary to
generate all the perms if you know which ones you may be concerned
with. :-)

--
Chris


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

Date: Tue, 15 Jul 2003 00:49:25 -0400
From: Matt Oliverius <moliverius@w-link.net>
Subject: sprintf help
Message-Id: <vh7bj9fb6sm239@corp.supernews.com>

Does anyone know of an alternate way of doing the following in Perl?

@caps{@buckets} = ('Half','Full')
[sprintf('%0*b', scalar @buckets, $_) =~ /[01]/g];




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

Date: Tue, 15 Jul 2003 09:23:06 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: testing for array or scalar in a hash.
Message-Id: <pth7hv080mnr205a4u77m8jkr8erfjj5kv@4ax.com>

Fred S wrote:

>I have a hash containing, data, everything is generated on the fly so 
>my hash, has some scalars, and some arrays, in it.
>How can I test wether a value of the hash is an array and then loop
>through it ?

If *all* you have in there are array (refs) and scalars, then you can
use ref() as a boolean test. For scalars, it will return the empty
string (false), for array refs, "ARRAY" (true).

-- 
	Bart.


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

Date: 14 Jul 2003 18:43:17 -0700
From: dwlepage@yahoo.com (david)
Subject: text parse
Message-Id: <b09a22ae.0307141743.2450c9a4@posting.google.com>

Im trying to parse a file with data such as this:
(ip's changed for obvious reasons)

acl add table=ipaddr name=127.0.0.1 burb=Firewall \
    comments='Firewall network object for DNS proxy ACL redirection' \
    lastchangedby='root on 08/12/02 13:36:23'
acl add table=ipaddr name=127.1.1.1 burb=external \
    lastchangedby='dlepage on 06/24/03 10:25:30'

I want the end output to look like:

acl add name=127.0.0.1 ipaddr=127.0.0.1 comments='Firewall network
object for DNS proxy ACL redirection'
acl add name=127.1.1.1 ipaddr=127.1.1.1 comments=

so basically I only want to capture the IP after the 'name=' value,
and anything in the 'comments' field, if at all. Here is what I have
so far, which works, but im so new to programming that I know my
coding stinks. Any suggestions to make this more efficient
appreciated.

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

my ($ip,$comment);

open(IN, "<$ARGV[0]") || die "Cant open $!";
flock (IN, 1);

while( <IN> ) {
s/\\//g; # get rid of newlines

        # match on acl's with comments
        if (/^acl add table=ipaddr name=(\d+\.\d+\.\d+\.\d+) burb=(.+)
comments=
(.+)/) {
                print "acl add name=$1 ipaddr=$1 comments=$3\n";
        }

        # else match without comments
        elsif (/^acl add table=ipaddr name=(\d+\.\d+\.\d+\.\d+)
burb=(.+)$/) {
                print "acl add name=$1 ipaddr=$1 comments=\n";
        }
}
close(IN);

-d


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

Date: Tue, 15 Jul 2003 10:39:40 +0200
From: Juergen Heck <btd.heck@t-online.de>
Subject: Re: TOO SLOW:     `echo ${LINE} | sed -n 's/^.* proto //p' | cut -f1 -d"  "`
Message-Id: <3F13BDCC.6C93637D@t-online.de>



secheese wrote:
> 
> I have a script that monitors a firewall drop log file and I need to
> pull the protocol fields.  I used to know exactly where this field
> was, so I could easily get the field with this statement:
> 
>         PROTOCOL=`awk 'print $5'`
> 
> But now the logs are dynamic and the field can be anywhere.  One thing
> I do know is that the protocol field always follows a field labelled
> "proto".  Thus the follow command gets it for me:
> 
>         PROTOCOL=`echo ${LINE} | sed -n 's/^.* proto //p' | cut -f1 -d" "`
> 
> Trouble is, this command takes about 10 times as long to run as the
> awk did.  The result is that the execution time for my script overall
> has gone from about 1 minute to 10 minutes.
> 
> Can anyone think of a faster way to get the job done?  BTW, perl is
> available, but I'm unfamiliar with the language.
> 
> Thanks.

PROTOCOL=`awk '{sub(/.* proto /,"") ; print $1' yourlogfile`
for entry in $PROTOCOL
do
 ### process $entry
done

or

awk '{sub(/.* proto /,"") ; print $1' yourlogfile | while read entry
do
###process $entry
done


Regards
Juergen


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

Date: Tue, 15 Jul 2003 09:32:23 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Translation with PERL?
Message-Id: <b1i7hv842prlkpshg45d4q1p3kap7qk3fp@4ax.com>

Jon wrote:

>The translation was
>done with property files holding each language as well as image urls.
>My questions is can something like this be done with perl and apache.
>Can a property file be just a text file that is referenced for
>different languages?

Yes.

As someone else pointed out, you can use modules to manipulate config
files to load the data. I myself would take a good look at YAML, which
provides a neat way to store perl data structures in rather plain text
files. Or you could use tabs separated text files (or CSV), and edit the
data in a spreadsheet like Excel.

If this is for mod_perl, it might be interesting to cache the data in an
itnernal global data structure (untested, but I think it should work).
That is: violate the strict separation of data spaces between scripts on
purpose, and use a global variable. 

You can hang whole hashes off a subkey, for example

	$text{NL}{title}

could hold the title for Dutch... while *all* translations for Dutch
hang under $text{NL}, which is a hash ref.

In this case, unless you want to have to restart the server every time a
translation changes, you should include a make-like system that check
the date of the last update of a file, and reload the data if the data
file had been changed. Be careful to include locking, you don't want to
reload the same data structure in two scripts at approximately the same
time.

-- 
	Bart.


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

Date: Tue, 15 Jul 2003 00:07:46 -0700
From: JS Bangs <jaspax@u.washington.edu>
Subject: Use module (maybe) w/o dying
Message-Id: <Pine.A41.4.55.0307150002510.66634@dante18.u.washington.edu>

I'm stumped. I wanted to use a module if it was available, but not to die
if the module was unavailable. I originally wrote:

our $WHATIF = 0;
eval {
	use Whatif;
	$WHATIF = 1;
};

 . . . and later looked at $WHATIF to see if the module was available. This
didn't work, because the use apparently gets pulled into BEGIN even from
inside the eval. So I went and read the docs on use, require, and import,
and followed the examples there in every permutation I could think of.
Still didn't work. What am I missing?

Jesse S. Bangs jaspax@u.washington.edu
http://students.washington.edu/jaspax/
http://students.washington.edu/jaspax/blog

Jesus asked them, "Who do you say that I am?"

And they answered, "You are the eschatological manifestation of the ground
of our being, the kerygma in which we find the ultimate meaning of our
interpersonal relationship."

And Jesus said, "What?"


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

Date: 15 Jul 2003 08:42:53 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: Use module (maybe) w/o dying
Message-Id: <slrnbh7fkd.75q.sholden@flexal.cs.usyd.edu.au>

On Tue, 15 Jul 2003 00:07:46 -0700, JS Bangs <jaspax@u.washington.edu> wrote:
> I'm stumped. I wanted to use a module if it was available, but not to die
> if the module was unavailable. I originally wrote:
> 
> our $WHATIF = 0;
> eval {
> 	use Whatif;
> 	$WHATIF = 1;
> };
> 
> . . . and later looked at $WHATIF to see if the module was available. This
> didn't work, because the use apparently gets pulled into BEGIN even from
> inside the eval. So I went and read the docs on use, require, and import,
> and followed the examples there in every permutation I could think of.
> Still didn't work. What am I missing?

eval "use Whatif;";
$WHATIF = 1 unless $@;

[snip a way long non-seperated sig]

-- 
Sam Holden



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

Date: Tue, 15 Jul 2003 09:53:44 +0100
From: "Richard S Beckett" <spikey-wan@bigfoot.com>
Subject: Re: Win32-OLE where's the info?
Message-Id: <bf0fh3$33e$1@newshost.mot.com>

>
http://aspn.activestate.com/ASPN/Perl/Products/ActivePerl/site/lib/Win32/OLE
 .html
> http://www.people.cornell.edu/pages/asu1/notes/perl-excel.html
> Sinan.


> Try my stand alone applet.
> TLViewer: turbo Object Browser for scripting
> http://mysite.verizon.net/res1ur2j/tlviewer.htm
>
> I even include the Perl creation code for the selected
> object.
>
> good luck,
> Mark Pryor


Thanks guys. That lot should keep me quiet for a bit, unless it goes
straight over my head, of course ;-)

R.




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

Date: 14 Jul 2003 20:07:52 -0700
From: joeminga@yahoo.com (Domenico Discepola)
Subject: Win32::OLE, Excel and OLE Automation question
Message-Id: <698c67f.0307141907.40cca162@posting.google.com>

Hello.  I have a protected Excel file (i.e. locked cells) that I
created.  I want to remove the protection on 1 column using
Win32::OLE.  Unfortunately, I cannot find my answer in the Microsoft
online help.  Any suggestions would be appreciated.  I suspect that my
problem lies in my understanding of OLE Automation and how its methods
and properties tie in with PERL so any "cookbook" links would help as
well.  Using the object browser in Excel (alt-f11, f2) does not
provide me with clear enough examples...

Here's my code (which executes but does not solve the problem).  As
far as I know, this code 'hides' the worksheet (click on Window,
Unhide to view it).
######################
#!perl

use strict;
use warnings;
use Win32::OLE;

my ${my_file} = $ARGV[0];

unless ( ${my_file} ) {
	printf STDERR "Usage: $0 excelfile\n";
	exit 2;
}

my $workbook = Win32::OLE->GetObject( "${my_file}" ) || die "Could not
open ${my_file}\n";

#Show Excel
$workbook->{Application}->{Visible} = 1;

#Select worksheet 1
my $sheet = $workbook->Sheets(1);

#Select column to unlock
$sheet->Columns("E:E")->{Select};

#Remove the locked property
$sheet->{Selection}->{Locked} = 0;

$workbook->{Save};
$workbook->Close();
exit 0;
########################3
Thanks


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

Date: 15 Jul 2003 04:56:08 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: Win32::OLE, Excel and OLE Automation question
Message-Id: <Xns93B9985BBBFFasu1cornelledu@132.236.56.8>

joeminga@yahoo.com (Domenico Discepola) wrote in 
news:698c67f.0307141907.40cca162@posting.google.com:

> Hello.  I have a protected Excel file (i.e. locked cells) that I
> created.  I want to remove the protection on 1 column using
> Win32::OLE.  Unfortunately, I cannot find my answer in the Microsoft
> online help.  Any suggestions would be appreciated.  I suspect that my
> problem lies in my understanding of OLE Automation and how its methods
> and properties tie in with PERL so any "cookbook" links would help as
> well.  Using the object browser in Excel (alt-f11, f2) does not
> provide me with clear enough examples...

I am not sure I could do a good job of explaining what is wrong with your 
code. Your original code produce some "useless use of hash" warnings. 
However, the following might be of some help:

#! C:/Perl/bin/perl.exe
use strict;
use warnings;

use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
$Win32::OLE::Warn = 3;

$| = 1;

my $my_file = shift @ARGV;

unless ($my_file) {
	print STDERR "Usage: $0 excelfile\n";
	exit 2;
}

my $Excel = Win32::OLE->GetActiveObject('Excel.Application')
	|| Win32::OLE->new('Excel.Application', 'Quit');

$Excel->{Visible} = 1;
my $Book = $Excel->Workbooks->Open("$my_file");
my $Sheet = $Book->Worksheets(1);

my $Range = $Sheet->Columns("E:E");
$Range->{Locked} = 0;

$Book->Save;
$Book->Close;

exit 0;

See also 
http://aspn.activestate.com/ASPN/Perl/Products/ActivePerl/site/lib/Win32/
OLE.html

-- 
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov


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

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


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