[11429] in Perl-Users-Digest
Perl-Users Digest, Issue: 5029 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 2 00:07:28 1999
Date: Mon, 1 Mar 99 21:00:22 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 1 Mar 1999 Volume: 8 Number: 5029
Today's topics:
Re: 2x strange behaviour in Perl script (Ronald J Kimball)
Re: @#/s#! Regular Expressions! :o( (Ronald J Kimball)
Re: Accessing a module written as a COM component layer <morrowc@his.com>
Re: baffled by MacPerl (Ronald J Kimball)
Re: C->Perl->C Problem <baillie@my-dejanews.com>
Re: cgi question (Ronald J Kimball)
Re: Determine web directory size <dimitrio@sympatico.ca>
Re: Determine web directory size <ebohlman@netcom.com>
Re: Do you really need to do 'open(whatever, ..) or die (Ronald J Kimball)
Dynamic Variables <smory@ptdprolog.net>
Re: Dynamic Variables (Larry Rosler)
Re: Finding the word after a word (Martien Verbruggen)
Re: Help - regex to extract two fields in "uptime" (Charles DeRykus)
Re: Help - regex to extract two fields in "uptime" (Larry Rosler)
Re: Help!! (Alastair)
How can i improve this code ? <f_berg@yahoo.com>
Re: How can i improve this code ? <ebohlman@netcom.com>
Re: how do I wildcard within eq '***' ? (Ronald J Kimball)
Re: How does one 'tie' a db file to a hash' <paxtond@ix.netcom.com>
Re: How does one 'tie' a db file to a hash' (Ronald J Kimball)
Re: newbie - writing html filter (Larry Rosler)
Re: Newbie: String manipulation. <ebohlman@netcom.com>
Re: OOP with wordpad <morrowc@his.com>
Re: open file problem (Ronald J Kimball)
Re: Pentium III Chips Released with IDs - Intel won't b <helmsjr@purdue.edu>
Re: SMTP question <morrowc@his.com>
Re: sysopen and NT (Ethan H. Poole)
Re: Text file -> Array?? <ebohlman@netcom.com>
Tom, where are the FAQ'lets ??? <mds-resource@mediaone.net>
Tough question <Jeff@postmark.net>
Re: using the perl open function (Ronald J Kimball)
Why can't my .pl find my SCRIPT ?? <mfuerst@advancenet.net>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 1 Mar 1999 23:57:28 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: 2x strange behaviour in Perl script
Message-Id: <1do0fj2.1oh2gw01cc94hwN@bay2-167.quincy.ziplink.net>
Thomas Ruedas <ruedas@geophysik.uni-frankfurt.de> wrote:
> for ($i=1; $i<=$imax; $i+2) {
^^^^
> The 2nd branch of the if block seems to work, while the script hangs
> when entering the 1st.
You're not actually incrementing $i.
$i+=2
This is also the source of the warning you mentioned:
> Useless use of addition in void context at gsi2bib.pl line 40.
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Mon, 1 Mar 1999 23:57:30 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: @#/s#! Regular Expressions! :o(
Message-Id: <1do0fmq.zw3d8graqarkN@bay2-167.quincy.ziplink.net>
Neil Jedrzejewski <jed@grafx.co.uk> wrote:
> I've written a Perl script in Perl5 that opens the POP3 box (using
> MAIL::POP3) reads the header and works out who its going to. This is
> fine if the mail has been relayed as it appears at the top of the
> message in the Recieved: field.
>
> However, some of the messages don't have this, and as such I need to
> be able to parse the To: field and get all the e-mail addresses from
> it, change the domain name and then put them into an array of people
> to be mailed to.
Shouldn't you be getting the addressees from the mail envelope, rather
than the message headers?
What do you do for blind carbon copies?
--
#!/usr/bin/sh -- chipmunk (aka Ronald J Kimball)
perl -s -e'print sort grep { /\s/ } keys %main::
' -- -is -' Just' -' another ' -'Perl ' -'hacker
' http://www.ziplink.net/~rjk/ [rjk@linguist.dartmouth.edu]
------------------------------
Date: Mon, 01 Mar 1999 23:05:00 -0500
From: Chris Morrow <morrowc@his.com>
To: Bob <dontspam.bob@textor.com>
Subject: Re: Accessing a module written as a COM component layer on NT
Message-Id: <36DB636C.F35432C8@his.com>
Is the database accessible through "normal" ODBC methods? if so access
it via a perl ODBC connection?
-Chris
Bob wrote:
>
> I am talking to a windows NT system guy who has a database which I need to
> access. He says that the best way to do this is for him to write a COM
> component in C++. Apparently the database is rather un-normalised and he is
> nervous about us accessing it directly.
>
> Does anyone know if it is possible to communicate with a COM component in
> Perl on Win 32?
>
> Bob
> bob@textor.com
------------------------------
Date: Mon, 1 Mar 1999 23:57:31 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: baffled by MacPerl
Message-Id: <1do0fsc.w1lppy1bu1b14N@bay2-167.quincy.ziplink.net>
23_skidoo <23_skidoo@geocities.com> wrote:
> can anyone explain why this works:
> [...]
> and this dies with the message "CP emails3.dat":
> foreach $line (@newlist) {
> print NEWLIST "$line" || print "CP emails3.dat\n";
print NEWLIST ("$line" || print "CP emails3.dat\n");
If $line contains either the null string or zero, then "$line" is false,
so the second print executes.
And what do you know, the first element in @newlist is the null string:
@newlist = '';
On the other hand, I can't certainly can't explain why this dies, since
you don't have any 'die' commands in your script.
> i'm running macperl
> 5.2.0r4 and the only difference i can see is that the first prog opens a
> file created by BBEdit, the second prog opens a file created by the
> first prog. *shrugs* any suggestions?
BBEdit has a very handy 'Find Differences' command, the equivalent of
Unix's `diff`. This command would have highlighted all the differences
between the two programs for you, including the assignment of the null
string to @newlist.
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
perl -le 'print "Just another \u$^X hacker"'
------------------------------
Date: Tue, 02 Mar 1999 01:23:08 GMT
From: Baillie <baillie@my-dejanews.com>
Subject: Re: C->Perl->C Problem
Message-Id: <7bfehj$jl3$1@nnrp1.dejanews.com>
In article <7bf3gh$9tq$1@nnrp1.dejanews.com>,
nadeem@gate.net wrote:
> you dumb-ass read the faqs
> http://rlz.ne.mediaone.net/Perl.doc/pod/perlembed.html#Compiling_your_C_progr
> am
>
Not that I mean anything to anyone here....but this truly disturbs and
disgusts me. There's no reason that anyone should have to be degraded like
this. I think we've all asked more than our share of stupid questions (I
know I sure the hell have, and for all you geniuses out there, I somehow
doubt anyone could get particularly skillful at anything without having asked
some stupid questions). I don't think this is what the perl community is
about, the sharing of source and ideas should overflow into the sharing of
knowledge, experience and hopefully a little kindness.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Mon, 1 Mar 1999 23:57:32 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: cgi question
Message-Id: <1do0g6k.u03smhhpj88gN@bay2-167.quincy.ziplink.net>
Justin Baugh <baughj@rpi.edu> wrote:
> [Mon Mar 1 07:40:40 1999] access to
> /home/mideprov/mideprovince-www/cgi-bin/pdb failed for XXX.XXX.XXX.XXX,
> reason: attempt to invoke directory as script
Apparently you're trying to invoke a directory as a script. Check your
URL and contact your sysadmin.
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Mon, 01 Mar 1999 21:12:35 -0500
From: Maria Ostapenko <dimitrio@sympatico.ca>
Subject: Re: Determine web directory size
Message-Id: <36DB4913.D7A4FAF@sympatico.ca>
This is a multi-part message in MIME format.
--------------F1CEC2388E3D7315B4F07419
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Try this: (excuse my wordiness, I'm only learning..)
#!D:/perl/bin/perl -w
my ($d, @f, $tsz);
$d = "D:/perl/bin";
opendir (DIR, $d) || die "Could not open dir $!";
@f = readdir DIR;
$tsz=0;
for (@f) {
$tsz += -s;
}
print $tsz;
closedir DIR;
Dimitri Ostapenko,
Not another perl hacker (yet)
Dmitry Diskin wrote:
> Hi,
>
> Is there any simple solution for count the total size of files in
> particular directory of web server?
>
> Dmitry.
--------------F1CEC2388E3D7315B4F07419
Content-Type: text/x-vcard; charset=us-ascii;
name="dimitrio.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Maria Ostapenko
Content-Disposition: attachment;
filename="dimitrio.vcf"
begin:vcard
n:Ostapenko;Dimitri
tel;cell:905.730.1959
tel;home:905.389.3660
tel;work:905.734/7476 x 258
x-mozilla-html:TRUE
org:Fantom Technologies Inc.;Engineering
adr:;;91 Ascoli Dr.;Hamilton;ON;L9B 1Y3;Canada
version:2.1
email;internet:dimitrio@sympatico.ca
title:CAD Designer (Euclid) / Sys Admin (Irix)
fn:Dimitri Ostapenko
end:vcard
--------------F1CEC2388E3D7315B4F07419--
------------------------------
Date: Tue, 2 Mar 1999 03:26:46 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Determine web directory size
Message-Id: <ebohlmanF7y6wn.KvE@netcom.com>
Maria Ostapenko <dimitrio@sympatico.ca> wrote:
: This is a multi-part message in MIME format.
Please configure your newsreader to post single-part messages in plain
text format.
: Try this: (excuse my wordiness, I'm only learning..)
: #!D:/perl/bin/perl -w
: my ($d, @f, $tsz);
: $d = "D:/perl/bin";
: opendir (DIR, $d) || die "Could not open dir $!";
: @f = readdir DIR;
: $tsz=0;
: for (@f) {
: $tsz += -s;
Bzzt! The filenames in $_ have no pathnames prepended, so -s is looking
for the sizes of files in the current directory, which may bear no
relation to $d.
: }
: print $tsz;
: closedir DIR;
------------------------------
Date: Mon, 1 Mar 1999 23:57:33 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Do you really need to do 'open(whatever, ..) or die..'
Message-Id: <1do0g97.1lr0m0f13l422hN@bay2-167.quincy.ziplink.net>
Baillie <baillie@my-dejanews.com> wrote:
> open(FH, "< $file") || die "can't open $file: $!";
> will only complain that the file doesn't exist, but will not die until
In complaining that the file does not exist, the script must die to
issue that complaint. Complaints without dying are done with warn.
Thank you for playing, I'm sorry you won't be coming back for our bonus
round...
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
perl -e'$_="\012534`!./4(%2`\cp%2,`(!#+%2j";s/./"\"\\c$&\""/gees;print'
------------------------------
Date: Tue, 02 Mar 1999 02:40:42 GMT
From: "Dan R. Smorey Jr." <smory@ptdprolog.net>
Subject: Dynamic Variables
Message-Id: <36DB4F80.4A4BC57D@ptdprolog.net>
I have no idea if this is an easy question or not, I'm pretty new to
Perl, about 2 months new. I'd like to know how to use dynamic
variables. It'd be easier if I just show the code than try to
explain...
$prod1_nw = "25";
$prod2_nw = "35";
$prod3_nw = "45";
$prod4_nw = "55";
# I'd like to print the prod(x)_nw's out with a for loop like this...
for $i (1 .. 4)
{
$prod_var = "$prod${i}_nw";
print "Product - $i - $prod_var\n";
}
Now maybe you can see what I mean by dynamic variables. I'd like to see
the printout...
Product - 1 - 25
Product - 2 - 35
Product - 3 - 45
Product - 4 - 55
I dont know how to reference the dynamic variable.
$prod_var = "$prod${i}_nw" isn't working and I'm not sure what the
syntax would be if there even is one. Knowing Perl I know there's a way
to do this and I know I'm probably maybe 2 characters off but I can't
figure it out.
Thank in advance for any help.
Dan R. Smorey Jr.
Programmer/Analyst
UnConundrum, Inc.
dsmorey@unconundrum.com
smory@ptdprolog.net
------------------------------
Date: Mon, 1 Mar 1999 20:07:02 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Dynamic Variables
Message-Id: <MPG.114503b9890092449896be@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <36DB4F80.4A4BC57D@ptdprolog.net>, on Tue, 02 Mar 1999
02:40:42 GMT smory@ptdprolog.net says...
> ... I'd like to know how to use dynamic variables.
>
> $prod1_nw = "25";
> $prod2_nw = "35";
> $prod3_nw = "45";
> $prod4_nw = "55";
...
> for $i (1 .. 4)
> {
> $prod_var = "$prod${i}_nw";
> print "Product - $i - $prod_var\n";
> }
...
> I dont know how to reference the dynamic variable.
They are called "symbolic references", but you don't want to use them!
> $prod_var = "$prod${i}_nw" isn't working and I'm not sure what the
> syntax would be if there even is one. Knowing Perl I know there's a way
> to do this and I know I'm probably maybe 2 characters off but I can't
> figure it out.
Well, yes. Maybe two characters off, but you don't want to use them!
$prod_var = ${"prod${i}_nw"};
works, but you don't want to use them!
Use a hash to hold the values, with your '$i's as the keys. If all your
keys are small non-negative integers, you can use an array instead. But
don't use symbolic references!
--
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 02 Mar 1999 01:14:01 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Finding the word after a word
Message-Id: <tXGC2.130$2%2.1024@nswpull.telstra.net>
In article <7bf4j7$ap3$1@nnrp1.dejanews.com>,
kalikste@uiuc.edu writes:
> What is the most elegant way to extract the word after a specific word in a
> string (words seperated by one space)? For example, if the string is "The
> quick brown fox jumps over the lazy dog", given "brown", I want to return
> "fox". In my situation, each word will only appear once in the string. I
> appreciate all your input.
(The string you give breaks that rule. I'll adapt it.)
One way:
$str = 'the quick brown fox jumps over a lazy dog';
$word = 'brown';
($next) = ($str =~ /
\b # Make sure we only match a whole word, and no,
# \s+ will not work.
\Q$word\E # escape possible metas in $word
\s+ # match as much whitespace as possible
(\S+) # match anything that's not whitespace, as much
# as possible, and capture it.
/x);
# Check $next for defined here.
Beware that punctuation is now part of a 'word', as per specification.
You can also do things with substr or split or even write a sub that
does a hash map of your sentence (in case you really need to do this
very often). I doubt that any of those, apart for very specific
optimisations would be better than this.
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | "In a world without fences,
Commercial Dynamics Pty. Ltd. | who needs Gates?"
NSW, Australia |
------------------------------
Date: Tue, 2 Mar 1999 00:37:54 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: Help - regex to extract two fields in "uptime"
Message-Id: <F7xz36.2BH@news.boeing.com>
In article <F7xx14.sE@news.boeing.com>,
Charles DeRykus <ced@bcstec.ca.boeing.com> wrote:
>if ($uptime =~ m/^\s+(.+?)/g and $uphash{time} = $1 and
> /\G\s+\w+\s+/g and $uphash{uptime} = $1 and
> /\G(.+?),/g and $uphash{users} = $1 and
> /\G\s+(\d+)/g and $uphash{one_min_load} = $1 and
> /\G\s+users,.+: /g and $uphash{five_min_load} = $1 and
> /\G([\d\.]+), /g and $uphash{fifteen_min_load} = $1 and
> /\G[([\d\.]+)/g) {
> ...
>}
Whoops:
if ($uptime =~ m/^\s+(.+?)/g and $uphash{time} = $1 and
/\G\s+\w+\s+/g and
/\G(.+?),/g and $uphash{uptime} = $1 and
/\G\s+(\d+)/g and $uphash{users} = $1 and
/\G\s+users,.+: /g and
/\G[\d\.]+), /g and $uphash{one_min_load} = $1 and
/\G([\d\.]+), /g and $uphash{five_min_load} = $1 and
/\G[([\d\.]+)/g and $uphash{fifteen_min_load} = $1)
{
...
}
--
Charles DeRykus
------------------------------
Date: Mon, 1 Mar 1999 18:41:31 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Help - regex to extract two fields in "uptime"
Message-Id: <MPG.1144efb6889b07329896bc@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <F7xx14.sE@news.boeing.com> on Mon, 1 Mar 1999 23:53:28 GMT,
Charles DeRykus <ced@bcstec.ca.boeing.com> says...
> In article <MPG.114358f44a7703d89896b5@nntp.hpl.hp.com>,
> Larry Rosler <lr@hpl.hp.com> wrote:
...
> >How about this neater way (preserving the world's limited supply of
> >semicolons):
> >
> > @uphash{ qw( time uptime users one_min_load five_min_load
> > fifteen_min_load ) } = $uptime =~ /*your regex here*/x;
> >
>
> I'd still go verbose... but I draw the line at plundering the
> world's supply of semicolons.
>
> if ($uptime =~ m/^\s+(.+?)/g and $uphash{time} = $1 and
> /\G\s+\w+\s+/g and $uphash{uptime} = $1 and
> /\G(.+?),/g and $uphash{users} = $1 and
> /\G\s+(\d+)/g and $uphash{one_min_load} = $1 and
> /\G\s+users,.+: /g and $uphash{five_min_load} = $1 and
> /\G([\d\.]+), /g and $uphash{fifteen_min_load} = $1 and
> /\G[([\d\.]+)/g) {
> ...
> }
There are lots of errors here.
You stop matching against $uptime and start matching against $_ on the
second line.
The regexes aren't correct, partly because each one has become a local
match in a set of local matches, rather than one great big match across
the entire string. (More on this later.)
Also, I'd be very concerned about breaking out too soon if one of those
matches had a zero value. How about commas and parentheses? The 'and'
tests on the right should be replaced by simple sequence commas or
(gasp) semicolons.
Having said all that, I benchmarked a corrected version against both of
the other ways previously posted, with these conclusions:
1. Although 'qw( time uptime ... )' looks like a constant list that
could be computed at compile-time, it is actually a run-time evaluation
(split ' ', 'time uptime ...') that creates a list which is the same
each time through the loop. Is there a potential optimization here?
Lesson: Don't use 'qw' in loops or inside of benchmarked code!
2. My hash-slice approach wasn't faster than doing the explicit
assignments. Lesson: Intuition fails yet again.
3. Your version with the multiple local regexes is almost twice as fast
as the single big regex. This probably has to do with the amount of
backtracking performed, which depends on how the big regex is written.
Lesson: Doing several individual matches sequentially *may* be
significantly faster than doing a global match.
Thanks for something new to consider!
--
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 02 Mar 1999 01:02:27 GMT
From: alastair@calliope.demon.co.uk (Alastair)
Subject: Re: Help!!
Message-Id: <slrn7dme86.5h.alastair@calliope.demon.co.uk>
> snip
>-------------
>Try commenting out the + sign like so: #"\+whatever",
>(put a backslash in front of your special characters)
Did you have to quote _all_ that?
--
Alastair
work : alastair@psoft.co.uk
home : alastair@calliope.demon.co.uk
------------------------------
Date: Tue, 02 Mar 1999 01:56:09 +0100
From: Frank Berg <f_berg@yahoo.com>
Subject: How can i improve this code ?
Message-Id: <36DB3729.BC5880AD@yahoo.com>
hi all,
first i'm pretty new to perl and apologize by advance if this code hurts
you somewhere :-), ok it quickly solve my problem but it's ugly and
heavy and i need some advices or 'another way to do it'.
i'm using this for printing a document made of different part of datas
that i fetch from a database, the problem is that i can't change the
organisation of the datas in the db , so i get $aref_data like this and
have to work with it...
Thanks
Frank
----------------------------------------
#/usr/local/bin/perl -w
use strict;
my $base = 1;
##data i ve to print in a certain order.
my $aref_data = [ [12, 1, 1, '(12) Im with 1...'], [3, 1, 1, '(3) Im
with 1'], [7, 1, 1, '(7) Im with 1'], [14, 12, 2, '(14) Im with 12'],
[5, 3 , 2, '(5) Im with 3'], [16, 14 , 3, '(16) Im with 14'], [25, 16 ,
4, '(25) Im with 16'], [22, 14, 3, '(22) Im with 14'], [28, 22, 4, '(28)
Im with 22']];
##i'm using an index because there's can be
##a lot of array contening a lot of text
## i think this is faster than manipulate
##directly @$aref_data but i don t really know in fact...
my @sorted_index;
foreach my $i (0..$#{$aref_data}) {
if ($aref_data->[$i][1] == $base) {
push @sorted_index, $i;
&get_withme($aref_data->[$i][0],$aref_data,\@sorted_index);
}
}
print "--------------------------1-----------------------\n\n";
print map ("\t"x$aref_data->[$_][2] . "$aref_data->[$_][3]\n"
,@sorted_index);
exit;
##This is really bad because i'm reparsing
## my array and recursively calling
##the sub ...but i didnt find anything else...yet
sub get_withme {
my ($id ,$aref_data,$a_sorted_index) = @_;
foreach my $j(0..$#{$aref_data}) {
if ($aref_data->[$j][1] == $id){
push @$a_sorted_index, $j;
&get_withme($aref_data->[$j][0],$aref_data,$a_sorted_index);
}
}
}
------------------------------
Date: Tue, 2 Mar 1999 03:21:32 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: How can i improve this code ?
Message-Id: <ebohlmanF7y6nw.KE5@netcom.com>
Frank Berg <f_berg@yahoo.com> wrote:
: first i'm pretty new to perl and apologize by advance if this code hurts
: you somewhere :-), ok it quickly solve my problem but it's ugly and
: heavy and i need some advices or 'another way to do it'.
The following looks cleaner and runs a little bit faster (1 second less
for 2000 iterations with the print statements commented out):
#/usr/local/bin/perl -w
use strict;
##data i ve to print in a certain order.
my $aref_data = [
[12, 1, 1, '(12) Im with 1...'],
[3, 1, 1, '(3) Im with 1'],
[7, 1, 1, '(7) Im with 1'],
[14, 12, 2, '(14) Im with 12'],
[5, 3 , 2, '(5) Im with 3'],
[16, 14 , 3, '(16) Im with 14'],
[25, 16 , 4, '(25) Im with 16'],
[22, 14, 3, '(22) Im with 14'],
[28, 22,4, '(28) Im with 22']
];
#note how much more readable the data is when you use whitespace
my (%children,%ids);
foreach my $i (0..$#{@$aref_data}) {
my $id = $aref_data->[$i][0];
push @{$children{$aref_data->[$i][1]}}, $id;
$ids{$id} = $i;
}
print "--------------------------1-----------------------\n\n";
print_tree(1);
sub print_tree {
my $root=shift;
foreach my $id (@{$children{$root}}) {
my $index = $ids{$id};
print "\t" x $aref_data->[$index][2], $aref_data->[$index][3],"\n";
print_tree($id);
}
}
------------------------------
Date: Mon, 1 Mar 1999 23:57:35 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: how do I wildcard within eq '***' ?
Message-Id: <1do0gto.18rt9ui13qbyndN@bay2-167.quincy.ziplink.net>
Mig <mig@isis.ie> wrote:
> I've replaced it with the line you suggested below and ran 'perl -c' on the
> file. It gives the error "/.*?\.aol$/: nested *?+ in regexp at line blah" .
> Is there something slightly amiss here?
Yes. You're using perl4. Time to upgrade!
(Non-greedy quantifiers were added in perl5.)
--
#!/usr/bin/sh -- chipmunk (aka Ronald J Kimball)
perl -s -e'print sort grep {/\s+?/} keys %main::
' -- -is -' Just' -' another ' -'Perl ' -'hacker
' http://www.ziplink.net/~rjk/ [rjk@linguist.dartmouth.edu]
------------------------------
Date: Mon, 01 Mar 1999 20:04:55 -0500
From: "J. Daniel Paxton" <paxtond@ix.netcom.com>
To: Eric The Read <emschwar@mail.uccs.edu>
Subject: Re: How does one 'tie' a db file to a hash'
Message-Id: <36DB3934.5852B216@ix.netcom.com>
Eric The Read wrote:
> "J. Daniel Paxton" <paxtond@ix.netcom.com> writes:
> > Anyway, I can't seem to tie the users.dbmx file to a hash. The process
> > dies after the following line:
> >
> > my $timesleft=tie %timesleft, "SDBM_File", "users.dbmx";
> > defined $timesleft or
> > die "Unable to open or create timesleft: \n";
> >
> > Why? I've checked the permissions on the directory and the file. Am I
> > missing something in the code?
>
> try
>
> die "Unable to open or create timesleft: $!" unless defined $timesleft;
>
> It reads better, and the $! variable contains the error string that tells
> you what went wront. In fact, I'd say you should almost always use $! in
> a die statement, and I'd only be exaggerating a *little* bit.
>
> -=Eric
Thanks....
well...I put your line in instead of mine and I'm getting the same error
message as before
Use of uninitialized value at WPS2.cgi line 17.
Usage: SDBM_File::TIEHASH(dbtype, filename, flags, mode) at WPS2.cgi line
30.
But I don't understand the reference. The error is at the same line where
the script will not tie the file to the hash. Am I missing an argument?
Any Help?
------------------------------
Date: Mon, 1 Mar 1999 23:57:36 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: How does one 'tie' a db file to a hash'
Message-Id: <1do0gvg.vusec6kt9ublN@bay2-167.quincy.ziplink.net>
J. Daniel Paxton <paxtond@ix.netcom.com> wrote:
[reordered for ease of response. :-) ]
> But I don't understand the reference. The error is at the same line where
> the script will not tie the file to the hash. Am I missing an argument?
^^^^^^^^^^^^^^^^^^^^^^^^^
Um... If you really can't answer that question yourself... :-(
> > > my $timesleft=tie %timesleft, "SDBM_File", "users.dbmx";
^^^^^^^^^^^ ^^^^^^^^^^^^
dbtype filename
> Use of uninitialized value at WPS2.cgi line 17.
> Usage: SDBM_File::TIEHASH(dbtype, filename, flags, mode) at WPS2.cgi line
^^^^^^ ^^^^^^^^ ^^^^^ ^^^^
> 30.
>
You are, in fact, missing *two* arguments. Refer to the documentation for
SDBM_File.
--
chipmunk (Ronald J Kimball) <rjk@linguist.dartmouth.edu>
perl -e 'print map chop, sort split shift, reverse shift
' 'j_' 'e._jP;_jr/_je=_jk{_jn*_j &_j :_j @_jr}_ja)_js$_j
~_jh]_jt,_jo+_jJ"_jr>_ju#_jt%_jl?_ja^_jc`_jh-_je|' -rjk-
------------------------------
Date: Mon, 1 Mar 1999 17:31:59 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: newbie - writing html filter
Message-Id: <MPG.1144df6d6890b6bc9896bb@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <ebohlmanF7xyKC.8Lx@netcom.com> on Tue, 2 Mar 1999 00:26:36
GMT, Eric Bohlman <ebohlman@netcom.com> says...
> Jamester76 <jdalldata@my-dejanews.com> wrote:
...
> : $i = 1;
> : while (<>)
> : {
> : chomp;
> : if (/<hr>/i) { # records begin with "<hr>" tag
> : if (/<!--newrec-->/i) { # dummy header for record
> : if (/<b>/i) { # "<b>" tage precedes name in file
>
> Unfortunately, in your sample HTML the <hr>, <!...>, and the <b> are all
> on different lines, but your code is applying the tests to the same line.
I missed that in my response. A quick fix might simply be:
next unless /<hr>/i;
last unless $_ = <>;
next unless /<!--newrec-->/i;
last unless $_ = <>;
next unless /<b>/i;
last unless $_ = <>;
Though it's easy to see how that might break on the wrong input.
...
> : $fn[$i] = $names[0];
> : $ln[$i] = $names[$#names];
> : print "$i $fn[$i] $ln[$i] \n";
>
> More Perlish:
> push @fn, shift @names;
> push @ln, shift @names;
Well, 'pop' instead of 'shift' for the second line. But what's wrong
with the indexes 0 and -1? Why modify the '@names' array when it's
going away anyhow?
...
--
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 2 Mar 1999 01:07:39 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Newbie: String manipulation.
Message-Id: <ebohlmanF7y0Gr.BDp@netcom.com>
Rob Moore <rob@best-buys.com> wrote:
: How do I get a string that only takes {$length} characters from {$name} and
: discards the rest? I want to end up with $shortname = REALNAME
perldoc -f substr
------------------------------
Date: Mon, 01 Mar 1999 23:06:54 -0500
From: Chris Morrow <morrowc@his.com>
To: kris <khhuntley@capitalnet.com>
Subject: Re: OOP with wordpad
Message-Id: <36DB63DE.4E2EC68B@his.com>
Kris,
Look into the Perl OLE Automation packages... they come as a ppm for
ActivePerl.
I assume you'll have to learn something about OLE Automation
capabilities in Word though :( (there is an example of an Excel
spreadsheet in the docs for the OLE stuff)
-Chris
kris wrote:
>
> I am a grade eleven student and I am wondering what I need to do to print
> into a word file. I am just wondering what object references that I would
> need to make to be able to print into a word document.
------------------------------
Date: Mon, 1 Mar 1999 23:57:37 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: open file problem
Message-Id: <1do0hi6.1o1tzar1gvp1fnN@bay2-167.quincy.ziplink.net>
Richard Partridge <r.partridge@dewynters.com> wrote:
> I want my perl script to open a data file on a seperate webserver...
> so I thought I could use something like
>
> (filehandle,">> http://www.somewhere.com/cgi-bin/datafile.txt");
>
> Is this legal perl as it doesn't seem to be working for me.....
Of course, you're missing the 'open', but other than that, no, you can't
use open() on remote files.
Look into the LWP modules.
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Mon, 01 Mar 1999 21:09:30 -0500
From: Jon Helms <helmsjr@purdue.edu>
To: Kenny Chaffin <kenny@kacweb.com>
Subject: Re: Pentium III Chips Released with IDs - Intel won't budge
Message-Id: <36DB485A.79499011@purdue.edu>
You afraid of making it easier to track down stolen CPUs? What are you
trying to hide that you don't want people to have your CPU ID? It isn't
like it can be used for much but tracking thefts.
Jon Helms
Kenny Chaffin wrote:
>
> In article <7bf1q2$cui$1@birch.prod.itd.earthlink.net>,
> kld_msmith@NOSPAMearthlink.net says...
> > Big Brother Inside wrote in message <36e3fbf9.6298553@news.earthlink.net>...
> > >
> > > Pentium III chip with the individual serial number that can
> > >track your web surfing and buying habits can now have the ID number
> >
> >
> > ANSI C does not contain any functions or structures regarding processor
> > serial numbers. Your post is off-topic for news://comp.lang.c but it might
> > be more appropriate on
> > comp.intel.quit.yer.whinin.if.you.dont.like.it.dont.buy.the.damn.thing.
> > 'kay?
> > --
> > Mike Smith. No, the other one.
> >
> >
> >
> >
> >
>
> Well you may not want to admit it, but it will affect you or your
> customers/clients/company....
> And as far as not buying it, that would be great if intel/microsoft
> didn't have a monopoly on the pc market....
>
> Best Wishes,
> KAC
> --
> KAC Website Design
> Custom Programming, Web Design, and Graphics
> kenny@kacweb.com - http://www.kacweb.com
------------------------------
Date: Mon, 01 Mar 1999 23:10:10 -0500
From: Chris Morrow <morrowc@his.com>
To: Rob Greenbank <rob@frii.com>
Subject: Re: SMTP question
Message-Id: <36DB64A2.DA925B0D@his.com>
This should be part of the mail parsing stuff... maybe in the
Mail::Header package???
(ps. a quick browse of the docs would have turned this up for you...
they name the modules quite nicely, except for penguin :)
-Chris
Rob Greenbank wrote:
>
> Does anyone know if I can get the message ID of a message I send with
> the perl SMTP module? I know SMTP servers return this, but I haven't
> seen anything in the module to get at it.
>
> Thanks,
>
> Rob Greenbank
> (rob@frii.com)
------------------------------
Date: Mon, 01 Mar 1999 21:01:44 -0500
From: ehpoole@ingress.com (Ethan H. Poole)
Subject: Re: sysopen and NT
Message-Id: <hoZYfCFZ#GA.184@rejz.ij.net>
[Posted and Emailed] In article <36dff9e9.13555008@news.memes.com>,
montejw@memes.com says...
>
>Hello,
>We've got a script on our ISP's NT server that uses
>sysopen
>function to create some temporary text files, writing them to the
>harddrive, then writing several lines to the files.
>
>We keep getting "Permission Denied" error from the server when running
>our script.
>
>The ISP sys admin thinks the temp files must already exist in order
>for Perl to write to them.
>
>Is this true? The documentation says sysopen will create a new file if
>one doesn't already exist.
>
>Anyone have a problem like this with NT?
Do the directories you are trying to create files in have "CHANGE" (RWX)
permissions enabled for the anonymous web user? You may be trying to create
a file in a directory with only Read and eXecute permissions and that is
guaranteed to result in a "Permission/Access Denied" message.
Also, are you certain your sysopen() call is attempting to access the
directory/file you think it is? If you are using relative paths you may be
attempting to access a working directory different from where the script
resides. If using absolute paths, doublecheck that the paths are correct.
--
Ethan H. Poole | Website Design and Hosting,
| CGI Programming (Perl & C)..
========Personal=========== | ============================
* ehpoole @ ingress . com * | --Interact2Day, Inc.--
| http://www.interact2day.com/
------------------------------
Date: Tue, 2 Mar 1999 01:06:06 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Text file -> Array??
Message-Id: <ebohlmanF7y0E6.BAL@netcom.com>
Brent Singers <brent.s@ihug.co.nz> wrote:
: I have a text file that looks like this:
: "Field1","Field2","Field3","Field4"
: "a1","b1","c1","d1"
: "a2","b2","c2","d2"
: "a3","b3","c3","d3"
: etc....
: It was exported from a Microsoft Access database. I need to do the
: following:
: 1) create a series of array's named "Field1", "Field2" etc
No, you don't need to do that. You need to create either an array of
arrays (two-dimensional array) if you want to access the columns by
number, or a hash of arrays if you want to access the columns by name.
See perllol and perldsc; if those don't make sense to you, read perldata
and perlref and then try the first two again.
: 2) populate those array's with the columns in the file (i.e. the
: values in the 'a' column going in @Field1.
: Does anybody have any ideas that would make this easy for me? I have
: looked on the web, in a few books and haven't found the solution.
Once you've got your array structures down, you need to learn how to use
Text::CSV (get it from CPAN) to split up your comma-separated values;
after that, your code will be trivial to write.
------------------------------
Date: Mon, 01 Mar 1999 20:54:43 -0600
From: "Michael D. Schleif" <mds-resource@mediaone.net>
Subject: Tom, where are the FAQ'lets ???
Message-Id: <36DB52F3.18FB97D2@mediaone.net>
Why stop now? Simply, because some repeated?
--
Best Regards,
mds
mds resource
888.250.3987
"Dare to fix things before they break . . . "
"Our capacity for understanding is inversely proportional to how much we
think we know. The more I know, the more I know I don't know . . . "
------------------------------
Date: Tue, 02 Mar 1999 03:00:05 +0100
From: Jeff Rus <Jeff@postmark.net>
Subject: Tough question
Message-Id: <36DB4625.358@postmark.net>
Hi,
I am creating an "add a link script" which allows users
to a link and a short biography. There will be about
ten categories and the pages are created ON-THE-FLY.
All the user information will be stored in a single
directory (I don't have a dedicated server, so they
can't create directories of their own).
My question: I want to add a random link script that
will show only pages from ONE category. Is this
possible if the pages (from a category) are not
in separate directories?
Thanks in advance,
Jeff Rus
------------------------------
Date: Mon, 1 Mar 1999 23:57:38 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: using the perl open function
Message-Id: <1do0hy0.jdbrqn5of1alN@bay2-167.quincy.ziplink.net>
Jay Glascoe <jglascoe@giss.nasa.gov> wrote:
> Larry Rosler wrote:
> >
> > > > open (WR, ">$DIR\\reg.htm");
> > >
> > > open WR, ">$DIR\\reg.htm" || die "can't open file: $!";
> >
> > No error will be reported if the 'open' fails, because the precedences
> > are wrong. Use 'or', or put parens around the arguments to 'open'.
>
> oops! sorry, I personally always use "or" in such a situation.
> I just wasn't sure whether that keyword was defined in Perl4.
It's not. In perl4, you should use || with parens:
open(WR, ">$DIR\\reg.htm") || die "can't open file: $!";
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Mon, 01 Mar 1999 20:29:33 -0600
From: Michael Fuerst <mfuerst@advancenet.net>
Subject: Why can't my .pl find my SCRIPT ??
Message-Id: <36DB4D0D.FEDB71AF@advancenet.net>
I wish to pull out javascript code from an HTML file.
I am running PERL on Win NT.
Here are
(a) my stripped down .pl file with comments indicating what I hope
would happen and what actually happened.
(b) the .html file that the .pl file is supposed to process.
All the blank lines are in this file as shown
*********** start of .pl file
use strict;
use FileHandle;
# open $stripped for reading
my $stripped = new FileHandle("obtest.html");
# read whole file into string
undef $/;
my $page = <$stripped>;
# attempt to pull out <SCRIPT .... </SCRIPT>
# This next line prints and puts only an ascii 10 and an ascii 32 into
$1
# (PROBLEM 1: I would think that this would put everything between
<SCRIPT> and </SCRIPT> into $1)
print $page =~ m'^\s*<SCRIPT.*>(.*)</SCRIPT>'smg;
print length($1) . ' ' . ord(substr($1,0,1)) . ' ' .
ord(substr($1,1,1);
# this next line, with a pattern which differs from the previous
# only in the lack of parens around the *.,
# prints out the embeded script including the <SCRIPT and </SCRIPT>
# (as I would expect)
print $page =~ m'^\s*<SCRIPT.*>.*</SCRIPT>'smg;
# this next line prints a "Use of uninitialized value" warning
# (PROBLEM 2: I would think $1 should remain unchanged, since nothing is
put into $1)
print $1;
********** end of .pl file
*********** start of obtest.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>SurveyTemplate</TITLE>
<META NAME="GENERATOR" CONTENT="Arachnophilia 3.9">
<META NAME="FORMATTER" CONTENT="Arachnophilia 3.9">
<SCRIPT LANGUAGE="JavaScript">
<!--
var ON = 1;
var OFF = 0;
var TRUE = 1;
var FALSE = 0;
var NOANS = "DKNA";
ChooseOneSet("<B>Heading for ChooseOneSet</B>", 2,"vcs", "cs1",
"Item1",
"alkjf a;lkjf aojf a;jkf a;skjf a f ;akdjf fjajf
a;ljdf al; a;sjf a;skjf asjdf a;sjkdf ;asjdf ;akjsdf
;ajsdf ;aksjdf ;alksjdf ;fajsd f "+
"as;lkjfakjflkdj;ksdfjjf ;ljdf ;lajsf ;ajf sl f");
ChooseOne("varchooseone","cs1","First choose one");
BRANCH("v.vcs1=='aa return'","cmt2");
UserInfo("<H1>Heading H1</H1>","<H2>Heading H2</H2>");
CheckBox("cb1","This is a first checkbox");
oneNodePerPage=1;
CheckBox("cb2","This is a second checkbox");
Comment("cmtname","This is a comment",10,40);
Comment("cmt2","Comment2<BR>This comment2.",10,50);
// end hide -->
</SCRIPT>
<FRAMESET ROWS="100%,*" ONLOAD="InitializeSurvey()">
<FRAME SRC="file://f:\Javascript\dummy.html" NAME="main" NORESIZE>
<FRAME SRC="file://f:\Javascript\dummy.html" NAME="answers" >
</FRAMESET>
</HEAD>
--
If this post is a question to a newsgroup, please also reply to me
if you can. Thanks.
Michael Fuerst
802 N Broadway
Urbana IL 61801
217 239 5844 (H)
352 6511 (D)
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". 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". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 5029
**************************************