[19067] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1262 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jul 7 14:05:49 2001

Date: Sat, 7 Jul 2001 11:05:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <994529111-v10-i1262@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 7 Jul 2001     Volume: 10 Number: 1262

Today's topics:
        FAQ: How stable is Perl? <faq@denver.pm.org>
    Re: Flags to use with DB_File tie call?? (Garry Williams)
    Re: HELP:didn't understood something with references... (Tad McClellan)
    Re: HELP:didn't understood something with references... (Mark Jason Dominus)
    Re: I know this must be in the manpages... number forma (Konstantinos Agouros)
    Re: IF statement madness (Mark Jason Dominus)
        Is there a more efficient way to code a hash pass?? <miscellaneousemail@yahoo.com>
        Is there a way to rename a function and use it?? <miscellaneousemail@yahoo.com>
    Re: Is there a way to rename a function and use it?? (Mark Jason Dominus)
    Re: login script with cgi? (Flipper)
    Re: login script with cgi? <andras@mortgagestats.com>
    Re: MySQL,DBI doesn't like my 'LIKE' query (Garry Williams)
        New User Question <mikes@escape.com>
    Re: New User Question (Garry Williams)
    Re: Perl & C(++) comparison (Sasa Janiska)
    Re: Perl and the NT Event Log. <>
        Posting HTML table from a file? <ted9669@ANTISPAM.yahoo.com>
    Re: Randomizing a list (Mark Jason Dominus)
    Re: Regex problem: Multiple matches across Multiple lin <ren@tivoli.com>
        Script won't DIE!!! <david.mohorn@home.com>
        Term::ANSIColor in Windows 2000's CMD <dont@mail.me>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 07 Jul 2001 12:17:03 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: How stable is Perl?
Message-Id: <35D17.39$T3.192148992@news.frii.net>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.

+
  How stable is Perl?

    Production releases, which incorporate bug fixes and new functionality,
    are widely tested before release. Since the 5.000 release, we have
    averaged only about one production release per year.

    Larry and the Perl development team occasionally make changes to the
    internal core of the language, but all possible efforts are made toward
    backward compatibility. While not quite all perl4 scripts run flawlessly
    under perl5, an update to perl should nearly never invalidate a program
    written for an earlier version of perl (barring accidental bug fixes and
    the rare new keyword).

- 

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to

    news:news.answers

or to the many thousands of other useful Usenet news groups.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-1999 Tom Christiansen and Nathan
    Torkington.  All rights reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.

                                                           01.06
-- 
    This space intentionally left blank


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

Date: Sat, 07 Jul 2001 15:49:21 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Flags to use with DB_File tie call??
Message-Id: <slrn9kebs1.h7k.garry@zfw.zvolve.net>

On Fri, 06 Jul 2001 19:18:43 -0700, $Bill Luebkert <dbe@wgn.net> wrote:
> "Carlos C. Gonzalez" wrote:
>> I have looked in the DB_File documentation, the Berkely DB documentation,
>> and in www.perl.com and have not yet found any listing of the values that
>> can be passed into the 4rth parameter (which above is O_RDWR|O_CREAT).
>> Does anyone know where I can get the various values for this paramenter.
>> They are flags of some sort designating how a file will be processed.  I
>> know that much.
> 
> Try Fcntl.pm

Well, The Fcntl manual page _itemizes_ the constants, but the open(2)
manual page _explains_ them.  

-- 
Garry Williams


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

Date: Sat, 7 Jul 2001 08:13:03 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: HELP:didn't understood something with references...
Message-Id: <slrn9kdv6f.pfe.tadmc@tadmc26.august.net>

Bruno Boettcher <bboett@erm6.u-strasbg.fr> wrote:

>i have made an object:
>package mailbox;
>use baseactor;
>use ObjectTemplate;
>use POSIX qw(strftime);


Where is "use strict;"?


>@ISA = ("baseactor");
>attributes("messages","deb");
>
>sub PRIVMSGaction
>{
>   my ($obj,$line) = @_;
>   my %settings = %{$obj->sysdata()};
>      @actMsg = @{$settings{$receiver}};
       ^^^^^^^

So this is a package ("global") variable then?  

I don't see it my()d anywhere...


>      $now_string = strftime "%a %b %e %H:%M:%S %Y", gmtime;
       ^^^^^^^^^^^
>      $now_string .= " : ".$msg." by ".$sender."\n";
                            ^^^^        ^^^^^^^

More "global" variables?


>      push(@actMsg,$now_string);
>      $settings{$receiver} = \@actMsg;


So if you call this for several objects, each will be referring
to the same array.

Is this the problem you are seeing?

Making it a lexical variable should fix that, or copy the contents
of the package variable into a new, anonymous array and take a
reference to _that_:

   $settings{$receiver} = [ @actMsg ];


>      $obj->sysdata(\%settings);
>      return 1;
>   }#if($line =~ /.*:(\S+)!(\S+) PRIVMSG $botname :mail (.*)$/)īŠ
>   return 0;
>}#sub PRIVMSGaction
>
>
>
>but it doesn't behave as expected....
>i can't get the refs to behave as refs... i allways get copies and the data i insert gt lost...


Even if you fix @actMsg, you are making copies, modifying the copy,
then overwriting the original.

Why not make the modifications to the hash via its reference directly
rather than via copies?


   # untested!
   sub PRIVMSGaction
   {
      my ($obj,$line) = @_;
      my $settings = $obj->sysdata();
         $now_string = strftime "%a %b %e %H:%M:%S %Y", gmtime;
         $now_string .= " : ".$msg." by ".$sender."\n";
   
         push(@{ $settings->{$receiver} },$now_string);
         return 1;
      }#if($line =~ /.*:(\S+)!(\S+) PRIVMSG $botname :mail (.*)$/)īŠ
      return 0;
   }#sub PRIVMSGaction



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


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

Date: Sat, 07 Jul 2001 17:35:04 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: HELP:didn't understood something with references...
Message-Id: <3b474825.5f66$333@news.op.net>

[mailed and posted]

In article <9i6cmu$ch7$1@news.u-strasbg.fr>,
Bruno Boettcher <bboett@erm1.u-strasbg.fr> wrote:
>i can't get the refs to behave as refs... i allways get copies and
> ? the data i insert gt lost... 

These lines perform copy operations:
>   my %settings = %{$obj->sysdata()};
>      @actMsg = @{$settings{$receiver}};

$obj->sysdata() is returning a hash reference.  The %{...} notation
says to get the hash.  The data from the hash is *copied* into
%settings, because the '=' operator always makes a copy.

Similarly, $settings{$receiver} is an array reference, but @actMsg = @{...}
says to copy the data from the array.


Try this instead:

>      my $settings = $obj->sysdata();
>      my $actMsg = $settings->{$receiver};
>      $now_string = strftime "%a %b %e %H:%M:%S %Y", gmtime;
>      $now_string .= " : ".$msg." by ".$sender."\n";
>
>      push(@$actMsg,$now_string);
>      $obj->sysdata($settings);
>      return 1;

If you don't understand what this is doing, please post again.

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: 7 Jul 2001 11:15:35 +0200
From: elwood@news.agouros.de (Konstantinos Agouros)
Subject: Re: I know this must be in the manpages... number formatting
Message-Id: <elwood.994497288@news.agouros.de>

In <3B462B4A.F13B9FC@home.com> Michael Carman <mjcarman@home.com> writes:

>Konstantinos Agouros wrote:
>> 
>> I might be blind, but what I am looking for is some way to print
>> larger integer numbers with digits (german way)
>> [...]
>> I played around with printf but couldn't find the trick...

>It's not a printf() option. Look at perlfaq5 "How can I output my
>numbers with commas added?" and adapt it to use dots instead of commas.
>Or, use it as is and whack it with tr/.,/,./ afterwards.
But it really has to be done by regexps... ? 
The C-Printf with localesupport seems to be able to do this... But ok
I go with approach... 

Thanks,

Konstantin

>-mjc
-- 
Dipl-Inf. Konstantin Agouros aka Elwood Blues. Internet: elwood@agouros.de
Otkerstr. 28, 81547 Muenchen, Germany. Tel +49 89 69370185
----------------------------------------------------------------------------
"Captain, this ship will not sustain the forming of the cosmos." B'Elana Torres


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

Date: Sat, 07 Jul 2001 18:00:14 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: IF statement madness
Message-Id: <3b474e0c.5ff4$353@news.op.net>

In article <3B45DC7E.1A880722@oracle.com>,
Graham Wood  <Graham.T.Wood@oracle.com> wrote:
>You have a hash called %cookies which contains the word "user" as a key
>and you want to know the corresponding value in the hash.
>
>To do this you don't need to iterate, you just access it via
>$cookies{user} as in
>    print "$cookies{user}\n";
>or
>    $user_cookie_value = $cookies{user};
>
>That's one of the reasons for using a hash.  You don't need to look at
>them all to find the one you want if you know the key you're looking for.

It amazes me that of four responses to this question, this is the only
one that seemed to make this point.

        Doing linear scans over an associative array is like trying to
        club someone to death with a loaded Uzi.

                -- Larry Wall


Thank you, Graham.
-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Sat, 07 Jul 2001 17:52:48 GMT
From: Carlos C. Gonzalez <miscellaneousemail@yahoo.com>
Subject: Is there a more efficient way to code a hash pass??
Message-Id: <MPG.15b0f9ee9fdf3cdf989698@news.edmonton.telusplanet.net>

Hi everyone, 

I was wondering if there was a more efficient (perhaps better) way to 
write the following function.

sub open_file
{
  my ($h, $file) = @_;  
  tie %$h, "DB_File", $file, O_RDONLY|O_CREAT, 0666, $DB_HASH 
    or die "Cannot open $file: $!\n";
  return;
}	

I call it by:

open_file(\%h, "D:/www/somefile.db");

The above seems to work just fine but I am wondering if there is a 
clearer way to write the open_file function regarding the hash 
references.  Such that I don't have to use "%$" to do it.  

Also is it good practice to put an empty return statement at the end of 
functions? I have read some allusions to this in some of the books I 
have. 

Thanks 

-- 
Carlos 
www.internetsuccess.ca


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

Date: Sat, 07 Jul 2001 17:08:39 GMT
From: Carlos C. Gonzalez <miscellaneousemail@yahoo.com>
Subject: Is there a way to rename a function and use it??
Message-Id: <MPG.15b0ef7aa32f31f1989696@news.edmonton.telusplanet.net>

Hi everyone,

I have read through a great deal of the 9 perlFAQ pages, perlfunc, and 
other documentation and am wondering if there is a way to rename a 
function and use it?? A constant function won't work if it doesn't 
evaluate to a constant.  

For example...in the following call....

  untie $h

what I am actually doing is closing the connection established between 
the hash %h and a file name opened with .... (using DB_File)

  tie %h, "DB_File", $file, O_RDONLY|O_CREAT, 0640, $DB_HASH 
    or die "Cannot open $file: $!\n";

Since I am creating a package that I may give to subscribers of my 
newsletter (who will not be Perl programmers per se) I am thinking it 
might be better to rename some functions from the standpoint of what they 
do in my package rather than keeping them as is.

For example instead of "untie %h" my subscribers would have a much easier 
time understanding "close_file(\%h)".  A programmer might look at this as 
untying the hash from the file and closing the file in the process.  A 
user of my package would just simply look at this as closing the file - 
never mind this hash thing.  I know that you might disagree with this but 
be that as it may is there a way to redefine the untie call under a 
different name without incurring the overhead of an actual function call.  

In C there is the #DEFINE statement where I could define every occurance 
of "untie" to be "close_file".  Is there anything similar in Perl??

Thanks

-- 
Carlos 
www.internetsuccess.ca


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

Date: Sat, 07 Jul 2001 17:44:07 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Is there a way to rename a function and use it??
Message-Id: <3b474a45.5faa$144@news.op.net>

In article <MPG.15b0ef7aa32f31f1989696@news.edmonton.telusplanet.net>,
Carlos C. Gonzalez  <miscellaneousemail@yahoo.com> wrote:
>In C there is the #DEFINE statement where I could define every occurance 
>of "untie" to be "close_file".  Is there anything similar in Perl??

There isn't anything like #define in Perl, but I think you can get
what you want this way:

        sub close_file {
          my $hashref = shift;
          untie %$hashref;
        }

Your users can use this by writing

        close_file(\%h);

If you don't like the '\', you can play a trick:

        sub close_file (\%) {
          my $hashref = shift;
          untie %$hashref;
        }

Now users can write

        close_file(%h);             

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Sat, 07 Jul 2001 13:19:10 GMT
From: twoflippers@icqmail.com.spamfilter (Flipper)
Subject: Re: login script with cgi?
Message-Id: <3b470c0f.2223247@news.uwa.edu.au>

G'day

>Isn't basic authentication with .htaccess/.htpassword available to you? It
>would be a lot cleaner and simpler.

Um... whats that and how do i implement it?

>Obviously not. The last thing you want to do is compare the username and
>the password as numeric values because that will let in anybody who enters
>a non-numeric password/username combination. You will want to use eq
>instead of == here.

will "eq" check letters as well as numerals?

>That's really a JavaScript question, isn't it?

probably but I thought there might be CGI\Perl commands to do the same

thnaks again
David


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

Date: Sat, 07 Jul 2001 10:20:09 -0400
From: Andras Malatinszky <andras@mortgagestats.com>
Subject: Re: login script with cgi?
Message-Id: <3B471A99.E67ED21E@mortgagestats.com>



Flipper wrote:

> G'day
>
> >Isn't basic authentication with .htaccess/.htpassword available to you? It
> >would be a lot cleaner and simpler.
>
> Um... whats that and how do i implement it?

Some servers (most notably Apache) allow you to create access control by
putting a special file called .htaccess into the directory to which you want to
restrict access. .htaccess then specifies a directory (customarily called
 .htpasswd) where the usernames and the corresponding passwords are stored. When
you try to access the directory through a browser, the server challenges you
for a password. Here's more info: http://www.apacheweek.com/features/userauth


>
>
> >Obviously not. The last thing you want to do is compare the username and
> >the password as numeric values because that will let in anybody who enters
> >a non-numeric password/username combination. You will want to use eq
> >instead of == here.
>
> will "eq" check letters as well as numerals?

It will, but as strings, not as numbers. You should REALLY read up on this.




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

Date: Sat, 07 Jul 2001 16:36:22 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: MySQL,DBI doesn't like my 'LIKE' query
Message-Id: <slrn9keejr.h7k.garry@zfw.zvolve.net>

On 6 Jul 2001 11:28:52 -0700, Miriam Raphael-Roberts
<miriamraphael@yahoo.com> wrote:

> This is my first time ever posting to a newsgroup. I hope you'll all
>  be able to help me.
> I'm trying to create a small search engine for my site that queries 
> the database. My program can execute and retrieve results for almost
>  every SQL statement, It doesn't let me do queries though with the
> 'LIKE' command. 

What do you mean by "doesn't let me do queries"?  

> The user enters the keyword and I search the database
> (on the description column) to look for the keyword. I printed the
> query and then pasted it into the MySQL command line interface and it
> worked properly. Something is going on from the time I send the query
> until Mysql
> executes it. 

What results do you get?  Is $dbh->errstr set?  

[snip]

> I've written some code below which is basically
> what my program is doing (I edited out the irrelvant parts). 

This is a very good technique to isolate the source of a problem.
Unfortunately, the code below will not compile.  Is that just a
transcription error or did you not try running the code below?  

> #!/usr/local/bin/perl

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

> my $query .= "select id from users where description like \'%perl%\' ;
> ";

This is confusing.  Why are you concatenating your query to an
uninitialized variable.  Why are you escaping single quotes?  

An alternate quoting character is often useful for SQL queries: 

  my $query = q{
    SELECT id
    FROM   users
    WHERE  description like '%perl%'
  };

> my(@row) = ();
> my(@select) = ();

Assigning an empty list is unnecessary:

  my @row;
  my @select;

> my($dbh,$sth,$rv,$sql);
> 
> $dbh = &ConnectToDB;

I assume that the subroutine ConnectToDB() succeeds.  Also the `&'
character used for calling subroutines is deprecated (unless you know
why you want it).  See the perlsub manual page: 

  $dbh = ConnectToDB();

or, if you have already declared or defined the subroutine, simply:

  $dbh = ConnectToDB;

> $sth = $dbh->prepare($query) or die "Cant prepare $statement:

Here you seemed to have left something off.  The quotes are not
closed.  This is a compilation error.  

> $rv = $sth->execute or  die $sth->errstr();
> 
> my($i) = 0;
> 
>         while(@row = $sth->fetchrow_array)
>         {
>                 for ($j=0; $j < @row; $j++)

                  for ( my $j=0; $j < @row; $j++ )

>                 { $select[$i+$j] = $row[$j]; }
>                 $i = $i + $j + 1;
>                 }

You seem to want @select to contain each row retrieved from the query.
Here's a simpler way to do that: 

  while ( @row = $sth->fetchrow_array ) {
    push @select, @row;
  }

> $rc = $sth->finish;
> 
> $dbh->disconnect || "failed to disconnect: $dbh->errstr()\n";
> print @select;

I see no reason why this code (with the compilation error corrected)
will not do what you seem to want.  Did you run it?  Did it encounter
any errors?  

-- 
Garry Williams


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

Date: Sat, 07 Jul 2001 12:46:40 -0400
From: mike <mikes@escape.com>
Subject: New User Question
Message-Id: <3B473CEF.9D65AB12@escape.com>

Hi,
    I would like to know the meaning of the following construct:

                while (<>) {print ............ }


            The (<>) doesn't seem like a complete expression.
 Where is the variable?

                                                        Thanks

Mike



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

Date: Sat, 07 Jul 2001 17:08:40 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: New User Question
Message-Id: <slrn9keggo.h7k.garry@zfw.zvolve.net>

On Sat, 07 Jul 2001 12:46:40 -0400, mike <mikes@escape.com> wrote:

>     I would like to know the meaning of the following construct:
> 
>                 while (<>) {print ............ }
> 
>             The (<>) doesn't seem like a complete expression.
>  Where is the variable?

You need to read the documentation that came with perl.  This
construct is explained in the perlop manual page under the "I/O
Operators" section.  It's a special case of the input operator
<FILEHANDLE>.  The null filehandle operator is a special case
implemented to behave like sed and awk.  It's a convenience.  See the
perlop manual page for an explanation of it behavior.  

-- 
Garry Williams


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

Date: Sat, 7 Jul 2001 10:24:54 +0200
From: ggd@gaura.nitai.hr (Sasa Janiska)
Subject: Re: Perl & C(++) comparison
Message-Id: <slrn9kdhqm.25n.ggd@gaura.nitai.hr>

On Fri, 6 Jul 2001 16:49:28 -0400, David Coppit <newspost@coppit.org> wrote:

Hi David!

>Having said that, you really have two questions: (1) Is Perl a capable
>programming language for non-script applications, and (2) Can Perl
>programs be made into stand-alone programs.
>

Thank you for so nicely clarifying the situation.

>Yes, and yes. I like Perl because I don't have to deal with storage
>management headaches, and because I'm more interested in getting the
>right result than getting a wrong result really quickly. Plus Perl is
>"higher-level" than C or C++. I find that I'm actually making progress
>toward a solution in Perl when I would still be programming
>infrastructure classes in C++. However, since Perl is fairly flexible
>(e.g. auto-coercion of types, dynamic dispatching of methods, etc.),
>you need to employ more restraint when developing large, long-lived
>systems. This is all IMHO, of course. :)
>

Nice to hear that.

It looks like I won't have any need for some other programming language 
(I've already replaced learning PHP with CGI scripts written in Perl).
 
In the past I was into programming with C(++), working with the 1st (I believe 
so) PC C++ compiler - Zortech, but I didn't do much programming for about 10 
years, and seeing how much the C++ evolved or become extended, I lost interest 
to get into again.

However, Perl looks very nice and I have a good feeling for it. Just need some 
time to jump in.

>As far as (2), the perl2exe program works fairly well, and perlcc has
>come a long way (although I haven't looked at it lately). There was
>also some noise of Perl eventually supporting the packaging up of
>modules so that all you need is the Perl interpreter and the package
>to run an application.
>

Very nice. I just plan to develop something with Tk capable to run on Linux 
eventually.

Thank you again for very promising words encouraging me in learning Perl 
further.

Sincerely,
Sasa



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

Date: Sat, 07 Jul 2001 16:52:47 +0100
From: Nick Porter <>
Subject: Re: Perl and the NT Event Log.
Message-Id: <mhaekt8tvd77h1jci6e790uspd4ucjk1d7@4ax.com>

On 06 Jul 2001 12:54:21 +0100, nobull@mail.com wrote:

>Nick Porter <nickp@flyingpig.com> writes:
>
>> Can anyone explain to this newbie how to interrogate the NT event log.
>
>This isn't really a Perl question.  Win32 provides an API to
>interrogate the event log.  The Win32::EventLog module provides a Perl
>mapping to this API.  The semantics of the API itself are largely
>independant of language and need to be understood (or guessed) before
>the Perl mapping of the API makes a lot of sense.

[NP] Thanks for that. I'll check out the Win32 module.

>> I've had a search at CPAN and other places for a module but have been
>> unsuccessfull.
>
>Do you mean you could not find Win32::EventLog or do mean something
>else by "unsuccessfull"?

[NP] I searched cpan with the command CPAN> search "event log" and
CPAN> search "windows nt". I also went to;
http://search.cpan.org/Development_Support  and;
http://search.cpan.org/Catalog/Operating_System_Interfaces/ but
couldn't find any module descriptions that referred to the NT event
log. So by 'unsuccessful' I meant that I was unable to find what I was
looking for. Was it really that unclear? I am unaware of any other
methods  for searching CPAN than the ones I used above. I am a new at
this so perhaps you could enlighten me on methods which are more
discriminating, other than posting to a newsgroup?




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

Date: 7 Jul 2001 15:04:30 GMT
From: Ted  Weston <ted9669@ANTISPAM.yahoo.com>
Subject: Posting HTML table from a file?
Message-Id: <9i78du$n8o$1@comets.cs.swt.edu>

I'm reading a file into a table, but I intend
to read it in line-by-line so I can alternate
colors between line of the table. Thus far:

 .
 .
 .
open (INFILE, "/tmp/out.test");

print header(),
start_html(-xbase=>'http://mysite/testpage
        -head=>meta({-http_equiv=>'Refresh', 
	-content=>'600'})),
font({-face => 'arial'},{-size=>3},
table({-width=>'100%', -height=>'130', 
	-border=>'undef',-cellpadding=>'0', 
	-cellspacing=>'1'},
while (<INFILE>) {
  @line = split (/|/);
  Tr(),
    td({-width=>'6%', -align=>'center', 
      -height=>'45'},[@line[0, 1, 3, 4, 6, 7]])
  }#end while
  )),
end_html();


Is there any way that I can use the while() inside
the table() section? I tried the HTML::Stream mod,
but I could not get it to give me anything but
"500 Internal Server" errors.
Any help is appreciated,
 .ted


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

Date: Sat, 07 Jul 2001 17:53:01 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Randomizing a list
Message-Id: <3b474c7d.5fcd$8d@news.op.net>

In article <3B45EE3F.E0A23968@bms.umist.ac.uk>,
Paul Boardman  <peb@bms.umist.ac.uk> wrote:
>The number of iterations necessary for a truly randomisation is
>debatable.

No, it isn't.  It's mathematical fact.

>  I use 100 here as a proof of principle.

Even 100 is not enough for unbiased shuffling with this algorithm.
Unless the list has fewer than 3 elements, this algorithm always
produces a biased shuffle.

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: 06 Jul 2001 22:17:16 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Regex problem: Multiple matches across Multiple lines
Message-Id: <m34rsp8m2r.fsf@dhcp9-173.support.tivoli.com>

On Fri, 06 Jul 2001, hillr@ugs.com wrote:

> Hello All, I am trying to parse a document and am running into
> difficulty ( see test script below my post) If this script is run as
> is, it takes a long time to return and $11 var is empty. However if
> I comment out the lines (.*\n) and SYMPTOM after the HARDWARE line
> the script returns without a long wait and I have what I need in the
> vars $1 - $10.  my question is How can I get the information between
> HARDWARE and SYMPTOM as var $11? And also continue on with the other
> information ( var $12 contains the information between SYMPTOM and
> SOLUTION?  Can anyone help me find out what I am doing wrong?
> 
> Thanks
> 
> Ron
> 
> undef $/;
> while (<DATA>)  {

Since you've undefined $/, this loop is only going to execute once.  It
probably makes more sense to simply assign <DATA> to $_ directly and
not have the loop.

> /
>              #start of record
>     PRODUCT: (.*)\n
>     SUBJECT:(.*)\n #get subject
>     \s*           #skip the new line
>     SUBMITTED\s+BY: (.*)?\s* SUBMITTED\s+DATE:(.*)\n # get name and date

                      ^^^^^

This is the type of construct that can lead to performance problems
whenever a match fails.  This one isn't too severe, but that "?" is
completely redundant.

> 
>     IR\s*\#:(.*)?\s* DOCUMENT\s+ID:(.*)\n # get IR and DOCUMENT ID
>     PLATFORM:(.*)?\s* OPERATING\s+SYSTEM:(.*)\n # get Platfoem and
> operating system
>     OS\s+VERSION:(.*)?\s+ UG\sVERSION:(.*) # get OS and UG version
>     \s+ # skip new line
>     =+  # skip the =
>     \s+ # skip new line
>     HARDWARE.*
>     (.*\n)   # get everything between hardware and symptom

The problem here is that there are multiple lines between HARDWARE and
SYMPTOM, but you only match one.  You could probably just use:

      ((?:.*\n)*?)   # get all the lines between hardware and symptom

Using a non-greedy quantifier to match multiple lines is quite a
performance benefit here.

>     SYMPTOM.*
>     #(.*)
>     #SOLUTION.*
>     #(.*)
>     #REFERENCE.*
>     #(.*)
>     /x;
> print $11;
> # I want $1 - $14 to put in a hash
> }
> 
> 
> __DATA__
> PRODUCT: UG
> SUBJECT: How to configure and check a modem on HP 9000 workstations
> 
> SUBMITTED BY: STEVE RICHES SUBMITTED DATE: 09/20/94 IR #: 0347378
> DOCUMENT ID: 001-0347378 PLATFORM: HPRISC OPERATING SYSTEM: HP-UX OS
> VERSION: 9.01 UG VERSION: V10.2
> 
> ================================================================================
> 
> HARDWARE/SOFTWARE CONFIGURATION
> -------------------------------
> HP 9000 series 300/400/700/800 workstations,
> HP-UX V9.x
> 
> SYMPTOM/PROBLEM

[rest of data snipped]

When I need to parse data such as this, and there is sufficient
context for each element of the match such that the overall format is
unimportant, I end up matching the individual pieces separately.  Here
is what I would use for this case:

#!/usr/bin/perl

use strict;
use warnings;

my %fields = (Product       => qr/^PRODUCT:\s*(.*)$/m,
              Subject       => qr/^SUBJECT:\s*(.*)$/m,
              Submitter     => qr/^SUBMITTED\s+BY:\s*(.*?)\s*SUBMITTED/m,
              Submitted     => qr/SUBMITTED\s+DATE:\s*(.*)$/m,
              IR            => qr/^IR\s*#:\s*(.*?)\s*DOCUMENT/m,
              DocID         => qr/DOCUMENT\s+ID:\s*(.*)$/m,
              Platform      => qr/^PLATFORM:\s*(.*?)\s*OPERATING/m,
              OS            => qr/OPERATING\s+SYSTEM:\s*(.*)$/m,
              OSVer         => qr/^OS\s+VERSION:\s*(.*?)\s*UG\s+VERSION/m,
              UGVer         => qr/UG\s+VERSION:\s*(.*)$/m,
              Hardware      => qr/^HARDWARE.*\n((?:.*\n)*?)SYMPTOM/m,
              Symptom       => qr/^SYMPTOM.*\n((?:.*\n)*?)SOLUTION/m,
              Solution      => qr/^SOLUTION.*\n((?:.*\n)*?)REFERENCE/m,
              Reference     => qr/^REFERENCE.*\n(.*)/ms);

$_ = do { local $/; <DATA> };     # slurp

my %data;
for my $field (keys %fields) {
    ($data{$field}) = /$fields{$field}/
       or die "Problem matching $field in $_\n";
}

# Now %data is populated, use it however desired.

__DATA__
There was too much data, so I snipped it from this post....
__END__

That's a first pass at it (tested), but there are some things I would
probably change.  For example, the multi-line fields have separators
in the data that I would probably skip.

-- 
Ren Maddox
ren@tivoli.com


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

Date: Sat, 07 Jul 2001 16:42:03 GMT
From: "David Mohorn" <david.mohorn@home.com>
Subject: Script won't DIE!!!
Message-Id: <vZG17.152916$qc.18301578@news1.rdc1.va.home.com>

if I run the following perl script, without passing any parameters, it
returns, "Hello World".  However, if I type in any arguments whatever (as
long as I don't do all required), it dies with usage message.  It was my
understanding that GetOptions would return failure if all of the required
arguments are not specified.

What am I doing wrong here?

#!/usr/bin/perl -w

use strict;
use Net::FTP;
use Getopt::Long;

use constant USAGEMSG => <<USAGE;
Usage: ftp_test.pl [options]
Options:
         --host <host>   Host name
         --user <user>   Login name
         --pass <pass>   Password
         --hash          Progress reports
USAGE

my ($HOST, $USERNAME, $PASS, $HASH);

die USAGEMSG unless GetOptions('host=s'  => \$HOST,
                               'user=s'  => \$USERNAME,
                               'pass=s'  => \$PASS,
                               'hash'    => \$HASH);

printf("Hello World\n");

exit 0;




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

Date: Sat, 7 Jul 2001 03:55:47 -0400
From: "noms" <dont@mail.me>
Subject: Term::ANSIColor in Windows 2000's CMD
Message-Id: <9i6fa8$qsk$1@bob.news.rcn.net>

Has anyone successfully used the Term::ANSIColor module in Windows 2000's
CMD using ActivePerl?  I've tried using code straight from the module's
documentation, but still see the standard colors.  If I run the same script
on a Linux console, everything works as expected.  Is this a limitation of
CMD or is there a special option to allow for ANSI colors in it?  Thanks for
your help.

PS: Russ, if you're reading, sorry for the email.  I read your "ask
questions in public" a bit too late :(




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

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


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