[7001] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 626 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 18 00:18:18 1997

Date: Tue, 17 Jun 97 21:00:21 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 17 Jun 1997     Volume: 8 Number: 626

Today's topics:
     "Bizarre copy of ARRAY" message from prototype fiddling (Peter Scott)
     a perl mode in emacs that does a better job with quotes <shimpei@socrates.caltech.edu>
     Adv Perl Prog Tutorial - 6/23-25/97 (John Donnelly)
     Command line args..? <kane@biteme.accesscomm.net>
     Re: Command line args..? (Nathan V. Patwardhan)
     Re: Command line args..? <dean@tbone.biol.sc.edu>
     Re: Command line args..? (Tung-chiang Yang)
     confusion on XS w/ a C++ .o file (felix k sheng)
     Re: Fastest way to insert an element into a list (Eric Roode)
     Re: HELP: How to limit the length of contents in guestb <perlprogrammer@hotmail.com>
     Re: HELP: How to limit the length of contents in guestb <perlprogrammer@hotmail.com>
     Re: help: pull down menus (Ian Stokes-Rees)
     Re: help: TEST-EXP ? TRUE-EXP :FALSE-EXP (Jahwan Kim)
     How to get data from server at all times? bz7328113@ntuvax.ntu.ac.sg
     Re: justa reply... (Faust Gertz)
     Re: leading zeroes (DCrouse495)
     Re: multiple white spaces (Craig Berry)
     Re: Perl script needs counter? (beryte)
     Problem w/unpack, eval and floating point <langlois@csn.net>
     Sorry another regex question - parsing HTML anchors???  topaz56@one.net
     Tie and Multidimensional hashes (and other stuff) <cmason@ti.com>
     Re: TIMING EXPERIMENT <flee@teleport.com>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 17 Jun 1997 22:33:54 GMT
From: pjscott-remove-to-email@euclid.jpl.nasa.gov (Peter Scott)
Subject: "Bizarre copy of ARRAY" message from prototype fiddling
Message-Id: <5o73ci$eli@netline.jpl.nasa.gov>

Experimenting with prototypes on 5.003 on SunOS 4.1.3, I thought to myself,
let's find out how I can pass two arrays to a subroutine and recover
them.  So I wrote:

sub foo (\@\@) {
my (@x, @y) = @_;
print "@x\n","@y\n";
}
@a = qw(a b c);
@b = qw(x y z);
foo(@a, @b);

and got back "ARRAY(0x906c0) ARRAY(0x90720)" for @x, nothing for @y.
At this point I deduced that using \@ in a prototype causes a reference 
to be passed - makes sense.  So I changed the prototype to (\@@), expecting 
to get back "ARRAY... x y z", but instead I got:

	Bizarre copy of ARRAY in aassign at - line 2.

Interesting.  Why didn't I get "ARRAY(0x906c0) x y z"?

This also occurred when I did the more logical 

sub foo (\@@) {
my ($x, @y) = @_;

which I don't understand, because surely it should be passing a
reference to @a - a scalar - followed by the list @b...?

-- 
This is news.  This is your      |  Peter Scott, NASA/JPL/Caltech
brain on news.  Any questions?   |  (Peter.J.Scott at jpl.nasa.gov)

Sorry for making email respondents edit the To: header; the spam is
just too bad otherwise.

Disclaimer:  These comments are the personal opinions of the author, and 
have not been adopted, authorized, ratified, or approved by JPL.


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

Date: 17 Jun 1997 22:28:03 GMT
From: Shimpei Yamashita <shimpei@socrates.caltech.edu>
Subject: a perl mode in emacs that does a better job with quotes?
Message-Id: <5o731j$n9@gap.cco.caltech.edu>

Both the perl-mode that comes with emacs 19.34b and cperl-mode included
in perl 5.004 are not terribly smart about syntax-highlighting lines with
unbalanced quotes, like, say,

s/'/'"'"'/g;  

(this is an actual line from the "gsh" script in perl 5.004 distribution)

I'm not too sure how the modes are parsing this line, but it thinks
the last ' opens a quoted string, and most everything after it are 
greyed out. Not cool.

In a more pedestrian example, using the single quote as an apostrophe
in comments also trigger this behavior, like

unlink("/var/mail/$USER");    # we don't like this person

I realize a fix might be very difficult, since the perl grammar is pretty
complex, but does anyone have a perl mode for emacs that fixes these bugs?

-- 
Shimpei Yamashita                  <http://socrates.caltech.edu/%7Eshimpei/>



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

Date: 17 Jun 1997 09:25:10 -0600
From: johnd@xor.com (John Donnelly)
Subject: Adv Perl Prog Tutorial - 6/23-25/97
Message-Id: <5o6a8m$hpf@xor.com>

	**Upcoming Advanced Perl Programming Tutorial**
Sessions are held at our training facility in Boulder, CO.
Contact me for further information, registration forms.
--John Donnelly, Training Coordinator
  XOR Network Engineering, Inc.
  http://www.xor.com/  johnd@xor.com  303-448-4816
				*****
                     Advanced Perl Programming
                  (Three Day Hands-on Lecture/Lab)
                    Tom Christiansen, Consultant
		Monday - Wednesday, June 23-25, 1997
				*****


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

Date: Tue, 17 Jun 97 19:16:26
From: "The Old Wolf" <kane@biteme.accesscomm.net>
Subject: Command line args..?
Message-Id: <igswamcwocr.pminews@max1-28.accesscomm.net>

Does anyone know a way to use  "-?" as a command line arg?
I set -s in my perl script but I can't seem to get $? or ARGV[0] to
cough up anything for me. Anything else, like a -c or whatnot works fine and
turns up $c = 1 etc..

						Thanks for your help







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

Date: 18 Jun 1997 01:28:55 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Command line args..?
Message-Id: <5o7dkn$lc1@fridge-nf0.shore.net>

The Old Wolf (kane@biteme.accesscomm.net) wrote:
: Does anyone know a way to use  "-?" as a command line arg?

It seems that the answer is no, because (by default) the Getopt
modules use $opt_whatever as the variable representing a value for the
switch.  Last time I checked, one couldn't declare a variable $opt_?.

--
Nathan V. Patwardhan
nvp@shore.net



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

Date: 17 Jun 1997 21:36:25 -0400
From: Dean Pentcheff <dean@tbone.biol.sc.edu>
Subject: Re: Command line args..?
Message-Id: <m1ena03d5y.fsf@nauplius.psc.sc.edu>

"The Old Wolf" <kane@biteme.accesscomm.net> writes:
> Does anyone know a way to use  "-?" as a command line arg?
> I set -s in my perl script but I can't seem to get $? or ARGV[0] to
> cough up anything for me. Anything else, like a -c or whatnot works fine and
> turns up $c = 1 etc..

At a guess, you're running on a Unix system, using a shell like sh or
csh.  In those shells, the '?' character is a wildcard matching a
single character.  So... your commandline contains an argument that
will be substituted with a one-character-long filename, if one exists
in the current directory.  

You'll need to enclose that argument in single quote to protect it
from the shell.

-Dean
-- 
N. Dean Pentcheff   <pentcheff@acm.org>   WWW: http://tbone.biol.sc.edu/~dean/
Biological Sciences, Univ. of South Carolina, Columbia SC 29208 (803-777-3936)
PGP ID=768/22A1A015 Keyprint=2D 53 87 53 72 4A F2 83  A0 BF CB C0 D1 0E 76 C0 
Get PGP keys and information with the command: "finger dean@tbone.biol.sc.edu"


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

Date: Wed, 18 Jun 1997 02:12:22 GMT
From: tcyang@netcom.com (Tung-chiang Yang)
Subject: Re: Command line args..?
Message-Id: <tcyangEBy8sM.D5E@netcom.com>

Your shell will catch '?' in '-?'.  Escape it and see if your Perl
script can make it.

=============================
The Old Wolf typed when the mommy tyrannosaurus found him:
: Does anyone know a way to use  "-?" as a command line arg?
: I set -s in my perl script but I can't seem to get $? or ARGV[0] to
: cough up anything for me. Anything else, like a -c or whatnot works fine and
: turns up $c = 1 etc..

--
========= Try the low-crossposting robomoderated 'alt.culture.taiwan' ===

soc.culture.taiwan, soc.culture.china (by SCC FAQ Team) FAQ's:
   http://www.iglou.com/tcyang/Taiwan_faq.shtml, China_faq.shtml


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

Date: 17 Jun 1997 22:58:17 GMT
From: felix@chance.em.nytimes.com (felix k sheng)
Subject: confusion on XS w/ a C++ .o file
Message-Id: <slrn5qe5s3.kko.felix@chance.em.nytimes.com>
Keywords: XS, C++

hello,

i've got a small problem trying to put a wrapper around a C++ .o file
that has been given to me.  in this object file is a function that
connects to a database, runs some simple queries and prints something
out.  it takes no arguments and returns and int.  actually, even 
simpler, if i create a c++ object file that contains a function foo()
which prints out "hey there".  when i run h2xs on it and ultimately
run make test it gives me (\ wrapped for aesthetic purposes):

cp rogue.pm ./blib/lib/rogue.pm
AutoSplitting rogue (./blib/lib/auto/rogue)
/usr/local/bin/perl5 -I/usr/local/lib/perl5/sun4-solaris/5.003 \
   -I/usr/local/lib/perl5 /usr/local/lib/perl5/ExtUtils/xsubpp  -C++ \
   -typemap /usr/local/lib/perl5/ExtUtils/typemap rogue.xs >rogue.tc \
   && mv rogue.tc rogue.c
Please specify prototyping behavior for rogue.xs (see perlxs manual)
gcc -c  -I/usr/local/include -O    -DVERSION=\"0.01\" -DXS_VERSION=\"0.01\" \
   -fpic -I/usr/local/lib/perl5/sun4-solaris/5.003/CORE  rogue.c
Running Mkbootstrap for rogue ()
chmod 644 rogue.bs
LD_RUN_PATH="" gcc -o blib/arch/auto/rogue/rogue.so -G -L/usr/local/lib \
   rogue.o  rlib/test2.o
chmod 755 blib/arch/auto/rogue/rogue.so
cp rogue.bs ./blib/arch/auto/rogue/rogue.bs
chmod 644 blib/arch/auto/rogue/rogue.bs
PERL_DL_NONLAZY=1 /usr/local/bin/perl5 -I./blib/arch -I./blib/lib \
   -I/usr/local/lib/perl5/sun4-solaris/5.003 -I/usr/local/lib/perl5 test.pl
1..1
Can't load './blib/arch/auto/rogue/rogue.so' for module rogue: ld.so.1: \
   /usr/local/bin/perl5: fatal: relocation error: symbol not found: \
   __ls__7ostreamPFR7ostream_R7ostream: referenced in \
   ./blib/arch/auto/rogue/rogue.so at /usr/local/lib/perl5/DynaLoader.pm \
   line 140.

 at blib/lib/rogue.pm line 41
BEGIN failed--compilation aborted at test.pl line 11.
not ok 1
make: *** [test_dynamic] Error 2

where can i get me this __ls__7ostreamPFR7ostream_R&ostream?  please,
if anyone can point me in the right direction that would be fantastic.
if i can provide more information i would love to, just let me know what.
thanks in advance.

'lx
                                      


--- felix sheng                                       pager     800 979 2171
 programmer                                           tel       212 597 8069
 the new york times electronic media company          e    felix@nytimes.com


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

Date: Wed, 18 Jun 1997 01:10:00 GMT
From: sdn@mv.mv.com (Eric Roode)
Subject: Re: Fastest way to insert an element into a list
Message-Id: <EBy5wp.Euw@mv.mv.com>

In article <yge910fbrc6.fsf@cave.gctech.com>,
David Wuertele  <dave@cave.gctech.com> wrote:
>I checked the man and the faq, but found no recommended way to insert an
>element into the middle of a big list:

[C-like code omitted for brevity]
>
>I am interested in both efficient-in-time and efficient-in-space methods.
>Any recommendations?

A good friend of mine relates: "When I was starting to program in Perl,
I would often think of a solution to a problem, start to code it, then
think to myself, 'Hmmm, wonder if Perl has something built-in to do 
this for me?'. It usually did."

Cultivate the habit of asking whether Perl already does what you want
for you, either in a built-in way, or in the wonderful CPAN modules.
Also, cultivate a fondness for the perlfunc page. :-)

In your case, the function you want is 'splice'. 

Happy hunting.


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

Date: Tue, 17 Jun 1997 19:34:53 -0700
From: perl guy <perlprogrammer@hotmail.com>
Subject: Re: HELP: How to limit the length of contents in guestbook script?
Message-Id: <33A7494D.3EED@hotmail.com>

perl guy wrote:
> 
> Larry D'Anna wrote:
> >
> > Jimmy wrote:
> >
> > > Hi, I have a guestbook script that was created using perl 5, and I
> > > want
> > > to limit the length of user's comments. Let say 500 characters.
> > >
> > > So, if someone write his comment over 500 characters, he will
> > > get a message to warn him.
> > >
> > > How can I do that?
> > >
> > > Thanks,
> > >
> > > Jimmy
> >
> >    Use javaScript to validate the input before it is sent.
> >
> > --
> > Larry D'Anna
> > javaGuy
> 
> Well I was going to ask why the heck someoen would make it so others
> HAVE to have java to use something.? That, to me, is totally uneeded and
> a waste of time. I use java for some things.. but when using perl/cgi
> scripts, it's better to (in my opinion) stay away from other things,
> like java. it's not needed and it's limiting to people going to your
> sites. /2 the people I know don't surf with java on anyway.. let alone,
> all the poor sob's that still use non-java capable browsers.. I say
> that's just a really bad idea!.. I believe he came here to ask (in this
> *perl* newsgroup), of how to do this, and I always see a lot of people
> saying to use java.. why?..  i thought this was a perl ng?.. sorry for
> the sarcasm.. but I think people are pointed towards java too much in
> here.. it's not needed, they can do it with perl, and they are asking in
> the perl ng.. so, why use java?.. Hmm.. whatever.. no offense.. but
> why?.

Sorry for losing it there for a moment.. it is fine to suggest other
options.. and after re-reading the post, I suppose you might mean it
working another way.. so I apologize... but still.. I just don't see the
use of it..


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

Date: Tue, 17 Jun 1997 19:29:56 -0700
From: perl guy <perlprogrammer@hotmail.com>
Subject: Re: HELP: How to limit the length of contents in guestbook script?
Message-Id: <33A74824.30D6@hotmail.com>

Larry D'Anna wrote:
> 
> Jimmy wrote:
> 
> > Hi, I have a guestbook script that was created using perl 5, and I
> > want
> > to limit the length of user's comments. Let say 500 characters.
> >
> > So, if someone write his comment over 500 characters, he will
> > get a message to warn him.
> >
> > How can I do that?
> >
> > Thanks,
> >
> > Jimmy
> 
>    Use javaScript to validate the input before it is sent.
> 
> --
> Larry D'Anna
> javaGuy

Well I was going to ask why the heck someoen would make it so others
HAVE to have java to use something.? That, to me, is totally uneeded and
a waste of time. I use java for some things.. but when using perl/cgi
scripts, it's better to (in my opinion) stay away from other things,
like java. it's not needed and it's limiting to people going to your
sites. /2 the people I know don't surf with java on anyway.. let alone,
all the poor sob's that still use non-java capable browsers.. I say
that's just a really bad idea!.. I believe he came here to ask (in this
*perl* newsgroup), of how to do this, and I always see a lot of people
saying to use java.. why?..  i thought this was a perl ng?.. sorry for
the sarcasm.. but I think people are pointed towards java too much in
here.. it's not needed, they can do it with perl, and they are asking in
the perl ng.. so, why use java?.. Hmm.. whatever.. no offense.. but
why?.


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

Date: Tue, 17 Jun 1997 14:37:49 GMT
From: ijstokes@speech1.uwaterloo.ca (Ian Stokes-Rees)
Subject: Re: help: pull down menus
Message-Id: <EBxCn1.nA5@novice.uwaterloo.ca>

For perl and cgi tutorials, check out:

http://agora.leeds.ac.uk/Perl/Cgi/start.html

http://www.stl.nps.navy.mil/~brutzman/perl/perl.html

http://agora.leeds.ac.uk/Perl/start.html

Ian.
-- 
Ian Stokes-Rees, DC 2571
Communications Research Group, University of Waterloo


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

Date: 18 Jun 1997 01:11:17 GMT
From: jahwan@supernova.math.lsa.umich.edu (Jahwan Kim)
Subject: Re: help: TEST-EXP ? TRUE-EXP :FALSE-EXP
Message-Id: <slrn5qeddl.qsu.jahwan@supernova.math.lsa.umich.edu>

On Mon, 16 Jun 1997 16:00:10 +0200, Sibenaler <patrick@arch.ethz.ch> wrote:
[snip]
> (defined($opt_t)) ? $type=$opt_t    : $type= "type_a";
[snip]
> Ok. Fine by now. This works. So I assumed that the second 
> line will act the same:
> IF ($opt_t) is defined, THEN ($type=$opt_t) ELSE ($type="type_a")
> 
> Strangely, this will now work, and the ELSE statement is ALWAYS
                       ^^^
    You mean "not"?
    
> evaluated. How come? Did I fall for a variable scope problem? I
> know that the second statement can be written as:
> 
> $type = (defined($opt_t)) ? $opt_t : "type_a"
> 
> ..but this will now work with the &usage routine. Is there a 
> difference between sub calls and assignments in this construct?
> As soon as there is an assignment in the ELSE expression, it 
> will always be carried out...
> 
> 
> Any hints? (Or did I simply fall for a common bug?)
>    greets, 
>     patrick

    One word: operator precedence.
    
Jahwan


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

Date: Wed, 18 Jun 1997 10:57:39 +0800
From: bz7328113@ntuvax.ntu.ac.sg
Subject: How to get data from server at all times?
Message-Id: <Pine.PMDF.3.91.970618104736.540561645A-100000@ntuvax.ntu.ac.sg>

I have modified the standard client sample program but the client seems 
to get only the first stream of data from the server. The data is sent 
from the server with a delay of a few milliseconds between the 
consecutive data. What I need is to get the data from the server at all 
times. Presently, I using "while <SOCKET> " loop to listen to the server 
at all times. But, this doesn't seems to work.

All your replies are greatly appreciated.

Thanks in advanced.

kkchiang.



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

Date: Tue, 17 Jun 1997 23:15:22 GMT
From: faust@wwa.com (Faust Gertz)
Subject: Re: justa reply...
Message-Id: <33a719eb.2713020@news.wwa.com>

On 17 Jun 97 at 15:33, Jason Costomiris wrote:

> Why are you bitching at me anyhow?  I didn't see a posting from you
> offering help.....

Actually, there is a message (see <33a7a002.4195501@news.wwa.com> and
<33a8da27.981235@news.wwa.com>) from me offering help and telling him
many of the same things you did.  Guess you didn't see it.  I was
only bitching 'cause it seemed like you were just trying to
frustrate him and not really offer help.  If that is not the case,
then I have no complaint.  So sorry if my complaint was misdirected.


Streben nach Wahrheit

Faust Gertz
Philosopher at Large

"The large print giveth, and the small print taketh away" - Tom Waits



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

Date: 17 Jun 1997 22:15:17 GMT
From: dcrouse495@aol.com (DCrouse495)
Subject: Re: leading zeroes
Message-Id: <19970617221501.SAA00992@ladder02.news.aol.com>

Mariana Wuerz <mariana.wuerz@fernuni-hagen.de> writes:

> $four=04
> 
> How can I get $four=4?

Marianna,  Ich habe hier ein subroutine.  Es ist einfach recursive und man
kann es einfach in Programm stecken.  zB

$stuff = <STDIN>;
$stuff = &nozeros($stuff);

####################################################
# DMC: 1-23-97
####################################################
sub nozeros
        { # star sub nozeros
        local($string) = @_;
        return $string if (substr($string,0,1) ne "0");
        return &nozeros(substr($string,1));
        } # end sub nozeros

und,  es mach nichts wie viele zeroes es gab.


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

Date: 18 Jun 1997 00:39:48 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: multiple white spaces
Message-Id: <5o7aok$h3f$1@marina.cinenet.net>

Simon Fairey (sfairey@metrica.co.uk) wrote:
: md4calle@mdstud.chalmers.se wrote:
: > In article <5nmeha$bf0@tsunami.traveller.com>, gbacon@adtran.com wrote:
: > > In article <EBL6ru.9on@seas.ucla.edu>,
: > >       trit@olympic.seas.ucla.edu (Tri Duy Tram) writes:
: > > : I am wondering how do you change multiple white spaces to just one single
: > > : white space?
: > >
: > > $str =~ s/\s+/ /g;
: > When I do this it removes all newlines as well? Is there a way to do
: > it without removing newlines?
: 
: I believe you need the 'm' flag so that it treats the string as multiple
: lines.
: i.e.
:   $str =~ s/\s+/ /gm;

Nope, that won't change the fact that the char-class \s includes 
newline.  There are two ways to improve the substitution to do its work 
better.  The first is to avoid do-nothing situations (assuming you don't 
want to change single tabs into single spaces, for example, just multiple 
"any whitespace" into a single space):

  s/\s{2,}/ /g;

That is, "turn two or more whitespace chars in a row into a single space."

The other thing you can do is be more specific about what counts as 
whitespace (for your purposes), by building a character class 
explicitly.  Combining this with the above suggestion, we get (e.g.):

  s/[ \t]{2,}/ /g;

Which means, "Replace any sequence of two or more spaces or tabs (or 
both, in any mixture) with a single space."

Hope this helps!

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: Tue, 17 Jun 1997 23:03:21 GMT
From: beryte@leb.net (beryte)
Subject: Re: Perl script needs counter?
Message-Id: <33a717ac.7609483@news.telecom.at>

On Tue, 17 Jun 1997 11:00:16 -0700, Ron Ablang
<cs008150@gaia.ecs.csus.edu> wrote:

>Could someone please help me modify this perl script?  What it does is
>it    
>takes an ascii text file and sends it to every user listed in the ascii
>text file "distribution_list".  What I would like for it to do now is to
>count how many users it sends mail to.  Thanks for your help.
>
>open(SOURCE,"distribution_list") || die "cannot open distribution_list";
>print "Enter file to distribute:  ";
>$distribution_file = <STDIN>;
>chop($distribution_file);
>print "Enter message subject string:  ";
>$subject = <STDIN>;
>chop($subject);
>print "This could take a while.  Please wait.\n\n";
          $number_of_users = 0;
>while ($field = <SOURCE>) {
>    chop($field);
>    unless (fork) {
>        exec("mailx -s '$subject' $field < $distribution_file");
          $number_of_users++;        
>    }
>    print "Message sent to: $field\n";
>    sleep 1;
>}
>print "All done!\n\n" ;
          print "$number_of_users\n";
>close(SOURCE);


beryte


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

Date: Tue, 17 Jun 1997 20:37:48 -0600
From: bruce langlois <langlois@csn.net>
Subject: Problem w/unpack, eval and floating point
Message-Id: <33A749FC.C3D51C7@csn.net>

I am having a problem with the following perl chunk:

#!/usr/local/bin/perl
use English;

$fpnum = eval 'unpack("f", $recbuf)';
if( $EVAL_ERROR ) {
  print "Garbage fp number\n";
  $fpnum = -1.;
}
else {
  print "$fpnum\n";
}

I am reading $recbuf from a binary file which should contain
a floating point number, but could also have garbage in it.
When the eval runs into a garbage value, perl dies with
a floating point exception and dumps core.  According to
the perl manual, the eval should catch the error and let
me process it.  Anybody have any ideas as to how to verify
that I have a real floating point number in $recbuf?  Any
help would be appreciated.
 
-- 
Everything goes better with a delayed blast fireball =8)
lothar@acsp.com
langlois@csn.net


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

Date: Wed, 18 Jun 1997 02:01:10 GMT
From: topaz56@one.net
Subject: Sorry another regex question - parsing HTML anchors??? Interesting though...
Message-Id: <33a73efa.128472207@news.mindspring.com>


I can't figure this out, even after reading (sporadically) through
understading regular expressions.  What operator matches
anything akin to * in unix?  Is it *? or (*) or .*?  What I'm trying
to do is to take input ($data below) & simply parse out the HTML
anchor, plus the intervening text, ie...

<a href="http://company.com">Company</a>

I'd like to dump the url and the name into separate variables, and to
add a bit of interest to this, I'd like it to smoothly handle text
files generated from Netscape bookmarks.  The rough anchors look like
this:

 <DT><A HREF="http://www.web-master.com/forums/career.html"
ADD_DATE="855631541" LAST_VISIT="863620321"
LAST_MODIFIED="855631523">The Professional Webmaster</A>

        <DT><A HREF="http://www.w3.org/pub/WWW/Journal/"
ADD_DATE="861305717" LAST_VISIT="863622870"
LAST_MODIFIED="861305705">World Wide Web Journal</A>

I need to remove from ADD_DATE --->LAST_MODIFIED##########"

My logic (& it is probably flawed) is to input this data as a scalar &
store the variables &url & name in a hash.  Am I thinking about this
correctly??? And how can I fix the regex below???

open (DATAFILE, "$data") || die "Can't open $data\n";	    # Open
filehandle or die

Thanks, Tom


    while (<DATAFILE>) {	  # this implicitly loads $_
($url,$name) = ($anchor =~ s/<a href=([^"*"])*>[*]<\[Aa]>/$1 $2/gi); 	
    

=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=
                 tporter@dtool.com     			
		 Thomas Porter, Ph.D.
	         THE DIGITAL TOOL GROUP
		 http://www.dtool.com

	   "Never attribute to malloc
that which can be adequately explained by stupidity"
=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o=o
	


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

Date: Tue, 17 Jun 1997 17:10:49 -0500
From: Chris Mason <cmason@ti.com>
Subject: Tie and Multidimensional hashes (and other stuff)
Message-Id: <33A70B69.2663@ti.com>

All-

(this is long. stick with it.)

	So, I have a bunch of scripts which build these big hashes out of a few
files so I can search them quickly.  The resulting hashes are large
(around 1-2mb each as far as I can guess), and currently are built
automatically on script startup and stay around until the script dies. 
They are updated whenever the files change on disk.
	The scripts work fine, and I've attached them to Apache using
mod_perl.  This allows the hash(es) to persist through requests.  Again,
they work fine (and are _very_ speedy), but each child server process
builds it own copy of each of these enormous hashes.  This is not good
(to the tune of around 20mb of ram and swap on a poor little 486).  This
is also wasteful because the data is the same in each (duplicate) hash,
and everytime the disk file changes, each of the children has to
independantly rebuild its hash.  This takes lots of time and swapping
and isn't very smily.
	I figured there has to be a better way. (being the optimistic perl
hacker that I am)  (stop here and write me if you can think of a better
way)
	I got it into my head to build a kind of tieable (sp?) net hash, which
would allow a hash to actually exist on another machine somewhere on the
network.  Someone wanting to use one of these big hash indexes would tie
to it using a Module, which I called Nethash (creative hunh?).  Nethash
opens a net connection to the server, which could already have the hash
built (and would rebuild it as neccesary), and then FETCHes and STOREs
would fly across the net.  This seemed like a not trivial but not
impossible thing to do, especially considering the whole bunch of
documentation that exists on tieing things.  It doesn't prove to be very
easy:

	First, just about every hash I use is multidimensional.  The only
information I can find on tieing multidimensional hashes is in the
MLDBM.pm docs which states:

> In particular, something like this will NOT work properly:
> 
>     $mldb{key}{subkey}[3] = 'stuff';  # won't work
> 
> This limitation exists because the perl TIEHASH interface currently has no
> support for multidimensional ties. 

This is not very encouraging as things go.  I thought about trying to
have FETCH return a tied hash like:

	sub FETCH {
		[...]
		[get name of sub hash from server as $1]
                tie %rethash, Nethash, $1, $info{'host'}, $info{'port'};
                return %rethash;
	}

Then this tied sub hash could access another hash on the server using
the same method as the first hash (emulating multi-dimensional hashes). 
Would something like this work?  Am I pushing too many boundaries here? 
I read through the source of MLDBM.pm but it seems to pull the whole sub
hash in from the DBM file and return it.  This would be a bad thing in
Nethash.  (It seems like the real solution is to have perl really handle
multidimensional tied hashes by passing in all the keys to the FETCH
method.)

	Second (and lastly), every bit of networking code I can find for perl
shows a server working by forking a separate process to handle each
request.  This doesn't make any sense for Nethash because it would
mitigate any memory gained from keeping a central copy of the hashes.
(Ie, when it forked a child to serve the request, it would copy over the
hash, in the same manner as Apache did when it forked a child to handle
the web request)
	This again isn't very rosy, because it seems (and I don't have much
experience here) that all of perl's socket calls block.  For example if
I create a socket:

		[...]
	        socket(HASHSOCK, PF_INET, SOCK_STREAM, $proto)
                        or carp ("Nethash: socket: $!.\n") and return
undef;
                connect(HASHSOCK, $conn)

and then try to read from it:

		while ($in = <HASHSOCK>) {...}

would block until there was data on the socket right?  This prevents me
from using a round robin approach inside of one proccess by keeping an
array of connections and then serving each one in turn.  I'm not really
concerned about high volume here, but it would be nice to be as scalable
as possible.

	To sum up, a Net-tieable hash seems like a Very Cool Thing.  It would
have lots of applications.  It just doesn't seem very easy to write.  A
wee sample of the code I've got so far is up at
<http://ros.res.cmu.edu/Nethash.pm>.  This just implements TIEHASH and
FETCH, and only on the client side.  If feel like taking a look at it go
ahead, but its not pretty right now.  I haven't tried it yet (ugh).

	Thanks in advance for any help you can offer.

Just a fellow perl hacker.

-c

PS- No I don't really want to build a *DBM file instead, because the
files change too often.

PPS - yes I did RTFM.  Every scrap of it that I could find.

--
Chris Mason  --  Documentation  Co-op - TI Software - cmason@ti.com -
x4391
"...the monstrous thing is not that men have created roses out of this
dung
heap, but that, for some reason or other, they should _want_
roses."-Miller


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

Date: 17 Jun 1997 20:22:38 -0700
From: Felix Lee <flee@teleport.com>
Subject: Re: TIMING EXPERIMENT
Message-Id: <sp7mfsegsh.fsf@teleport.com>

Randal Schwartz <merlyn@stonehenge.com> writes:
> And unlike TCL, Perl has *real* datatypes.

well, the datatypes in tcl8.0 are about as real as perl4's
datatypes, and the internal structure is comparable.  but
the speed isn't _quite_ there yet.

# perl4.036    11.73user 0.01system 0:12.35elapsed
# perl5.003	3.24user 0.01system 0:03.25elapsed
    for ($k = 0; $k < 1000; ++$k) {
        for ($j = 0; $j < 1000; ++$j) {
        }
    }

# tclsh8.0b1	13.61user 0.01system 0:13.65elapsed
    # loop is wrapped in a proc, otherwise it doesn't
    # get compiled.
    proc foo {} {
	for {set k 0} {$k < 1000} {incr k} {
	    for {set j 0} {$j < 1000} {incr j} {
	    }
	}
    }
    foo

# timings are on a random pentium-100 running linux


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

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


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

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

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

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". 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 626
*************************************

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