[22399] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4620 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 25 09:05:57 2003

Date: Tue, 25 Feb 2003 06:05:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 25 Feb 2003     Volume: 10 Number: 4620

Today's topics:
        Apache::Request->new or ->instance.. <spamfilter@cheiron-it.nl>
    Re: calling mrtg from a perlscript  (Joe Smith)
    Re: conditional operator "?:" (Joe Smith)
        DBD and DBI on Solaris 64 bit <rich.bevan@bt.com>
    Re: FAQ proposal: Why can't I compare two strings using <REMOVEsdnCAPS@comcast.net>
        Help, FTP.pm path not found! (G Bishop)
    Re: Help, FTP.pm path not found! <me@privacy.net>
    Re: If statement chacking if a variable is something OR <REMOVEsdnCAPS@comcast.net>
    Re: Installing perl on XP using Cygwin (Joe Smith)
    Re: locate 1, 1 wont work properly, perhaps it's only m (Anno Siegel)
    Re: locate 1, 1 wont work properly, perhaps it's only m <tyrannous@o-space.com>
    Re: Non-blocking file I/O, (Joe Smith)
    Re: Not a Perl guy but need help <ian@WINDOZEdigiserv.net>
    Re: Not a Perl guy but need help <bushong@OCF.Berkeley.EDU>
    Re: Not a Perl guy but need help <ian@WINDOZEdigiserv.net>
    Re: Parsing line into hash... <krahnj@acm.org>
    Re: Parsing line into hash... (Anno Siegel)
    Re: Premature end of script headers errors <nobody@dev.null>
        Silencing Default Error Output of getopts <spero126NOSPAM@yahoo.com>
    Re: Silencing Default Error Output of getopts (Anno Siegel)
    Re: Subroutine does not 'see' parameter passed to it (Joe Smith)
    Re: Subroutine does not 'see' parameter passed to it (Anno Siegel)
    Re: translate ( tr ) question <REMOVEsdnCAPS@comcast.net>
    Re: translate ( tr ) question <hideki@massassi.net>
    Re: Using Perl to parse C buffers under Linux (need hel <dont@want.spam>
    Re: variable assignment question. help <dont@want.spam>
    Re: variable assignment question. help <krahnj@acm.org>
    Re: wanted: BZIP2 module for Win32 and Linux (Joe Smith)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 25 Feb 2003 12:47:34 +0100
From: "Frank Maas" <spamfilter@cheiron-it.nl>
Subject: Apache::Request->new or ->instance..
Message-Id: <3e5b5907$0$145$e4fe514c@dreader9.news.xs4all.nl>

Hi,

While writing several PerlHandlers for the same request I "lost" the posted
contents of a form. Digging into the docs I found that using
Apache::Request->new
and ->param 'eats' the content data, so it cannot be used later on. This
sur-
prised me somehow, but I changed my code into using ->instance and it works.
However... I try to use CPAN modules as much as possible and they all seem
to favour the ->new method, thus eating my params... Now a solution would be
to use the Apache::RequestNotes (is that still favoured?), but then I still
have a problem with the CPAN modules that need access to the posted / cookie
data.

What would be a good solution here? And why is the functionality of ->new
not
simply replaced by ->instance? [Or am I now really talking nonsense]?

Best regards,

--Frank




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

Date: Tue, 25 Feb 2003 11:15:41 GMT
From: inwap@inwap.com (Joe Smith)
Subject: Re: calling mrtg from a perlscript 
Message-Id: <xfI6a.4627$io.186698@iad-read.news.verio.net>

In article <3e52bfa8$0$2235$e4fe514c@dreader6.news.xs4all.nl>,
Rob <cyberob@freemail.nl> wrote:
>Hello group,
>
>We use MRTG with RRD to monitor our servers.
>
>We have a perl script called mrtgmon.pl which executes the mrtg script
>with a "do" function from a subroutine, it works but the perl process
>runs out of memory.

Not all of the mrtg script needs to be done on each loop.

First change "do" to "require" so the function definitions are loaded
into memory once.  Inside your subroutine, call all the functions that
the mrtg main program would have called.
	-Joe

P.S. "comp.lang.perl" is not the name of a valid newsgroup.
-- 
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.


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

Date: Tue, 25 Feb 2003 12:40:38 GMT
From: inwap@inwap.com (Joe Smith)
Subject: Re: conditional operator "?:"
Message-Id: <avJ6a.4632$io.186344@iad-read.news.verio.net>

In article <b2rebs$5ed4@nrn2.NRCan.gc.ca>,
Christian Caron <nospam@nospam.org> wrote:
>
>my $test2 = "it contains |";
>($test2 =~ /\|+/) ? $empty2 = $test : $empty2 = "it doesn't contain |";

I recommend using the '$var = (cond) ? "true" : "false";' form of the
conditional operator.  Your $empty2 line can be rewritten as:

  $empty2 = ($test2 =~ /\|+/) ? $test : "it doesn't contain |";

	-Joe

-- 
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.


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

Date: Tue, 25 Feb 2003 11:36:01 +0000
From: Rich <rich.bevan@bt.com>
Subject: DBD and DBI on Solaris 64 bit
Message-Id: <3E5B5521.71FCE32A@bt.com>

I am running Solaris 9 64 bit which comes with Perl v5.6.1 built for
sun4-solaris-64int. I want to build in the DBD and DBI modules for
Oracle, but the only compiler I have is running on a 32bit Solaris
system. I can configure the 64 bit system to use the 32 bit system's
compiler using NFS mounts. The question is, is will this work ? i.e will
the DBD and DBI modules compiled on the 64 bit system using the 32 bit
system's compiler achieve what I am after ?

Thanks for any help

Richard



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

Date: Tue, 25 Feb 2003 05:50:46 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: FAQ proposal: Why can't I compare two strings using == ?
Message-Id: <Xns932D459C34798sdn.comcast@216.166.71.239>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

"Jürgen Exner" <jurgenex@hotmail.com> wrote in
news:3MM5a.8267$_J5.4846@nwrddc01.gnilink.net: 

> One of the most frequently asked questions is
>     "Why can't I compare two strings using == ?"
> 
> Suggested answer:
> The operator "==" compares the numerical values of its operands.
> Chances are you want to compare the textual values in which case you
> should use the operator "eq" instead. For further details please check
> "perldoc perlop".


Perhaps this proposal should be expanded to include

    "Why can't I compare two strings/numbers using = ?"

We've seen that a few times in the past couple weeks, too.

- -- 
Eric
print scalar reverse sort qw p ekca lre reh 
ts uJ p, $/.r, map $_.$", qw e p h tona e;

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBPltYiGPeouIeTNHoEQKeGACg9EJk3OhUtNVFTE3gUWpy+dNJ2voAoPaT
LitZwRitjc7xP0w0MKX32ZAN
=E6yD
-----END PGP SIGNATURE-----


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

Date: 25 Feb 2003 03:54:08 -0800
From: gbishop@hsm.co.uk (G Bishop)
Subject: Help, FTP.pm path not found!
Message-Id: <519becd0.0302250354.1253cbb3@posting.google.com>

I have the libnet module installed with no errors. When I try to run a
perl script that uses NET::FTP, I get the following error:

######################################################
Can't locate NET/FTP.pm in @INC (@INC contains:
/usr/lib/perl5/5.6.0/i386-linux /usr/lib/perl5/5.6.0
/usr/lib/perl5/site_perl/5.6.0/i386-linux
/usr/lib/perl5/site_perl/5.6.0 /usr/lib/perl5/site_perl .) at ftp.pl
line 3.BEGIN failed--compilation aborted at ftp.pl line 3.
######################################################

The FTP.pm file in question is in:

######################################################
/usr/lib/perl5/site_perl/5.6.0/Net/FTP.pm
######################################################

The problem to me looks like a case issue with the directory being
called 'Net' rather than 'NET'.

Is there a file that holds module paths that I can edit to resolve
this issue. I have tried renaming the folder but this causes other
issues.

Thanks in advance,

Guy.


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

Date: Tue, 25 Feb 2003 23:33:29 +1100
From: "Tintin" <me@privacy.net>
Subject: Re: Help, FTP.pm path not found!
Message-Id: <b3fnqp$1lrctg$1@ID-172104.news.dfncis.de>


"G Bishop" <gbishop@hsm.co.uk> wrote in message
news:519becd0.0302250354.1253cbb3@posting.google.com...
> I have the libnet module installed with no errors. When I try to run a
> perl script that uses NET::FTP, I get the following error:
>
> ######################################################
> Can't locate NET/FTP.pm in @INC (@INC contains:
> /usr/lib/perl5/5.6.0/i386-linux /usr/lib/perl5/5.6.0
> /usr/lib/perl5/site_perl/5.6.0/i386-linux
> /usr/lib/perl5/site_perl/5.6.0 /usr/lib/perl5/site_perl .) at ftp.pl
> line 3.BEGIN failed--compilation aborted at ftp.pl line 3.
> ######################################################
>
> The FTP.pm file in question is in:
>
> ######################################################
> /usr/lib/perl5/site_perl/5.6.0/Net/FTP.pm
> ######################################################
>
> The problem to me looks like a case issue with the directory being
> called 'Net' rather than 'NET'.

No, the problem is that you are mistyping the module name.

You should have

use Net::FTP;

in your script, not

use NET::FTP;





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

Date: Tue, 25 Feb 2003 05:53:31 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: If statement chacking if a variable is something OR something else?
Message-Id: <Xns932D461398FB9sdn.comcast@216.166.71.239>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

"Daby" <daby55@NOSPAM.com> wrote in
news:b3dsms$iqq$1@newsg1.svr.pol.co.uk: 

> Sorry for the bad reproduction of a code sample. The syntax wasn`t
> corrent and I have not used "If". However I do wonder if I did
> actually use "=" instead of "==" by mistake.

Suggestion:  If you have some code that you need help with, copy/paste it 
into a message here, rather than retyping it.  Retyping breeds typos.

- -- 
Eric
print scalar reverse sort qw p ekca lre reh 
ts uJ p, $/.r, map $_.$", qw e p h tona e;

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBPltZLWPeouIeTNHoEQKwbQCgiTO3i4En5M0KBSn82KF0H6iscrkAn11K
D5mgfXDQduhxakZlyUWysxa+
=lZzO
-----END PGP SIGNATURE-----


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

Date: Tue, 25 Feb 2003 11:56:21 GMT
From: inwap@inwap.com (Joe Smith)
Subject: Re: Installing perl on XP using Cygwin
Message-Id: <FRI6a.4628$io.186344@iad-read.news.verio.net>

In article <b32vpd$n9k$1@ctb-nnrp2.saix.net>,
Henry Holland <s-p-o-e-d-n-i-e-k-@-g-m-x-.-n-e-t> wrote:
>Hi,
>
>I'm having trouble compiling perl on cygwin.

If you just want to install perl (as your subject line states),
then there is no need to compile it.

Run the cygwin setup.exe, click on "Interpreters", then "perl".
Takes about one minute to install the perl-5.8.0 binaries
over a cable modem.
	-Joe

-- 
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.


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

Date: 25 Feb 2003 11:09:16 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: locate 1, 1 wont work properly, perhaps it's only meant for linux
Message-Id: <b3fiss$bc6$3@mamenchi.zrz.TU-Berlin.DE>

 <tyrannous@o-space.com> wrote in comp.lang.perl.misc:
> locate 1, 1 wont work properly, perhaps it's only meant for linux
> 
> 
> use Term::ASCIIScreen;

What is Term::ASCIIScreen?  It isn't on CPAN.

> system 'cls'; locate 1,1;
> 
> print chr(65);
> 
> could someone please tell me how to get this to work on a Windows ME system?

What does the documentation say?

Anno


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

Date: Tue, 25 Feb 2003 13:30:21 -0000
From: <tyrannous@o-space.com>
Subject: Re: locate 1, 1 wont work properly, perhaps it's only meant for linux
Message-Id: <b3fr5d$5se$1@newsg4.svr.pol.co.uk>

i'm sorry, i meant ANSIScreen

"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:b3fiss$bc6$3@mamenchi.zrz.TU-Berlin.DE...
> <tyrannous@o-space.com> wrote in comp.lang.perl.misc:
> > locate 1, 1 wont work properly, perhaps it's only meant for linux
> >
> >
> > use Term::ASCIIScreen;
>
> What is Term::ASCIIScreen?  It isn't on CPAN.
>
> > system 'cls'; locate 1,1;
> >
> > print chr(65);
> >
> > could someone please tell me how to get this to work on a Windows ME
system?
>
> What does the documentation say?
>
> Anno




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

Date: Tue, 25 Feb 2003 12:32:35 GMT
From: inwap@inwap.com (Joe Smith)
Subject: Re: Non-blocking file I/O,
Message-Id: <DnJ6a.4631$io.186344@iad-read.news.verio.net>

In article <c57c103.0302171808.6fee1a1@posting.google.com>,
jtd <adwser@hotmail.com> wrote:
>A related question is, suppose I use raid 5 (3ware escalade), will
>that affect my ability to parallelize reads?

If all your logical disks use the same bunch of physical disks,
then parallel reads will most likely slow each other down.
-- 
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.


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

Date: Tue, 25 Feb 2003 11:13:01 GMT
From: "Ian.H [dS]" <ian@WINDOZEdigiserv.net>
Subject: Re: Not a Perl guy but need help
Message-Id: <sijm5vkfvutj434davg0rutmnl11t8c0g1@4ax.com>
Keywords: Remove WINDOZE to reply

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

In a fit of excitement on Tue, 25 Feb 2003 09:44:04 +0000 (UTC),
Michael Bushong <bushong@OCF.Berkeley.EDU> managed to scribble:

> Ian.H [dS] <ian@windozedigiserv.net> wrote:
> : Well, you did appallingly and need more help than just with Perl.
> 
> 
> : - - There's no question in your post.
> : - - No Perl related material in your post
> : - - Asking fro an e-mail response is just rude!
> 
> 
> : It appears so far that you're not doing so well doesn't it? I'd
> hang : on and wait for your callcentre to become available, your
> post was a : waste of bandwidth in total.. almost on the borders of
> trolling.  
> 
> Ahhh, Ian.  You are such a card.  I did not want to inundate the
> group with inane questions as I have all of 9 hours of experience
> with Perl at this point.  As for trolling, naaah, I think you have
> that covered tough guy.  It's always the guys who got picked on
> because they were chumps that flex their muscle in newsgroups. 
> Still feeling a tad inadequate?  


Not at all.

You pretty much asked if you could ask (in a round about kind of
way).

Ok, so you're new to Perl, as I was once, as was everyone who
frequents this group, if you're that new, are you sure whatever
question you had but failed to ask isn't into the FAQ? You did read
the FAQ didn't you?

If you have a question, no matter how "stupid" or "trivial" it may
_appear_, I suspect you would have gotten a better response had you
asked it. 99% of people will remember the fact that they were new
once before, and will help out, even if giving you the right syntax
to use for Perldoc (as it can be somewhat confusing for new comers to
work out how to use efficiently).

My serious suggestion, is to read the FAQ if you haven't to see if
your question is already covered. If not, or you can't find it, post
some thoughts, examples, or places you've tried to look, somethign to
show some effort on your part, and almost immaterial of the question
(as long as it's Perl related), you'll get help in some way.

The idea of Usenet is to help others in that way (for this and it's
type of group at least). It also provides an archive of information.
So, had you asked your question(s) and got satisfactory answers (of
one definition or other), then in 10 years time maybe, when someone
also has trhe same query, voila! it has already been convered, _then_
preventing inundating the group with not neccessarily "stupid" or
"annoying" questions, but repeatedly covered questions.

These are my opinions and not that of others from the group, although
they may have some input too, not for me to say.



Regards,

  Ian

-----BEGIN xxx SIGNATURE-----
Version: PGP 8.0

iQA/AwUBPltPu2fqtj251CDhEQJMnQCgx1uLc2j52/GYbvF5/b6o9LpODUwAoNI8
W4pejhq3MnRdZ9o8TU7SwQiL
=F2iV
-----END PGP SIGNATURE-----

-- 
Ian.H  [Design & Development]
digiServ Network - Web solutions
www.digiserv.net  |  irc.digiserv.net  |  forum.digiserv.net
Scripting, Web design, development & hosting.


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

Date: Tue, 25 Feb 2003 11:46:56 +0000 (UTC)
From: Michael Bushong <bushong@OCF.Berkeley.EDU>
Subject: Re: Not a Perl guy but need help
Message-Id: <b3fl3g$pd0$1@agate.berkeley.edu>


I had all of 9 hours' experience when I first posted.  I had some issues
with renaming files (before I closed them) as well as when to use shared
versus exclusive file locks.

I am assigning ID's to XML elements.  The ID's have to all be unique, so
I am using a logfile to track the latest ID's and incrementing as I
assign them.  Multiple users must access multiple files simultaneously,
but there must be a single logfile to ensure that the ID's are unique.

I started with:

open (LOGFILE, "+<logfile")		or die "Cannot find logfile.";
flock (LOGFILE, LOCK_SH)		or die 'Cannot lock logfile.";

I am not sure if this is sufficient.  The O'Reilly books suggest an
exclusive lock in some instances (presumably this one).  If I do that, I
am not entirely sure what to use to open and lock the file.

useFcntl qw(:DEFAULT :flock);
sysopen (LOGFILE, "logfile", RDWR) 	or die "Cannot open logfile.";
flock(LOGFILE, LOCK_EX)			or die "Cannot lock logfile.";


I honestly haven't a clue if this is necessary.  Moreover, in my XML
files, I have to do my ID assignment through temp files.  Do I need to
lock my temp files, truncate, and then write to them?  Or is that
overkill?

Finally, Programming Perl  suggests writing a separate file  to create a
semaphore.  This seems like overkill in my simple situation, but  being
unfamiliar with Perl, I have no idea.

-Mike


Ian.H [dS] <ian@windozedigiserv.net> wrote:
: -----BEGIN xxx SIGNED MESSAGE-----
: Hash: SHA1

: In a fit of excitement on Tue, 25 Feb 2003 09:44:04 +0000 (UTC),
: Michael Bushong <bushong@OCF.Berkeley.EDU> managed to scribble:

:> Ian.H [dS] <ian@windozedigiserv.net> wrote:
:> : Well, you did appallingly and need more help than just with Perl.
:> 
:> 
:> : - - There's no question in your post.
:> : - - No Perl related material in your post
:> : - - Asking fro an e-mail response is just rude!
:> 
:> 
:> : It appears so far that you're not doing so well doesn't it? I'd
:> hang : on and wait for your callcentre to become available, your
:> post was a : waste of bandwidth in total.. almost on the borders of
:> trolling.  
:> 
:> Ahhh, Ian.  You are such a card.  I did not want to inundate the
:> group with inane questions as I have all of 9 hours of experience
:> with Perl at this point.  As for trolling, naaah, I think you have
:> that covered tough guy.  It's always the guys who got picked on
:> because they were chumps that flex their muscle in newsgroups. 
:> Still feeling a tad inadequate?  


: Not at all.

: You pretty much asked if you could ask (in a round about kind of
: way).

: Ok, so you're new to Perl, as I was once, as was everyone who
: frequents this group, if you're that new, are you sure whatever
: question you had but failed to ask isn't into the FAQ? You did read
: the FAQ didn't you?

: If you have a question, no matter how "stupid" or "trivial" it may
: _appear_, I suspect you would have gotten a better response had you
: asked it. 99% of people will remember the fact that they were new
: once before, and will help out, even if giving you the right syntax
: to use for Perldoc (as it can be somewhat confusing for new comers to
: work out how to use efficiently).

: My serious suggestion, is to read the FAQ if you haven't to see if
: your question is already covered. If not, or you can't find it, post
: some thoughts, examples, or places you've tried to look, somethign to
: show some effort on your part, and almost immaterial of the question
: (as long as it's Perl related), you'll get help in some way.

: The idea of Usenet is to help others in that way (for this and it's
: type of group at least). It also provides an archive of information.
: So, had you asked your question(s) and got satisfactory answers (of
: one definition or other), then in 10 years time maybe, when someone
: also has trhe same query, voila! it has already been convered, _then_
: preventing inundating the group with not neccessarily "stupid" or
: "annoying" questions, but repeatedly covered questions.

: These are my opinions and not that of others from the group, although
: they may have some input too, not for me to say.



: Regards,

:   Ian

: -----BEGIN xxx SIGNATURE-----
: Version: PGP 8.0

: iQA/AwUBPltPu2fqtj251CDhEQJMnQCgx1uLc2j52/GYbvF5/b6o9LpODUwAoNI8
: W4pejhq3MnRdZ9o8TU7SwQiL
: =F2iV
: -----END PGP SIGNATURE-----

: -- 
: Ian.H  [Design & Development]
: digiServ Network - Web solutions
: www.digiserv.net  |  irc.digiserv.net  |  forum.digiserv.net
: Scripting, Web design, development & hosting.


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

Date: Tue, 25 Feb 2003 12:00:54 GMT
From: "Ian.H [dS]" <ian@WINDOZEdigiserv.net>
Subject: Re: Not a Perl guy but need help
Message-Id: <dhmm5vge6rjnovs79tk6ql74q7os4l493j@4ax.com>
Keywords: Remove WINDOZE to reply

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

In a fit of excitement on Tue, 25 Feb 2003 11:46:56 +0000 (UTC),
Michael Bushong <bushong@OCF.Berkeley.EDU> managed to scribble:

> I had all of 9 hours' experience when I first posted.  I had some
> issues with renaming files (before I closed them) as well as when
> to use shared versus exclusive file locks.
> 
> I am assigning ID's to XML elements.  The ID's have to all be
> unique, so I am using a logfile to track the latest ID's and
> incrementing as I assign them.  Multiple users must access multiple
> files simultaneously, but there must be a single logfile to ensure
> that the ID's are unique.  
> 
> I started with:
> 
> open (LOGFILE, "+<logfile")		or die "Cannot find logfile.";
> flock (LOGFILE, LOCK_SH)		or die 'Cannot lock logfile.";
> 
> I am not sure if this is sufficient.  The O'Reilly books suggest an
> exclusive lock in some instances (presumably this one).  If I do
> that, I am not entirely sure what to use to open and lock the file.
> 
> useFcntl qw(:DEFAULT :flock);
> sysopen (LOGFILE, "logfile", RDWR) 	or die "Cannot open logfile.";
> flock(LOGFILE, LOCK_EX)			or die "Cannot lock logfile.";
> 
> 
> I honestly haven't a clue if this is necessary.  Moreover, in my
> XML files, I have to do my ID assignment through temp files.  Do I
> need to lock my temp files, truncate, and then write to them?  Or
> is that
> overkill?
> 
> Finally, Programming Perl  suggests writing a separate file  to
> create a semaphore.  This seems like overkill in my simple
> situation, but  being unfamiliar with Perl, I have no idea.
> 
> -Mike


Mike, 

After reading this, it shows some initiative on your part, and shows
that you have atleast, attempted yourself (which will rate highly
here in this group).

Now, tbh, I'm not sure if it's overkill off the top of my head, but
I'm also curious, so will have a look through the Perldoc etc myself
to satisfy my own curiosity and in hope of shedding some light on it
for you too (unless someone comes up with an answer before hand of
course).

Going back to my past comments, can you now see the benefit of asking
the question regardless of how "silly" _you_ may feel it is? Ok, so
your initial reason for posting here wasn't to help but to ask for
help, which is fine, but now, 2 people will hopefully benefit from
your question. You'll have your answer, and I'll have refreshed my
memory =)



Regards,

  Ian

-----BEGIN xxx SIGNATURE-----
Version: PGP 8.0

iQA/AwUBPlta9Gfqtj251CDhEQIEMACg5DBATxvlvQC4JNKxBjCWrnaLX1gAoKhI
jEIJNXWRxxTeAlxK67AThV9K
=8PWW
-----END PGP SIGNATURE-----

-- 
Ian.H  [Design & Development]
digiServ Network - Web solutions
www.digiserv.net  |  irc.digiserv.net  |  forum.digiserv.net
Scripting, Web design, development & hosting.


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

Date: Tue, 25 Feb 2003 13:42:37 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Parsing line into hash...
Message-Id: <3E5B72B5.7A9DA613@acm.org>

Sara wrote:
> 
> I tried a few tricks that I thought would work, but as is often the
> case, it's a struggle to get pipelined processing in Perl. I think
> there is a solution here but I can't find it.

You just have to know the right "trick".

> APL would ace this, but
> its a natural Right to Left processor.
> 
> $_ = 'TEST DATA cat 1 dog 2 mouse 6 eel 9 moose 4';
> 
>   my %h= split /\s+/, s/^TEST\s+DATA\s+//; # doesnt work
>   my %h= split /\s+/, (s/^TEST\s+DATA\s+//); # doesnt work
>   my %h= split /\s+/, ($_ =~ s/^TEST\s+DATA\s+//); # doesnt work
>   my %h= split /\s+/, scalar s/^TEST\s+DATA\s+//; # doesnt work

    my %h = split ' ', (/^TEST\s+DATA\s+(.*)/)[0]; # does work


John
-- 
use Perl;
program
fulfillment


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

Date: 25 Feb 2003 13:56:33 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Parsing line into hash...
Message-Id: <b3fsmh$nrh$1@mamenchi.zrz.TU-Berlin.DE>

Sara <genericax@hotmail.com> wrote in comp.lang.perl.misc:
> Hamish Marson <hamish@travellingkiwi.com> wrote in message
> news:<3E5A4889.6010105@travellingkiwi.com>...
> > I have a datafile that contains lines in the following format
> > 
> > <IDENT> key value
> > 
> > e.g.
> > 
> > USER HITS fred 22 john 36 joe 33
> > 
> > where key value is repeated many times. I want to read the key value 
> > pairs into a hash... But am having problems. I'm trying
> > 
> > if ((%userhits) = (/^USER HITS(\s(\w+)\s(\d+))+/)) {
> > 
> > which matches, but doesn't get the desired result of a hash with the 
> > expected numbers in the expected keys...
> > 
> > How exactly should I do this? 
> 
> I tried a few tricks that I thought would work, but as is often the
> case, it's a struggle to get pipelined processing in Perl. I think
> there is a solution here but I can't find it. APL would ace this, but
> its a natural Right to Left processor.
> 
> $_ = 'TEST DATA cat 1 dog 2 mouse 6 eel 9 moose 4';
> 
>   my %h= split /\s+/, s/^TEST\s+DATA\s+//; # doesnt work
>   my %h= split /\s+/, (s/^TEST\s+DATA\s+//); # doesnt work
>   my %h= split /\s+/, ($_ =~ s/^TEST\s+DATA\s+//); # doesnt work
>   my %h= split /\s+/, scalar s/^TEST\s+DATA\s+//; # doesnt work
> 
> # curiously this DOES work, which should be the same result as the
> trials above?
>   s/^TEST\s+DATA\s+//;
>   my %h= split /\s+/; 
> 
> Grrr might as well use Java if I wanted to double the number of lines
> in my code? Well Java would be more like 10x the number of lines, but
> I always look for "Less is More" when it comes to lines of code.
> However these types of problems are vexing. I must be missing
> something.

You are apparently expecting s/// to return the modified string,
but it doesn't.  Changing the string is a side effect.  The
return value in scalar context (that is the context of split()'s
second argument) is just a boolean that tells whether the regex
part of the s/// matched or not.

You can access a captured match of m// through a list slice if
you want to extract part of a string in a single expression.  What
you were up to is probably something like

    my %h = split ' ', (/^TEST DATA (.*)/)[ 0];

However, that doesn't deal graciously with the case that the pattern
doesn't match.  Combining the lines you got to work is better in this
respect:

    my %h= split /\s+/ if s/^TEST\s+DATA\s+//;

Anno


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

Date: Tue, 25 Feb 2003 13:27:27 GMT
From: Andras Malatinszky <nobody@dev.null>
Subject: Re: Premature end of script headers errors
Message-Id: <3E5B6F01.2020501@dev.null>

Premature end of script headers is a CGI error message (it comes from 
the web server, not Perl). It basically indicates that your script 
started running (as opposed to not even being found or having the wrong 
permission or the wrong shebang line), but then something terrible 
happened before it could finish printing the proper CGI headers.

There is no way for us to tell what exactly the problem is with your 
script without actually seeing it. I recommend you read the section 
under  "How can I get better error messages from a CGI program?" in 
perlfaq9 and follow the advice given there.


Chumley the Walrus wrote:

> I have all my files chmoded correctly, but I keep getting an internal
> server error when trying to access my perl script/ page. In my error
> logs, I get a:
> 
> Premature end of script headers
> 
> ...which tells me little or nothing. 
> 
> 
> Any ideas? Thanks for help
> 



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

Date: Tue, 25 Feb 2003 11:48:41 -0000
From: "Spero" <spero126NOSPAM@yahoo.com>
Subject: Silencing Default Error Output of getopts
Message-Id: <b3fl3o$42a$1@wisteria.csv.warwick.ac.uk>

Hi,

I've googled and googled, read man pages and web pages and can't find the
answer to this.

How do I silence the default output of getopts?

My code:

use Getopt::Std;
getopts('hf:d:c');
 ...

In this situation:
perlfile -z

Outputs:
Unknown option: z

How do I stop this? (I will add my own error message)

Thank-you,

Spero




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

Date: 25 Feb 2003 13:02:02 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Silencing Default Error Output of getopts
Message-Id: <b3fpga$jav$2@mamenchi.zrz.TU-Berlin.DE>

Spero <spero126NOSPAM@yahoo.com> wrote in comp.lang.perl.misc:
> Hi,
> 
> I've googled and googled, read man pages and web pages and can't find the
> answer to this.
> 
> How do I silence the default output of getopts?
> 
> My code:
> 
> use Getopt::Std;
> getopts('hf:d:c');
> ...
> 
> In this situation:
> perlfile -z
> 
> Outputs:
> Unknown option: z
> 
> How do I stop this? (I will add my own error message)

Since Getopt's warnings are unconditional, you'll probably have
to catch the warnings through $SIG{ __WARN__}.  See %SIG in perlvar
for more.

Anno


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

Date: Tue, 25 Feb 2003 12:26:14 GMT
From: inwap@inwap.com (Joe Smith)
Subject: Re: Subroutine does not 'see' parameter passed to it
Message-Id: <GhJ6a.4630$io.186344@iad-read.news.verio.net>

In article <620c2f02.0302191753.4e9d22de@posting.google.com>,
george <georgem@crystalgraphics.com> wrote:
> Thanks for your response.  There was no error message.  Without the
>semicolon, no record was written to the database.  With the semicolon,
>then a record was written to the database -- so that is how I know that
>the subroutine was evolked.

Wrong interpretation.  The subroutine was not invoked, but executable
statements in the module file were.

Inside of 'use', when perl sees an executable block that is not
part of a subroutine definition, it acts the same as
	BEGIN {
	  ...
	}
which will execute the ... statements before your main program
even starts.
		-Joe
-- 
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.


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

Date: 25 Feb 2003 12:37:22 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Subroutine does not 'see' parameter passed to it
Message-Id: <b3fo22$jav$1@mamenchi.zrz.TU-Berlin.DE>

Joe Smith <inwap@inwap.com> wrote in comp.lang.perl.misc:
> In article <620c2f02.0302191753.4e9d22de@posting.google.com>,
> george <georgem@crystalgraphics.com> wrote:
> > Thanks for your response.  There was no error message.  Without the
> >semicolon, no record was written to the database.  With the semicolon,
> >then a record was written to the database -- so that is how I know that
> >the subroutine was evolked.
> 
> Wrong interpretation.  The subroutine was not invoked, but executable
> statements in the module file were.
> 
> Inside of 'use', when perl sees an executable block that is not
> part of a subroutine definition, it acts the same as
> 	BEGIN {
> 	  ...
> 	}
> which will execute the ... statements before your main program
> even starts.

This isn't quite correct.  No "BEGIN {}" is assumed around executable
statements in a file, whether the file is called directly or via "use".
However, the "use" statement itself is executed at compile time (as
if a "BEGIN {}" block was around it).  So relative to the "use"-ing
file, executable statements in the module file happen at compile time,
but not relative to the module file itself.

Anno


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

Date: Tue, 25 Feb 2003 05:59:28 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: translate ( tr ) question
Message-Id: <Xns932D4715D52C7sdn.comcast@216.166.71.239>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

"Hideki Ono" <hideki@massassi.net> wrote in news:b3evl6$2os$1
@news.sfc.keio.ac.jp:

> tr/J-Z/10-27/;

Uh, no.

- -- 
Eric
print scalar reverse sort qw p ekca lre reh 
ts uJ p, $/.r, map $_.$", qw e p h tona e;

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBPltakGPeouIeTNHoEQLmRACgoy+FgvMIz8gp6uHGLYjOrBqPFTIAnRng
DEsmTfx3BDBhgrkrkTwmmBDC
=lQ9t
-----END PGP SIGNATURE-----


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

Date: Tue, 25 Feb 2003 21:38:36 +0900
From: "Hideki Ono" <hideki@massassi.net>
Subject: Re: translate ( tr ) question
Message-Id: <b3fo0q$m1o$1@news.sfc.keio.ac.jp>

Sorry about that =)

"Eric J. Roode" <REMOVEsdnCAPS@comcast.net> wrote in message
news:Xns932D4715D52C7sdn.comcast@216.166.71.239...
> -----BEGIN xxx SIGNED MESSAGE-----
> Hash: SHA1
>
> "Hideki Ono" <hideki@massassi.net> wrote in news:b3evl6$2os$1
> @news.sfc.keio.ac.jp:
>
> > tr/J-Z/10-27/;
>
> Uh, no.
>
> - --
> Eric
> print scalar reverse sort qw p ekca lre reh
> ts uJ p, $/.r, map $_.$", qw e p h tona e;
>
> -----BEGIN xxx SIGNATURE-----
> Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
>
> iQA/AwUBPltakGPeouIeTNHoEQLmRACgoy+FgvMIz8gp6uHGLYjOrBqPFTIAnRng
> DEsmTfx3BDBhgrkrkTwmmBDC
> =lQ9t
> -----END PGP SIGNATURE-----



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

Date: Tue, 25 Feb 2003 13:33:48 +0000
From: Chris Lowth <dont@want.spam>
Subject: Re: Using Perl to parse C buffers under Linux (need help)
Message-Id: <DsK6a.316$yu.49651@newsfep2-gui>

David J. Topper wrote:

> Hi folks,
> 
> I've been looking at "man perl_embed" and having some luck.  IE., I can
> get things to compile.  But I am at a loss to really make things work.
> Here's the background:
> 
> 1.  I have an old C program which uses its own parser.  I've managed to
> change it so that I can:
> 
> P_PROG < text.pl
> 
> and it now uses perl to parse the file and trigger PROG's functions.
> Woohoo!
> 
> But what I'd like even more now is to be able to have a function whereby
> I can say:
> 
> 
> parse_buf(*inbuf);
> 
> where inbuf is a string buffer containing a valid perl script.  I'm
> trying stuff like the following:
> 
> int perl_parse_buf (char *inBuf) {
> dSP;
> STRLEN n_a;
> SV *command = NEWSV(1099, 0);
> 
> char *embedding[] = { "", "-e", "0" };
> 
> perl_interp = perl_alloc();
> perl_construct( perl_interp );
> 
> perl_parse(perl_interp, NULL, 3, embedding, NULL);
> PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
> perl_run(perl_interp);
> 
> sv_setpv(command, inBuf);
> eval_sv(command, TRUE);
> 
> 
> return 0;
> }
> 
> but it doesn't seem to be working.  I'd love to hear from people with
> some input on teh subject.
> 
> Thanks,
> 
> DT
> --
> Technical Director, Virginia Center for Computer Music

It's a different function - but this comes from a project I worked on 
recently. It calls a named perl function from C, passing it 2 string 
arguments. Maybe you could use it as some kind of prototype .?.

It assumes a pre-existing (pre-declared) perl interpreter already in the 
core of the calling app.


char *call_string_function(char *funcname, char *arg1, char *arg2)
{
        dSP ;
        int count;
        char *rtn;
        SV *sv;

        ENTER; SAVETMPS; PUSHMARK(SP);

        if (arg1 != NULL) XPUSHs(sv_2mortal(newSVpvn(arg1, strlen(arg1))));
        if (arg2 != NULL) XPUSHs(sv_2mortal(newSVpvn(arg2, strlen(arg2))));

        PUTBACK;

        count = call_pv(funcname, G_SCALAR);

        SPAGAIN;

        if (count != 1)
                croak("%s didnt return 1 value", funcname);

        sv = POPs;
        if (!SvOK(sv))
                rtn = NULL;
        else {
                rtn = SvPV(sv, PL_na);
                rtn = strdup(rtn);
        }

        PUTBACK; FREETMPS; LEAVE;

        return rtn;
}

Chris

-- 
My real e-mail address is
chris <at> lowth <dot> com


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

Date: Tue, 25 Feb 2003 13:25:33 +0000
From: Chris Lowth <dont@want.spam>
Subject: Re: variable assignment question. help
Message-Id: <UkK6a.315$yu.48079@newsfep2-gui>

Louis wrote:

> hi all,
> 
> i used to follow to get cpu status. can i have one 'awk' command to
> get all counters? or any script help?
> 
> i.e.
> my ($user, $nice, $system) = `awk '/$cpu / {print \$2, \$3, \$4}' <
> /proc/stat `;
> 
> ######################################################
> # get cpu stat info /proc/stat
> my $user = `awk '/$cpu / {print \$2}' < /proc/stat `;
> my $nice = `awk '/$cpu / {print \$3}' < /proc/stat `;
> my $system = `awk '/$cpu / {print \$4}' < /proc/stat `;
> ######################################################

No need to mix perl and awk - do it all in perl! Try this ..

open(F, "< /proc/stat") || die "Cant open /proc/stat";
$cpu = "cpu";
($key,$user,$nice,$system) = split(/\s+/, (grep(/^$cpu /, <F>))[0]);
close(F);
print "User: $user\n";
print "Nice: $nice\n";
print "System: $system\n";


Chris
-- 
My real e-mail address is
chris <at> lowth <dot> com


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

Date: Tue, 25 Feb 2003 13:58:08 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: variable assignment question. help
Message-Id: <3E5B765C.BDA2788E@acm.org>

Louis wrote:
> 
> i used to follow to get cpu status. can i have one 'awk' command to
> get all counters? or any script help?
> 
> i.e.
> my ($user, $nice, $system) = `awk '/$cpu / {print \$2, \$3, \$4}' <
> /proc/stat `;
> 
> ######################################################
> # get cpu stat info /proc/stat
> my $user = `awk '/$cpu / {print \$2}' < /proc/stat `;
> my $nice = `awk '/$cpu / {print \$3}' < /proc/stat `;
> my $system = `awk '/$cpu / {print \$4}' < /proc/stat `;
> ######################################################

Why use AWK when you can do it in perl?

open STAT, '/proc/stat' or die "Cannot open /proc/stat: $!";
while ( <STAT> ) {
    if ( /$cpu\s+(\d+)\s+(\d+)\s+(\d+)/ ) {
        ( $user, $nice, $system ) = ( $1, $2, $3 );
        last;
        }
    }
close STAT;



John
-- 
use Perl;
program
fulfillment


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

Date: Tue, 25 Feb 2003 12:18:51 GMT
From: inwap@inwap.com (Joe Smith)
Subject: Re: wanted: BZIP2 module for Win32 and Linux
Message-Id: <LaJ6a.4629$io.186344@iad-read.news.verio.net>

In article <bYJ4a.1260487$TJ.177153@post-02.news.easynews.com>,
Edward Wildgoose <Ed+nospam@ewildgoose.demon.co.uk@> wrote:
>Apologies if this is the wrong place.  I have a need for a BZIP2 module in
>the style of the current zlib library
>
>Anyway, this would be contributed back to CPAN for all to use, but ...

What is wrong with the Bzip2 modules already on CPAN?

http://search.cpan.org/search?query=bzip2&mode=module

>particularly have a need for the stream compression functions with "partial
>flush", etc, ie so I can use it for compressing a real time data stream.

Like IO::Filter::bzip2, perhaps?
	-Joe

-- 
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.


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

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


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