[17529] in Perl-Users-Digest
Perl-Users Digest, Issue: 4949 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 22 11:05:38 2000
Date: Wed, 22 Nov 2000 08:05:12 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <974909111-v9-i4949@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 22 Nov 2000 Volume: 9 Number: 4949
Today's topics:
CGI in a table <jaedma@yahoo.com>
Re: Conditional includes with cookies <bruce@trendstat.nojunkmail.com>
Re: die (Honza Pazdziora)
Re: die <mjcarman@home.com>
Re: die (Tad McClellan)
email parsing body <khanrahan@cypresscom.net>
Re: Executing own module as root? <meisl@amvt.tu-graz.ac.at>
Re: Extracting data from a ps command <crowj@aol.com>
Re: Extracting data from a ps command (Tad McClellan)
Re: HELP! bring variables out of a subroutine? (Tad McClellan)
Re: HELP! bring variables out of a subroutine? <mjcarman@home.com>
How do I read line by line of data from a file using pe yatink@my-deja.com
Re: How do I read line by line of data from a file usin (Clay Irving)
How to output query row-by-row to HTML <michael.segulja@sgi-lsi.com>
Re: How to output query row-by-row to HTML <josef.moellers@fujitsu-siemens.com>
Re: I need a fork example, please jwetsell@bigfoot.com
Re: Memory limitation & memory leak <mjcarman@home.com>
Need help with file splitting <johan.sunnerstig@netgiro.com>
Re: need some help with regex (Tad McClellan)
Re: OT:Re: Eurodate mysteries (Tad McClellan)
passing parameter problem <thestas@dolnet.gr>
Perl and Netscape's history.dat <josef.moellers@fujitsu-siemens.com>
perl version of html tag richard_dobson@my-deja.com
permissions issue...i think akothek@my-deja.com
Re: Problem with simple del file script (Honza Pazdziora)
Re: Problem with simple del file script (Rafael Garcia-Suarez)
Question: How to Return script name from within script. <deanderson2@mmm.com>
Re: quick sorting question (Tad McClellan)
receive email and process via perl x_y_u@my-deja.com
Re: running a script as root (Villy Kruse)
Simple Question :) (Energy)
Re: Simple Question :) <meisl@amvt.tu-graz.ac.at>
Re: Simple Question :) <geoff-at-farmline-dot-com@127.0.0.1>
Re: Simple Question :) <ronh@iainc.com>
Re: trouble blessing object (Rafael Garcia-Suarez)
Re: trouble blessing object <mjcarman@home.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 22 Nov 2000 09:47:02 -0600
From: "Jim" <jaedma@yahoo.com>
Subject: CGI in a table
Message-Id: <3a1beaeb$0$617$7f8943f3@newsreader.visi.com>
I have a perl cgi script (a clock) that I want to put into a table in an
html page. I cant figure out what code to put the table cell (img...embed
ect).
Thanks for any help
------------------------------
Date: Wed, 22 Nov 2000 08:49:23 -0700
From: Bruce K <bruce@trendstat.nojunkmail.com>
Subject: Re: Conditional includes with cookies
Message-Id: <3A1BEB03.98B11511@trendstat.nojunkmail.com>
Frederik Vincx wrote:
>
> hi,
>
> I've been looking all over the net for stuff about conditional includes, and
> this was the online 'good' thing I found
> http://wsabstract.com/howto/conssi.shtml . On that page they show you how to
> use different includes depending on the browsertype.. well, I'd really like
> to use different includes depending on a selection the user made that is
> store in a cookie .., but it just won't work.. Does anyone know how to do
> that?
Frederik,
Try this:
<!--#if expr="${HTTP_COOKIE} = /cookie.text/" -->
(Now if someone could show me how to create a redirect inside SSI, I
could go to bed happy...)
--
Bruce Kube
Systems Analyst
Trendstat Capital Management, Inc.
(Please post reply to newsgroup and
please fix return address if responding directly via e-mail)
------------------------------
Date: Wed, 22 Nov 2000 13:50:36 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: die
Message-Id: <G4FIGC.IoA@news.muni.cz>
On Wed, 22 Nov 2000 13:26:47 GMT, melet@my-deja.com <melet@my-deja.com> wrote:
>
> die do not work in my perl script. I have no output. I don't understand.
Your code, versions, environment?
--
------------------------------------------------------------------------
Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
.project: Perl, DBI, Oracle, MySQL, auth. WWW servers, MTB, Spain.
Petition for a Software Patent Free Europe http://petition.eurolinux.org
------------------------------------------------------------------------
------------------------------
Date: Wed, 22 Nov 2000 08:16:14 -0600
From: Michael Carman <mjcarman@home.com>
Subject: Re: die
Message-Id: <3A1BD52E.AB6A9515@home.com>
melet@my-deja.com wrote:
>
> die do not work in my perl script. I have no output.
> I don't understand.
>
> could you help me?
Not without something more to go on. Tell us what you're doing! Try to
trim down your code to a small example that doesn't behave as you expect
it to and post it here.
-mjc
------------------------------
Date: Wed, 22 Nov 2000 09:17:01 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: die
Message-Id: <slrn91nlat.mb9.tadmc@magna.metronet.com>
On Wed, 22 Nov 2000 13:50:36 GMT, Honza Pazdziora <adelton@fi.muni.cz> wrote:
>On Wed, 22 Nov 2000 13:26:47 GMT, melet@my-deja.com <melet@my-deja.com> wrote:
>>
>> die do not work in my perl script. I have no output. I don't understand.
>
>Your code, versions, environment?
^^^^^^^^^^^
use PSI::ESP;
From the information-free content of the post, I'll venture a
guess that the environment is "a CGI program" and that die()'s
output is going to a server log.
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 22 Nov 2000 10:58:38 -0500
From: Kevin Hanrahan <khanrahan@cypresscom.net>
Subject: email parsing body
Message-Id: <3A1BED2E.4AFEC523@cypresscom.net>
Can anybody tell me how to parse out the body of an email and pass it to
another prog. or part of the same program as a variable? Can you give me
an example? I am new to perl and am trying to learn from seeing actual
examples...thanks
------------------------------
Date: 22 Nov 2000 15:22:02 +0100
From: Christian Meisl <meisl@amvt.tu-graz.ac.at>
Subject: Re: Executing own module as root?
Message-Id: <m3aeasqe7p.fsf@famvtpc59.tu-graz.ac.at>
mgjv@tradingpost.com.au (Martien Verbruggen) writes:
> What is the exact error? What sort of module is this? What C code is
> this? Is the C code clean? debugged, purified, whatever you normally do
> to make sure it doesn't leak or cross memory boundaries anywhere? What
> system calls do you use? Have you tried debugging this to see where that
> 'memory error' occurs? Tried to fiddle the compiler flags to make the
> compilation phase as tight and pedantic as possible?
>
> Instead of battling the symptoms with brute force, maybe you should
> concentrate on trying to find the cause.
I'm sorry for being a bit too short in my explanation: I have a
interface card and a driver that is written in C. As the driver is
very simple, the following "unirel.xs" seems to be sufficient to
operate the card:
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "stdio.h"
#include "unistd.h"
#include "asm/io.h"
#define adr 0x0300
MODULE = unirel PACKAGE = unirel
void Init ()
CODE:
iopl(3);
outb(128,adr+3);
outb(155,adr+7);
void Set (a, b)
int a
int b
CODE:
outb(a,adr);
outb(b,adr+1);
The documentation of the card says that the original card driver has
to be used with root permissions, so I thought that I have to give
root permissions to the resulting perl module, as well.
Unfortunately, I do NOT "speak" C, so maybe there are some basic
mistakes...
Best regards,
Christian
--
Christian Meisl <meisl@amvt.tu-graz.ac.at> www.amft.tu-graz.ac.at
Inst. f. Apparatebau, Mech. Verfahrenstechnik und Feuerungstechnik
--------------- A day for firm decisions!!!!! Or is it? ---------------
PGP fingerprint: DF48 2503 0411 F0EF 149C 851B 1EF0 72B9 78B6 034A
------------------------------
Date: Wed, 22 Nov 2000 09:40:22 -0500
From: John Crowley <crowj@aol.com>
Subject: Re: Extracting data from a ps command
Message-Id: <3A1BDAD6.92C20ED8@aol.com>
vivekvp wrote:
>
> I am trying to extract the time from a ps unix command - but it does
> not have regularly spaced columns. So the split command does not work
>
> What I am trying to do is get the time - if it greater that a certain
> amount - send the PID and user via email to the sysadmin. How do I
> separate the time?
>
> Thanks,
>
> V
>
> UID PID PPID C STIME TTY TIME COMMAND
> root 0 0 0 Nov 18 ? 1:26 swapper
> root 1 0 0 Nov 18 ? 0:04 init
> root 2 0 0 Nov 18 ? 5:55 vhand
> root 3 0 0 Nov 18 ? 5:57 statdaemon
> root 4 0 0 Nov 18 ? 0:20 unhashdaemon
> root 7 0 0 Nov 18 ? 0:00 ttisr
> root 13 0 0 Nov 18 ? 0:11 lvmkd
> root 14 0 0 Nov 18 ? 0:11 lvmkd
> root 15 0 0 Nov 18 ? 0:11 lvmkd
> root 16 0 0 Nov 18 ? 0:12 lvmkd
> root 17 0 0 Nov 18 ? 0:12 lvmkd
> root 18 0 0 Nov 18 ? 0:12 lvmkd
> root 19 0 0 Nov 18 ? 7:45 netisr
> root 20 0 0 Nov 18 ? 6:51
> netisr
>
> --
> He who fights and runs away, lives to run another day!
>
look for ps formatting options in man ps or split with /s+
------------------------------
Date: Wed, 22 Nov 2000 08:44:35 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Extracting data from a ps command
Message-Id: <slrn91nje3.m1u.tadmc@magna.metronet.com>
On Wed, 22 Nov 2000 11:51:53 GMT, vivekvp <vivekvp@spliced.com> wrote:
> I am trying to extract the time from a ps unix command - but it does
>not have regularly spaced columns.
^^^ ^^^^^^^^^^^^^^^^
The columns below look regularly spaced to me.
Got data that shows what you mean there?
>How do I
>separate the time?
perldoc -f substr
> UID PID PPID C STIME TTY TIME COMMAND
> root 0 0 0 Nov 18 ? 1:26 swapper
> root 1 0 0 Nov 18 ? 0:04 init
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 22 Nov 2000 09:01:33 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: HELP! bring variables out of a subroutine?
Message-Id: <slrn91nkdt.m1u.tadmc@magna.metronet.com>
On Wed, 22 Nov 2000 15:40:10 +0600, Konstantin Stupnik <skv@iis.nsk.su> wrote:
>
>perl is a very tricky thing :)
No need to repeat the obvious :-)
>If you will write in C something like this:
>
>char* myfunc()
>{
> char buf[256];
> strcpy(buf,"Hello, world!");
> return buf;
>}
>
>you will break everything,
Yes, C distracts you from your real problem by making you do your
own memory management.
>since variables that are created on stack will be
>destroyed after return from function.
Variables that are created on the stack will be destroyed after
return from the function in Perl too.
>In perl everything is rather different.
It helps if you can get to understand the difference between
a variable and a value, and the ramifications of builtin garbage
collection.
>sub mysub{
> my $str="Hello, world!";
Value is in a variable taken from the heap there.
> return $str;
Value (not the variable) goes on the stack there.
>}
>
>this will work fine.
This one returns a _string_ (value) not an "address" (reference).
It does not compare very directly with your C example.
The _variable_ ($str) _is_ destroyed when the block exits.
But the _value_ is pushed onto the stack before the block exits.
>Even this:
>
>sub mysub{
> my $str="Hello, world!";
> return \$str;
>}
>
>will work fine!!
Yes. Perl has garbage collection. C does not, so you have to mess
with memory management yourself.
>You have returned reference
So this sub is most comparable to your C example.
>to local variable,
Ack!
Don't call them local variables.
Call them lexical/static/my variables.
"local" means something else in a Perl context (it means "global" !!)
Perl FAQ, part 7:
"What's the difference between dynamic and lexical (static) scoping?
Between local() and my()?"
>and everything will be fine.
>Nothing is broken.
>Even more, every time you will call this sub,
>you will gain reference to new variable!!!
Garbage collection sure is handy, huh?
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 22 Nov 2000 08:22:32 -0600
From: Michael Carman <mjcarman@home.com>
Subject: Re: HELP! bring variables out of a subroutine?
Message-Id: <3A1BD6A8.117DD6AC@home.com>
webbgroup@my-deja.com wrote:
>
> What happens when I have multiple variables. Can I return all
> of those??
>
> sub mysub
> {
> my $str="Hello, World!";
> $addition= 5+7;
> return $str,$addition;
> )
>
> NEVERMIND ... I DID IT..AND IT WORKED. THANKS GUYS..
Just don't try that with
return(@array, @another);
or you'll be unpleasantly surprised. Perl flattens subroutine arguments
(and return values) into flat lists when it passes them. If you want to
pass/return multiple arrays and/or hashes you'll need to do it by
reference.
-mjc
------------------------------
Date: Wed, 22 Nov 2000 14:51:07 GMT
From: yatink@my-deja.com
Subject: How do I read line by line of data from a file using perl
Message-Id: <8vgmgo$naq$1@nnrp1.deja.com>
Hi,
How do I read line by line of data from a file using perl ?
I have file, each line has some instructions...
I need to read each time and do some processing.
Thanks,
Yatin.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 22 Nov 2000 15:34:05 GMT
From: clay@panix3.panix.com (Clay Irving)
Subject: Re: How do I read line by line of data from a file using perl
Message-Id: <slrn91nprd.h6d.clay@panix3.panix.com>
On Wed, 22 Nov 2000 14:51:07 GMT, yatink@my-deja.com <yatink@my-deja.com> wrote:
>How do I read line by line of data from a file using perl ?
>I have file, each line has some instructions...
>I need to read each time and do some processing.
Read the FAQ.
--
Clay Irving <clay@panix.com>
All life's answers are on TV. - Bart Simpson
------------------------------
Date: Wed, 22 Nov 2000 09:26:42 -0600
From: "Michael Segulja" <michael.segulja@sgi-lsi.com>
Subject: How to output query row-by-row to HTML
Message-Id: <3a1be372$1_2@newsa.ev1.net>
I have a database that stores MP3 information. I have a Perl script that
runs a query on the database depending on the genre. I want each row to be
output to an HTML page line by line, but I'm not sure how to do it. Here's
the code I have so far:
--Begin Perl code
my $genre = "\"Rock\"";
my $ary_ref = $dbh->selectall_arrayref("SELECT DISTINCT artist FROM mp3main
WHERE genre=$genre");
foreach my $item(@$ary_ref) {
push @ary, $item->[0];
}
print "$_\n" for @ary;
--End Perl code
This works, but it output everything to one line, i.e.:
Artist 1 Artist 2 Artist 3 Artist 4
I want it to output each row one line at a time like this:
Artist 1
Artist 2
Artist 3
Artist 4
I tried this:
--Being Perl code
my $genre = "\"Rock\"";
my $sth = $dbh->prepare("SELECT DISTINCT artist FROM mp3main WHERE
genre=$genre");
$sth->execute();
my $row = $sth->fetchrow_hashref;
while (my @fieldNames = keys %$row) {
foreach my $fieldName(@fieldNames) {
print "$fieldName\n";
}
}
$sth->finish();
--End Perl code
This doesn't work. It actually outputs the word artist. I'm a beginner at
this, and I'm using this project as a way to learn Perl, so I hope somebody
can help me. I've tried reading the documentation in perldoc DBI on the
different fetchrow commands, but I just get more confused I guess.
Thanks very much for your help,
Michael
------------------------------
Date: Wed, 22 Nov 2000 16:37:28 +0100
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: How to output query row-by-row to HTML
Message-Id: <3A1BE838.BD5AFBE3@fujitsu-siemens.com>
Michael Segulja wrote:
Although this is an HTML question more than a Perl question:
In HTML, a newline is not represented by a newline character but rather
by a "line break":
<br>
--Begin Perl code
my $genre =3D "\"Rock\"";
my $ary_ref =3D $dbh->selectall_arrayref("SELECT DISTINCT artist FROM
mp3main
WHERE genre=3D$genre");
foreach my $item(@$ary_ref) {
push @ary, $item->[0];
}
print "$_<br>\n" for @ary;
---------^^^^
--End Perl code
HTH
-- =
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T. Pratchett)
------------------------------
Date: Wed, 22 Nov 2000 15:19:15 GMT
From: jwetsell@bigfoot.com
Subject: Re: I need a fork example, please
Message-Id: <8vgo5a$ot1$1@nnrp1.deja.com>
In article <8xAQ5.7647$3j.3111666@news1.gvcl1.bc.home.com>,
Peter@PSDT.com wrote:
[snip]
>
> Hence (untested):
>
> use Errno;
> while (1) {
> last if my $pid = fork;
> if (defined $pid) {
> ServerTalk();
> exit;
> }
> elsif $!{EAGAIN} {
I'm new to Perl. Can you tell me what this is checking? $!(EAGAIN)???
Thank you - John
> sleep 5; # Give it another chance to find a process slot
> }
> else {
> die "Couldn't fork: $!\n";
> }
> }
>
> >print " talking to the server right now".
> >
> >Will this work. Is fork what I need to do this?
>
> Close, and yes. Read what perldoc -f fork has to say about buffer
flushing.
> You probably also want
>
> local $SIG{CHLD} = 'IGNORE';
>
> in the right place, but you should understand the related issues of
child processes
> on your operating system first. perldoc perlipc for starters.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 22 Nov 2000 07:57:27 -0600
From: Michael Carman <mjcarman@home.com>
Subject: Re: Memory limitation & memory leak
Message-Id: <3A1BD0C7.A1004EAB@home.com>
[Post reordered to reflect the natural flow of time]
Jon wrote:
> Michael Carman wrote:
>> Jon wrote:
>>>
>>> If I have a localized (my) reference to a hash of hash to an
>>> array within a function, does all the memory used to build
>>> this structure gets freed and be made available when Perl
>>> exit the function?.
>>
>> Maybe -- it depends on what you do with that reference. Do
>> you abandon it or return it to the caller?
>
> I am sure the reference to the structure was not returned upon
> exiting the function and that's what was confusing to us.
Well, that's not the only way of keeping the memory in use. You could
also push() the reference onto an external array, etc.
> We also noticed that the memory usage grew considerably after
> we have exited the function and re-enter it the second time.
The my() will allocate "new" memory each time the function is called,
but unless something is still aware of the data from the last call, the
memory should be reused.
> We were working out of the assumption that the freed memory when
> the script exited the function the first time will be re-used when
> we hit the same function the second time.
It should, but it sounds like your function is having side-effects you
didn't know about. Maybe you're mucking about with globals from inside
the sub? If you can post a (reasonably-sized) example which exhibits the
problem, we might be able to spot it for you. (Or at least give you a
sanity check. :)
-mjc
------------------------------
Date: Wed, 22 Nov 2000 15:49:37 GMT
From: Sunner <johan.sunnerstig@netgiro.com>
Subject: Need help with file splitting
Message-Id: <8vgpud$qg6$1@nnrp1.deja.com>
Hi.
I have a script that's supposed to write a report out of a logfile.
At first the logfile is crammed with all sorts of stuff, but now the
script reduces it to the two parts I need, an ID number, and a status
code that tells how an operation went.
A processed file might look like this:
10002000 0
10002000 0
10001000 0
10002000 3
10002000 2
10001000 5
With the 8 digit number being the ID and the 1 digit number being the
code.
Now as long as there arent too many operations performed, counting them
by hand is feasible, but with 1000 ops its a bit harder.
So what I wanna do is make a short report that would look something
like:
10002000 had 2 code 0's
10002000 had 1 code 3's
10002000 had 1 code 2's
10001000 had 1 code 0's
10001000 had 1 code 5's
Or something similar.
It doesnt need to contain anything else than the ID, status code, and
number of times really.
How can this be done in a decently short time(I havent got the kind of
time to read through a 1000 page perl bible at the present time)?
I'd really appreciate any help with this.
Regards
//Johan
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 22 Nov 2000 07:20:41 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: need some help with regex
Message-Id: <slrn91negp.m1u.tadmc@magna.metronet.com>
On Wed, 22 Nov 2000 11:14:00 +0100, Michael Guenther
<MiGuenther@lucent.com> wrote:
>
>metamp@my-deja.com wrote in message <8vff64$pjb$1@nnrp1.deja.com>...
>
>>if ($query->param('texfield_name') != /[^a-zA-Z]/)
>This one not not working ....
>
> if (not($query->param('texfield_name') = /[^a-zA-Z]/) )
>the syntax ! for not usually not work with pattern matching.
>I don't know why, but it is always the same.
>
>
>Maybe someone else can tell us why "!" and "not" are not the same in that
>case
You seem to be more than a little confused about Perl's operators.
There are several that "look like" combinations of others but
that is just coincidence.
! logical not
not logical not
!= not equal
== equal
= assignment
~ bitwise complement
=~ binding (true if matched, false if no match)
!~ binding (false if matched, true if no match)
You want one of the last 2 if you want to bind a pattern match
to a string to try and match against.
Both of the above do strange stuff, likely not what you wanted to do.
if ($query->param('texfield_name') !~ /[^a-zA-Z]/)
^^
if ( not $query->param('texfield_name') =~ /[^a-zA-Z]/)
^^^ ^^
Now _those_ do the same thing, as they should.
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 22 Nov 2000 08:07:47 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: OT:Re: Eurodate mysteries
Message-Id: <slrn91nh93.m1u.tadmc@magna.metronet.com>
On Wed, 22 Nov 2000 22:37:08 +1100, Martien Verbruggen
<mgjv@tradingpost.com.au> wrote:
>On Wed, 22 Nov 2000 10:31:26 GMT,
> coluche@my-deja.com <coluche@my-deja.com> wrote:
>
>> I'm sure there are more
>> deserving causes to spill blood upon, like from which end should one
>> break a boiled egg.
As with nearly all specifications, this one makes apriori
assumptions too.
The first question to be answered when approaching the egg-breaking
problem is along what axis the breaking is to take place.
You have assumed the breaking will take place laterally (across
the shorter dimension).
If you instead assume that the breaking will take place longitudely (sp?)
then the decision goes away, due to symmetry.
You also seemed to have missed the Use Case where the egg
is broken in the center, rather than at one end or the other.
So while reading this thread, keep in mind that the less-than-useful
implementation suggestions are a consequence of your poor specification...
You should also expect some degree of derision for asking a question
without first consulting the relevant docs.
The `big-endian' and `little-endian' problem is documented in
perlfunc.pod (though that is for the egg *eating* habits of
the Lilliputians rather than about egg *breaking* habits. You
can modify it for your application).
>I hope you're not suggesting that one should break the blunt end first.
It depends on what you want to emphasize. You chose whichever one
communicates your intentions more clearly.
>it's obvious that that's wrong.
[ herein we manage to drift back on-topic...]
I am amazed that a Perler would have such a non-TMTOWTDI attitude:
if ($condition eq $important) { print 'write it this way' }
print 'write it this way' if $action eq $important;
Perl lets you break it at either end. If it's good enough for
Perl is should be good enough for us!
Freedom rulz!
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 22 Nov 2000 16:32:16 +0200
From: "Theodore Stassinos" <thestas@dolnet.gr>
Subject: passing parameter problem
Message-Id: <8vgmm0$hvo$1@ulysses.noc.ntua.gr>
Hi everybody.
I've constructed a simple search engine using perl.
When the user put something in a text box, to find it i call a perl program
tha performs the search.
In the result page, i have a link which takes the user back to the initial
html page to redo a search if he likes.
My problem, although, is that i want to pass a parameter from that link to
my initial html file with the previous search strings that the user entered,
presenting them in a text box.
Can you suggest me something?
(The search.html file posts a form with the name "f2" containing the text
box (name=sText) i want to fill every time the user returns to that page)
Thank you in advance
Theodore
------------------------------
Date: Wed, 22 Nov 2000 16:15:59 +0100
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Perl and Netscape's history.dat
Message-Id: <3A1BE32F.959A1FD0@fujitsu-siemens.com>
Hi,
I use Perl (5.0 patchlevel 5 subversion 3) on a SuSE6.3 system running
Netscape=AE Communicator 4.7
I'm trying to extract the history from the history.dat file with a
script from the camel book:
#! /usr/bin/perl
use DB_File;
$filename =3D "$ENV{HOME}/.netscape/history.dat";
print "Opening $filename\n";
dbmopen(%NS_Hist, "$filename", undef)
or die "Can't open netscape history file: $!";
while (($url, $when) =3D each %NS_Hist) {
next unless defined($when);
chop($url, $when);
$w =3D scalar(localtime(unpack("V", $when)));
print "$w: $url\n";
}
dbmclose(%NS_Hist);
exit(0);
Unfortunately it prints the error message
Can't open netscape history file: at /home/josef/bin/nshist line 11.
and dies.
The strace output shows that it opens the history.dat file twice, each
time reading a couple of bytes. I've tried replacing the DB_File by any
one of the other *DBM_File modules to no avail. I also used the "tie"
syntax to no avail.
What's happening?
-- =
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T. Pratchett)
------------------------------
Date: Wed, 22 Nov 2000 15:32:04 GMT
From: richard_dobson@my-deja.com
Subject: perl version of html tag
Message-Id: <8vgotl$ph1$1@nnrp1.deja.com>
Hi,
i am using cgi :html3 to import shortcuts for tables.
I am returning input data from the user to the browser in the form of a
table. Does anyone know how to specify the cell width so that if the
data contained in it is over a certain length it starts a new line and
extends the row downwards instead of across?
Basically, i need to wrap the text
thanks in advance
Richard
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 22 Nov 2000 15:53:30 GMT
From: akothek@my-deja.com
Subject: permissions issue...i think
Message-Id: <8vgq5m$qk0$1@nnrp1.deja.com>
this should have a simple solution.
i have written a perl program that is basically a wrapper around a
bunch of perl and shell scripts. runs fine when i or other users cd to
the dir and run it. but cant run the program from other dirs...it does
not find the inner scripts...my question is:
do i need to explicitly specify the complete pathname in all the inner
scripts?
or
can i add some code to the wrapper script that will fake the cd and run
OK...clearly this option is preferable because it would amount to
lesser work and easier to maintain...i tried system("cd /home/mydir")
but that did not do it...also tried ENV{PWD} = "home/mydir" and that
didnt work either!!!
pls advise...
thanks!
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 22 Nov 2000 14:21:29 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: Problem with simple del file script
Message-Id: <G4FJvt.3Au@news.muni.cz>
On Wed, 22 Nov 2000 13:52:36 GMT, jkipp@mbna.com <jkipp@mbna.com> wrote:
> $path='h:\dbm\mediacreate';
>
> opendir (WDIR, "$path") or die "Can't open $path: $!";
>
> while ($file= readdir WDIR) {
> next if $file=~/^\./;
> $age= -M "$path/$file";
>
> if ($age > 30) {
> # print "$file\n"; # this works
> `del $file` # this does not
> # unlink $file #this does not
unlink "$path/$file" or print STDERR "Error unlinking $path/$file: $!";
will say something hintfull?
--
------------------------------------------------------------------------
Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
.project: Perl, DBI, Oracle, MySQL, auth. WWW servers, MTB, Spain.
Petition for a Software Patent Free Europe http://petition.eurolinux.org
------------------------------------------------------------------------
------------------------------
Date: Wed, 22 Nov 2000 15:01:23 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Problem with simple del file script
Message-Id: <slrn91nnv7.l5d.rgarciasuarez@rafael.kazibao.net>
jkipp@mbna.com wrote in comp.lang.perl.misc:
> I am trying to go through a directory and delete files that are older
> than 30 days. Here is what I have, it will print the files, no problem,
> but will not delete. Thanks for any suggestion
> Jim
> ------
> $path='h:\dbm\mediacreate';
>
> opendir (WDIR, "$path") or die "Can't open $path: $!";
>
> while ($file= readdir WDIR) {
> next if $file=~/^\./;
> $age= -M "$path/$file";
>
> if ($age > 30) {
> # print "$file\n"; # this works
> `del $file` # this does not
> # unlink $file #this does not
unlink "$path/$file" or warn "Can't unlink $path/$file: $!\n";
> }
> }
You figured out correctly how to calculate the age of the file. Its
path is "$path/$file", not $file. Adding a warning including the $!
variable (as I did) would have helped you to find the cause of the
error.
--
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: Wed, 22 Nov 2000 09:39:35 -0600
From: "Darold Anderson" <deanderson2@mmm.com>
Subject: Question: How to Return script name from within script.
Message-Id: <8vgpbp$8t7$1@magnum.mmm.com>
I am writing some scripts that have a sub in them that is generic across
about a dozen or so other scripts. I want to generate some error messages
from within the sub and would like to include the name of the script that
generated the error so that I can see which one of the dozen actually
created it.
I know I can send it as an input parameter like this:
/usr/local/bin/perl/example1.plx <P1> <P2> example1.plx
but I would rather have it done within the module like this:
sub foo {
if (...) {
...;
}else {
$log = "generic error message generated from $filename";
}
}
Where $filename returns the name of the script that is currently running
(example1.plx).
Any and all ideas are welcome!
Thank you,
Darold Anderson
------------------------------
Date: Wed, 22 Nov 2000 08:21:15 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: quick sorting question
Message-Id: <slrn91ni2b.m1u.tadmc@magna.metronet.com>
On Wed, 22 Nov 2000 05:26:18 GMT, fhinchey@my-deja.com
<fhinchey@my-deja.com> wrote:
>In article <8vfdgt$og9$1@nnrp1.deja.com>,
> fhinchey@my-deja.com wrote:
>> I have a text file with five tab seperated colums. The first three
>> columns are numbers, one for year, one for day. The other two contain
>> text that doesn't need to be sorted. I would like to sort these lines
>> in ascending order beginning with the first column(year), then second
>> (month), then third(day).
>Jeez are you stupid or what! Everyone knows you have to use a
>Swarten...negger or something. :-)
Your problem is due to greediness.
/^Sch.*/ finds the body builder's name (married to a Kennedy,
recognized by millions)
you want non-greedy:
/^Sch.*?/ finds the hacker's name (not married (though with
some sort of tenuous connection to that Hemingway
girl), recognized by (perhaps) thousands)
>I actually did a quick study on this technique and came up with this
>code for doing the sort - it works, but maybe there's a more elegant
>solution out there.
Most elegant would be to arrange for it to be a string-sorting
problem so that you can use the default sort().
If you zero-pad the first 3 fields so that they are always the
same length, then you can simply sort() them with no custom
sort sub/block needed.
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 22 Nov 2000 15:28:51 GMT
From: x_y_u@my-deja.com
Subject: receive email and process via perl
Message-Id: <8vgon8$pd9$1@nnrp1.deja.com>
I have a domain name and can set up email address. I want to have all
mail sent to process@myhost.com to be processed by a perl script. I
pretty sure this *can* be done, I'm just not sure *how*
Modules I should use would be cool, but some example scripts would be
great!
Thanks!!!!!
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 22 Nov 2000 15:35:12 GMT
From: vek@pharmnl.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: running a script as root
Message-Id: <slrn91nptf.2i5.vek@pharmnl.ohout.pharmapartners.nl>
On Wed, 22 Nov 2000 23:13:49 +1100,
Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
>On Wed, 22 Nov 2000 10:43:56 GMT,
> Alex Hart <news@#nospam#althepal.com> wrote:
>> Is it possible to allow anyone to run a particular script as root?
>
>Yes. But what does this have to do with Perl? Find out about sudo or
>maybe about the setuid possibilities on unices.
>
Perl script perhaps. Perl programs ar often refered to as scripts.
Perl somtimes comes with suidperl that alows the suid bit
to be honoured. This may or may not work on a specific system.
Villy
------------------------------
Date: Wed, 22 Nov 2000 14:20:40 GMT
From: ed_energy@hotmail.com (Energy)
Subject: Simple Question :)
Message-Id: <3a1bd60c.7900760@news.telepac.pt>
Hello and please sorry for my bad english
Please can someone tell me how to remove the first 3 caracteres from a
file name in perl?
I have;
var = "tn_name.jpg";
And I need to remove the first 3 caracteres "tn_" so the var will look
like this:
var = "name.jpg";
Thank you very much for your help on this
------------------------------
Date: 22 Nov 2000 15:25:00 +0100
From: Christian Meisl <meisl@amvt.tu-graz.ac.at>
Subject: Re: Simple Question :)
Message-Id: <m37l5wqe2r.fsf@famvtpc59.tu-graz.ac.at>
ed_energy@hotmail.com (Energy) writes:
> I have;
> var = "tn_name.jpg";
>
> And I need to remove the first 3 caracteres "tn_" so the var will look
> like this:
>
> var = "name.jpg";
If you want to remove the tn_ you may write
$var =~ s/^tn_//;
Regards,
Christian
--
Christian Meisl <meisl@amvt.tu-graz.ac.at> www.amft.tu-graz.ac.at
Inst. f. Apparatebau, Mech. Verfahrenstechnik und Feuerungstechnik
---------------------- Spelling is a lossed art. -----------------------
PGP fingerprint: DF48 2503 0411 F0EF 149C 851B 1EF0 72B9 78B6 034A
------------------------------
Date: Wed, 22 Nov 2000 14:30:10 -0000
From: "Geoff Winkless" <geoff-at-farmline-dot-com@127.0.0.1>
Subject: Re: Simple Question :)
Message-Id: <8vgl9k$rd5$1@soap.pipex.net>
"Energy" <ed_energy@hotmail.com> wrote in message
news:3a1bd60c.7900760@news.telepac.pt...
: Hello and please sorry for my bad english
: Please can someone tell me how to remove the first 3 caracteres from a
: file name in perl?
:
: I have;
: var = "tn_name.jpg";
:
: And I need to remove the first 3 caracteres "tn_" so the var will look
: like this:
:
: var = "name.jpg";
perldoc -f substr
Geoff
------------------------------
Date: Wed, 22 Nov 2000 09:51:55 -0500
From: Ron Hartikka <ronh@iainc.com>
Subject: Re: Simple Question :)
Message-Id: <3A1BDD8B.3B9437B0@iainc.com>
First, you need to read perlfaq's and perlre and perlop.
Here is one of many ways:
$old = "tn_shortname.jpg";
($new = $old) =~ s/^...(.*)/$1/;
print "\$old: $old\n\$new: $new\n";
This prints:
$old: tn_shortname.jpg
$new: shortname.jpg
You may need some explanation:
First, $old is copied to $new.
Then, the =~ operator tells the s operator of perl:
1) look in $new, for, in order:
^ the start of $new.
... the first 3 characters of $new - whatever they are
(.*) the rest of $new, that is, any number of other
characters in $new, all of them, whatever they are
The () around the .* in the last bit cause perl to store all but the first
3 characters in $new in a special variable $1.
2) subsitute $1 for what was found in the (.*).
Good luck.
Ron
Energy wrote:
> Hello and please sorry for my bad english
> Please can someone tell me how to remove the first 3 caracteres from a
> file name in perl?
>
> I have;
> var = "tn_name.jpg";
>
> And I need to remove the first 3 caracteres "tn_" so the var will look
> like this:
>
> var = "name.jpg";
>
> Thank you very much for your help on this
------------------------------
Date: Wed, 22 Nov 2000 15:09:55 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: trouble blessing object
Message-Id: <slrn91nof7.l5d.rgarciasuarez@rafael.kazibao.net>
David Waters wrote in comp.lang.perl.misc:
> I'm creating a class which uses the DBI module
> and some of my own functionality.
>
> I'd like to make $dbh only available to DBI and
> a subroutine of my choosing.
>
> ############################
> package myClass;
>
> sub new {
> ...
> }
>
> sub connect {
> my ($self,@args) = @_;
> my $dbh = DBI->connect($args[0],$args[1],$args[2]);
> return $dbh;
> }
> ###############################
>
> so if I do,
> my $dbi = myClass->new;
> my $dbh = $dbi->connect(...);
> $dbh->disconnect;
>
> this all works fine.
>
> I've added the subroutine 'hello' which
> I'd like $dbh to be only able to access.
> so I tried changing the 'connect' routine and encapsulating
> 'hello' in a new package as follows.
>
> sub connect {
> ....
> bless $dbh, "NewClass";
> }
>
> package NewClass;
> sub hello {
> print "hello\n";
> }
>
> $dbh can access the 'hello' subroutine but it is now not
> able to access DBI subroutines.
>
> How do I make it available to both?
You're trying to redefine the class of an object at runtime. This is
dangerous, but Perl allows it (it may even work for your case, if you
make NewClass inherit from DBI -- with the @ISA variable). If you want
to define a subclass of DBI, define it, and instantiate $dbh as an
instance of this new class.
I'm not sure to understand your goal, but it seems that you look at the
problem the wrong way. A less complex solution is probably possible. Can
you define more precisely what you're trying to achieve?
--
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: Wed, 22 Nov 2000 08:37:50 -0600
From: Michael Carman <mjcarman@home.com>
Subject: Re: trouble blessing object
Message-Id: <3A1BDA3E.72531A12@home.com>
David Waters wrote:
>
> I'm creating a class which uses the DBI module
> and some of my own functionality.
>
> I'd like to make $dbh only available to DBI and
> a subroutine of my choosing.
>
> ############################
> package myClass;
>
> sub new {
> ...
> }
>
> sub connect {
> my ($self,@args) = @_;
> my $dbh = DBI->connect($args[0],$args[1],$args[2]);
> return $dbh;
> }
> ###############################
>
> so if I do,
> my $dbi = myClass->new;
> my $dbh = $dbi->connect(...);
> $dbh->disconnect;
>
> this all works fine.
>
> I've added the subroutine 'hello' which
> I'd like $dbh to be only able to access.
> so I tried changing the 'connect' routine and encapsulating
> 'hello' in a new package as follows.
>
> sub connect {
> ....
> bless $dbh, "NewClass";
> }
Don't do this -- you're changing the class of $dbh when you invoke the
connect() method, and then it's no longer a member of myClass, and thus
will not be able to access it's methods!
> package NewClass;
> sub hello {
> print "hello\n";
> }
>
> $dbh can access the 'hello' subroutine but it is now not
> able to access DBI subroutines.
>
> How do I make it available to both?
With inheritance:
package NewClass;
@NewClass::ISA = qw(myClass);
sub new {
my $proto = shift;
my $class = ref(proto) || $proto;
my $self = {};
#...
return bless $self, $class;
}
sub hello {
print "hello\n";
}
Then, in your program:
my $dbh = NewClass->new;
When you try to invoke a method, Perl will look first in the base class
(NewClass) -- if it doesn't find anything, it will look in the parent
class, etc.
q.v. perltoot
-mjc
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 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.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 4949
**************************************