[13160] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 570 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 17 23:07:21 1999

Date: Tue, 17 Aug 1999 20: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)

Perl-Users Digest           Tue, 17 Aug 1999     Volume: 9 Number: 570

Today's topics:
    Re: Anyone have an example...Uploading Images? (David Efflandt)
    Re: Anyone need an INDEPENDENT CONTRACTOR??? <cassell@mail.cor.epa.gov>
    Re: Array, Subroutine question soccerreferee@my-deja.com
    Re: Array, Subroutine question (Martien Verbruggen)
    Re: automatic text formatting for 80 chars a line <pdobbs@home.com>
    Re: Compiling to executable using ActivePerl <collin.starkweather@colorado.edu>
    Re: Connecting to UNC share via Perl/CGI <tbornhol@prioritytech.com>
    Re: Counting lines of block of text (Martien Verbruggen)
        DBI & Oracle connect problem. <lye@table.jps.net>
        DBI: prepare, and execute with placeholders - fails. leroy@mpi.com
    Re: Help a newbie. Please. <kangas@anlon.com>
        How do I read in just one line from file? <pdobbs@home.com>
    Re: How do I read in just one line from file? (Martien Verbruggen)
    Re: How do I read in just one line from file? (Larry Rosler)
    Re: How to view code as text in working cgi script (Filip M. Gieszczykiewicz)
    Re: Modulo of a string (Larry Rosler)
        Parent/Child Relation with Win32::Process <kangas@anlon.com>
    Re: PERL & EXCEL (Martien Verbruggen)
    Re: Q:Two perl programs printing to one txt file (Larry Rosler)
        SNMP module senthilr@email.com
    Re: THE CPU and LOOPS IN PERL (Martien Verbruggen)
        using fork/exec in perl sharda@hotmail.com
    Re: using fork/exec in perl (David Efflandt)
    Re: Wacky Programming Tales (Was Re: Why use Perl when  <71351.356@compuserve.com>
        what does eq do on lists? <john@dlugosz.com>
    Re: what does eq do on lists? (Sam Holden)
        Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)

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

Date: 18 Aug 1999 01:17:12 GMT
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Anyone have an example...Uploading Images?
Message-Id: <slrn7rk2ko.ho.efflandt@efflandt.xnet.com>

On Tue, 17 Aug 1999 14:59:04 -0400, Matt <splinter@monmouth.com> wrote:
>Hi,
>
>Does anyone know where I can see an example script of someone's in which the
>script takes the multipart/form data from an image field and writes it in
>binary to a remote server (or the local computer for perl).

perldoc CGI (type that into your shell or a DOS window if you have Perl
installed in Windows).

-- 
David Efflandt   efflandt@xnet.com   http://www.xnet.com/~efflandt/
http://www.de-srv.com/   http://cgi-help.virtualave.net/


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

Date: Tue, 17 Aug 1999 17:21:04 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Anyone need an INDEPENDENT CONTRACTOR???
Message-Id: <37B9FC70.35890C1F@mail.cor.epa.gov>

Jason Reed wrote:
> 
> marcel.grunauer@lovely.net (Marcel Grunauer) writes:
> 
> > >And I am looking for someone to clear 4.6 acres of land.....
> >
> > Or should that be 5.6 acres of perlland?
> 
> perldoc perldozer

Perldozer.  Isn't that a story by Theodore Sturgeon?

I think it's about some newbies who come across a big program
without -w or 'use strict'.  They start it up, and pay for
their refusla to read the docs.

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Tue, 17 Aug 1999 23:32:41 GMT
From: soccerreferee@my-deja.com
Subject: Re: Array, Subroutine question
Message-Id: <7pcreo$ql1$1@nnrp1.deja.com>

In article <37c01fc8.7459089@news.skynet.be>,
  bart.lateur@skynet.be (Bart Lateur) wrote:
> >Did you try it both ways?
> No I hadn't. Now I have. I was right.

Bart,

Indeed you were, I simply put the subroutine at the front of my code and
it worked fine.  I'll use better form next time - thanks for the tip!



Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Wed, 18 Aug 1999 02:57:45 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Array, Subroutine question
Message-Id: <Jipu3.226$lF2.7678@nsw.nnrp.telstra.net>

In article <1dwnmun.15dr7v1dp3vupN@p183.tc2.state.ma.tiac.com>,
	rjk@linguist.dartmouth.edu (Ronald J Kimball) writes:
> Bart Lateur <bart.lateur@skynet.be> wrote:

>> Euh... Shouldn't you switch the order? I.e. define the sub *first*, and
>> put the sub call below that.
> 
> Did you try it both ways?
> 
> Doesn't matter

But it does matter when the sub has a prototype (like in the orignal
example):

# perl -wl
@a = (1, 2, 3, 4);
foo (@a);
sub foo (\@) { print join '+', @_ }
__END__
1+2+3+4

# perl -wl
a = (1, 2, 3, 4);
sub foo (\@) { print join '+', @_ }
foo (@a);
__END__
ARRAY(0xce3a4)

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | Make it idiot proof and someone will
Commercial Dynamics Pty. Ltd.       | make a better idiot.
NSW, Australia                      | 


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

Date: Wed, 18 Aug 1999 01:59:37 GMT
From: Paul Dobbs <pdobbs@home.com>
Subject: Re: automatic text formatting for 80 chars a line
Message-Id: <37BA155D.9BE2160F@home.com>

Hey Bart.. would that wrap any length of text to being
multiple lines
of 80 characters max or just something that was only say 100
chars?

Bart Lateur wrote:
> 
> Abigail wrote:
> 
> >    $text =~ s/\n+//g;
> >    $text =~ s/.{80}/\n/g;
> 
> You really want to delete all that text in those lines with 80
> characters or more?
> 
> And I'd prefer wrapping on whitespace, and not in the middle of words,
> thank you.
> 
>         $text =~ s/(.{1,80})\s+/$1\n/g;
> 
>         Bart.


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

Date: Tue, 17 Aug 1999 17:12:07 -0600
From: Collin Starkweather <collin.starkweather@colorado.edu>
To: Martin Wachters <GOAWAYSPAMBASTARDSmartin3@dds.nl>
Subject: Re: Compiling to executable using ActivePerl
Message-Id: <37B9EC47.11D4D849@colorado.edu>

Purchase the ActiveState Perl Developer's Kit and look up PerlApp.pl.

Some modules, such as the libwww bundle, still have some problems when
compiled to binaries, but other than that, I've been compiling scripts
like mad, including those with modules of my own construct, with great
success.

Hope this helps,

-Collin

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Collin Starkweather                                 (303) 492-4784
University of Colorado            collin.starkweather@colorado.edu
Department of Economics          http://ucsu.colorado.edu/~olsonco
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Martin Wachters wrote:
> 
> Hi all!
> I am developping an application to automatically write midifiles (using the
> MidiPerl module)
> I am using ActivePerl 517 (for win32)
> Could anyone please tell me if it is possible to compile my perl program to
> an executale?
> If so, what should I do?
> 
> Many thanks!!!
> 
> Martin


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

Date: Wed, 18 Aug 1999 00:15:49 GMT
From: "Tim Bornholtz" <tbornhol@prioritytech.com>
Subject: Re: Connecting to UNC share via Perl/CGI
Message-Id: <VWmu3.150$mH1.447@news.rdc1.ne.home.com>

<sandman69@my-deja.com> wrote in message news:7pcf0n$gu4$1@nnrp1.deja.com...
> I am having problems connecting to an NT share on another serverfrom a
> Browser.
> I have a form to allow servername, sharename and a test variable to be
> submitted to my perlscript.
>
> The webpage authenticates the connecting user using the NT PDC.
 ...

> Things work perfectly if I send params to the script via a command line
> interface... not using param of course but reading in @ARGV.

This is more than likely a permissions peroblem.  When you run this from the
command line NT is using your permissions.  When you run this through the
browser,
the permissions are for the user account the web server runs under.

hth,
Tim Bornholtz
tbornhol@prioritytech.com






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

Date: Tue, 17 Aug 1999 23:27:28 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Counting lines of block of text
Message-Id: <Admu3.135$lF2.3949@nsw.nnrp.telstra.net>

In article <37B9D1C1.FC5F758C@mail.cor.epa.gov>,
	David Cassell <cassell@mail.cor.epa.gov> writes:
> Martien Verbruggen wrote:

>> It is off by $[ - 1
> 
> I'll agree.. but only if you promise never never never never
[snip]
> to use that in real code.

Except of course when setting $[ = 42, which, as we all know, is deep
magic.

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | You can't have everything, where would
Commercial Dynamics Pty. Ltd.       | you put it?
NSW, Australia                      | 


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

Date: 17 Aug 1999 17:36:43 -0700
From: Parai Ly <lye@table.jps.net>
Subject: DBI & Oracle connect problem.
Message-Id: <37ba001b@news1.jps.net>

I'm just started out w/ getting a database up and running.  I'm going
through a tutorial which shows you how to connect.

The problem is when I try to connect, I get the below error. 

$ perl ~/dbi.pl
DBI->connect failed: ORA-12154: TNS:could not resolve service name (DBD ERROR: OCIServerAttach) at /home/lye/dbi.pl line 4

Here's the script: 

Any help welcome.  Thanks,

use strict;
use DBI;
#dbi:Oracle:TEST123
my $dbh = DBI->connect( 'dbi:Oracle:TEST123',
                           'scott',
                           'tiger',
                           {
                             RaiseError => 1,
                             AutoCommit => 0
                           }
                         ) || die "Database connection not made: $DBI::errstr";

   my $sql = qq{ CREATE TABLE employees ( id INTEGER NOT NULL, 
                                          name VARCHAR2(128), 
                                          title VARCHAR2(128), 
                                          phone CHAR(8) 
                                        ) };
   $dbh->do( $sql );

   $dbh->disconnect();



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

Date: Wed, 18 Aug 1999 02:12:04 GMT
From: leroy@mpi.com
Subject: DBI: prepare, and execute with placeholders - fails.
Message-Id: <7pd4pc$18n$1@nnrp1.deja.com>

hi !
following the pod of DBI, my usage of prepare/bind_param/execute
fails.

at the beginning I had :
>
>my $sqlinsert = "insert into ClusterFlag (repId, flag,
clusteringSchemeId,
clusterStep) " .
>	" values (?, ? , $clusteringNameId, '$clusterStep')";
>
>my $sthinsert = $dbh->prepare($sqlinsert);
>
>
>while( ($clusterRep,$flag) = each %flags) {
>    if(($rc = $sthinsert->execute($clusterRep,$flag))<1) {
>	if($rc<0 || (!$rc)) {
>	    die "insert [clusterFlag : $clusterRep '$flag' ] failed : "
 .$sthinsert->errstr;
>	}else{
>	    warn "insert [clusterFlag : $clusterRep '$flag' ] failed : "
 .$sthinsert->errstr;
>	}
>   }
>   TraceLog->send_trace("flagged $clusterRep as $flag");
>}

but this would not work!
always it complains that the 'command is idle'.

changing to :
$sthinsert->bind_param(1,$clusterRep);
$sthinsert->bind_param(2,$clusterRep);
$sthinsert->execute();

provokes the same kind of error.

eventually, removing the placeholder and changing
into a 'do' command on a new string each iteration works
but this will lack performance.


what am I doing wrong ?

please also reply on my e-mail adress, as I don't check this newsgroup
too often.

thanks!

christophe


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Tue, 17 Aug 1999 21:46:16 -0500
From: Mike <kangas@anlon.com>
To: johndankey@my-deja.com
Subject: Re: Help a newbie. Please.
Message-Id: <37BA1E78.D40F3EDB@anlon.com>

make the 'I' in your If a LOWER-CASE 'i'....

I got the same error you did and when i changed the case of that letter it
worked fine.

johndankey@my-deja.com wrote:

> I'm new to Perl and trying to adjust a certain shopping cart program.
> The following code:
>
>         If ($FORM{'country'} eq 'US') {
>                 $c = 1;
>                 $aca = 10;
>         }
>
> gives me a syntax error on the line with the $aca variable.  Please,
> God, what am I doing wrong? (Besides denting the wall with my forehead
> the past five hours?
>
> Thanks.
>
> Dan
>
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.

--
Michael Kangas
Anlon Systems, Inc.
kangas@anlon.com




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

Date: Wed, 18 Aug 1999 01:34:46 GMT
From: Paul Dobbs <pdobbs@home.com>
Subject: How do I read in just one line from file?
Message-Id: <37BA0F8A.6F8B2852@home.com>

Generally new to Perl. Already made 2 fun things with it and
have
dug/read over FAQ's and bought/read "Perl:Annotated
Archives".

 But one thing vexes me so.. in other languages I have used,
I could
use the format like this to read in data from a file

open filename
 Input NumberOf$
for x = 1 to NumberOf$
 Input NameOf$(x)
 Input Desc$(x)
next x
close filename

In Perl, the only means of reading a file that I have seen
so
far is to run it in a loop until EOF as follows:

open handle filename
$counter=0;
 while (<handle>)
 {
 $yourdata[$counter]=$_;
 $counter++;
 }
close (handle)

 But in that way, after reading in the data, I also have to
add code
to separate out each data item to the name I REALLY want for
the
variable. IE: 
$yourdata[0] might be a $NumberOfAreas
$yourdata[1] might be a $NameofArea1
$yourdata[2] might be a $DescofArea1

 You know? So, how do I do it more like the 1st way so that
I
can collect groups of data in a pass instead of just
sticking it all
into one array? Your help appreciated. And hey, feel free to
play with
the Graffiti wall I made at
http://24.112.27.28/cgi-bin/PaulsWall.cgi

Paul
pdobbs@home.com


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

Date: Wed, 18 Aug 1999 02:38:38 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: How do I read in just one line from file?
Message-Id: <O0pu3.218$lF2.7678@nsw.nnrp.telstra.net>

In article <37BA0F8A.6F8B2852@home.com>,
         Paul Dobbs <pdobbs@home.com> writes:

> open filename
>  Input NumberOf$
> for x = 1 to NumberOf$
>  Input NameOf$(x)
>  Input Desc$(x)
> next x
> close filename
 
> In Perl, the only means of reading a file that I have seen so far is
> to run it in a loop until EOF as follows:

Nonsense. And the documentation is clear about that.

>  So, how do I do it more like the 1st way so that I can
>  collect groups of data in a pass instead of just sticking it all
>  into one array?  Your help appreciated. 

One possibility:

open(FF, $filename) || die "Cannot open $filename for read: $!";

my $NumberOf = <FF>; 
# no need to get rid of the newline, used as number only

my @NameOf;
my @Desc;

foreach my $i ( 1..$NumberOf )
{
         push @NameOf, scalar <FF>;
         push @Desc, scalar <FF>;
}

# Get rid of the newlines
chomp @NameOf;
chomp @Desc;

close FF;

assuming a data file like:

3
name1
desc1
name2
desc2 is here
name3
desc3
other stuff goes here

I don't know that other language you used well enough to know if that
assumption is valid.

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | +++ Out of Cheese Error +++ Reinstall
Commercial Dynamics Pty. Ltd.       | Universe and Reboot +++
NSW, Australia                      | 


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

Date: Tue, 17 Aug 1999 19:45:09 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: How do I read in just one line from file?
Message-Id: <MPG.1223be11348cf05f989e68@nntp.hpl.hp.com>

[Posted and a courtesy copy sent.]

In article <37BA0F8A.6F8B2852@home.com> on Wed, 18 Aug 1999 01:34:46 
GMT, Paul Dobbs <pdobbs@home.com> says...

[using a 'newsreader' X-Mailer: Mozilla 4.5 [en]C-AtHome0405  (Win95; U)
that is butchering line wrapping]

> In Perl, the only means of reading a file that I have seen
> so
> far is to run it in a loop until EOF as follows:
> 
> open handle filename
> $counter=0;
>  while (<handle>)
>  {
>  $yourdata[$counter]=$_;
>  $counter++;
>  }
> close (handle)

Why post pseudo-Perl?  We all know how to read the Real Stuff, and the 
above is annoying.

You might want to look at the 'push' function, which simplifies what you 
are doing considerably.  But it ultimately reduces to

  @yourdata = <HANDLE>;

where in list context the whole file is read into the array.

In scalar context (such as the iterator of your 'while' loop), the 
readline operator <HANDLE> reads exactly one line.  You can deal with it 
any way you wish.  There is certainly no need to read the entire file if 
all you want is a few lines.

   $line1 = <HANDLE>;
   $line2 = <HANDLE>;
   ...

That assumes that you don't mind storing undefs if the file runs out of 
data.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 18 Aug 1999 02:03:56 GMT
From: fmgst+@pitt.edu (Filip M. Gieszczykiewicz)
Subject: Re: How to view code as text in working cgi script
Message-Id: <7pd4ac$77k$1@usenet01.srv.cis.pitt.edu>

In Article <37B5A827.5F8D74B7@ERASEjps.net>, through puissant locution, Warren Bell <resource@ERASEjps.net> soliloquized:
>How can I call a cgi program on the web to see it's code?  Is there a
>way to do this? Any adjustments I can do to my browser?
>Can you do this with Unix, I've got wget and lynx?

I read this as:

>How can I call a the sound of a 911 Porche on the street to get its engine?
>Is there a way to do this? Any adjustments I can do to my ears?
>Can you do this with a machine shop, I've got lathe and mill?

Not without a Trekkie transporter you can't...
-- 
Filip "I'll buy a vowel" Gieszczykiewicz  |  http://www.repairfaq.org/

                   Always and everything for the better!
 Now exploring whatever, life, and the meaning of it all... and 'not' :-)


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

Date: Tue, 17 Aug 1999 15:57:55 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Modulo of a string
Message-Id: <MPG.122388cd5269fbc6989e65@nntp.hpl.hp.com>

In article <37babd24.2209028@news.skynet.be> on Tue, 17 Aug 1999 
20:04:21 GMT, Bart Lateur <bart.lateur@skynet.be> says...
> tsreyb@my-deja.com wrote:
> 
> >What I was hoping to do is reduce arbitrary strings
> >to a number between 0 & N-1, where N is the modulo
> >value.
> 
> Can be done.

Indeed.  See below.
 
> >For example, if N is 7, I can process a different
> >segment of an array each day of the week. After
> >7 days, all of the elements will have been processed
> >once & only once.
> 
> Can't be done. You not only want to reduce the strings to a number, but
> to a *different* number from each other as well?

I don't know for sure.

> >[Eventually in this code I won't
> >have the names in an array .. so doing a modulo on
> >the array index won't work]
> 
> And yet it's you best shot. Load the strings into an arry and use the
> index, or into a hash, string as the key, incremented number as the
> value.
> 
>   $i = 0;
>   while(<DATA>) {
> 	chomp;
> 	$index{$_} = $i++;
>   }
>   print $index{'Joe'};

I think something like the following mught get close to what he was 
thinking of.


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

my %index;

chomp, $index{$_} = (2 + ord) % 7 while <DATA>;

print map "$_ => $index{$_}\n" => sort keys %index;
__DATA__
a
b
c
d
Joe
Sally

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Tue, 17 Aug 1999 21:56:39 -0500
From: Mike <kangas@anlon.com>
Subject: Parent/Child Relation with Win32::Process
Message-Id: <37BA20E7.C6DAC78E@anlon.com>

How do I get a varible from the child to the parent?? Please fill in the
question marks if you can or I am doing this completely wrong. This is
for a larger program which runs 10-15 processes in parrallel.

Any help is much appreciated.

#####     Parent process(main.pl)     #####
use Win32::Process;
Win32::Process::Create($ProcessObj,
                       "d:\\Perl\\bin\\Perl.exe",
                       "Perl test.pl",
                        1,
                        NORMAL_PRIORITY_CLASS,
                       ".");

print "The child varible X is ", ???????????????????, ".\n";

#####     child process(test.pl)     #####
$X = 5;

--
Michael Kangas
Anlon Systems, Inc.
kangas@anlon.com




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

Date: Wed, 18 Aug 1999 02:47:00 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: PERL & EXCEL
Message-Id: <E8pu3.223$lF2.7678@nsw.nnrp.telstra.net>

In article <37B92041.236CE5A0@earthling.net>,
	kilimount <kilimount@earthling.net> writes:

>                        $xlfile ="c:\\filename.xls";

>                        $workbook = $xl_app->Workbooks->Open($xlfile);

>                        $worksheet = $workbook->Worksheets(1);

> Perl Builder's debugger is returning this line :
> Can't call method "Worksheets" without a package or object reference at
> script line 19.
> Thanx in advance for your help,

That most likely means that $workbook, which you use as a reference to
an object is undefined. The most likely reason for that is that
$xl_app->Workbooks->Open($xlfile); returned an undefined value,
probably because it failed, which may actually be caused by $xlfile
not existing, or not being a valid excel file or whatever.

You should consult the manual of the modules you're using to find out
how to get information from that Open function about what went wrong.

$workbook = $xl_app->Workbooks->Open($xlfile) 
	|| die "Something went wrong: " . 
		[insert module specific method for getting the error];

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | For heaven's sake, don't TRY to be
Commercial Dynamics Pty. Ltd.       | cynical. It's perfectly easy to be
NSW, Australia                      | cynical.


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

Date: Tue, 17 Aug 1999 17:06:58 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Q:Two perl programs printing to one txt file
Message-Id: <MPG.12239901179a4dc4989e66@nntp.hpl.hp.com>

In article <7pco42$o5f$1@nnrp1.deja.com> on Tue, 17 Aug 1999 22:35:47 
GMT, danmex@my-deja.com <danmex@my-deja.com> says...
 ...
> I understand I must use some locking mechanism, and a new question
> comes to mind: what is a good/correct way for one of the programs "to
> wait" until the file is unlocked? A while-loop? A sleep?.

`perldoc -f alarm` has a good example for how to wait with a timeout.

> And another: Is there any way for the programs to "get in line"? I.E.:
> Program 1 is writing, program 2 is waiting and enters a whileloop,
> program 3 is also waiting and entes a whileloop. I'd like program 2 to
> get at the file first, but the whileloop does not guarantee program 3
> will let that happen?

I can't think of a way without storing some sort of state information in 
the filesystem, which seems very expensive in a high-volume environment.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Tue, 17 Aug 1999 22:57:10 GMT
From: senthilr@email.com
Subject: SNMP module
Message-Id: <7pcpc0$p1o$1@nnrp1.deja.com>

Hi:

I was trying to install SNMP v1.8.1.  When I do 'make test' I get these:

Bad operator(DEFINITIONS): At line 1 in
/usr/local/share/snmp/mibs/IF-MIB.txt
Bad operator(DEFINITIONS): At line 1 in
/usr/local/share/snmp/mibs/TCP-MIB.txt
Bad operator(DEFINITIONS): At line 1 in
/usr/local/share/snmp/mibs/UDP-MIB.txt
Bad operator(DEFINITIONS): At line 1 in
/usr/local/share/snmp/mibs/SNMPv2-MIB.txt
Bad operator(DEFINITIONS): At line 1 in
/usr/local/share/snmp/mibs/RFC1213-MIB.txt

 ....


Any ideas..

Thanks,
 ..Senthil.


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Wed, 18 Aug 1999 02:24:03 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: THE CPU and LOOPS IN PERL
Message-Id: <7Pou3.214$lF2.7678@nsw.nnrp.telstra.net>

In article <11020643E71FD311ACAA0008C7C563F3AF2307@gblon1c3ex1.wcom.co.uk>,
	"Mujakporue, Trey" <tmujak@wcom.co.uk> writes:
> I needed to create a script that would continuously do a few things and not
> exit (until i explicitly killed it!) but after writing and running it, i
> found out that it was taking up to much CPU time and slowing the machine
> down. The script in question is attached below, is there any other way i
> could write this so it wouldn't use so much CPU time?

Yes, don't write your loop so closely. Use sleep, or something with a
higher resolution to wait a while before resuming the loop. If it
really needs to loop this tight, then it will use CPU.

You should really consider indenting your code a bit better. And
commenting it better. Putting a comment like this:

>         open (FILE, $file) ; # open it

is hardly instructive, is it? It only serves to make it all denser,
instead of clarifying things.

You should use -w and use strict in your code. It will help you debug
it a bit better.

> while (1) {
> $i = 0 ; # Count variable.
> $x = time() ; # get the time in seconds since 1970
> $y = $x+=60 ; # add 60 seconds to the time above.

# marker 1

> $time = time() ;

You could have re-used the $x above.

> @localtime = localtime($time) ;
> @moretimes = localtime($time) ;

@moretimes = @localtime = localtime($time);

> ($year,$month,$date,$hour, $minute,$seconds) = @moretimes[5,4,3,2,1,0] ;
> ($date,$month,$year) = @localtime[3,4,5] ;

# marker 2

Why do you do this second one again?

A lot of redundant code in here, and a lot of unnecessary system
calls. Replace everything between #marker 1 and #marker 2 with:

($seconds, $minute, $hour, $date, $month, $year) = localtime($x);

> $month += 1 ; 
> $year += 1900 ;
> $theotherdate = sprintf ("%d%02d%02d%02d%02d\n", $year, $month, $date,
> $hour, $minute, $second ) ;
> $date = sprintf ("%d%02d%02d\n", $year, $month, $date ) ;
> chomp $date ;
> chomp $theotherdate ;

Huh? First you explicitly add the \n to the date with sprintf, and
then you chomp it off again? No wonder your CPU is busy.

> # Using the above the date is now in the format YYMMDD.

actually, it's YYYYMMDD

> $logfilename = "logfile_$date.log" ;
> 
> 	$file = "x://somedir//$logfilename" ; # get the logfile to use.

Don't use double slashes. It's not necessary. Only when using
backslashes do you need to escape them.

> 	open (FILE, $file) ; # open it ,

You really should check for failure here before continuing. 

>     seek (FILE, 0,2) ;  # go to the end of the file (since we 
>     			# are only going to count the entries that 
> 			#come in after we initialize the proggy, not before
> it)
>     do {
>      
>     $x = time() ;	# keep getting the time. we need to keep cheking !!
>         while (<FILE>) { # and while the file is open
>     	  if ($_  =~ /RELAY_SUCCESS/i){ 	# if we match relay succces,
>            print  $i++.", " ;	#add 1 to the current value of $i 
>              }
> 	   }  
>     	seek (FILE, 0,1) ; # errm.. cant remember what this bit does! ;o(
> prolly seeks to the EOF again!

# perldoc -f seek
[snip]
On some systems you have to do a seek whenever you switch between reading
and writing.  Amongst other things, this may have the effect of calling
stdio's clearerr(3).  A WHENCE of C<1> (C<SEEK_CUR>) is useful for not moving
the file position:

    seek(TEST,0,1);
[snip]

Since you aren't writing, it's effectively a no-op.

>      }
> 
>       until ($x >= $y) ; 	# keep doing the above until this line is

So, you are busy looping until you are approximately 60 seconds
further. Why not open the file, seek to the end, sleep for 60 seconds,
then read to the end? Then there's no busy wait. Or even sleep for a
few seconds.

(A better comment would have actually stated that that was the aim,
instead of explaining what the 'until' statement does)

You might also be interested in the FAQ:

# perldoc perlfaq5
     How do I do a tail -f in perl?

It explains how to do this a bit better.

> true.
>       
>  # Now we need to create a file in which to keep the count ;
>  open (COUNTFILE, ">x://somedir//minutecount.txt") ;
> # And we also need another file to keep historical counts!!
>  open (HISTFILE, ">>x://somedir//mincount-history.txt") ;

again: check, and you don't need the double slashes.

> CONFIDENTIALITY NOTICE

Huh? You just posted this to Usenet. That means the world is the
recipient. Dejanews will have a copy of it for anyone to keep.

Oh well.

It's not as if I would want to copy it without some major changes :)

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | You can't have everything, where would
Commercial Dynamics Pty. Ltd.       | you put it?
NSW, Australia                      | 


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

Date: Wed, 18 Aug 1999 00:22:10 GMT
From: sharda@hotmail.com
Subject: using fork/exec in perl
Message-Id: <7pcub8$sie$1@nnrp1.deja.com>

Hi guys,

    I am working on a system in which the perl script has to process 20
log files every hour.

   I plan to run 4 instances of this script simultaneously to reduce
the parsing time.

   Is there a way in which I can fork 4 processes, and then make these
4 processes parse these log files in a loop(thus whenever a child
process completes the parsing of one log file, it can take the next log
file and parse it, till all the log files are processed). Would
appreciate if any code example is given.

   I have a little understanding of unix processes/IPC. I think, if the
script forks a child process and then uses "exec"(or a variant of it),
it will execute the given command and then die, giving back the control
to the parent process.

   Now, I dunno how to do all this in perl.Would appreciate if anyone
could give me some guidance on this. Is there any way such that once
the child processes are created, they die only after parsing all the
log files? if yes, how do we do that?

   I understand that the concept of threading is being incorporated
into perl, but i don't know how to implement it. Is there any code
example which i can look at?

Thanx in advance.

rajesh


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: 18 Aug 1999 02:15:01 GMT
From: efflandt@xnet.com (David Efflandt)
Subject: Re: using fork/exec in perl
Message-Id: <slrn7rk613.ho.efflandt@efflandt.xnet.com>

On Wed, 18 Aug 1999 00:22:10 GMT, sharda@hotmail.com <sharda@hotmail.com> wrote:
>Hi guys,
>
>    I am working on a system in which the perl script has to process 20
>log files every hour.
>
>   I plan to run 4 instances of this script simultaneously to reduce
>the parsing time.
>
>   Is there a way in which I can fork 4 processes, and then make these
>4 processes parse these log files in a loop(thus whenever a child
>process completes the parsing of one log file, it can take the next log
>file and parse it, till all the log files are processed). Would
>appreciate if any code example is given.

perldoc perlipc

Just divide the files among 3 forks and have the main script handle its
share.

>   I have a little understanding of unix processes/IPC. I think, if the
>script forks a child process and then uses "exec"(or a variant of it),
>it will execute the given command and then die, giving back the control
>to the parent process.

I don't think there is a need to exec anything unless you need to run an
external program and understand that exec will never return.

>   I understand that the concept of threading is being incorporated
>into perl, but i don't know how to implement it. Is there any code
>example which i can look at?

I haven't gotten into that yet.  I think it saves memory, but not time
(unless multi-processor).

-- 
David Efflandt   efflandt@xnet.com   http://www.xnet.com/~efflandt/
http://www.de-srv.com/   http://cgi-help.virtualave.net/


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

Date: Tue, 17 Aug 1999 22:53:47 -0400
From: "T. C. Mits" <71351.356@compuserve.com>
Subject: Re: Wacky Programming Tales (Was Re: Why use Perl when we've got Python?!)
Message-Id: <7pd7f9$ais$1@ssauraaa-i-1.production.compuserve.com>

That's not so strange.   Perhaps at a software house with a lot of propeller
heads, but at a place where application customization and other 'light
projects are done, little things like that help those who do not dream of
algorithms in their spare time or who don't plan to specialize and master a
particular language.   Besides once you've been bitten by the '==' in C (and
you don't use a good lint, because the boss won't buy one), #define EQ ==,
is not a sin.   Well, yes it is, but its not, but.....


Brad Howes <bradh@mediaone.net> wrote in message
news:wjy7lmxbwh7.fsf_-_@bradh.ne.mediaone.net...
>snips<

> Hey! I actually worked on a project where someone did this! Also in their
> funky include file was
>
>   #define AND &&
>   #define OR  ||
>
> It was the most bizarre thing I ever saw -- not so much the include file,
> but the resulting code. As if a Pascal moths had come in, eaten at some
> code and left little Wirth fragments sprinkled around. Has anyone else
> encountered such strange programming behavior?
>
> ...now back to my language is bigger/longer/wider/stiffer than yours
>
> --





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

Date: Tue, 17 Aug 1999 20:41:07 -0500
From: "John M. Dlugosz" <john@dlugosz.com>
Subject: what does eq do on lists?
Message-Id: <208F7691D51D04B1.335619AA67C52965.B642C04DE1838C7C@lp.airnews.net>

The expression
    @a[0..3] eq @b
doesn't do what I thought it would.  It's not a compile-time error, either.
So what does it do, if not compare all four strings?  It produces undef in
the case I expect true, when b has four elements that match the first four
elements of a.

--John





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

Date: 18 Aug 1999 02:00:43 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: what does eq do on lists?
Message-Id: <slrn7rk4v9.die.sholden@pgrad.cs.usyd.edu.au>

On Tue, 17 Aug 1999 20:41:07 -0500, John M. Dlugosz <john@dlugosz.com> wrote:
>The expression
>    @a[0..3] eq @b
>doesn't do what I thought it would.  It's not a compile-time error, either.
>So what does it do, if not compare all four strings?  It produces undef in
>the case I expect true, when b has four elements that match the first four
>elements of a.
 
It does a string comparison of @a[0..3] and @b.

To do so it first convert @a[0..3] and @b to strings.

I'm not sure what you mean by undef being the result though :

@a = (1,2,3,4,5,6,7,8,9,10);
@b = (1,2,3,4);
print "match" if (@a[0..3] eq @b);

Will output match...
So will :

@a=(1,2,3,4,5,6,7,8);
@b=('fred','bill',3,['red', 'orange', { key => 'value' }]);
print "match" if (@a[0..3] eq @b);

So that isn't the way you want to do it...

You could just loop over the minimum lagth array and compare the appropriate
elements.  Or you could use join() to create the strings to compare, but
then you have the problem of what to use as the first argument to join, so
you don't get any collisions.

-- 
Sam

Some of you know what the Perl slogan on Windows is, and you can say it
with me: "It's a good thing there's more than one way to do it, because
most of them don't work."  --Larry Wall


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

Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 1 Jul 99)
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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq" from
almanac@ruby.oce.orst.edu. The real FAQ, as it appeared last in the
newsgroup, can be retrieved with the request "send perl-users FAQ" from
almanac@ruby.oce.orst.edu. Due to their sizes, neither the Meta-FAQ nor
the FAQ are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq" from
almanac@ruby.oce.orst.edu. 

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 V9 Issue 570
*************************************


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