[6531] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 156 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 21 18:09:07 1997

Date: Fri, 21 Mar 97 15: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           Fri, 21 Mar 1997     Volume: 8 Number: 156

Today's topics:
     Re: [Q] for loop - making multiple arrays (Dylan Northrup)
     A Call for Clarity (Schwartzian Transform Considered Sc <tchrist@mox.perl.com>
     CGI HELP <mystikal@ilinks.net>
     cls || ClrScr?? <peter@uhu.com>
     Re: Dereferencing... <jims@ss5mth44.franklin.com>
     Re: Getting data in random order. (Brian Jepson)
     Re: Getting data in random order. (Tad McClellan)
     Help needed with PERL script! (Neil Johnson)
     Re: How to concat many digits to be one string? <rootbeer@teleport.com>
     Re: Looking for "HTML to Plain Text"  perl script <jstern@world.northgrum.com>
     Re: NNTPClient 2.6 problems (Nathan V. Patwardhan)
     Re: numerical values as hash indices:  bad idea? <dehon_olivier@jpmorgan.com>
     Re: Parser with state support??? <keesh@cs.cmu.edu>
     Re: Parsing a string <tchrist@mox.perl.com>
     Re: Perl and MUDs <brett@speedy.speakeasy.org>
     Perl script..help! <len.morrissey@sympatico.ca>
     Re: Reg: tr command (Brian Jepson)
     Re: running the first perl program (Tad McClellan)
     Re: Single character representing all regexp metacharac <rootbeer@teleport.com>
     Re: Suidperl! <rootbeer@teleport.com>
     Re: term 'regular expressions' considered undesirable <vladimir@cs.ualberta.ca>
     Re: term 'regular expressions' considered undesirable <tchrist@mox.perl.com>
     Re: TEST for empty DIR <rootbeer@teleport.com>
     Re: TEST for empty DIR <jhi@alpha.hut.fi>
     Re: trouble matching multiple fields (Piers Cawley)
     Re: trouble matching multiple fields <psrc@exmachina.com>
     Re: Unpack Cobol Comp-3 data <brobbins@pls.com>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 21 Mar 1997 13:11:55 GMT
From: northrup@chem.ufl.edu (Dylan Northrup)
Subject: Re: [Q] for loop - making multiple arrays
Message-Id: <5gu1er$ki@nostromo.clas.ufl.edu>

An infinite number of monkeys in the guise of Randal Schwartz  <merlyn@stonehenge.com> wrote:
=:>>>>> "Opera" == Opera Ghost <OperaGhost@NetTown.com> writes:
=:
=:Opera> uh...i guess ull need perl5 too...
=:
=:Like there's any other version of Perl out?
=:
=:The development team recently moved the 4.0 sources from CPAN/src/4.0
=:to CPAN/src/unsupported/4.0.  That should be a clue to y'all out
=:there.  (I think tchrist was voting to move it to
=:CPAN/src/flea-bitten-dead-carcasses/, but that wouldn't have been
=:mirrorable on 8.3 filesystems. :-)

There's always CPAN/src/flea/bitten/dead/carcass/ though that does chew up a
few more inodes (and you have to truncate 'carcasses').  However, it would
be far more discouraging for people do get and would hopefully make them
think twice (assuming there *was* a first thought to begin with).

--
Dylan Northrup <*> northrup@pobox.com <*> http://pobox.com/~northrup <*>
Ask me about e-mail P.O. Boxes <*> "I don't want the world, just your half"
---------------
Random B5 Quote
---------------
"Like you said, I never start a converstaion unless I know where it's
  going.  But I always leave a little room for someone to dissappoint
  me.  Thanks for not doing it."
  -- Security Chief Garibaldi, "Comes the Inquisitor"



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

Date: 21 Mar 1997 21:11:28 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: A Call for Clarity (Schwartzian Transform Considered Scary)
Message-Id: <5guti0$hsm$1@csnews.cs.colorado.edu>

Enclosed you will find a posting pinched from the Python group that
shows the fear and shock and pain and anger and resentment that the
Schwartzian Transform and code of similar ilk too often invoke.  Sure,
some of Aaron's points are a bit weak, like forgetting the purpose of
$1 and $2, but by and large his general sentiment -- especially about
the ST -- is shared by many far and wide.  You should see me try to
teach the ST to regular people in regular classes.  They all *HATE* it.
They're rather play with scoping of lexicals in closures than the ST,
and that's saying something.  And they'd *certainly* rather write something
that ran 10x slower than use something they find it hard to understand.
Strange but true.

By extolling the clever and concise over the overt and obvious, one
can give Perl an undeservedly poor reputation.  Newcomers don't always
understand the difference between code designed for an obfuscated
Perl contest and code code carefully crafted for maintainability and
long life.  When writing kludgy/kluglich code designed for ephemeral
coolness or as a Perl puzzler instead of for the more customary goal
of long-term understandabilty, I would ask that you please try to state
this goal explicitly.

Yes, I know I myself am far from blameless in this, which is why I
don't want this missive to be viewed as a stone hurled at Randal.
It's not.  Randal, after all, gave us all this powerful but perilous
idiom, plus many others of tremendous utility that we all employ in our
daily programming pursuits.  As for me personally, sure, I confess that
I wrote inscrutable code back in my Perl babytalk days, and sometimes
still do (please don't look in my /tmp :-).  Heck, even recently I wrote
L<perltoot/"Closures as Objects">, and even labelled it as being of work
of Hubris.  But Hubris has its dark side as well, and it's its dark side
that can tarnish Perl's luster.

Mind you, I happen to use the ST:TOS ("Schwartzian Transform: Tricky
Obfuscated Stuff") myself for sorting.  Yes, I find it interesting,
efficient, and elegant.  So do Larry and Randal.  But most people aren't
of this mindset, nor can we hope to lead them to such a mindset.

Mostly, I guess I'm just tired of getting beaten up about Perl's alleged
"for wizards/hackers only" reputation that this stuff engenders.

Wasn't there a module that encapsulated the ST in a module that hid away
the scary bits?  If someone recalls where it is, can we please get it
on CPAN and try to encourage its use?

If it's at all possible, I would ask that whenever you used
the ST, that you would *please* reference its documentation in
http://www.perl.com/all_about/sort.html to help allay these black marks
against Perl.

Remember: One man's cool is the next man's crud.  

--tom

    From: "Aaron Watters" <arw@dante.mh.lucent.com>
    Subject: Re: Legislating Morality (was: Why Python? Vs. Perl ?)
    Message-ID: <199703211443.JAA26234@dante.mh.lucent.com>

    > From: Tom Christiansen <tchrist@mox.perl.com>
    > In comp.lang.python, 
    >     "Aaron Watters" <arw@dante.mh.lucent.com> writes:
    > :@sorted = map  {$_->[0]} 
    > :          sort {$b->[2] <=> $a->[2] or $b->[1] <=> $a->[1]} 
    > :          map  {/(\w\w\w)(\d\d)/; [$_, $hash{$1}, $2]}
    > :          @array;
    > :
    > :What is that supposed to do?  Well, I can't understand it,
    > :but it was supposed to do this:
    > 
    > Aaron, get a grip, will you man?  *THIS IS NOT NORMAL CODE*...

    How come I kept running into stuff like this then?  And this is
    actually relatively clean compared to some stuff I've seen.  
    Still, I think it shows some features
    that may not be desirable for larger scale programs that must
    be understood by more than one programmer (especially if
    some of those programmers are moderately skilled and
    easily corrupted by temptation).

    Where did $a and $b come from?  What is $_, and does it
    mean two different things in two different places inside the
    same expression?  I forget how that $1 and $2 thing works,
    I'll have to get out Tom's book again...  Thank God it stops
    after just four lines, at least I have *some* hope of figuring
    out what's going on...  There is simply no analogue in Python
    (or Lisp AFAIK)... APL or Forth maybe.

    Don't get me wrong, for quicky one liners this stuff is great,
    but you really don't want to see this kinda stuff in the middle
    of a largish program that you've never seen before.  But Larry
    is right "programmers can program assembly in any language"
    even though Python encourages you not to (as I think I
    demonstrated in the quoted post, which see).
	-- Aaron Watters
    ===
    Can't I have just a little temptation?  -MPSFTHG


-- 
	Tom Christiansen	tchrist@jhereg.perl.com

    pos += screamnext[pos]  /* does this goof up anywhere? */
        --Larry Wall in util.c from the perl source code


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

Date: Fri, 21 Mar 1997 16:18:40 -0500
From: MyStIkAl <mystikal@ilinks.net>
Subject: CGI HELP
Message-Id: <3332FB30.24C9@ilinks.net>

I have a page with some javascript which prompts you for you name and
enters it in a table with some other things such as the browser type, 
how many times that the person has been there and some more.
http://www.ilinks.net/~mystikal/   <--if ya wanna check it out.
but, I have some CGI script that puts the users name and ip address
and some other stuff, but I don't know how to make it print it out in 
the table

HERE'S THE SCRIPT
------------------------------------------------------------------------
#!/bin/sh

echo content-type: text/plain
echo

echo <tr><td>Server Software</td><td>$SERVER_SOFTWARE</td></tr>
echo <tr><td>Server Name</td><td>$SERVER_NAME</td></tr>
echo <tr><td>Server Port</td><td>$SERVER_PORT</td></tr>
echo <tr><td>Your Browser Accepts</td><td>$HTTP_ACCEPT</td></tr>
echo <tr><td>Your Host Name</td><td>$REMOTE_HOST</td></tr>
echo <tr><td>Your IP Address</td><td>$REMOTE_ADDR</td></tr>
------------------------------------------------------------------------
the <tr><td>..... are neccesary to complete the table
but how do I refer to it in the HTML document.

any help would be appreciated
you can post replys here or email me
thanks,    
MyStIkAl
mailto:mystikal@ilinks.net
http://www.ilinks.net/~mystikal/


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

Date: Fri, 21 Mar 1997 17:36:26 -0500
From: Peter Tapolyai <peter@uhu.com>
Subject: cls || ClrScr??
Message-Id: <33330D69.1978@uhu.com>

How do you clear the screen in perl ?


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

Date: Fri, 21 Mar 1997 21:17:58 GMT
From: Jim Shi <jims@ss5mth44.franklin.com>
Subject: Re: Dereferencing...
Message-Id: <5guv89$9mc@hideout.emanon.net>



@{$_[0]} is what you want. try it.


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

Date: 21 Mar 1997 19:40:38 GMT
From: bjepson@bjepson.ids.net (Brian Jepson)
Subject: Re: Getting data in random order.
Message-Id: <slrn5j56p6.qa.bjepson@bjepson.ids.net>

In article <3332CF68.B3A@mcs.net>, Timothy Shell wrote:
>I have been unable to come up with an elegant way to do this, and as
>always, there's this nagging suspicion that I'm overlooking something
>simple.
>
>I want to output a list of records in a random sequence each time the
>program runs.  So if I have a data file with 100 records, I'd like to
>pick, say, 20 records at random and display them in no particular order.
>
[...]

Perhaps something along these lines would achieve what you're trying 
to do; I'm sure there's another way to do it, but this seems to work:

=========================== cut here =========================== 
#!/usr/bin/perl

srand(time);

# read each line in, key it by a random number
#
while (<DATA>) {
    $key = rand();

    # just in case we get the same one twice.
    #
    while ($lines{$key}) {
        $key = rand();
    }

    $lines{$key} = $_;
}

# sort the random keys
#
@keys = sort keys %lines;

# grab the first five lines
#
for (1..5) {
    $key = shift @keys;
    print $lines{$key};
}

__DATA__
Row Number 1
Row Number 2
Row Number 3
Row Number 4
Row Number 5
Row Number 6
Row Number 7
Row Number 8
Row Number 9
Row Number 10
=========================== cut here =========================== 

Hope this helps,

-- 
Brian Jepson * (bjepson@ids.net)  *  http://www.ids.net/~bjepson
  Int(ra|er)net Database Developer, Author, Crypto-Fluxologist
Non-Prophet Arts Technology Flux:      http://www.ids.net/~as220
WWW/Database/NT,Java/Database: http://www.ids.net/~bjepson/books



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

Date: Fri, 21 Mar 1997 15:24:04 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Getting data in random order.
Message-Id: <k9uug5.iv2.ln@localhost>

Timothy Shell (tshell@mcs.net) wrote:
: I have been unable to come up with an elegant way to do this, and as
: always, there's this nagging suspicion that 
: I'm overlooking something simple.
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

You are overlooking the existence of the new perl FAQ  ;-)


: I want to output a list of records in a random sequence each time the
: program runs.  So if I have a data file with 100 records, I'd like to
: pick, say, 20 records at random and display them in no particular order.


A word search for 'random' turns up:

faq.4:=head2 Why aren't my random numbers random?
faq.4:http://www.perl.com/CPAN/doc/FMTEYEWTK/random, courtesy of Tom
faq.4:=head2 How do I shuffle an array randomly?
faq.4:=head2 How do I select a random element from an array?
faq.5:=head2 How do I randomly update a binary file?
faq.5:=head2 How do I select a random line from a file?


I expect that should get you going...


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: Fri, 21 Mar 1997 20:47:21 GMT
From: njohnson@enterprise.net (Neil Johnson)
Subject: Help needed with PERL script!
Message-Id: <3333e394.1376587@news.enterprise.net>

Hi,

It's thanks to previous help in this newsgroup that I have got this
far on my Perl script so please don't fail me now!!

My script (Which is at the bottom of this message) displays an HTML
page indexing the server's directories and files. But I have a few
questions and queries.

Firstly I the path that the script starts to index from is stored in
the $dir but I want to allow people to addan argument at the end of
the script when executing e.g. index.pl?d:\\wwwroot\ftp\ 

I know you can change $dir to this: $dir=ARGV[0]

But is there a piece of script that can check if a path is given and
if not reverts back to the default of $dir=".." ??

Secondly, and this is the bit I have gone desperate on, is there
anyway I can get the file dates & times so I can display them too. The
script already displays file name, directory, file size and file age
(in days) but is there anyway I can get the other file details such as
date & time of each file??

The last problem is how to format the $TotalSizeMb string into
999,999,999 instead of 999999999. I have found a piece of code that
does this but I have no idea of where to put it!

The peice of code is:

1 while s/(\d)(\d\d\d)(?!\d)/$1,$2/g; 

Hope you all can help!! By the way the script is to be used on
Microsoft IIS. The script is below:

#!/usr/bin/perl -w 

$dir = "..";

# Create HTML file & content header

print "<Content-type: text/html\n\n>";
print "
<HTML>
<HEAD><TITLE>File Index</TITLE></HEAD>
<BODY BGCOLOR=#FFFFFF>
<FONT FACE=Arial>
<P>
<H2>Indexer</H2>
</P>
<TABLE>
<TR>
<TD><B>Directory </B></TD>
<TD><B>File Name</B></TD>
<TD><B>Size(Bytes) </B></TD>
<TD><B> Age(days)</B></TD>
</TR>
<TD><HR></TD><TD><HR></TD><TD><HR></TD><TD><HR></TD>
";

$TotalSize = 0;
$DirSize = 0;
&traverse($dir);                           

sub traverse {
    local($DirSize) = 0;
    local($dir) = shift;
    local($path);
    unless (opendir(DIR, $dir)) {
        warn "Can't open $dir\n";   # Error message if we cannot open
directory
	closedir(DIR);
	return;
    }
    foreach (readdir(DIR)) {
	next if $_ eq '.' || $_ eq '..';
	$path = "$dir/$_";
	if (-d $path) {                      # Read Sub-Directories
	    &traverse($path);
        } elsif (-f _) {                     # Read all files
        $size = -s _;                        # Get file size
        $age = int (-M _);                   # Get file age
        $DirSize = $DirSize + eval(-s _);    # Calculate directory
size 
	print "
	<TR>
	<TD>$dir</TD>
	<TD>$_</TD>
	<TD ALIGN=RIGHT>$size</TD>
	<TD ALIGN=RIGHT>$age</TD>
        </TR>";
	}
    }
    print "<TR><TD><B>$dir</B></TD><TD><B>Total Dir</B></TD><TD
ALIGN=RIGHT><B>$DirSize</B></TD></TR>";
    $TotalSize = $TotalSize + $DirSize;	
	closedir(DIR);
}

        $TotalSizeMb = ($TotalSize / 1024) / 1024;
        $TotalSizeMb = int ($TotalSizeMb);
        print "
</TABLE>
<H2>Total in directory tree $dir = $TotalSizeMb Mb</H2><P>
<HR>
</FONT>
</BODY>
</HTML>
";


Neil 
njohnson@enterprise.net  


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

Date: Fri, 21 Mar 1997 12:49:05 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Joruno Jobana <b39jrj@nontri.ku.ac.th>
Subject: Re: How to concat many digits to be one string?
Message-Id: <Pine.GSO.3.96.970321123912.14218P-100000@kelly.teleport.com>

On Fri, 21 Mar 1997, Joruno Jobana wrote:

> #/usr/bin/perl
> srand(time|$$);
> for($i=0;$i<8;$i++) {
>   $ID[$i]=int(rand(10));
> }
> 
> 	I want to concat all 8 digits to be one string;

You seem to want a random number from 00000000 to 99999999, right? The sub
here will probably be faster than calling rand eight times. Hope this
helps!

    #!/usr/bin/perl -w

    use strict;

    # Sub to return a random string of eight digits in the
    # range 00000000 to 99999999.
    sub rand8 () {
	join '', map { sprintf "%04d", $_ }
	    rand 10000, rand 10000;
    }

    srand;

    for (1..5) {
	print rand8, $/;
    }


-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: Fri, 21 Mar 1997 18:16:35 GMT
From: Jim Stern <jstern@world.northgrum.com>
Subject: Re: Looking for "HTML to Plain Text"  perl script
Message-Id: <3332D083.1C5@world.northgrum.com>

Kathleen Ramsey wrote:
> 
> Where can I find a "HTML to Plain Text"  perl script.

Try Gisle Aas's module HTML::FormatText.  See CPAN.

-- 
Jim Stern -- Views here are my own, not Northrop Grumman's.   (El
Segundo, CA)


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

Date: 21 Mar 1997 20:24:12 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: NNTPClient 2.6 problems
Message-Id: <5guqpc$hpd@fridge-nf0.shore.net>

Prince Mystery (mystery@itis.com) wrote:

: I'm trying to get the latest articles in a particular group from the
: last 24 hours.  Unfortunately, the server at which I'm trying to
: retrieve these articles does not implement the newnews command.  When I
: run help, here is the list I'm given:

I'll venture a guess that your server is running INN, or something that
has a revised subset of NNTP commands.  Our server (INN) at work does not 
allow newnews, and my ISP's doesn't seem to, either.

The commands you've listed below look a lot like the innd commands, though.
You might ask your provider about nnrp, more specifically if they can/will
run it.  Just speculation, though.

:         authinfo
:         help
:         ihave
:         check
:         takethis
:         list
:         mode
:         quit
:         head
:         stat
:         xpath
:         xreplic
: For more information, contact "news" at this machine.

--
Nathan V. Patwardhan
nvp@shore.net



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

Date: 21 Mar 1997 17:12:41 +0000
From: Olivier Dehon <dehon_olivier@jpmorgan.com>
Subject: Re: numerical values as hash indices:  bad idea?
Message-Id: <njzohcdkw3a.fsf@jpmorgan.com>

really_eliot@dg-rtp.dg.com_but_mangled_to_stop_junk_email writes:

> 
> 
> I've been told many times that one should never attempt to compare two
> floating-point values for equality, because, for example, you could be
> trying to compare 1.0000000000 to 0.9999999999, and the result would
> be "not equal", even if that isn't what you expected.  Fair enough.
> 
> Now Perl, by default, represents all numerical values as floating
> point numbers.  If I were to use such a value as a key to a hash
> (associative array), the value would be converted into a string and
> the string would be used as the actual key value.  Right?  Correct me
> if I'm wrong.  Later, if I go to access that array entry by
> calculating a numerical value and using that as the key, once again a
> floating point is converted to a string and used as the actual key.
> 
> Thus I could end up generating a key of "1.00000000" (or perhaps just
> "1") the first time, and "0.99999999999" the second time (depending on
> what calculations I used to generate the index) and finding that my
> array entry had "disappeared".  Or so it appears to me.
> 
> Should I conclude that using numerical values, or at least numerical
> values that are the result of any kinds of calculations, as keys to an
> associative array is a Bad Idea?
> 
Yes, you're right.

There is a way of getting around that problem, if you can assume that
your keys will not be too close from one another. e.g. if the minimal
difference between two consecutive keys is at least .001, then you
could use sprintf on the keys to use keys with 3 decimal digits, that is:
$key = sprintf("%.3f", $key);

This will make sure that your keys are rounded off before parsing the hash.
Gurus will tell if I'm wrong ;-)

Hope this helps.
Olivier Dehon



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

Date: Fri, 21 Mar 1997 15:37:06 -0500
From: Eric Kischell <keesh@cs.cmu.edu>
Subject: Re: Parser with state support???
Message-Id: <3332F171.41C6@cs.cmu.edu>

Sorry if this is a dup post.
e.-

Eric Kischell wrote:
> 
> Hello,
> 
> I am currently learning Perl and Java to augment my Web skills.
> 
> A project at work requires simple parsing abilities from a messy "log
> file" to generate a clean report file.  A "tagged" log file line may
> have related items on following lines without a tag.
> 
> On the PERL FAQ String::MatchMany and
> Text:: ::Parser seemed close to want I need.
> 
> I am a Perl NEWBIE and have about 2 weeks of a JAVA course.
> Does anyone have recs for simple code "modules" that would
> only require slight modifications to perform the above.
> 
> e.-
> 
> p.s.: Perl was recommended and Java seemed like it has some basic
> support for String parsing via StringTokenizer.
> 
> ex. file in)
> Configuration: Optotrak configuration filename:
> /jjj/mrrob/ios_project/data/config/file.cfg      @Fri Dec 13 11:59:04 1996
> 
> ...
> Junk: this is junk
> Morejunk:  more junk
> ...
> 
> Configuration:
> Number of probes= 6
>          @Fri Dec 13 11:59:04 1996
> 
> Configuration:
> Probe name      number  strobe num      max distance    calib method    calib for       valid
> for wand        valid for calib calib order.
> super_x rb#1  1  0.600 0  2 1 1  1
> world rb#2  2  0.600 0  0 0 0  0
> hip rb#3  3  0.600 0  0 0 0  0
> tool_top rb#4  4  1.000 0  2 0 1  2
> tool_bot rb#5  4  1.000 0  2 0 1  3
> rb-06056 rb#6  5  0.600 0  2 1 1  4
>          @Fri Dec 13 11:59:04 1996
> 
> Data Acquisition Sphere: Pt #1 out of 1 collect f/ Sphere Centroid.
> Pt x = 417.908905   y = -343.905121  z = 200.959473   collect by Ball
> Probe.   @Fri Dec 13 12:01:58 1996
> 
> 
> 
> ex. file out)
> 
> This is a nice report
> ---------------------
> Number of probes= 6 at Fri Dec 13 11:59:04 1996
> 
> Optotrak configuration filename:
> /IUS/mrcas2/ios_project/data/config/opto.cfg
> 
> Probe name      number  strobe num      max distance    calib method    calib for       valid
> for wand        valid for calib calib order.
> super_x rb#1  1  0.600 0  2 1 1  1
> 
> Pt x = 417.908905   y = -343.905121  z = 200.959473   collect by Ball
> Probe at Fri Dec 13 12:01:58 1996
> ----------------------
> 
> thx in adv
> e.-


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

Date: 21 Mar 1997 20:13:30 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Parsing a string
Message-Id: <5guq5a$csq$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited authors via email]

In comp.lang.perl.misc, dbenhur@egames.com writes:
:Steven R. Johnson wrote:
:> I guess basicly what I want to do is remove everything between 
:> all the <>
:
:s/<[^>]*>//g; # replace all <...> with nothing
:
:try reading man perlre

I do wish people would stop giving that "solution", since
it so often fails.  Consider when the tag spans a line, like this:

    <SELECT NAME="whatever"
	    MUTIPLE=1
    >

Or when the string in the tag has a bracket in it, like this:

    <IMG SRC="/path/foo.gif" ALT="Prompt>">

That's why I have this in the part 9 of the FAQ:

Q:  How do I remove HTML from a string?

A:  The most correct way (albeit not the fastest) is to use
    HTML::Parse from CPAN (part of the libwww-perl distribution,
    which is a must-have module for all web hackers).

    Many folks attempt a simple-minded regular expression
    approach, like `s/<.*?>//g', but that fails in many cases
    because the tags may continue over line breaks, they may
    contain quoted angle-brackets, or HTML comments may be present.
    Plus folks forget to convert entities, like `&lt;' for
    example.

    Here's one "simple-minded" approach, that works for most
    files:

        #!/usr/bin/perl -p0777
        s/<(?:[^>'"]*|(['"]).*?\1)*>//gs

    If you want a more complete solution, see the 3-stage striphtml 
    program in

	http://www.perl.com/CPAN/authors/Tom_Christiansen/scripts/striphtml.gz 

--tom
-- 
	Tom Christiansen	tchrist@jhereg.perl.com
    OOPS!  You naughty creature!  You didn't run Configure with sh!
    I will attempt to remedy the situation by running sh for you...
        --Larry Wall in Configure from the perl distribution


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

Date: 21 Mar 1997 12:01:39 -0800
From: Brett McCormick <brett@speedy.speakeasy.org>
Subject: Re: Perl and MUDs
Message-Id: <7vg1xpovz0.fsf@speedy.speakeasy.org>


I am certainly interested, and have been thinking about doing this for
quite a long time.. I just need the free time to do it.  However, if
there was enough interest, I'm sure a cooperative development effort
could get going.  All interested, let me know and I'll create a
mailing list (provided enough are interested).

Wade Holst <wade@cs.ualberta.ca> writes:

> 
> 
> I was wondering if there are any individuals currently looking into using
> Perl as the programming language for a new type of Multiple-User-Dimension.
> I'd be interested in contributing to such a venture.
> 
> 
> Wade Holst
> 
> 
> 
> 
> 


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

Date: Thu, 20 Mar 1997 15:12:44 -0800
From: Len Morrissey <len.morrissey@sympatico.ca>
Subject: Perl script..help!
Message-Id: <3331C46C.421D@sympatico.ca>

I have created a simple perl script with simply "if" statements that
simply takes the content of a "form" of a web page, and sends the content
back to the html user in a formatted way.

MY QUESTION...now I want to simply send the same formatted html page to
an email.  Can I write this into my script.  I know that formail.cgi does
similiar things, but it's not exactly what I want (too complex).  Here is
 what my script for the html return page...

#!/usr/bin/perl
require ("cgi-lib.pl");&ReadParse (*input);
print "Content-Type: text/html\n\n";
print "<html><head><title>Res Builder Test 1</title></head>\n";
print "<body bgcolor=\"#ffffff\"> \n";

if ( $input{'Name'} ){
     print "<FONT SIZE=+2><center><b>$input{'Name'}\
\n</b></center></FONT><BR>";
}

and so on...will a simple "sendmail" suffice...how do I write it in.  As
you may have guess, I'm just beginning to write my own cgi scripts.  I
appreciate any suggestions...thanks!

Len Morrissey



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

Date: 21 Mar 1997 21:19:34 GMT
From: bjepson@bjepson.ids.net (Brian Jepson)
Subject: Re: Reg: tr command
Message-Id: <slrn5j5cim.11r.bjepson@bjepson.ids.net>

In article <3332DD90.3E5B@eos.ncsu.edu>, Zacharia George wrote:
>Hi,
>	Could someone please tell me how to convert from Uppercase to 
>Lowercase in a string EXCEPT for the first letter of each word in the
>string. I assume that the "tr" command (I may be wrong!) can do this but
>I am not sure how. 
>e.g.:
>to convert
>ZACHARIA GEORGE to Zacharia George
>
[...]

You can use the substitution operator to do this, as in:

  @frob = ("MCBAIN", "JACQUES DEMOLAY", "MR. FICTION");
  print join("\n", grep s/\b(\w+)\b/\L\u$1/g, @frob);

which yields:

  Mcbain
  Jacques Demolay
  Mr. Fiction

But is it what you really want? If you're going to do this with a
large number of names, the few exceptions to the rule will cause 
problems, as shown with McBain and DeMolay. I'm not sure how to deal
with exceptions like that except on a case-by-case basis. I have the
same problem in a system I'm working on; lots of names, all in 
uppercase, from all parts of the world.

Hope this helps,

-- 
Brian Jepson * (bjepson@ids.net)  *  http://www.ids.net/~bjepson
  Int(ra|er)net Database Developer, Author, Crypto-Fluxologist
Non-Prophet Arts Technology Flux:      http://www.ids.net/~as220
WWW/Database/NT,Java/Database: http://www.ids.net/~bjepson/books



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

Date: Fri, 21 Mar 1997 15:19:01 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: running the first perl program
Message-Id: <50uug5.iv2.ln@localhost>

Keping Chen (kchen@laurel.ocs.mq.edu.au) wrote:

: I am self-teaching CGI/FORMS, and running the first program. There is
: one problem. My program runs command line okay but not from the browser
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
: Netscape. 


Then you have a CGI question, not a perl question.


The newsgroup for CGI questions is:

comp.infosystems.www.authoring.cgi


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: Fri, 21 Mar 1997 11:59:49 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: x@apocalypse.org
Subject: Re: Single character representing all regexp metacharacters? wheeere?
Message-Id: <Pine.GSO.3.96.970321115840.14218H-100000@kelly.teleport.com>

On Fri, 21 Mar 1997 x@apocalypse.org wrote:

> Is there a single escaped character which represents all the
> metacharacters recognized by the perl regexp engine?

It sounds as if you want to use quotemeta. Does that do anything for you?
Hope this helps!

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: Fri, 21 Mar 1997 12:30:02 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Pedro Vapi <vapi@student.dei.uc.pt>
Subject: Re: Suidperl!
Message-Id: <Pine.GSO.3.96.970321122757.14218M-100000@kelly.teleport.com>

On Fri, 21 Mar 1997, Pedro Vapi wrote:

> I need to run the script wrapsuid to turn my program in binary! It is
> because, i supose, Linux doesn't suport suid scripts...

Actually, although Linux doesn't have setid scripts, Perl can be compiled
to use those (otherwise useless) bits to emulate them so well that you
don't need to use wrapsuid. That's an easier solution, in general. Good
luck!

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: 21 Mar 1997 13:15:57 -0700
From: Vladimir Alexiev <vladimir@cs.ualberta.ca>
Subject: Re: term 'regular expressions' considered undesirable
Message-Id: <ombu8df1c2.fsf@tees.cs.ualberta.ca>

In article <5gt41k$c5v@samba.rahul.net> c.c.eiftj@33.usenet.us.com (Rahul Dhesi) writes:

> The above examples would have been better written as anchored:
> 
>    /^a.*b.*c/	# greedy, needs backtracking, slow, not regular expression
>    /^a.*?b.*?c/  # non-greedy, no backtracking, fast, regular expression

Still wrong. Both match exaclt the same strings. Greedy matching says "return
(one of) the way(s) to match which maximize the (leftmost) greedy *".
Non-greedy match says "return (one of) the way(s) to match which minimizes the
(leftmost) non-greedy match". Neither changes the set of matching strings, nor
the set of ways to match.

> Now the second one needs no backtracking:
>      find an 'a' or fail;
>      skip past all non-'b' characters;
Wrong. Consider /^a.*?b[^b]*?c/ and the string 'abbc'. It will initially pick
the first b in the string as the b in the regexp, assuming that the .*? is
empty.  Then it will have to reconsider and assign one b to the .*?

> A non-anchored version simply repeats the search at every point in the
> search string
This would be a very naive and slow way to implement it.

>    /^a[^b]*?b[^c]*?c/ # non-greedy, no backtracking, fast, regular expression
This one won't need backtracking indeed.

> some patterns are regular expressions and others are not, and calling all of
> them regular expressions is not a good idea.
You have a very wrong idea of what is a regular expression, I'm afraid.
Regular languages are ones that can be produced using regular operations:
empty, letter, concatenation, alternative, and star. The greedy/non-greedy
distinction doesn't come into play here at all. Some of the perl extensions
still keep it regular (eg foo{m,n} is just foo{m}|foo{m+1}|..|foo{n} where
foo{x} stands for 'foo foo ..<x times>.. foo') and some don't (eg (.*)\1 is
not even a context-free language).

How a matcher is implemented (backtracing etc) has no bearing on the langauge
it recognizes (unless it's implemented incorrectly :-). Consider this: DFA
(deterministic automata) and NFA (non-deterministic ones) have the same
expressive power, namely that of regular languages. The standard construction
that converts a NFA into an equivalent DFA takes as states of the DFA to be
the powerset of the states of the NFA. Thus if the NFA has n states, the DFA
has 2^n. Which doesn't mean that any self-respecting programmer will implement
it that way. 

> If we must use a mathematical term, we should use it correctly.
Indeed ;-)


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

Date: 21 Mar 1997 21:43:42 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: term 'regular expressions' considered undesirable
Message-Id: <5guvee$ikd$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    c.c.eiftj@33.usenet.us.com (Rahul Dhesi) writes:
:The important point in all this is that some patterns are regular
:expressions and others are not, and calling all of them regular
:expressions is not a good idea.  The term 'search pattern' or just
:'pattern' is nicely generic and does not cause any confusion.  Those
:being introduced to search patterns for the first time will find no
:useful meaning in the term 'regular expression' anyway, since it's not
:an English term but a mathematical term.  If we must use a mathematical
:term, we should use it correctly.

I'll make a deal: you get everyone to first rename their grep programs to
gspp, and I'll change the perl docs.  Remember that grep allows \1 stuff
in its regular expressions.

Don't we have anything more important to argue about?

--tom
-- 
	Tom Christiansen	tchrist@jhereg.perl.com

    "Yes, you can think of almost everything as a function, but this may upset
    your wife." --Larry Wall


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

Date: Fri, 21 Mar 1997 11:58:14 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Lewis Taylor <lewis@nexusint.com>
Subject: Re: TEST for empty DIR
Message-Id: <Pine.GSO.3.96.970321115113.14218G-100000@kelly.teleport.com>

On Thu, 20 Mar 1997, Lewis Taylor wrote:

> Here is a very long (and primative) routine I wrote to test if the
> directory in $d is empty
> 
> $c=0;
> opendir(D,$d);while(readdir(D)){$c++;}closedir(D);
> if ($c > 2)                  # remember ./ and ../
> {#directory not empty}
> else 
> {#directory empty}
>   
> it works but there must be more elegant code to do the same, is there?

Maybe it's no more elegant, but here's my routine, which will return much
sooner on a large directory. It returns true if you give it the name of an
empty directory. If error checking matters (and it should!) you'll be glad
to know that if it can't open the directory, it will return undef, at
which point you can check $! for the error code.

sub empty_dir ($) {
    local(*DIR, $_);
    return unless opendir DIR, $_[0];
    while (defined($_ = readdir DIR)) {
        next if /^\.\.?$/;
        closedir DIR;
        return 0;
    }
    closedir DIR;
    1;
}

Enjoy!

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: 21 Mar 1997 21:13:49 +0200
From: Jarkko Hietaniemi <jhi@alpha.hut.fi>
Subject: Re: TEST for empty DIR
Message-Id: <oee913hhxci.fsf@alpha.hut.fi>


> why not just skipping . and .. and the next readdir()
> either fails (due to an error or an empty directory)
> or it succeeds ?

Because the '.' and '..' might not be the first two entries.
Been there, seen that.

-- 
$jhi++;
# Jarkko Hietaniemi <URL:http://www.iki.fi/~jhi/> <URL:mailto:jhi@iki.fi>
# Lost interest?  It's so bad I've lost apathy.
# Not speaking for any past, present, or future employers.


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

Date: 21 Mar 1997 13:52:49 GMT
From: pdcawley@aladdin.net (Piers Cawley)
Subject: Re: trouble matching multiple fields
Message-Id: <5gu3rh$6gm$1@gunnar.aladdin.net>

In article <3331CBDF.3B4C@exmachina.com>,
	Paul S R Chisholm <psrc@exmachina.com> writes:
> I have lines of the form:
> 	name field=value field=value
> and want to match the results with a minimum of fuss. I first tried: 
> 	m/^(\w+)(?:\s+(\w+)=(\S+))*$/
> (match the first word, then successive field=value pairs). Interesting
> result: three things are always matched, and $2 and $3 are undefined if
> there are no field=value pairs. Here's some sample text and what appears
> to be matched:
> 
> foo			(foo, undefined, undefined) why match three?
> foo one=1		(foo, one, 1) okay
> foo one=1 two=2		(foo, two, 2) what happened to one and 1?
> 
> I tried:
> 	m/\s+(\w+)=(\S+)*$/g

How about:

my @matches;
s/((\w+)=(\S+))/push(@matches, ($2,$3)),$1/eg 
	if @matches = /^(\w+)(?:\s+|$)/;

It's not quite done in one big match, but it works, which has to be
good news...

-- 
Piers Cawley


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

Date: Fri, 21 Mar 1997 16:03:58 -0500
From: Paul S R Chisholm <psrc@exmachina.com>
Subject: Re: trouble matching multiple fields
Message-Id: <3332F7BE.3D42@exmachina.com>

I maybe sort of now understand why:
>         m/^(\w+)(?:\s+(\w+)=(\S+))*$/
*always* matches three elements (where the second and third are
undefined if there are no key=value pairs to match, and the second and
third are from the *last* key=value pair if there is more than one
pair).

Perl is literally returning the last thing matched by the appropriate
grouping parentheses. I would have guessed, if grouping parentheses
match multiple times (because they're inside a * or + regex or something
else that can match multiple times), they return multiple back
references. I would have guessed wrong. (For one thing, it would wreak
havok with static back references.) It seems like some single Perl
regular expression ought to return all the elements, thus:

input:		returned		above returns:
foo		(foo)			(foo, undef, undef)
foo A=a		(foo, A, a)		(foo, A, a)
foo A=a B=b 	(foo, A, a, B, b)	(foo, B, b)

but I can't think of any single regex that'll do that.

David Bell's reply made me realize that:
>         m/\s+(\w+)=(\S+)*$/g
should have been (if I wanted multiple matches!):
	m/\s+(\w+)=(\S+)/g
which works just fine in array context or in a while loop, ala pp.
252-253 and 258-259 of Jeffrey Friedl's MASTERING REGULAR EXPRESSIONS
(did I mention it's a great book?-)

This approach is a bit of a pain, since I match the beginning in one
regex and everything else in another. It works, though, and there's
something to be said for that....

David Bell's reply was a little bit of a red herring, since he
recommended putting the result in a hash instead of an array. It's array
context either way (and I *do* care about order in this case). I greatly
appreciated the reply, anyway, since it put me on the right track.

--Paul S. R. Chisholm, AirMedia, Inc. (formerly Ex Machina)
mailto:psrc@exmachina.com  http://www.exmachina.com/~psrc
I'm not speaking for the company, I'm just speaking my mind


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

Date: Fri, 21 Mar 1997 14:48:53 -0500
From: Bert Robbins <brobbins@pls.com>
Subject: Re: Unpack Cobol Comp-3 data
Message-Id: <3332E625.4F57@pls.com>

Bill Cowan wrote:
> 
> Yufang &Zhihong Zou wrote:
> >
> > Hi, there,
> >
> > I was looking for some perl scripts or helps to unpack COBOL
> > COMP-3 data into ascii data. Any suggestion will be highly
> > appreciated.
> >
> > Thanks,
> > Zhihong,
> 
> If I remember correctly, COMP-3 is also called "packed decimal", which
> stores one digit in each nibble (or nybble in Camel II), i.e. one digit
> in a group of 4 bits.  If true, then you should consider using
> pack/unpack function and the template character "h" or "H".
> 
> It appears that each h/H position would get one nibble (one digit) out
> of the packed decimal field.  You would still need to be careful of
> where  the plus or minus sign is stored as one nibble.
> 
> Please post any conversion routine that you may develop.

If I remember correctly the formula for determining how many
bytes are used on a Comp-3 is:

  ( number-of-bytes / 2 ) + 1

Example:

  99 VARIABLE-NAME   PIC 9999999999 COMP-3.

  With VARIABLE-NAME contianing the value 1234567890 would 
  result in the following bytes being stored:

    01 23 45 67 89 0F

  Which would mean that you have six bytes. The last nibble
  is the sign and I can't remember what is positive and
  what is negative, but I do remember that a value of "F" means
  that it is unsigned.

--
Bert Robbins


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

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

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