[24045] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6242 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 10 14:05:50 2004

Date: Wed, 10 Mar 2004 11: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           Wed, 10 Mar 2004     Volume: 10 Number: 6242

Today's topics:
    Re: [OT] Rockets Alternative <bmb@ginger.libs.uga.edu>
        array performance- references problem <andreas.goetz.external@fujitsu-siemens.com>
    Re: array performance- references problem <nobull@mail.com>
        Calling another program <s020274@cuhk.edu.hk>
    Re: Calling another program <ittyspam@yahoo.com>
    Re: Calling another program <ceo@nospan.on.net>
    Re: Calling another program <s020274@cuhk.edu.hk>
    Re: Calling another program <nobull@mail.com>
        DBI and DBD problems <koh@sikkerhet.no>
    Re: DBI and DBD problems <Me@myco.com>
        help using output from Expect (Kevin Cheramie)
    Re: How to redirect headers in Perl? (Crazy Monkey)
    Re: How to use times? (Chris Marshall)
    Re: How to use times? <tadmc@augustmail.com>
    Re: How to use times? <s020274@cuhk.edu.hk>
    Re: How to use times? <s020274@cuhk.edu.hk>
    Re: How to use times? <ittyspam@yahoo.com>
    Re: How to use times? <s020274@cuhk.edu.hk>
    Re: How to use times? <ittyspam@yahoo.com>
    Re: How to use times? <tore@aursand.no>
    Re: Multiple compares -- TMTOWTDI (Steve The Geek)
    Re: Multiple compares -- TMTOWTDI <tadmc@augustmail.com>
        Parsing <td> tags with HTML::Parser after a certain eve <parimi@nowhere.none.com>
    Re: Perl module for analyzing log files <tadmc@augustmail.com>
        perl on windows <chatiman@free.fr>
    Re: perl on windows <minter@lunenburg.org>
    Re: perl on windows <matthew.garrish@sympatico.ca>
    Re: perl on windows <usenet@morrow.me.uk>
    Re: Quoting non-numbers <fifo@despammed.com>
    Re: Quoting non-numbers <roel-perl@st2x.net>
    Re: Quoting non-numbers (Anno Siegel)
    Re: regex  <tadmc@augustmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 10 Mar 2004 09:16:21 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: [OT] Rockets Alternative
Message-Id: <Pine.A41.4.58.0403100914450.19862@ginger.libs.uga.edu>

On Tue, 9 Mar 2004, Ben Morrow wrote:
>
> Quoth "George Kinley" <georgekinley@hotmail.com>:
> > Hi
> > Is there any  way  for rockets to fly in space , other then throwing mass
> > out in one direction and moving in other
>
> Yes.

But Microsoft has patented it.

Brad


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

Date: Wed, 10 Mar 2004 13:55:58 +0100
From: "Andreas Goetz" <andreas.goetz.external@fujitsu-siemens.com>
Subject: array performance- references problem
Message-Id: <c2n38u$41h$1@nntp.fujitsu-siemens.com>

I'm creating a logfile analyzer for my company. I need to store blocks of
log lines in a global array, to later retrieve them.

Approach 1:    push @statements, join("\n", @lines)
Working fine, but seems ugly as I later need to access the individual lines
from @statements:
foreach $statement (@statements){
    @lines = split("\n", $statement)
}

Comes Approach 2: Just use arrays:    push @statements, [@lines]
later:
foreach $statement (@statements){
    # use @{$statement}
}

This should take care of the unneeded join/splits. Only problem: performance
is worse by a factor of 5, probably due to pushing an array onto an array?

Approach 3: Use references:    push @statements, \@lines
laster:
foreach $statement (@statements){
    # use @$line;
}

Only problem here: as I parse the log file into chunks of lines, I need to
reuse the @lines array during parsing (after the push). Question is- how do
I clean out (or recreate) @lines without destroying the reference stored in
the array?
I think what I need is a 'fresh' variable that keeps the referenced data
intact. More or les like removing the link from @lines to the actual array
data it represents. Does this make sense?

Thanks,
Andi




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

Date: 10 Mar 2004 13:26:05 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: array performance- references problem
Message-Id: <u965dc96ky.fsf@wcl-l.bham.ac.uk>

"Andreas Goetz" <andreas.goetz.external@fujitsu-siemens.com> writes:

> from @statements:
> foreach $statement (@statements){
>     @lines = split("\n", $statement)
> }

You should always declare all variables as lexically scoped in the
smallest applicable lexical scope unless there is a positive reason to
do otherwise.

 foreach my $statement (@statements){
     my @lines = split("\n", $statement)
 }

> Comes Approach 2: Just use arrays:    push @statements, [@lines]
> later:
> foreach $statement (@statements){
>     # use @{$statement}
> }
> 
> This should take care of the unneeded join/splits. Only problem: performance
> is worse by a factor of 5, probably due to pushing an array onto an array?
> 
> Approach 3: Use references:    push @statements, \@lines
> laster:
> foreach $statement (@statements){
>     # use @$line;
> }

Note: both 2 and 3 use references.  The difference is that 2 creates a copy.

 push @statements, [@lines]

Is much the same as 
 {
    my @copy_of_lines = @lines;
    push @statements, \@copy_of_lines;
 }

> Only problem here: as I parse the log file into chunks of lines, I need to
> reuse the @lines array during parsing (after the push). Question is- how do
> I clean out (or recreate) @lines without destroying the reference stored in
> the array?

If by "clean out" you mean clear then, you sould note that you should
always declare all variables as lexically scoped in the smallest
applicable lexical scope unless there is a positive reason to do
otherwise.  Doing so usually avoids this issue.

> I think what I need is a 'fresh' variable that keeps the referenced data
> intact.

You mean something like

 my @copy_of_lines = @lines;

You can even say...

 my @lines = @lines;

 ... but you'll get a warning if you are at the same scope where @lines
was previously declared.

> More or les like removing the link from @lines to the actual array
> data it represents. Does this make sense?

Only vaguely.  If you want to have a two instances of the contents of
@lines and be able to change one without changing the other then you
are going to need to make a copy.  It was the creating of a second
copy that slowed you down in the first place.  

Are you sure you really need a copy?  Could you perhaps alter the
algorithm that reuses the @lines array during parsing (after the push)
so that it doesn't alter the contents of @lines?

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Thu, 11 Mar 2004 00:26:46 +0800
From: "Tsui Wai-ming" <s020274@cuhk.edu.hk>
Subject: Calling another program
Message-Id: <c2nfk6$1vbb$1@justice.itsc.cuhk.edu.hk>

Well, if I want to use Perl to call another console program to do something,
what function can I use? I tried 'system' but it didn't work :(

Sorry this question is too simple but I'm really a self-learning beginner of
Perl...

Many thanks!
Ming.




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

Date: Wed, 10 Mar 2004 11:56:45 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Calling another program
Message-Id: <20040310115519.W27834@dishwasher.cs.rpi.edu>

On Thu, 11 Mar 2004, Tsui Wai-ming wrote:

> Well, if I want to use Perl to call another console program to do something,
> what function can I use? I tried 'system' but it didn't work :(
>
> Sorry this question is too simple but I'm really a self-learning beginner of
> Perl...
>

What do you mean by "it didn't work"?  That's possibly the least helpful
description you can give us.  Did the program hang?  Did you get syntax
errors?  Did you not get the result you were expecting?  What happend?

system is one of three ways of running an external program.  The others
are backticks and pipes.  What are you trying to do?

Paul Lalli


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

Date: Wed, 10 Mar 2004 16:56:09 GMT
From: Chris <ceo@nospan.on.net>
Subject: Re: Calling another program
Message-Id: <JMH3c.22431$hw2.12900@newssvr31.news.prodigy.com>

Tsui Wai-ming wrote:
> Well, if I want to use Perl to call another console program to do something,
> what function can I use? I tried 'system' but it didn't work :(
> 

First of all, I'd say 90% (or more) of the time that I see someone use 
system() or any other method of fork and execute (eg. qx(), 
back-tick(command)back-tick, etc), it for some functionality that 
already exists in Perl or in a popular module (not even an obscure 
module).  So...  I'd say, esp. if you are just beginning, it would be 
prudent to approach system(), qx(), etc. with some pause and consider 
that more than likely "Perl can already do that" -- whatever "that" is 
-- without shelling and to look for the Perl solution and not the quick 
and easy (and unelegant) "hack."

Secondly, define why you think your system() command "didn't work" as 
you say (not having read the rest of this thread).  What makes you think 
it "didn't work."  Share your results with the group and then you can 
get a definitive answer on why it did or did not work as well as whether 
you should even be using system() for the problem at hand.  As I said, 
most of the time, system() is not only unnecessary, it's usually 
"hackish" and bad form.

-ceo

--
"Bad FORM!... EDMUND!" -King Peter
_The Lion, The Witch and The Wardrobe_


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

Date: Thu, 11 Mar 2004 01:31:51 +0800
From: "Tsui Wai-ming" <s020274@cuhk.edu.hk>
Subject: Re: Calling another program
Message-Id: <c2nje7$21qh$1@justice.itsc.cuhk.edu.hk>


"Chris" <ceo@nospan.on.net> 级糶秎ン穝籇
:JMH3c.22431$hw2.12900@newssvr31.news.prodigy.com...
> Tsui Wai-ming wrote:
> > Well, if I want to use Perl to call another console program to do
something,
> > what function can I use? I tried 'system' but it didn't work :(
> >
>
> First of all, I'd say 90% (or more) of the time that I see someone use
> system() or any other method of fork and execute (eg. qx(),
> back-tick(command)back-tick, etc), it for some functionality that
> already exists in Perl or in a popular module (not even an obscure
> module).  So...  I'd say, esp. if you are just beginning, it would be
> prudent to approach system(), qx(), etc. with some pause and consider
> that more than likely "Perl can already do that" -- whatever "that" is
> -- without shelling and to look for the Perl solution and not the quick
> and easy (and unelegant) "hack."
>
> Secondly, define why you think your system() command "didn't work" as
> you say (not having read the rest of this thread).  What makes you think
> it "didn't work."  Share your results with the group and then you can
> get a definitive answer on why it did or did not work as well as whether
> you should even be using system() for the problem at hand.  As I said,
> most of the time, system() is not only unnecessary, it's usually
> "hackish" and bad form.
>
> -ceo
>

Really thanks for your comments. My script is like this:

chdir( "C:\\Praat\\" );
system( "praatcon.exe", "sine.praat" );

I changed the directory to where the console is, then the first argument of
system() is the name of the console and second is the name of the script.
This time I got it work but did you mean you had a better way to do the same
thing?

> --
> "Bad FORM!... EDMUND!" -King Peter
> _The Lion, The Witch and The Wardrobe_




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

Date: 10 Mar 2004 17:50:13 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Calling another program
Message-Id: <u91xo08ucq.fsf@wcl-l.bham.ac.uk>

"Tsui Wai-ming" <s020274@cuhk.edu.hk> writes:

> "Chris" <ceo@nospan.on.net> 级糶秎ン穝籇
> :JMH3c.22431$hw2.12900@newssvr31.news.prodigy.com...
> >
> > First of all, I'd say 90% (or more) of the time that I see someone use
> > system() or any other method of fork and execute (eg. qx(),
> > back-tick(command)back-tick, etc), it for some functionality that
> > already exists in Perl or in a popular module (not even an obscure
> > module).  So...  I'd say, esp. if you are just beginning, it would be
> > prudent to approach system(), qx(), etc. with some pause and consider
> > that more than likely "Perl can already do that" -- whatever "that" is
> > -- without shelling and to look for the Perl solution and not the quick
> > and easy (and unelegant) "hack."
> 
> system( "praatcon.exe", "sine.praat" );

> This time I got it work but did you mean you had a better way to do the same
> thing?

Well that would obiviously depend on what praatcon.exe does.

I have no idea what praatcon.exe but from the fact that you refer to
it as a "console" I'd guess you were in the 10%. 

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 10 Mar 2004 13:13:23 +0100
From: Ketil <koh@sikkerhet.no>
Subject: DBI and DBD problems
Message-Id: <404f063f$1@news.wineasy.se>

Hi,
I have an oracle server and have installed dbd and DBI perl modules.
When I connect to the database, I resice the folloing errors:

DBI connect('salabim:1521','ids',...) failed: ORA-06401: NETCMN: invalid 
driver designator (DBD ERROR: OCIServerAttach) at ./ora_test.pl line 6
Database connection not made: ORA-06401: NETCMN: invalid driver 
designator (DBD ERROR: OCIServerAttach) at ./ora_test.pl line 6.

perl code is simple and here it is:

#!/usr/bin/perl

use strict;
use DBI;

my $dbh = DBI->connect( 'dbi:Oracle:salabim:1521',
                         'ids',
                         'ids',
                       ) || die "Database connection not made: 
$DBI::errstr";
$dbh->disconnect();

database name : SALABIM
user:ids
passwd:ids

can anyone help me ?

Ketil Heggtveit



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

Date: Wed, 10 Mar 2004 18:39:22 +0530
From: Abhinav <Me@myco.com>
Subject: Re: DBI and DBD problems
Message-Id: <syE3c.9$PB5.56@news.oracle.com>



Ketil wrote:
> Hi,

> I have an oracle server and have installed dbd and DBI perl modules.
> When I connect to the database, I resice the folloing errors:
> 
> DBI connect('salabim:1521','ids',...) failed: ORA-06401: NETCMN: invalid 
> driver designator (DBD ERROR: OCIServerAttach) at ./ora_test.pl line 6
> Database connection not made: ORA-06401: NETCMN: invalid driver 
> designator (DBD ERROR: OCIServerAttach) at ./ora_test.pl line 6.
>
bash $ oerr ora 06401
06401, 00000, "NETCMN: invalid driver designator"
// *Cause:  The login (connect) string contains an invalid driver 
designator.
// *Action: Correct the string and re-submit.
--
1. Ensure that TNS_ADMIN is set, and tnsnames.ora specifies the correct 
entry for the db

> perl code is simple and here it is:
> 
> #!/usr/bin/perl
> 
> use strict;
> use DBI;
> 
> my $dbh = DBI->connect( 'dbi:Oracle:salabim:1521',
>                         'ids',
>                         'ids',
>                       ) || die "Database connection not made: 

2. Consider setting $TWO_TASK and connecting through that.
  my $dbh = DBI->connect( 'dbi:Oracle:',
  ...........
-----8<---------------

HTH
Regards
Abhinav
> 
> can anyone help me ?
> 
> Ketil Heggtveit
> 



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

Date: 10 Mar 2004 10:33:37 -0800
From: kevinc@mobiletel.com (Kevin Cheramie)
Subject: help using output from Expect
Message-Id: <12a7c28e.0403101033.6fc0ca50@posting.google.com>

I'm unsure how to break down and use what is returned by expect in the
rest of my script.  I want to issue a command and split the results of
that command into several different variables. I then want to use
those variables in the rest of my script. Here is a snipet:

  $expcxn = Expect->spawn("telnet 10.10.10.10\r") or die "Cannot spawn
telnet: $!\n\n";
  $expcxn->expect($timeout, "assword:") or die "Did not get a password
prompt: $!/n/n";
  print $expcxn "thepassword\r";
  $expcxn->expect($timeout, "go>") or die "Did not get command prompt:
$!/n/n";
  print $expcxn "show info $ARGV[0]\r";
  $expcxn->expect($timeout, "go>") or die "Did not get command prompt:
$!/n/n";
  exit(-1);

The 'show info' command is what produces the info I want to split and
use. What do I have to do to get whatever is returned and put it into
variables I can use in other commands?


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

Date: 10 Mar 2004 09:18:46 -0800
From: wlin98004@hotmail.com (Crazy Monkey)
Subject: Re: How to redirect headers in Perl?
Message-Id: <db81df92.0403100918.1f90f0a0@posting.google.com>

> use LWP::Simple;
> 
> my $page1=get("userid:password@www.site.com");
> 

This form of passing user authentication WAS supported by IE only. 
Due to URL spoofing, even IE doesn't allow it anymore.


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

Date: 10 Mar 2004 05:30:45 -0800
From: c_j_marshall@hotmail.com (Chris Marshall)
Subject: Re: How to use times?
Message-Id: <cb9c7b76.0403100530.117cf9fb@posting.google.com>

"Tsui Wai-ming" <s020274@cuhk.edu.hk> wrote in message news:<c2m1hm$188s$1@justice.itsc.cuhk.edu.hk>...
> I've written a script using 'times' to compute the time needed to execute a
> code, but it always gives me 0 seconds.  

There's already Benchmark module specifically for this.

   perldoc Benchmark

to see how to use it.


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

Date: Tue, 9 Mar 2004 23:03:22 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: How to use times?
Message-Id: <slrnc4t8cq.57h.tadmc@magna.augustmail.com>

Tsui Wai-ming <s020274@cuhk.edu.hk> wrote:

>   open( IN, ">>time.txt" ) or die( "Cannot open file: $!" );


That is an odd choice of filehandle for a file opened for output...


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


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

Date: Thu, 11 Mar 2004 00:21:30 +0800
From: "Tsui Wai-ming" <s020274@cuhk.edu.hk>
Subject: Re: How to use times?
Message-Id: <c2nfae$1v4g$1@justice.itsc.cuhk.edu.hk>


"Tad McClellan" <tadmc@augustmail.com> 级糶秎ン穝籇
:slrnc4t8cq.57h.tadmc@magna.augustmail.com...
> Tsui Wai-ming <s020274@cuhk.edu.hk> wrote:
>
> >   open( IN, ">>time.txt" ) or die( "Cannot open file: $!" );
>
>
> That is an odd choice of filehandle for a file opened for output...

Oh...what choice should I use instead?
Thanks :)

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




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

Date: Thu, 11 Mar 2004 00:22:36 +0800
From: "Tsui Wai-ming" <s020274@cuhk.edu.hk>
Subject: Re: How to use times?
Message-Id: <c2nfcc$1v5g$1@justice.itsc.cuhk.edu.hk>

Thank everyone for the opinions!

Ming :)

"Tsui Wai-ming" <s020274@cuhk.edu.hk> 级糶秎ン穝籇
:c2m1hm$188s$1@justice.itsc.cuhk.edu.hk...
> I've written a script using 'times' to compute the time needed to execute
a
> code, but it always gives me 0 seconds.  Could anyone see if my syntax is
> wrong?
>
> if ( $choiceA ) {
>  $start = ( times )[0];
>
>  if ( $choiceB ) {
>   $end = ( times )[0];
>   $dur = $end - $start;
>   open( IN, ">>time.txt" ) or die( "Cannot open file: $!" );
>   print( IN "$dur\t" );
>   close( IN ) or die( "Cannot close file: $!" );
>  }
> }
>
>
>




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

Date: Wed, 10 Mar 2004 11:58:13 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: How to use times?
Message-Id: <20040310115654.P27834@dishwasher.cs.rpi.edu>

On Thu, 11 Mar 2004, Tsui Wai-ming wrote:

> "Tad McClellan" <tadmc@augustmail.com> =BC=B6=BCg=A9=F3=B6l=A5=F3=B7s=BBD
> :slrnc4t8cq.57h.tadmc@magna.augustmail.com...
> > Tsui Wai-ming <s020274@cuhk.edu.hk> wrote:
> >
> > >   open( IN, ">>time.txt" ) or die( "Cannot open file: $!" );
> >
> >
> > That is an odd choice of filehandle for a file opened for output...
>
> Oh...what choice should I use instead?
> Thanks :)

Generally, if you're opening a file for output, you name it something like
OUT or OUTFILE or OUTPUT.  Files that are opened for input, conversely,
should be named IN or INFILE or INPUT or something similar.

This will not affect the execution of your program, of course.  But it
makes it easier for future maintainers (including yourself) to see what's
happening in your code.


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

Date: Thu, 11 Mar 2004 01:02:31 +0800
From: "Tsui Wai-ming" <s020274@cuhk.edu.hk>
Subject: Re: How to use times?
Message-Id: <c2nhn7$20mf$1@justice.itsc.cuhk.edu.hk>

Thanks a lot again~
Ming~

"Paul Lalli" <ittyspam@yahoo.com> 级糶秎ン穝籇
:20040310115654.P27834@dishwasher.cs.rpi.edu...
On Thu, 11 Mar 2004, Tsui Wai-ming wrote:

> "Tad McClellan" <tadmc@augustmail.com> 级糶秎ン穝籇
> :slrnc4t8cq.57h.tadmc@magna.augustmail.com...
> > Tsui Wai-ming <s020274@cuhk.edu.hk> wrote:
> >
> > >   open( IN, ">>time.txt" ) or die( "Cannot open file: $!" );
> >
> >
> > That is an odd choice of filehandle for a file opened for output...
>
> Oh...what choice should I use instead?
> Thanks :)

Generally, if you're opening a file for output, you name it something like
OUT or OUTFILE or OUTPUT.  Files that are opened for input, conversely,
should be named IN or INFILE or INPUT or something similar.

This will not affect the execution of your program, of course.  But it
makes it easier for future maintainers (including yourself) to see what's
happening in your code.




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

Date: Wed, 10 Mar 2004 12:15:28 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: How to use times?
Message-Id: <20040310121412.J27834@dishwasher.cs.rpi.edu>

On Thu, 11 Mar 2004, Tsui Wai-ming wrote:

> Thanks a lot again~
> Ming~
>
> "Paul Lalli" <ittyspam@yahoo.com> =BC=B6=BCg=A9=F3=B6l=A5=F3=B7s=BBD
> :20040310115654.P27834@dishwasher.cs.rpi.edu...
> On Thu, 11 Mar 2004, Tsui Wai-ming wrote:
>
> > "Tad McClellan" <tadmc@augustmail.com> =BC=B6=BCg=A9=F3=B6l=A5=F3=B7s=
=BBD
> > :slrnc4t8cq.57h.tadmc@magna.augustmail.com...
> > > Tsui Wai-ming <s020274@cuhk.edu.hk> wrote:
> > >
> > > >   open( IN, ">>time.txt" ) or die( "Cannot open file: $!" );
> > >
> > >
> > > That is an odd choice of filehandle for a file opened for output...
> >
> > Oh...what choice should I use instead?
> > Thanks :)
>
> Generally, if you're opening a file for output, you name it something lik=
e
> OUT or OUTFILE or OUTPUT.  Files that are opened for input, conversely,
> should be named IN or INFILE or INPUT or something similar.
>
> This will not affect the execution of your program, of course.  But it
> makes it easier for future maintainers (including yourself) to see what's
> happening in your code.


Please take a few moments to go read the posting guidelines of this group.
Among the guidelines you seem to routinely break are: Do not post your
reply above what you are replying to;  Do not post to the list simply
saying "it doesn't work".

Thank you,
Paul Lalli


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

Date: Wed, 10 Mar 2004 18:53:11 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: How to use times?
Message-Id: <pan.2004.03.10.17.50.22.762446@aursand.no>

On Thu, 11 Mar 2004 00:21:30 +0800, Tsui Wai-ming wrote:
>>>   open( IN, ">>time.txt" ) or die( "Cannot open file: $!" );

>> That is an odd choice of filehandle for a file opened for output...

> Oh...what choice should I use instead?

What do you think?  You're naming the filehandle 'IN', but are opening the
file for writing.  More information:

  perldoc -f open

> Thanks :)

No problem, but consider consulting the documentation before you ask next
time.  It will save us _and_ you time.


-- 
Tore Aursand <tore@aursand.no>
"Nothing is certain but death and taxes. Of the two, taxes happen
 annually." -- Joel Fox


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

Date: 10 Mar 2004 05:58:55 -0800
From: slkleine@hotmail.com (Steve The Geek)
Subject: Re: Multiple compares -- TMTOWTDI
Message-Id: <863f122c.0403100558.1da0c4ec@posting.google.com>

Jim Gibson <jgibson@mail.arc.nasa.gov> wrote in message news:<090320041313445654%jgibson@mail.arc.nasa.gov>...
> In article <863f122c.0403090937.688d1c2d@posting.google.com>, Steve The
> Geek <slkleine@hotmail.com> wrote:
> 
> > The logic works, but there's gotta be a better way.
> > 
> > FUNCTION
> > The job of this subroutine is to filter out TRAP codes from our daily
> > syslog files, specifically Generic TRAP 6 in combination with specific
> > trap 1, 2, 418 or 419.[1]
> > 
> > I've searched through Perl CD Bookshelf 4.0 to little gain[2].
> > 
> > FWIW, I'm of classification 'Newbie'.
> > 
> > Thanks in advance!
> It is best to post a complete, working program. Always put these lines
> at the top:

<< much good advice recognized & snipped >>

Since posting it, I've made a few (lot) of changes, but here's the
whole thing as it currently stands as working code (Server names
changed to XXXXXXXX to protect the guilty):

######################################
## EnterasysEventLogParser.pl
## Creation date: 200400308
## Last edit: 200400310
## Author: Steve Kleine
############################################################################
##	This script looks through a comma-delimited enterasys log file and
## filers out anything that's not a warning or critical. From there,
it
## excludes RMON, Microsoft, and port up/down events. What remains is
the
## things to look at.
############################################################################
##  Log files are kept at \\XXXXXXXX\C$\Program Files\Enterasys
Networks\
## NetSight Element Manager\Log.
##  The filename is formatted YYYYMMDD.CSV. The script will look for
the log
## file produced the previous day.
############################################################################
##	Declare variables
############################################################################
require 5.002;
use strict;
my ($Day, $Month, $Year) = (localtime)[3..5];   #time data
my (@DataLine, $File, $FilePath,
$FileName,$PreviousDay,$PreviousMonth,$PreviousYear);
my (@Month, @Days, @DaysFormat);
my ($LinesRead, $LinesWrite, $LineFromLog);
my ($ReturnCode,$LOG);
############################################################################
##	Initialize variables
############################################################################

$FilePath = '\\\\XXXXXXXX\\C$\\Program Files\\Enterasys
Networks\\NetSight Element Manager\\Log\\';
@Month = qw /01 02 03 04 05 06 07 08 09 10 11 12/;
@Days = qw /00 31 28 31 30 31 30 31 31 30 31 30 31/;
@DaysFormat = qw /00 01 02 03 04 05 06 07 08 09/;
@DaysFormat[10..31] = 10..31;
$LinesRead = $LinesWrite =  0;

##  The following modifies months & days when it's the first of the
month and
## a previous day's record is requested. It also modifies year if it's
the
## first of the year.
$Month = @Month[$Month], $Day = @DaysFormat[$Day];

$Year +=1900, $PreviousMonth=$Month, $PreviousYear = $Year -1,
$PreviousDay=@DaysFormat[$Day-1];
if ( !$PreviousDay )
    {
    $PreviousMonth=@Month[$Month-1],
$PreviousDay=@Days[$PreviousMonth]
    }
if ( !$PreviousMonth )
    {
      $PreviousMonth = "12", $PreviousDay = "31"
    }

$FileName = "$FilePath$Year$PreviousMonth$PreviousDay\.CSV";

############################################################################
## MAIN ROUTINES
############################################################################
## OPEN FILES FOR READ & WRITE
############################################################################
open LOG , $FileName or die "I can\'t find yesterday's file $!.";
open WriteLog , '>>c:\Filtered_log.csv' or die "Can't create write
file: $!";
print WriteLog 'Date,Type,IP address,Source,What happened,What it
means,Generic TRAP,specific TRAP';
############################################################################
##  Parse logfile
############################################################################

while (defined($LineFromLog = <LOG>))
  {
  $LinesRead ++;
  @DataLine = split /,/, $LineFromLog;
#  print "@DataLine[1..31]\n";
  if (@DataLine[2] eq 'Warning')  #Only deal with warnings
    {
    if (@DataLine[7] ne "Microsoft")  #Removing Microsoft crap
      {
      &RemoveIrrelevantCodes(@DataLine);
      if ($ReturnCode)
        {
        print WriteLog "\n$ReturnCode";
        $LinesWrite ++;
        }
      }
    }
  }
############################################################################
##  ENDING ROUTINES
############################################################################
print "\n$LinesRead lines were parsed from the logfile.\n$LinesWrite
were written to filtered file.\n";
print WriteLog "\n$LinesRead lines were parsed from the
logfile.\n$LinesWrite were written to filtered file.\n";

close WriteLog;
close LOG;

############################################################################
## SUBROUTINES
############################################################################
##  Removes items from line that are RMON thresholds and port up/down
## messages. These are worthless in the current environment
##  The code specified for these traps is "6" in field 14 AND 1, 2,
418, or
## 419 in field 15. Only if both of these are true will that line be
ignored.
############################################################################
sub RemoveIrrelevantCodes
{$ReturnCode = undef;  #Initialize $ReturnCode
  if ((@DataLine[14] == "6")) #General class of TRAP
  {
    if (@DataLine[15] == "1") #RMON exceeded
    {return}
    if (@DataLine[15] == "2") #RMON in spec
    {return}
    if (@DataLine[15] == "418") #Port up
    {return}
    if (@DataLine[15] == "419") #Port down
    {return}
  }
    $ReturnCode = join (",", @DataLine[1,2,5,7..9,14,15])
}


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

Date: Wed, 10 Mar 2004 09:12:15 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Multiple compares -- TMTOWTDI
Message-Id: <slrnc4uc2f.1pd.tadmc@magna.augustmail.com>

Steve The Geek <slkleine@hotmail.com> wrote:
> Jim Gibson <jgibson@mail.arc.nasa.gov> wrote in message news:<090320041313445654%jgibson@mail.arc.nasa.gov>...
>> In article <863f122c.0403090937.688d1c2d@posting.google.com>, Steve The
>> Geek <slkleine@hotmail.com> wrote:

>> > The job of this subroutine is to filter out TRAP codes from our daily
>> > syslog files, specifically Generic TRAP 6 in combination with specific
>> > trap 1, 2, 418 or 419.[1]

> Since posting it, I've made a few (lot) of changes, but here's the
> whole thing as it currently stands as working code

> require 5.002;
> use strict;


You are missing a line here:

   use warnings;

You should always enable warnings when developing Perl code.


> my (@DataLine, $File, $FilePath,

[snip code]

> $FilePath = '\\\\XXXXXXXX\\C$\\Program Files\\Enterasys
> Networks\\NetSight Element Manager\\Log\\';


You should declare your variables in the smallest possible scope,
which is usually when you first access the variable.

None of the extra backslashes are needed, except for the final one.

You can use sensible slashes instead of silly ones.

   my  $FilePath = '/XXXXXXXX/C$/Program Files/'
                 . 'Enterasys Networks/NetSight Element Manager/Log/';



> $Month = @Month[$Month], $Day = @DaysFormat[$Day];
           ^                      ^
           ^                      ^

You should always enable warnings when developing Perl code.

Why are you using the comma operator instead of two statements?


> if ( !$PreviousMonth )
>     {
>       $PreviousMonth = "12", $PreviousDay = "31"
>     }


You should use one of the Date::* modules for processing dates.


> $FileName = "$FilePath$Year$PreviousMonth$PreviousDay\.CSV";


Dots are not special in strings, you do not need to backslash them.


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


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

Date: Wed, 10 Mar 2004 11:38:00 -0700
From: Ravi Parimi <parimi@nowhere.none.com>
Subject: Parsing <td> tags with HTML::Parser after a certain event
Message-Id: <Pine.GSO.4.58.0403101128470.6538@shellfish.ece.arizona.edu>

Hi,
	I have been trying to extract the text enclosed within the <td>
tags in a HTML page only after finding a previous <a href=...> line.

The format of the HTML is as:

<td><a href="/?services&KeyConfig_select=test1">Key1</a></td>
<td>UserName</td>

I have been able to extract test1 and Key1. What I want to do next is to
extract UserName.

Main parts of my code doing the parsing are as below:


my $parser = HTML::Parser->new(api_version => 3);
        $parser->handler(start => \&mysub,'self,tagname,attr');
        $parser->parse($page);
        $parser->eof;

sub mysub
{
        my ($parser,$tagname,$attr) = @_;
        return if (!defined $tagname or !defined $attr->{href});
        return unless $tagname eq 'a';
        print "Contents are $tagname and $attr->{href}\n";
        my @arr = split /=/,$attr->{href};
        if (defined $arr[2]) {
                push @KEYS,$arr[2]
        } else {
                return;
        }
        $parser->handler(text => \&extract, 'self,tagname,attr');
        $parser->handler(end => \&end, 'self,tagname');
}

sub extract
{
        my ($self,$tag,$attr) = @_;
        return unless $tag eq 'td';
        print "Extract , tag = $tag\n";
        print "Text is $attr->{$tag}\n";
}
sub end
{
        my ($self, $tag) = @_;
        return unless $tag eq 'td';
        $self->handler(text => undef);
        $self->handler(end => undef);
}

I am not sure how to add a handler for extracting the text within <td>
following the <a href...> line. Can someone show me how to do this?

Thanks in advance,
--ravi



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

Date: Wed, 10 Mar 2004 07:57:53 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Perl module for analyzing log files
Message-Id: <slrnc4u7n1.1kh.tadmc@magna.augustmail.com>

Krishna Srinivasan <krishna@multimediastudio.com> wrote:

> Am looking for a CPAN Perl Module


Then you are in the wrong place.


   http://search.cpan.org

is where you look for CPAN modules.


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


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

Date: Wed, 10 Mar 2004 14:14:22 +0100
From: "chatiman" <chatiman@free.fr>
Subject: perl on windows
Message-Id: <404f14a0$0$312$626a14ce@news.free.fr>

Hello,

I'm willing to write an app for windows with perl having a GUI.
So here's a few questions :
- What are the supported libraries for the GUI (gtk ?, qt ?, ... ?) ?
- Is there examples of apps writen entirely in perl ?
- What about PerlScript for building the whole app ?
Are the perl features limited with PerlScript ?
- Can perl be bundled with the app or not ?

Thanks





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

Date: Wed, 10 Mar 2004 14:12:14 GMT
From: "H. Wade Minter" <minter@lunenburg.org>
Subject: Re: perl on windows
Message-Id: <2nF3c.105045$jx3.7900221@twister.southeast.rr.com>

chatiman <chatiman@free.fr> wrote:
> Hello,
> 
> I'm willing to write an app for windows with perl having a GUI.
> So here's a few questions :
> - What are the supported libraries for the GUI (gtk ?, qt ?, ... ?) ?

Probably the best-supported one is Perl/Tk - there are a couple of great
books on it, and the comp.lang.perl.tk newsgroup is very helpful

> - Is there examples of apps writen entirely in perl ?

I have one - a fairly sizable Unix/Win32 GUI app written in Perl.
http://www.lunenburg.org/mrvoice/

> - Can perl be bundled with the app or not ?

Yes, you can use PAR (http://par.perl.org/) to bundle your script and 
all required modules into a single Win32 .exe file that you can distribute.

--Wade


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

Date: Wed, 10 Mar 2004 09:11:11 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: perl on windows
Message-Id: <2mF3c.3879$j05.249573@news20.bellglobal.com>


"chatiman" <chatiman@free.fr> wrote in message
news:404f14a0$0$312$626a14ce@news.free.fr...
> Hello,
>
> I'm willing to write an app for windows with perl having a GUI.
> So here's a few questions :
> - What are the supported libraries for the GUI (gtk ?, qt ?, ... ?) ?

You could try the Tk extensions, but I wouldn't recommend it if you want a
standard looking windows app. You could also try the Win32::GUI module. I
haven't used it myself, but it sounds more promising for Windows-only work.

> - Is there examples of apps writen entirely in perl ?

I'm sure there are, but I'm not Google...

> - What about PerlScript for building the whole app ?

PerlScript is the ASP implementation of Perl. Are you building an app or a
web page?

> Are the perl features limited with PerlScript ?

If you're planning for it to run client-side, you'd better hope that
everyone who wants to access your page has Perl installed on their machine.

> - Can perl be bundled with the app or not ?

I guess we're back to a standalone app now? The answer is yes, your code can
be compiled into an executable if that's what you really trying to ask. If
you actually want to bundle Perl with your app, it would be a good idea to
check the license agreement...

Matt




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

Date: Wed, 10 Mar 2004 15:22:36 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: perl on windows
Message-Id: <c2nbrs$re7$1@wisteria.csv.warwick.ac.uk>


Quoth "Matt Garrish" <matthew.garrish@sympatico.ca>:
> 
> "chatiman" <chatiman@free.fr> wrote in message
> news:404f14a0$0$312$626a14ce@news.free.fr...
> > Hello,
> >
> > I'm willing to write an app for windows with perl having a GUI.
> > So here's a few questions :
> > - What are the supported libraries for the GUI (gtk ?, qt ?, ... ?) ?
> 
> You could try the Tk extensions, but I wouldn't recommend it if you want a
> standard looking windows app.

I would. As of quite some time ago it uses standard Windows widgets, unlike say
Gtk which doesn't.

Ben

-- 
don't get my sympathy hanging out the 15th floor. you've changed the locks 3
times, he still comes reeling though the door, and soon he'll get to you, teach
you how to get to purest hell. you do it to yourself and that's what really
hurts is you do it to yourself just you, you and noone else ** ben@morrow.me.uk


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

Date: Wed, 10 Mar 2004 11:28:53 +0000
From: fifo <fifo@despammed.com>
Subject: Re: Quoting non-numbers
Message-Id: <20040310112849.GB24713@fleece>

At 2004-03-10 10:49 +0000, Roel van der Steen wrote:
> On Wed, 10 Mar 2004 at 10:37 GMT, Stevens wrote:
> > I'm trying to create a regular expression that takes a list of space
> > delimited words and numbers and encloses every non-number within single
> > quotes.
> > 
> > e.g 1967 foo 3.234 system_analyst 87834/d23434 would be returned as 1967
> > 'foo' 3.234 'system_analyst' '87834/d23434'
> > 
> 
> #!/usr/bin/perl
> use strict;
> use warnings;
> 
> $_ = '1967 foo 3.234 system_analyst 87834/d23434';
> s/(\S+)/'$1'/g;
> print $_;

That quotes the numbers as well though.  You might want to replace the
substitution with something like

  s/(\S+)/my $word = $1; $word =~ m(^[\d.,]+$) ? $word : "'$word'"/eg;

with the m( ... ) matching whatever the definition of a 'number' should be.


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

Date: 10 Mar 2004 12:16:48 GMT
From: Roel van der Steen <roel-perl@st2x.net>
Subject: Re: Quoting non-numbers
Message-Id: <slrnc4u1sc.dqn.roel-perl@localhost.localdomain>

On Wed, 10 Mar 2004 at 11:28 GMT, fifo wrote:
> At 2004-03-10 10:49 +0000, Roel van der Steen wrote:
>> On Wed, 10 Mar 2004 at 10:37 GMT, Stevens wrote:
>> > I'm trying to create a regular expression that takes a list of space
>> > delimited words and numbers and encloses every non-number within single
>> > quotes.
>>
> That quotes the numbers as well though.  You might want to replace the

Sorry, I'll try to read the question better next time. :)


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

Date: 10 Mar 2004 12:45:19 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Quoting non-numbers
Message-Id: <c2n2kv$sar$1@mamenchi.zrz.TU-Berlin.DE>

Stevens <auto87829@hushmail.com> wrote in comp.lang.perl.misc:
> Dear all,
> 
> I'm trying to create a regular expression that takes a list of space
> delimited words and numbers and encloses every non-number within single
> quotes.
> 
> e.g 1967 foo 3.234 system_analyst 87834/d23434 would be returned as 1967

Use quotes to indicate where the example text begins and ends.

> 'foo' 3.234 'system_analyst' '87834/d23434'
>
> I can't get the syntax right ... how could you do this?

What have you tried?  What syntax error are you getting?  It helps when
you show your effort.

    my $y = join ' ', map /[^\d.]/ ? "'$_'" : $_,  split ' ', $x;

Anno


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

Date: Tue, 9 Mar 2004 22:59:59 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: regex 
Message-Id: <slrnc4t86f.57h.tadmc@magna.augustmail.com>

yamini <yamini_rajan@nospam.com> wrote:

> $_="{NP_P}<p>TGF-beta</p>{/NP_P} {VP_act}phosphorylated{/VP_act} {NP_B}<AND><p>EGFR</p>_,_<p>ERK</p>_and_<B>p38MAPK</B></AND>{/NP_B} in {NP}a_<AND><B>PKC-</B>_and_<B>MMP-dependent</B>_manner</AND>{/NP} .";
> 
> I have to write a regex that extracts the information within {NP_B}<AND>...</AND>{/NP_B}.


   m!{NP_B}<AND>(.*?)</AND>{/NP_B}!g


> I have to validate all the tags(<p>,</p>,<B>,</B>,AND>,</AND) within {NP_B}..{/NP_B}.


What does "validate" mean when you say it?

Are we supposed to already know the rules for the markup language
you are using?

What markup language are you using?

What rules must the "tags" follow in order to be "valid"?


> Also there may be any no of occurrences of the above said tags within {NP_B}..{/NP_B},and i have to extract all of them.
> 
> expected output:


Output expected from what?


> EGFR,ERK,p38MAPK
> 
> can anyone help me to get the solution?


Show us what you have so far, and we will help you fix it.


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


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

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


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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

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

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


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


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