[18043] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 203 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 2 18:10:38 2001

Date: Fri, 2 Feb 2001 15:10:17 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <981155417-v10-i203@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 2 Feb 2001     Volume: 10 Number: 203

Today's topics:
        Initial Caps <barryg@kingcon.com>
    Re: Initial Caps shanmughom_sivasubra@my-deja.com
        mod_perl and htaccess <wells@cedarnet.org>
        Newbie Q.  How I install DBI on win32? <vortex@inetfree.net>
    Re: Opera Hotlist To HTML <tore@extend.no>
        Ordering elements in hash tables nair_anoop@my-deja.com
    Re: Ordering elements in hash tables <motiNOvus@hotSPAMmail.com>
    Re: Ordering elements in hash tables <tony_curtis32@yahoo.com>
        Ouput pdf file from perl script br.hcc@rlg.org
    Re: Perl 5.6 Solaris (2.6 & 2.8) memory problems (Ilya Zakharevich)
        Perl Puzzle! wtf is going on here... cookconsulting@my-deja.com
    Re: Perl Puzzle! wtf is going on here... (Gary E. Ansok)
    Re: Perl Puzzle! wtf is going on here... (Craig Berry)
    Re: regexp <Kien_Ha@Mitel.COM>
    Re: replace a matched string (Garry Williams)
    Re: saving the name and value for a variable <ren.maddox@tivoli.com>
    Re: saving the name and value for a variable tanase_costin@my-deja.com
    Re: search index/stop words/performance (Eric Bohlman)
        select and perlvar <thoren@southern-division.com>
    Re: Simple Random Number Problem <dperham@dperham.eng.tvol.net>
    Re: Simple Random Number Problem <dperham@dperham.eng.tvol.net>
        teste <barryg@kingcon.com>
        Trouble with split (LK)
    Re: Trouble with split tigra@sky.deep.ru
        Vim quickfix mode with Perl (=?iso-8859-1?Q?J=F6rg?= Ziefle)
    Re: Why can't my DTD work? (Eric Bohlman)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 2 Feb 2001 17:06:44 -0800
From: "Barry Glick" <barryg@kingcon.com>
Subject: Initial Caps
Message-Id: <F3D71846642C7031.2F367D7AA052277B.1AD7779D470FD0C9@lp.airnews.net>

I'm in a on-line web master class, now learning to do CGI/PERL scripts.  The
class has very little in the way of help, so I help some one in this
newsgroup can help me.

My assignment was to create a simple CGI script that will take input from
the user in a form, strip out the extraneous characters (+,=,&), then print
it with the first letter of each word capitalized.  I can almost do it with
this:

$value =~ s/\s(\w)/ \u$1/g;

But that only capitalizes the first letter of every word AFTER the first
one, since the first word has no space.  Can anyone tell me how to
capitalize the first letter of ALL words entered into, say, a text box of an
HTML form?

Thanks in advance for any help.

Barry Glick
barryg@kingcon.com






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

Date: Fri, 02 Feb 2001 22:40:49 GMT
From: shanmughom_sivasubra@my-deja.com
Subject: Re: Initial Caps
Message-Id: <95fd1f$r0s$1@nnrp1.deja.com>

You can try

  $value = s/(\w)(\w|\s)/\u$1/g;

In article
<F3D71846642C7031.2F367D7AA052277B.1AD7779D470FD0C9@lp.airnews.net>,
  "Barry Glick" <barryg@kingcon.com> wrote:
> I'm in a on-line web master class, now learning to do CGI/PERL
scripts.  The
> class has very little in the way of help, so I help some one in this
> newsgroup can help me.
>
> My assignment was to create a simple CGI script that will take input
from
> the user in a form, strip out the extraneous characters (+,=,&), then
print
> it with the first letter of each word capitalized.  I can almost do
it with
> this:
>
> $value =~ s/\s(\w)/ \u$1/g;
>
> But that only capitalizes the first letter of every word AFTER the
first
> one, since the first word has no space.  Can anyone tell me how to
> capitalize the first letter of ALL words entered into, say, a text
box of an
> HTML form?
>
> Thanks in advance for any help.
>
> Barry Glick
> barryg@kingcon.com
>
>


Sent via Deja.com
http://www.deja.com/


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

Date: Fri, 02 Feb 2001 15:55:25 -0600
From: Steve Wells <wells@cedarnet.org>
Subject: mod_perl and htaccess
Message-Id: <3A7B2CCD.9C1029F9@cedarnet.org>


I have an extranet with a lot of the code heavily "stolen" from
Lincoln's Cookie-Based Access Control libraries in "Writing Apache
Modules in Perl and C".  I would like to add the ability to block off
directories based on a require directive within the .htaccess files.

In other words if I wanted only users "Tom and Randal" and group "god"
to access the directory I would like to setup my .htaccess like so:

---------
require users Tom Randal
require group god

---------

Those familiar with the book will recognize that earlier in the chapter
(chap. 6) there is a section which covers parsing this information,
however it is my belief that because the directive is called as,
PerlAccessHandler and not PerlAuthenHandler nor PerlAuthzHandler it
doesn't seem to recognize the require directive.

My question is:

Does my conclusion hold any water?

How would I go about getting the results of the require methods since my
program doesn't seem to have access to them?

Should I parse the .htaccess files by hand?  What's a better way?

Can you point me to more information on this topic?  Is there a better
place to post these types of questions?

TIA,
STEVE


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

Date: Fri, 2 Feb 2001 13:30:20 -0800
From: "vortex" <vortex@inetfree.net>
Subject: Newbie Q.  How I install DBI on win32?
Message-Id: <t7m9qaaarasq16@corp.supernews.com>

Hello, my name is Geoffrey Gertken, my email is at vortex@inetfree.net.  My
question is how do I install the DBI module or DB_File module on my win32
machine running win98se.  Thanks.




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

Date: Fri, 2 Feb 2001 20:26:53 +0100
From: Tore Aursand <tore@extend.no>
Subject: Re: Opera Hotlist To HTML
Message-Id: <MPG.14e5286bd53084ee989885@news.online.no>

In article <3A7A8FCD.F60F0FBD@web.de>, daniel42@web.de says...
> I want to write a little script which converts the opera
> hotlist file (.adr, I think) to HTML. (So that I can put
> my bookmarks on the net and surf from other places.) But
> I could not figure out how opera reconstructs the tree
> structure of the bookmark folders from the .adr file. Does
> anyone here know that?

Yes.  Every folder inside a folder has an extra line with a '-' in the 
 .adr file.  Very easy to understand if you compare the text file with 
the layout of the bookmarks which Opera generates.

> Sorry if you think that's OT but my hope is that any perl
> programmer here has already written such a tool and
> therefore solved the problem.

No excuse;  This is *totally* off-topic, as it has absolutely *nothing* 
to do with Perl (except the fact that you want to use Perl to solve a 
problems which has nothing to do with Perl). :)

Try one of the Opera newsgroups next time, and DO NOT reply to this 
message in this newsgroup.  I'm reading most of the Opera newsgroups, 
so you can reach me there.


-- 
Tore Aursand - tore@extend.no - http://www.extend.no/~tore/


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

Date: Fri, 02 Feb 2001 20:53:23 GMT
From: nair_anoop@my-deja.com
Subject: Ordering elements in hash tables
Message-Id: <95f6nu$krr$1@nnrp1.deja.com>

I am using a %FORM hash table in Perl to contain
all ($key, $value) pairs from a HTML form after
parsing them appropriately. However, if I simply
use a foreach ... top print these values on
screen, they are not printed in the order the
input boxes are palced on screen. Is there a
special mechanism to get them in the right
order ? I need this since I need to write down
the data in a flat file.

Thanks in advance.


Sent via Deja.com
http://www.deja.com/


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

Date: Fri, 2 Feb 2001 13:35:10 -0800
From: "B McDonald" <motiNOvus@hotSPAMmail.com>
Subject: Re: Ordering elements in hash tables
Message-Id: <tLFe6.44$gp6.68495@news.pacbell.net>


<nair_anoop@my-deja.com> wrote in message
news:95f6nu$krr$1@nnrp1.deja.com...
> I am using a %FORM hash table in Perl to contain
> all ($key, $value) pairs from a HTML form after
> parsing them appropriately. However, if I simply
> use a foreach ... top print these values on
> screen, they are not printed in the order the
> input boxes are palced on screen. Is there a
> special mechanism to get them in the right
> order ? I need this since I need to write down
> the data in a flat file.
>

there is a module that allows you to do this, but it carries a hefty
computational penalty. check out the responses to my post on this same
subject, "printing arrays of hashes", from 1/30/01.

brian




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

Date: 02 Feb 2001 15:51:58 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Ordering elements in hash tables
Message-Id: <87vgqsbvnl.fsf@limey.hpcc.uh.edu>

>> On Fri, 02 Feb 2001 20:53:23 GMT,
>> nair_anoop@my-deja.com said:

> I am using a %FORM hash table in Perl to contain all
> ($key, $value) pairs from a HTML form after parsing them
> appropriately. However, if I simply use a foreach
> ... top print these values on screen, they are not
> printed in the order the input boxes are palced on
> screen. Is there a special mechanism to get them in the
> right order ? I need this since I need to write down the
> data in a flat file.

There is no "right order".  The elements of a hash are not
ordered.  Even worse in this case, there is no restriction
on what order the fields are sent you by the
browser/user-agent *nor* how a particular
browser/user-agent might lay out the fields from the form
on its display.

What you can do is to define the required order of the
fields in your program (array) and iterate over that to
extract the fields' values.

Also, it sounds like you are using some nasty old CGI
library, you might want to consider moving to using the
CGI.pm module:

    perldoc CGI

Fwups set to comp.infosystems.www.authoring.cgi which IMHO
is more relevant.

hth
t
-- 
Eih bennek, eih blavek.


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

Date: Fri, 02 Feb 2001 22:24:09 GMT
From: br.hcc@rlg.org
Subject: Ouput pdf file from perl script
Message-Id: <95fc1t$pv1$1@nnrp1.deja.com>

Hi,
   I'm new to this group. I wrote a simple perl
script to output a pdf file to STDOUT:

#!perl
 print "Content-type: application/pdf\n\n";
 open(PDF,"my.pdf");
 while(<PDF>) {
  print $_;
 }
 close(PDF);

  This code doesn't work as my browser just displays blank screen. I
use the same code to output tiff and jpg files and that works ok. Any
help is highly appreciated.

hc


Sent via Deja.com
http://www.deja.com/


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

Date: 2 Feb 2001 21:41:48 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Perl 5.6 Solaris (2.6 & 2.8) memory problems
Message-Id: <95f9is$ri9$1@charm.magnus.acs.ohio-state.edu>

[A complimentary Cc of this posting was sent to 
<pangloss@stefan.com>],
who wrote in article <95dg27$5t3$1@nnrp1.deja.com>:
> Folks,
> 
> I seem to be having a memory problem with Perl 5.6 and Solaris
> (versions 2.6 & 2.8). This memory issue doesn't seem to occur when
> running the same Perl program under AIX, Linux or Digital Unix.

>     alignbytes=8, usemymalloc=y, prototype=define

Try to re-Configure with -Uusemymalloc.  Do not think this will
improve things (I expect things to get worse), but short of fixing
Solaris bugs, this may be the only action you may perform now...

Ilya


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

Date: Fri, 02 Feb 2001 19:47:21 GMT
From: cookconsulting@my-deja.com
Subject: Perl Puzzle! wtf is going on here...
Message-Id: <95f2s6$ha6$1@nnrp1.deja.com>

I have slaved over a script to separate out the month from a web server
log, and it works, however something very unusual happens: <> swallows
the first non-matching line.  Here is the code and sample execution
passage, and test results.

Anyone have any idea why this happens?  Workaround?

thanks in advance,
Cook
#############################
#!/usr/bin/perl
# perlpuzzle.pl
# usage:  perl perlpuzzle.pl Jan access

$Month=shift; # first argument is Month to separate out
$LogData ="";

#read in file from command line, skipping lines where the netscape
#  log format date Month doesn't match the command line parameter
while(  <> !~  m/(\d+)\.(\d+)\.(\d+)\.(\d+)(\s)(\W)(\s)(\W)(\s)(\[)(\d
{2})\/$Month\//)
{}

#collect the rest of the log file entries...
while (  <>)
{ $LogData = $LogData.$_; }

# Note: tried for the above:
# while (  <>  =~  m/(\d+)\.(\d+)\.(\d+)\.(\d+)(\s)(\W)(\s)(\W)(\s)(\[)
(\d{2})\/$Month\//)
# didn't work... wtf!?

print "$LogData";
$LogData ="";
print "\ntest section\n";

@testdata= (qq|93.136.100.28 - - [08/Dec/2000:18:49:22 -
0800] "POST /sessionservice HTTP/1.0" 200 689|,
qq|94.136.100.28 - - [08/Dec/2000:18:49:22 -
0800] "POST /notificationservice HTTP/1.0" 200 2|,
qq|95.136.100.28 - - [08/Dec/2000:18:49:22 -0800] "POST /loggingservice
HTTP/1.0" 200 163|,
qq|96.16.184.59 - - [08/Dec/2000:18:49:09 -
0800] "GET /images/productLogo.gif HTTP/1.0" 304 -|,
qq|97.16.184.59 - - [08/Dec/2000:18:49:09 -
0800] "GET /images/SNAWhite.gif HTTP/1.0" 304 -|,
qq|98.16.184.59 - - [08/Dec/2000:18:49:09 -
0800] "GET /images/productName.gif HTTP/1.0" 200 878|,
qq|99.136.192.112 - - [31/Dec/2000:16:41:02 -
0800] "POST /sessionservice HTTP/1.0" 200 721|,
qq|100.136.192.111 - - [01/Jan/2001:08:51:25 -
0800] "POST /sessionservice HTTP/1.0" 200 722|,
qq|101.136.192.112 - - [01/Jan/2001:08:51:25 -
0800] "POST /sessionservice HTTP/1.0" 200 722|,
qq|102.136.192.113 - - [01/Jan/2001:08:51:27 -0800] "GET /login
HTTP/1.0" 200 1091|,
qq|103.136.192.114 - - [01/Jan/2001:08:51:34 -
0800] "POST /sessionservice HTTP/1.0" 200 352|,
qq|104.136.192.115 - - [01/Jan/2001:08:51:34 -
0800] "GET /images/productLogo.gif HTTP/1.0" 200 4149|,
qq|105.136.192.116 - - [01/Jan/2001:08:52:17 -
0800] "POST /sessionservice HTTP/1.0" 200 352|,
qq|106.136.192.111 - - [01/Jan/2001:08:51:33 -
0800] "POST /sessionservice HTTP/1.0" 200 344|);


foreach $line  (@testdata)
{
if ($line !~  m/(\d+)\.(\d+)\.(\d+)\.(\d+)(\s)(\W)(\s)(\W)(\s)(\[)(\d
{2})\/$Month\//)
{ next;}
else
{$LogData =$LogData."\n".$line;}
}

print "$LogData";

__END__;
#place in file "access" for above:
93.136.100.28 - - [08/Dec/2000:18:49:22 -0800] "POST ... HTTP/1.0" 200
689
94.136.100.28 - - [08/Dec/2000:18:49:22 -
0800] "POST /notificationservice HTTP/1.0" 200 2
95.136.100.28 - - [08/Dec/2000:18:49:22 -0800] "POST /loggingservice
HTTP/1.0" 200 163
96.16.184.59 - - [08/Dec/2000:18:49:09 -
0800] "GET /images/productLogo.gif HTTP/1.0" 304 -
97.16.184.59 - - [08/Dec/2000:18:49:09 -0800] "GET /images/SNAWhite.gif
HTTP/1.0" 304 -
98.16.184.59 - - [08/Dec/2000:18:49:09 -
0800] "GET /images/productName.gif HTTP/1.0" 200 878
99.136.192.112 - - [31/Dec/2000:16:41:02 -0800] "POST /sessionservice
HTTP/1.0" 200 721
100.136.192.111 - - [01/Jan/2001:08:51:25 -0800] "POST /sessionservice
HTTP/1.0" 200 722
101.136.192.112 - - [01/Jan/2001:08:51:25 -0800] "POST /sessionservice
HTTP/1.0" 200 722
102.136.192.113 - - [01/Jan/2001:08:51:27 -0800] "GET /login
HTTP/1.0" 200 1091
103.136.192.114 - - [01/Jan/2001:08:51:34 -0800] "POST /sessionservice
HTTP/1.0" 200 352
104.136.192.115 - - [01/Jan/2001:08:51:34 -
0800] "GET /images/productLogo.gif HTTP/1.0" 200 4149
105.136.192.116 - - [01/Jan/2001:08:52:17 -0800] "POST /sessionservice
HTTP/1.0" 200 352
106.136.192.111 - - [01/Jan/2001:08:51:33 -0800] "POST /sessionservice
HTTP/1.0" 200 344


#########test results
101.136.192.112 - - [01/Jan/2001:08:51:25 -0800] "POST /sessionservice
HTTP/1.0" 200 722
102.136.192.113 - - [01/Jan/2001:08:51:27 -0800] "GET /login
HTTP/1.0" 200 1091
103.136.192.114 - - [01/Jan/2001:08:51:34 -0800] "POST /sessionservice
HTTP/1.0" 200 352
104.136.192.115 - - [01/Jan/2001:08:51:34 -
0800] "GET /images/productLogo.gif HTTP/1.0" 200 4149
105.136.192.116 - - [01/Jan/2001:08:52:17 -0800] "POST /sessionservice
HTTP/1.0" 200 352
106.136.192.111 - - [01/Jan/2001:08:51:33 -0800] "POST /sessionservice
HTTP/1.0" 200 344


test section

100.136.192.111 - - [01/Jan/2001:08:51:25 -0800] "POST /sessionservice
HTTP/1.0" 200 722
101.136.192.112 - - [01/Jan/2001:08:51:25 -0800] "POST /sessionservice
HTTP/1.0" 200 722
102.136.192.113 - - [01/Jan/2001:08:51:27 -0800] "GET /login
HTTP/1.0" 200 1091
103.136.192.114 - - [01/Jan/2001:08:51:34 -0800] "POST /sessionservice
HTTP/1.0" 200 352
104.136.192.115 - - [01/Jan/2001:08:51:34 -
0800] "GET /images/productLogo.gif HTTP/1.0" 200 4149
105.136.192.116 - - [01/Jan/2001:08:52:17 -0800] "POST /sessionservice
HTTP/1.0" 200 352
106.136.192.111 - - [01/Jan/2001:08:51:33 -0800] "POST /sessionservice
HTTP/1.0" 200 344

## wtf!?  it's the same regex matching!  why does <> swallow the first
non-matching line? (100.136.192.111 - - [01/Jan/2001..)


Sent via Deja.com
http://www.deja.com/


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

Date: 2 Feb 2001 20:29:15 GMT
From: ansok@alumni.caltech.edu (Gary E. Ansok)
Subject: Re: Perl Puzzle! wtf is going on here...
Message-Id: <95f5ar$n2k@gap.cco.caltech.edu>

In article <95f2s6$ha6$1@nnrp1.deja.com>,  <cookconsulting@my-deja.com> wrote:
>I have slaved over a script to separate out the month from a web server
>log, and it works, however something very unusual happens: <> swallows
>the first non-matching line.  Here is the code and sample execution
>passage, and test results.
>
>Anyone have any idea why this happens?  Workaround?
>
>while(  <> !~  m/(\d+)\.(\d+)\.(\d+)\.(\d+)(\s)(\W)(\s)(\W)(\s)(\[)(\d
>{2})\/$Month\//)
>{}

Every time you reference <>, you read a line of input.  The above is
roughly equivalent to

loop:  $temp = <>;
       goto loop if $temp !~ m!pattern!;

If you walk though this code, you should see why you're losing a line.
(You only get the automatic assignment to $_ when <> is the only
thing in the condition, like in your next loop.)

I might write just one loop, like this:

    while (<>) {
        next unless m!pattern!;
        $LogData .= $_;
    }

or

    while (<>) {
        $LogData .= $_ if m!pattern!;
    }

The first one is easier to extend to more complicated processing, and
it seems clearer to me.

-- Gary Ansok


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

Date: Fri, 02 Feb 2001 21:57:07 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Perl Puzzle! wtf is going on here...
Message-Id: <t7mb9jn34ejr54@corp.supernews.com>

cookconsulting@my-deja.com wrote:
: I have slaved over a script to separate out the month from a web server
: log, and it works, however something very unusual happens: <> swallows
: the first non-matching line.
[muchos snippos]

Your test reads each line and tests it.  When a line doesn't match, you
exit that loop...and then read another line at the beginning of the
processing section.  The line that triggered loop exit gets thrown away.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "When the going gets weird, the weird turn pro."
   |               - Hunter S. Thompson


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

Date: Fri, 02 Feb 2001 19:42:03 GMT
From: Kien Ha <Kien_Ha@Mitel.COM>
Subject: Re: regexp
Message-Id: <3A7B0D62.D7C69F04@Mitel.COM>

Robert Morrissey wrote:
> 
> Hi,
>     I'm looking for a way to match something 'unless' it occurs in a certain
> way, I'll give an example as this isn't clear:
> 
> I have (say) a string that is "mp3s/01-perl-is-great.mp3" and want to rename
> it as "mp3s/01-perlisgreat.mp3", so I am looking for a way to say replace
> all "-" with "" unless "-" occurs after a forward slash and two digits. I'm
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

$_ = "mp3s/01-perl-is-great.mp3";
s#(?<!\/\d{2})-##g;


> not asking for a regular expression obviously, this was just an example --
> but rather I am banging my head against the wall for a way to incorporate an
> 'unless' into a regexp -- is this possible?
> 
   
perldoc perlre.
having a look at the 'zero-width assertion' section in perlre may help.


> Thanks in advance,
> 
>     Robert Morrissey


-- 
Kien


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

Date: Fri, 02 Feb 2001 21:49:18 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: replace a matched string
Message-Id: <yXFe6.541$Sn3.20643@eagle.america.net>

On Fri, 02 Feb 2001 09:55:54 GMT, Ian Boreham <iboreham@my-deja.com>
wrote:
>In article <Yppe6.411$Sn3.15609@eagle.america.net>,
>  garry@zvolve.com (Garry Williams) wrote:
>
>> Use a different match that explicitly matches *only* the part that you
>> want replaced instead of the whole string:
>>
>>   s/(book_.*?)\b/$1_buff/g;
>
>This is OK, but I'd prefer:
>
> s/(book_\w+)/$1_buff/g;
>
>which is more explicit (and more concise).

[snip]

>In general, if you only want a certain type of character to be matched,
>specify only that kind.

Yup.  The `.' can't really be part of the OP's specification.  It's
likely \w.  Didn't really think about it; I just kept it from his
attempt.  

You make a good point.  

Now that I think about it. I have to admit that sometimes *false*
laziness is why I use .* or .+ instead of what I really want.  

-- 
Garry Williams


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

Date: 02 Feb 2001 14:10:06 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: saving the name and value for a variable
Message-Id: <m3k8784zj5.fsf@dhcp11-177.support.tivoli.com>

tanase_costin@my-deja.com writes:

>  Does anybody have a hint how to find out the name of a variable, as it
> is used in the Perl script? What I mean is:

Basically no.  There have been one or two threads asking this
recently, and though there are things that seem like they might work
at first glance, they fail when lexical variables come into play.

>  I use the following syntax
> 
>   $avar = 1;
>   print HANDLE "\$avar = ".$avar."\n";
> 
>  As I repeat this kind of lines over and over in my script I would like
>  to define a function, "nameofvar" in such a way that

In general, when you store a value somewhere, you don't really care
about the name of where you are storing it.  (Well, as a programmer
you care, so that you can get it back again, but that's not what I
mean.)  If you are in a situation where the name of where you are
storing the value is also important, then you probably want to use a
hash instead of a variable.

>  nameofvar($avar) to return the name used in my program for it.

If you use a hash, then you would have something like $hash{akey},
where "akey" would be the name of the "variable".  Then you wouldn't
even need the "nameofvar" routine.

If you need more information on exactly how to use this, feel free to
ask.

-- 
Ren Maddox
ren@tivoli.com


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

Date: Fri, 02 Feb 2001 22:10:11 GMT
From: tanase_costin@my-deja.com
Subject: Re: saving the name and value for a variable
Message-Id: <95fb7q$p8q$1@nnrp1.deja.com>


>  Ren Maddox <ren.maddox@tivoli.com> wrote:

> tanase_costin@my-deja.com writes:
>
> >  Does anybody have a hint how to find out the name of a variable, as
it
> > is used in the Perl script? What I mean is:
>
> Basically no.  There have been one or two threads asking this

 Sorry..., next time I'll try harder to find previous similar questions.

> If you need more information on exactly how to use this, feel free to
> ask.
> Ren Maddox
> ren@tivoli.com

 Thank you a lot, your answer give me confidence that I am not using
machine-guns against flies... What I do is to use a hash and tie
function. In this way, as you point out I have the key the value and
everything I need is read-write to file at dbmopen-close time ,

 Thanks again,

 Costin Tanase





Sent via Deja.com
http://www.deja.com/


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

Date: 2 Feb 2001 20:51:38 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: search index/stop words/performance
Message-Id: <95f6kq$4kj$1@bob.news.rcn.net>

Craig Bennett <theclyde@mindless.com> wrote:
> My jokes site has 26 directories (some have subdirectories). They are
> filled with jokes as .txt files.  I wrote a program to create an index file
> for search purposes, with a modest stoplist. The file is set up with one
> joke per line (see below). The index file is 500k

> directory/filename.ext|Keyword1Keyword2keyword3

> It does the search by opening the file, then going through each line to see
> if the requested keywords are in it. The search is working, but it is a bit
> slower than i would like it.

> Is there any easy way for me to increase the speed? Is having a large file
> slowing it down? Would using several smaller index files increase the
> speed?

Try turning your logic inside out so that instead of associating file 
names with lists of keywords, you associate keywords with lists of file 
names.  The best way to do this is to make the file a tied DBM hash 
where the keys are keywords and the values are comma/pipe/whatever 
separated lists of the filenames containing the keyword.  That way all it 
takes is a single hash lookup rather than a linear search.  The downside 
is that you're trading speed for space; if, as seems reasonable, the 
filenames are longer than the individual keywords, storing lists of 
filenames will take up more space.  But it sounds like the tradeoff would 
be worth it in this case.


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

Date: Fri, 2 Feb 2001 23:11:22 +0100
From: Thoren Johne <thoren@southern-division.com>
Subject: select and perlvar
Message-Id: <MPG.14e54ee2a634a07a989827@news.btx.dtag.de>

is there a place in perldoc, where i can see if a special variable is on 
a 'per filehandle basis', like the example in 'perldoc -f select' says:

$oldfh = select(STDERR); $| = 1; select($oldfh);

problem is: i thought that analogous to the above example

$oldfh = select(STDERR); $\ = ' err '; select($oldfh);
$oldfh = select(STDOUT); $\ = ' out '; select($oldfh);

print STDOUT "hello";
print STDOUT "world!";
print STDERR "hello";
print STDERR "world!";

should yield:
hello out world! out hello err world! err

but what it prints is: 
hello out world! out hello out world! out

does 'select' actual work as expected with '$|' but not with '$\'?

-- 
----------------------------------------------------------------------
Thoren Johne - 8#X - thoren@southern-division.com
Southern Division Classic Bikes - www.southern-division.com


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

Date: 02 Feb 2001 15:00:07 -0500
From: Doug Perham <dperham@dperham.eng.tvol.net>
Subject: Re: Simple Random Number Problem
Message-Id: <8166isony0.fsf@wgate.com>

"What A Man !" <whataman@home.com> writes:

> Why am I getting 2 numbers for $td in the coding below?
> Most of the time $td turns out to be 3 numbers, but
> occasionally I get 2 numbers, such as 44 or 78 (and they
> are even lower numbers than what I have specified).

try 
 
  perldoc -f rand

your usage of rand is confused

> 
> ### random number for temp directories
> $td = rand(@num = 100 .. 1000);

rand expects a scalar. the returned number will be between 0 and the
supplied scalar.  you are passing it a 901 element array. it does not
work with arrays, so it converts it into a scalar. the scalar value of
an array is the number of elements it contains, thus your line of code
is a long winded way of saying

 $td = rand(901);

this will yield a random value between 0 and 901, which is why you are
getting numbers under 100 (roughly 1/9th of the time, i'd imagine)

try this 

 $td = 100 + rand(900);

this will yield values between 100 and 1000


> @td = split ( /\./, $td );
> $td = $td[0];
> $tmpdir = "$dir/$td";
> 
> Thanks,
> Dennis

-- 
Doug Perham                                          o{..}o     
dperham@wgate.com                                moo! (oo)___   
WorldGate Communications, Inc.                        (______)\ 
                                                      / \  / \  


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

Date: 02 Feb 2001 15:08:37 -0500
From: Doug Perham <dperham@dperham.eng.tvol.net>
Subject: Re: Simple Random Number Problem
Message-Id: <813ddwonju.fsf@wgate.com>


Oops I forgot something else

Doug Perham <dperham@dperham.eng.tvol.net> writes:

> "What A Man !" <whataman@home.com> writes:
> 
> > Why am I getting 2 numbers for $td in the coding below?
> > Most of the time $td turns out to be 3 numbers, but
> > occasionally I get 2 numbers, such as 44 or 78 (and they
> > are even lower numbers than what I have specified).
> 
> try 
>  
>   perldoc -f rand
> 
> your usage of rand is confused
> 
> > 
> > ### random number for temp directories
> > $td = rand(@num = 100 .. 1000);
> 
> rand expects a scalar. the returned number will be between 0 and the
> supplied scalar.  you are passing it a 901 element array. it does not
> work with arrays, so it converts it into a scalar. the scalar value of
> an array is the number of elements it contains, thus your line of code
> is a long winded way of saying
> 
>  $td = rand(901);
> 
> this will yield a random value between 0 and 901, which is why you are
> getting numbers under 100 (roughly 1/9th of the time, i'd imagine)
> 
> try this 
> 
>  $td = 100 + rand(900);
> 
> this will yield values between 100 and 1000
> 
> 
> > @td = split ( /\./, $td );
> > $td = $td[0];

that is called making an integer from a floating point number the "hard
way". Ouch!

  $td = int($td);


> > $tmpdir = "$dir/$td";
> > 
> > Thanks,
> > Dennis
> 
> -- 
> Doug Perham                                          o{..}o     
> dperham@wgate.com                                moo! (oo)___   
> WorldGate Communications, Inc.                        (______)\ 
>                                                       / \  / \  

-- 
Doug Perham                                          o{..}o     
dperham@wgate.com                                moo! (oo)___   
WorldGate Communications, Inc.                        (______)\ 
                                                      / \  / \  


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

Date: Fri, 2 Feb 2001 12:49:08 -0800
From: "Barry Glick" <barryg@kingcon.com>
Subject: teste
Message-Id: <73EBEE459E6FA1B6.B133EAB04EA7EF4E.CA25C4D1A5A52145@lp.airnews.net>

hellow




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

Date: Fri, 02 Feb 2001 19:32:49 GMT
From: lkenny@fisheries.org (LK)
Subject: Trouble with split
Message-Id: <3a7b0abb.21967837@wingate>

I have written a piece of code that is supposed to split a string on a
box.  the code is as follows:

	open(FILE,"$file") || die("Cannot open file $file: $!"); 
	$data = do { local $/; <FILE>; };
	close (FILE);
 	$data =~ s/\n/"|"/eg;
  	@data = split(//, $data);                     
	open (FIEL, ">>$dats");
 	print FIEL "$data\n\n\n";
	print FIEL "@data";

$data has many boxes in it that indicate a record break.  So I want to
split on it and make eac record a pipe-delimited file.  When @data
prints out, the boxes are gone, but it hasn't split.  It just deleted
the boxes.  Is the box character a "special" one, and that is why it
isn't working.  Or is there something I'm missing in the split
function to make it execute properly.

Once again, all help is appreciated.

LK


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

Date: Fri, 02 Feb 2001 20:50:08 GMT
From: tigra@sky.deep.ru
Subject: Re: Trouble with split
Message-Id: <95f6hs$kpb$1@nnrp1.deja.com>

In article <3a7b0abb.21967837@wingate>,
  lkenny@fisheries.org (LK) wrote:
> I have written a piece of code that is supposed to split a string on a
> box.  the code is as follows:
>
> 	open(FILE,"$file") || die("Cannot open file $file: $!");
> 	$data = do { local $/; <FILE>; };
> 	close (FILE);
>  	$data =~ s/\n/"|"/eg;
>   	@data = split(/ /, $data);
> 	open (FIEL, ">>$dats");
>  	print FIEL "$data\n\n\n";
> 	print FIEL "@data";
>
> $data has many boxes in it that indicate a record break.  So I want to
> split on it and make eac record a pipe-delimited file.  When @data
> prints out, the boxes are gone, but it hasn't split.  It just deleted
> the boxes.  Is the box character a "special" one, and that is why it
> isn't working.  Or is there something I'm missing in the split
> function to make it execute properly.
>
> Once again, all help is appreciated.

First of all, why do you use s/\n/"|"/eg instead of just s/\n/|/g ?
Next: just can't get what you mean under "boxes". As I've understood a
"box" is just an ordinary "space". Considering this, your problem is
both in split and print.
When you split the substring matching your split pattern actually goes
nowhere. Only the substrings between matches will populate the target
list. So this is the place where the "spaces" are deleted.
So when you ask perl to print "@data" it just does the following:
print join($", $data);
So it's common that $" = ''; The result is obvoiuos: you see the output
as if delimeters were deleted.

BTW. Splitting strings with more than one "boxes"  groupped together
will result in empty records. Then this would help:
split / +/, $data;

Sergey


Sent via Deja.com
http://www.deja.com/


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

Date: 2 Feb 2001 19:23:04 GMT
From: gt4556a@acmex.gatech.edu (=?iso-8859-1?Q?J=F6rg?= Ziefle)
Subject: Vim quickfix mode with Perl
Message-Id: <slrn97m28o.q23.gt4556a@acmex.gatech.edu>

There must be hordes of Perl hackers using Vim.

Does anybody use the quickfix mode within Vim (and even the perl
debugger?)?

Jörg Ziefle


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

Date: 2 Feb 2001 21:00:15 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Why can't my DTD work?
Message-Id: <95f74v$4kj$2@bob.news.rcn.net>

u8526505@ms27.hinet.net wrote:
> I'm using XML:Parser module but it always ignore my DTD setting.
> For example
> if I set my DTD like this
> <!ELEMENT  person (Name+)>
> <!ELEMENT  Name   (CDATA)>
> the parser won't give any error message even I lost the <Name> tag.
> Do I need more modules to enable this function?

Yep.  XML::Parser is non-validating.  You'll need XML::Checker or one of 
its relatives, which can be found in the libxml-enno package on CPAN.



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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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

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

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 203
**************************************


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