[8455] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2072 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 11 11:15:03 1998

Date: Wed, 11 Mar 98 08:02:09 -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           Wed, 11 Mar 1998     Volume: 8 Number: 2072

Today's topics:
    Re: random numbers? <webmaster@disconova.com>
        Regex & Variables <brian@laserlink.net>
    Re: regexp <rjk@coos.dartmouth.edu>
        rlogin for cgi-skript? (Bjoern Guenzel)
    Re: Skipping within a line to read URL? (John Moreno)
    Re: Speed of sort routine vs. one-by-one compare   (123 (Kenneth Herron)
    Re: Speed of sort routine vs. one-by-one compare (123) <dformosa@st.nepean.uws.edu.au>
        splice -- useful uses? (John Klassa)
        Traversing directory trees. <ckc@dmi.dk>
    Re: Traversing directory trees. <Tony.Curtis+usenet@vcpc.univie.ac.at>
    Re: Uploading files gt 16mb bombs... (Clinton Pierce)
    Re: What is PERL? Learn JAVA instead? <webmaster@disconova.com>
        Where are the Win32 docs? <kairys@mi.sl.com>
    Re: Wierd redirection problem with Location: <dboorstein@shopcfn.com>
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Wed, 11 Mar 1998 17:26:51 +0200
From: Markku Uttula <webmaster@disconova.com>
Subject: Re: random numbers?
Message-Id: <3506AD3B.1411@disconova.com>

mwsasser!nospam!@timetrend.com wrote:
 
>         I'm trying to generate real random numbers but all I generally
> get are numbers from 8 to 14 when I try adding 3 random numbers from 1
> to 6.  Should not 9 be the average number here?  I'm trying
> int(rand(6)+1)   what am I missing?

I'm reading Programming Perl, 2nd edition, finnish translation. In my
book the description for rand is on page 230...

int(rand 6)+1;
^^^      ^  ^
|||      |  |
for round numbers
         |  |
         Multiplier
            |
            this is now 1-6 rather than 0-5

Anyway, I'm sorry, but your question was somewhat unclear. Hope this
helps you out.
-- 
Markku Uttula             | If I ever though you would read this, I
would
webmaster@disconova.com   | have written something useful in here...
http://www.disconova.com/ |                             - Mickey Mouse


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

Date: Wed, 11 Mar 1998 10:22:20 -0500
From: "Brian Morin" <brian@laserlink.net>
Subject: Regex & Variables
Message-Id: <6e6a0j$hsm$1@usenet40.supernews.com>


I'm having a heck of a time trying to change a variable with a regex.
Here is the code.

The input looks like this

Area = "west"

I'm trying to pull out ONLY whats IN the double-quotes, not the quotes
themselves. Then I'm also trying to put that into a variable, or change the
variable that currently holds the information.

$field1 = "Area = \"west\"" # The input is actually from a file.. This is
for testing.
$field1 =~ /"[^"]*"/gi;     # This matches the whole double-quote, and
information inside.
print "$&\n";               # This prints out the string.

I would like to be able to simply change the $field1 with a regex, but can't
get it to fly.

$field2 = ($field1 =~ /"[^"]*"/gi;) # Only produces 1's

Any help is appreciated.

Thanks.

Brian Morin
brian@laserlink.net






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

Date: Tue, 10 Mar 1998 22:22:45 -0500
From: Ronald J Kimball <rjk@coos.dartmouth.edu>
To: bourhis@qcd.th.u-psud.fr
Subject: Re: regexp
Message-Id: <35060387.BFD8C09A@coos.dartmouth.edu>

[posted and mailed]

bourhis@qcd.th.u-psud.fr wrote:
> 
> In article <3500CBD3.8EF643D@coos.dartmouth.edu>,
>   rjk@coos.dartmouth.edu wrote:
> >
> > [posted and mailed]
> >
> > bourhis@qcd.th.u-psud.fr wrote:
> > >
> > > I want to remove the sequence '\n', five spaces and one character which is
> not
> > > whitespace in a string. I tried the regexp /\n {5}\S/ but it does not
> work.
> > > Strangely (for me), the regexp / {5}\S/ and /\n {5}/ works.
> >
> > Are you sure the string only has 5 spaces between the \n and the
> > non-whitespace character?  It sounds to me like it has more than that.
> 
> Yes, you are right, but there should be only 5 spaces. First, here is the code

As it turns out, there are 6 spaces.  Read on.

> #!/usr/local/bin/perl
> 
> open(IN, "example.f");
> @line = <IN>;
> $line = "@line";
          ^^^^^^^

When an array is interpolated into a string, the elements of the array are
separated by the value of the special variable $".  In other words, that
expression is equivalent to
join($", @line);

And, what do you know, the default value of $" is ' ', a space.  So you've
just added a space to the beginning of every line in your input (except the
first).  You target string now has 6 spaces where you are trying to match 5.

A better way to do this would be to do the join yourself:

@lines = <IN>;
$file = join('', @lines);


But if you don't actually need an array of lines later in the script, this is
probably the best way:

undef $/;
$file = <IN>;

$/ is the input record separator.  If its value is undefined, the entire file
is read in all at once.  (Note that I've changed the variable name to $file;
$line was a misnomer.) 

> $line =~ s/\n {5}\S//g;
> print $line;
> 
> and here is the file "example.f" in which I want to remove the sequence '\n',
> five spaces and '_' (the last one could be another non white character so I
> use \S in the regexp).
> ...
>         SUBROUTINE the_big_routine  ( param1   , param2 param23
>      _    param21, param3 )
  ^^^^^
  12345

See the perlvar manpage for more info about $" and $/.

-- 
 _ / '  _      /         - aka -             rjk@coos.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: Wed, 11 Mar 1998 14:53:37 GMT
From: guenzel.p1@usa.net (Bjoern Guenzel)
Subject: rlogin for cgi-skript?
Message-Id: <889627787.19672.0.nnrp-05.c1ed20e5@news.demon.co.uk>

Apologies if this is a trivial question - I admit that I am very new
to Perl and was unable so far to digest the whole of 'Programming
Perl' (you might just point me to the relevant section).

The problem I have is that I want to use a program that is installed
at my university's network with a CGI-script. Only the program seems
only to be available on a certain machine - now I wonder, how can I
make sure my cgi-skript gets executed on that machine? Or can I
somehow have the cgi script to rlogin to that machine?
I suppose qx/rlogin .../ won't work....?-(

A related question might be the one that is stated in the idiots-guide
to solving cgi problems: the script might not be running under my
userid. But the solution to this is not given in the idiots guide. So
do I (as I want it to write files into my directory)

1. somehow make the script log on to run under my UID?

2. somehow give 'wwwuser' write permission to my directories?
(this seems undesireable, as I don't want to give anybody besides my
own script to access my files)

3. write a small kind of server (emon) thingy that is constantly
running under my UID and waits for input from the CGI skript, which it
then sinks into a file?
(I think our sysadmin wouldn't be happy about this :-( )

4. something else?


Sorry if these are just stupid suggestions - I admit that I don't
rally have a clue, but it would be nice to have some direction in
which I should research. I have a thick UNIX book sitting on my table,
and I suppose I could somehow sort out all this group permissions
stuff or server stuff, but it would also cost a lot of time and might
in the end be unrelevant :-(

Therefore I would be thankful for any helpul suggestions!


Bjoern



 



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

Date: Wed, 11 Mar 1998 10:06:15 -0500
From: phenix@interpath.com (John Moreno)
Subject: Re: Skipping within a line to read URL?
Message-Id: <1d5q0ph.eev0tkbihslcN@roxboro0-003.dyn.interpath.net>

Craig Berry <cberry@cinenet.net> wrote:

] Shaila V. Kulkarni (skulk@Glue.umd.edu) wrote:
] : I am having trouble with the following bit and really don't know why
] : my code isn't working.
] 
] Showing your code would help us figure out why.  Otherwise, see
] comp.lang.perl.psychic-friends. :)
] 
] : This line is present in a file i need to read:
] : 
] : [Sun Feb  1 00:07:38 1998] access to /homes/kanlis/public_html/Greek/grlinks.htm
] : l failed for neh116.pdx.oneworld.com, reason: File does not exist
] : 
] : I need to grab only the URL. there are several thousand of these
] : lines and the URLs vary in length. obviously some have more '/' than
] : others.
] 
] Well, if the words 'access to' always precede the url, and it never
] has internal spaces (which I believe you can count on for urls), you
] can do it inelegantly yet effectively with:
] 
]   my ($url) = $line =~ /access to\s+(\S+)/;

That it doesn't have a space would depend upon how the url is being
stored - file names can and do have spaces in them, so that MIGHT not be
able to be guaranteed.

But since it seems to be on just one line. my ($url) = $line =~ /access
to (.+)$/;

Or he might prefer:

  my ($url) = $line =~ m#(\S*/.+)$#;

if there aren't any /'s in the preceding text (which there wasn't in his
example).  Of course both of these assume that the url is on just one
line - not sure what you'd do then.

-- 
John Moreno
I am trying to convince the author of YA-NewsWatcher that the latest
version should be released to the public.  He doesn't think there's much
interest in a new version.  Help me prove him wrong.  To do so, send me
mail <mailto:phenix@interpath.com> with a Subject of New YA.  Comments
on what you like/dislike in the current version will be appreciated.


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

Date: 11 Mar 1998 15:40:49 GMT
From: kherron@campus.mci.net (Kenneth Herron)
Subject: Re: Speed of sort routine vs. one-by-one compare   (123)
Message-Id: <6e6ba1$q4p$1@news.campus.mci.net>

In article <x7sooptxic.fsf@sysarch.com>, Uri Guttman  <uri@sysarch.com> wrote:
|abigail@fnx.com (Abigail) writes:
|
|> Ken Fox (kfox@pt0204.pto.ford.com) wrote on 1653 September 1993 in
|> <URL: news:6e523s$t533@eccws1.dearborn.ford.com>:
|> ++ abigail@fnx.com (Abigail) writes:
|> ++ > Uri Guttman (uri@sysarch.com) wrote:
|> ++ > ++ abigail@fnx.com (Abigail) writes:
|> ++ > 
|> ++ > Rubbish. You got to move a linear number of records. That will dominate
|> ++ > the time spend. 
|> ++ 
|> ++ Abigail is right.  Uri has some very weird ideas about algorithm
|
|i resemble that remark. i happened to have studied algorithm analysis
|with ron rivest (the r of rsa).  
|
|> ++ analysis.  However, Abigail assumes a naive insertion.  If the
|> ++ insertions are cached in memory and memory is large enough to hold all
|> ++ insertions, then the physical movement only has to be done once.  A very
|> ++ efficient linear algorithm with nice sequential disk I/O can do all
|> ++ the insertions at once.
|
|read the problem. a single record inserted into a single file on
|disk. no ram caches, buffers etc. show me how to process all the records
|without doing the same I/O. my solution at least lowers the number of
|record compares. which can add up to signifigant cpu if the compare is
|long or complex and the file is large. I/O is usually not cpu intensive
|and is a CONSTANT for the purposes of analysis.

Once you find the insertion point for the new record, the insertion
time is linear on file size (record count).  That's O(n), and it
doesn't matter how you found the insertion point.  So it's not
unreasonable to ignore this aspect of the process for the moment.

A binary search of the file will take O(log2n) compares (~16 here),
versus O(n) for the linear search (~25,000).  Since each record
has to be read from the file, the compares should be considered 
expensive.  So binary search appears to be winning.

HOWEVER, if you have to recopy the whole file, a linear search lets you
combine the search for the insertion point with the copy of the front
part of the file.  Which means one pass over the file, not prefaced
with a bunch of random-access reads.  Use buffered I/O (e.g. stdio) and
you get all or most of the benefits of big reads.

And, while I/O is pretty efficient on modern systems, it's more of a
heavyweight than you're giving it credit for.  A CPU could do several
hundred or thousand number/string compares in the time it takes to set
up a disk read, not to mention that CPU power is increasing faster than
disk bandwidth and modern servers are generally I/O bound.

Conclusions:  If you can update the file in place (rewrite the tail
portion), then use binary search to find the insertion point.  If you
have to rewrite the whole file, and if the comparison function is
fairly simple (you're sorting on lexical or numerical order instead of
by MD5 hash, for example) then my inclination would be to start by
minimizing I/O, which means the linear search+copy.  But hey,
profile & test.
-- 
Kenneth Herron -- kherron@campus.mci.net
"When Microsoft first took control of the Funk & Wagnalls Encyclopedia
product, there was a flattering biography of Bill Gates.  But it said he
was known as a tough competitor.  Now it says that he's known for his
charitable contributions." -- Gary Reback, <http://www.ljx.com/reback/>


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

Date: 11 Mar 1998 13:18:48 GMT
From: ? the platypus {aka David Formosa} <dformosa@st.nepean.uws.edu.au>
Subject: Re: Speed of sort routine vs. one-by-one compare (123)
Message-Id: <889622327.661877@cabal>

In <x73egpvqf2.fsf@sysarch.com> Uri Guttman <uri@sysarch.com> writes:

[...]

>but as i said ALL algorithms will have the same overhead reading in the
>file and writing it out again. so it it a constant and you ignore it for
>analysis.

Not true,  some alogrthums that are memory hungery will force a meachean
into swapping, this is very detramental to speed.


--
Please excuse my spelling as I suffer from agraphia see the url in my header. 
Never trust a country with more peaple then sheep. 
Support NoCeM http://www.cm.org/                   
I'm sorry but I just don't consider 'because its yucky' a convincing argument


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

Date: 11 Mar 1998 15:26:16 GMT
From: klassa@aursgh.aur.alcatel.com (John Klassa)
Subject: splice -- useful uses?
Message-Id: <6e6aeo$17m$1@aurwww.aur.alcatel.com>

I've been programming in perl (or is that "programming perl"? :-)) for a
few years now.  In that time, I have never once used splice...  Either my
code is more convoluted than it would be, were I to use splice, or splice
just isn't that useful in the application domain in which I operate.

Either way, what do people use splice for?  I know what it does and how to
use it, but I don't really have a handle on cool places it might show up.
I don't know of any handy perl idioms that make use of it, for example.

Food for discussion...

Thanks,
John

-- 
John Klassa / Alcatel Telecom / Raleigh, NC, USA <><


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

Date: 11 Mar 1998 14:46:07 +0100
From: Casper Kvan Clausen <ckc@dmi.dk>
Subject: Traversing directory trees.
Message-Id: <wvpen09jq74.fsf@pratt.ejoper.dmi.min.dk>

Hey all.

This one has given me some headaches...

Given a directory tree and a starting directory, I have to return all
sub-directory paths from the given directory.

Simplified example:

Given the following directory structure:

a-------b
 \
  ------c-------d
         \
          ------e------f--------g
                        \
                         -------h

And given the argument "a c", the output should resemble the
following:

  Possible paths from 'a c' are:

  d
  e f g
  e f h

My only idea so far goes something like this:

sub do_dir {
  opendir(WORK, "$_");
  @content = grep /^[^.]/, readdir WORK;
  close (WORK);
  foreach $file (@content) {
    do_dir $file if -d $file;
  }
}

This is just the basic algorith, of course. It'll need some way of
collecting the directory names and so on, which is trivial.

My problem with this is that TMTOWTDI, and I suspect this head-on
recursive approach is among the least efficient, not to mention hard
to grasp at a glance. I would thus be most pleased if someone could
come up with another approach or point me to an appropriate module.

I would also appreciate pointers to modules which would allow me to
build these sorts of trees and look up possible traversals from a
given node, since there is a chance I can get to rewrite the whole
thing (including data structures).

Thanks in advance,
Kvan.
-- 
-------Casper Kvan Clausen------ | 'Ah, Warmark, everything that passes
----------<ckc@dmi.dk>---------- |  unattempted is impossible.'
           Lokal  544            |   
I do not speak for DMI, just me. |        - Lord Mhoram, Son of Variol.      


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

Date: 11 Mar 1998 15:59:43 +0100
From: Tony Curtis <Tony.Curtis+usenet@vcpc.univie.ac.at>
Subject: Re: Traversing directory trees.
Message-Id: <7xogzdqnmo.fsf@beavis.vcpc.univie.ac.at>

Re: Traversing directory trees., Casper <ckc@dmi.dk> said:

Casper> Given a directory tree and a starting directory, I
Casper> have to return all sub-directory paths from the
Casper> given directory.

Try the File::Find module

-- 
Tony Curtis, Systems Manager, VCPC,      | Tel +43 1 310 93 96 - 12; Fax - 13
Liechtensteinstrasse 22, A-1090 Wien, AT | http://www.vcpc.univie.ac.at/

"Everything I am, I learned on the back of cereal boxes" ~ RJ, "Over the Hedge"


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

Date: 11 Mar 1998 15:04:23 GMT
From: cpierce1@cp500.fsic.ford.com (Clinton Pierce)
To: dwillis@nswc.navy.mil (Diane T. Willis)
Subject: Re: Uploading files gt 16mb bombs...
Message-Id: <6e695n$o473@eccws1.dearborn.ford.com>

In article <1998Mar10.190536.3994@relay.nswc.navy.mil>,
	dwillis@nswc.navy.mil (Diane T. Willis) writes:
>I have a program that accepts any file of your choice and will upload
>it to a designated directory on a server.  Everything works fine until
>the file gets to a certain size, like around 16 MB.  Then it bombs.
>But smaller files work fine.  Anybody have any ideas?  I'm new
>to Perl and thought that variables adjusted automatically.
>
Hmm...a little more info would be helpful:

        1. Does the file transfer 1%?  30%?  99%?  And then fail?
        2. Does the file show up completely, just corrupt?
        3. Are you going through a firewall?
        4. Are you using the standard modules?
        5. Is the questionable Perl on the sending end or the receiving 
	   end?

Aside from all that...

Perl does adjust variables automatically, and in fact will keep enlarging
them until you are out of memory.  (Are you out of memory?)  Is this a
cgi script?  Is there something in the server log (like an "Out of Memory"
message)?

-- 
+------------------------------------------------------------------------+
|  Clinton A. Pierce    |   "If you rush a Miracle Man,   | http://www.  |
|  cpierce1@ford.com    |     you get rotten miracles"    | dcicorp.com/ |
| fubar@ameritech.net   |--Miracle Max, The Princess Bride| ~clintp      |
+------------------------------------------------------------------------+
GCSd-s+:+a-C++UALIS++++P+++L++E---t++X+b+++DI++++G++e+>++h----r+++y+++>y*



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

Date: Wed, 11 Mar 1998 16:20:02 +0200
From: Markku Uttula <webmaster@disconova.com>
Subject: Re: What is PERL? Learn JAVA instead?
Message-Id: <35069D92.385A@disconova.com>

Robert F. Harrison wrote:

>> Perl 4.036, way back in the early 70's[1].  Unfortunately, "Ja
>> Va" means "Yes Go" in Swedish/Spanish (per word) so the name

I'm propably out of line with this comment, but as swedish being my 2nd
native language, I'd like to inform everybody that :

1) "Ja" really means "Yes" in swedish, but
2) "Va" means nothing... if it instead was "Vad" then it'd be "What"

Forget I exist, this was coming outside the subject.

And besides, "Eiffel" has a deeper in some language, can't remember if
it was Heprew or what :)
-- 
Markku Uttula
webmaster@disconova.com


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

Date: Wed, 11 Mar 1998 07:07:25 -0500
From: "Michael Kairys" <kairys@mi.sl.com>
Subject: Where are the Win32 docs?
Message-Id: <35068aa6.0@news.ic.net>

I installed 5.04.04 from the standard source distribution and libwin32 0.10
likewise. The core Perl documentation ended up in lib\Pod\html\pod\*.html;
the Win32 documentation if any didn't end up anywhere.

The Win32 FAQ says "Documentation for Perl for Win32 is provided in HTML
format in the docs subdirectory of your perl directory. This has the
documentation from the standard perl distribution, as well as documentation
for Win32- specific extensions". This doesn't seem to apply.

Three directories of the libwin distribution had docs subdirectories, and
some but not all of the others had pod blocks in the pm files, and from
these I was able to assemble my own docs dirctory, but it is (1) not
complete, and (2) not easy to access, since it is not cross-linked or
indexed.

Is there a complete set of docs out thre anywhere, and/or was there
something wrong with my installatio nthat I didn't get a docs directory with
all this sutff in it as per the FAQ?




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

Date: Wed, 11 Mar 1998 10:36:24 -0500
From: Dan Boorstein <dboorstein@shopcfn.com>
Subject: Re: Wierd redirection problem with Location:
Message-Id: <3506AF78.D4D20062@shopcfn.com>

culrich@i2000.net wrote:
> The combination
> 
>              print "Content-type: text/html\n";
>              print "Location: /page1.htm\n\n";
> 
> is successfully used to redirect to a page on your own server.  This is how
> you tell Perl to do it, and it works perfectly, as described in many Perl
> manuals

what manual are you using? it is wrong. and, with which user agents did
you test this? 

<ANTHROPOMORPHIZE>
perl has no idea that you are printing an http header. it will not fix
your problems for you, and apparently your http server will not either.
</ANTHROPOMORPHIZE>

see this URI:

$u = "Location: http://www.cis.ohio-state.edu/htbin/rfc/rfc2068.html";
print "$u\n\n";

see section 14.30.


-- 
# dan boorstien <dboorstein@shopcfn.com>
seek DATA,0,0;print($_=<DATA>),__END__
Just another Perl hacker,


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

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

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