[19307] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1502 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 12 14:05:36 2001

Date: Sun, 12 Aug 2001 11:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <997639508-v10-i1502@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 12 Aug 2001     Volume: 10 Number: 1502

Today's topics:
    Re: A persistant 'study'? (Anno Siegel)
        Accessing a widget when defined local to a sub <Pcmann1@btinternet.com>
    Re: Get rid of some ratio ftp <murat.uenalan@gmx.de>
    Re: how to test $X le 'z' (Anno Siegel)
    Re: how to test $X le 'z' <flavell@mail.cern.ch>
    Re: Learning Perl, 2nd Edition (Dat Nguyen)
    Re: Learning Perl, 2nd Edition (Randal L. Schwartz)
    Re: Learning Perl, 2nd Edition <godzilla@stomp.stomp.tokyo>
    Re: Line counting in a file (Yves Orton)
    Re: Need help with error trying to use string as ARRAY  <shutupsteve@awdang.no.thanks.com>
    Re: Newbie Question: Can't write file in data directory <bkennedy99@Home.com>
    Re: Newbie Question: Can't write file in data directory (David Efflandt)
    Re: Newbie Question: Can't write file in data directory <webmaster@dsxs.net>
        Perl -w and -W flags <holland@origo.ifa.au.dk>
    Re: Perl -w and -W flags <ilya@martynov.org>
    Re: Regular expression to take HTML comments out?? (Anno Siegel)
        searching files from linux to Internet (brian)
    Re: searching files from linux to Internet (Tad McClellan)
    Re: Shouldn't sub foo {} be equivalent to sub foo {retu <tinamue@zedat.fu-berlin.de>
    Re: Shouldn't sub foo {} be equivalent to sub foo {retu (Martien Verbruggen)
    Re: Unexplained process killing (Moran Goldstein)
    Re: Warning  pragma -w (Chas Friedman)
    Re: Warning  pragma -w <gnarinn@hotmail.com>
        Win32::Console - reading input (Glenn)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 11 Aug 2001 22:51:39 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: A persistant 'study'?
Message-Id: <9l4ctr$ll9$2@mamenchi.zrz.TU-Berlin.DE>

According to D. Bron <DBron@Flashmail.NOSPAM.com>:
> Hello,
> 
> Is it possible to save the study() of a string?  I have a script 
> that searches a very large text file.  The text file never 
> changes, but the regular expressions which search it do.  I'd 
> like to use study() on the text file once, and thereafter use 
> that study() each time I run my script (with different regular 
> expressions).  Actually, I'd prefer to somehow save the study() 
> of each line of the file, and be able to reference them later 
> somehow (perhaps with an array).  Can I do this, and if so, how?

I am not aware of a method to make study() results persistent (save
them to file), if that's what you're asking.  You can't even have
more than one study()'d string in a program at one time, as the
documentation says.  I'm afraid that approach won't work as you hope.

Anno


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

Date: Sun, 12 Aug 2001 19:01:27 +0100
From: "Peter Mann" <Pcmann1@btinternet.com>
Subject: Accessing a widget when defined local to a sub
Message-Id: <9l6g85$a0g$1@uranium.btinternet.com>

Dear All,
In the following example, 'my' is used to keep combo1 local to the sub
'donotebook', because otherwise I get errors when using 'strict', such as:

           "Global symbol "$combo1" requires explicit package name at nb4.pl
line 48."

But then, since its local to 'denotebook' how can I access it from the other
sub 'fillCombo'?

I wanted to avoid moving all items from denotebook out of the function and
global because in my full version, I have more pages in the notebook, and
hence it would get messy.

Could someone please advise me on how this should be best structured, the
examples Ive looked at are all different from this example.

Thanks in advance,
  - Pete





use Tk;
use Tk::DialogBox;
use DBI;
use Tk::NoteBook;
use Tk::LabEntry;
use TK::BrowseEntry;
use strict;

use vars qw($top);

$top = MainWindow->new;
my $pb = $top->Button(-text => "Notebook", -command => \&donotebook);
$pb->pack;
MainLoop;

my $f;

sub donotebook {
    if (not defined $f) {

 $f = $top->DialogBox(-title => "Example",
        -buttons => ["OK", "Cancel"]);
 my $n = $f->add('NoteBook', -ipadx => 6, -ipady => 6);

 my $page1_p = $n->add("page1", -label => "Page 1");
 my $page2_p = $n->add("page2", -label => "Page 2");

 my $combo1=$page1_p->BrowseEntry(-label=>"combo box : ");
 $combo1->pack(-side=>'top', -anchor=>'nw');


 $n->pack(-expand => "yes",
   -fill => "both",
   -padx => 5, -pady => 5,
   -side => "top");
  }
  my $result = $f->Show;
}





sub fillCombo
{
  $combo1->insert('end', "one", "two", "three");
}






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

Date: Sun, 12 Aug 2001 19:58:33 +0200
From: "Murat Uenalan" <murat.uenalan@gmx.de>
Subject: Re: Get rid of some ratio ftp
Message-Id: <9l6fui$7ier0$1@ID-71895.news.dfncis.de>

Sounds like he wants to test the performance of ftp-servers without leaving
a file (and a sign of intrusion) on it.

"Martien Verbruggen" <mgjv@tradingpost.com.au> schrieb im Newsbeitrag
news:slrn9nco26.cq.mgjv@martien.heliotrope.home...
> On Sun, 12 Aug 2001 14:31:06 +0800,
> Foot <crud_alex@yahoo.com> wrote:
> > Is there any way to check how many percentage of a file is completed
while
> > retrieveing it using Net:FTP?
>
> Call the retr() method on the object that represents your connection.
> What comes back from $ftp->retr() is a Net::FTP::dataconn object, which,
> as the manual page explains, can be treated as a IO::Socket::INET
> object.  It has a read() method that you can use to get the data in
> blocks. between blocks, you can do things.
>
> > Then kill the process once the file's completion reach 99%?
>
> Why would you ever want to do this?
>
> Martien
> --
> Martien Verbruggen              |
> Interactive Media Division      |
> Commercial Dynamics Pty. Ltd.   | What's another word for Thesaurus?
> NSW, Australia                  |




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

Date: 11 Aug 2001 23:26:32 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: how to test $X le 'z'
Message-Id: <9l4ev8$ll9$4@mamenchi.zrz.TU-Berlin.DE>

According to Ilya Martynov  <ilya@martynov.org>:
> 
> jp> I seem to be having a problem testing for the value of a character
> jp> variable.
> jp> the code is as follows
> 
> jp> for ( $letter = 'a' ; $letter le 'z'; $letter++)
> jp> {
> jp>  print $letter."\n";
> jp> }
> 
> 
> jp> Now I would think this would print the letters a to z but 
> jp> instead it prints  a to zz.
> 
> jp> What am I doing wrong?
> 
> You are using ++ for string. In Perl operator ++ used with string is
> magical (see 'perldoc perlop' chapter 'Auto-increment and
> Auto-decrement') so
> 
>     $letter = 'z';
>     $letter ++;
>     print $letter;
> 
> will print 'aa' instead of '{' (next char in ASCII table after 'z').

True, but that shouldn't stop anyone from using ++ on strings to
walk through the alphabet.  All you have to do is adjust the loop
condition.  A little more compact:

my $letter = 'a';
print $letter++, "\n"  while $letter ne 'aa';

Anno


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

Date: Sun, 12 Aug 2001 19:19:24 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: how to test $X le 'z'
Message-Id: <Pine.LNX.4.30.0108121910300.29384-100000@lxplus023.cern.ch>

On Aug 11, Anno Siegel twiddled the eigenstates thus:

> my $letter = 'a';
> print $letter++, "\n"  while $letter ne 'aa';

How's that look on EBCDIC-based platforms, then?  perldoc perlport
makes a number of points about (not) relying on specific properties of
chr(), pack() and so on, but it doesn't seem to mention anything
specifically about ++ on strings.  Whereas the perlop Auto-increment
section which you mentioned, doesn't say anything one way or the other
about EBCDIC.  I don't have an EBCDIC-based platform at my disposal
just now, so I thought I might just ask whether the "magic" was strong
enough to deal with that.





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

Date: 12 Aug 2001 10:18:28 -0700
From: thucdat@hotmail.com (Dat Nguyen)
Subject: Re: Learning Perl, 2nd Edition
Message-Id: <6b1f50ac.0108120918.3d99cc34@posting.google.com>

hakonrk@fys.uio.no (Haakon Riiser) wrote in message news:<slrn9ncvjs.a9.hakonrk@s.hn.org>...
> [Randal L. Schwartz]
> 
> > The second edition is a fine book, but I also think the third edition
> > is better.  Those are not contradictory positions!  Although depending
> > on your goals they may end up supporting different behaviors.
> 
> I was planning on using Perl in Unix system administration, replacing
> sed & awk for many tasks.  I've heard that the 3rd edition is targeted
> less towards Unix users, so I think I'll keep the 2nd edition.  I assume
> the difference between Perl 5.004 and 5.6 isn't very important in an
> introductory book such as this.
> 
> Anyway, thanks for answering my question!

With the upcoming "Parrot", should I bother with "Programming Perl
3rd" and "Learning Perl 3rd" at all?

Dat


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

Date: 12 Aug 2001 10:25:48 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Learning Perl, 2nd Edition
Message-Id: <m1d76142cj.fsf@halfdome.holdit.com>

>>>>> "Dat" == Dat Nguyen <thucdat@hotmail.com> writes:

Dat> With the upcoming "Parrot", should I bother with "Programming Perl
Dat> 3rd" and "Learning Perl 3rd" at all?

If you don't want to use Perl for the next two or three years, sure.
Perl6 is still a *long* ways off.

And, most of what the camel and llama teach you will be perfectly
applicable in Perl6.  Most people will probably only notice the syntax
of references and array/hash elements changing, and some would say for
the better and more DWIMmier.  The Perl5 team has also committed to
sticking around for a half dozen years or so as well, maintaining the
old code base, so there's still a lot of Perl5 life left.

print "Just another Perl hacker,"

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Sun, 12 Aug 2001 10:48:19 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Learning Perl, 2nd Edition
Message-Id: <3B76C163.CE27DE12@stomp.stomp.tokyo>

Randal L. Schwartz wrote:
 
> >>>>> Dat Nguyen wrote:
 
> > With the upcoming "Parrot", should I bother with "Programming Perl
> > 3rd" and "Learning Perl 3rd" at all?

> If you don't want to use Perl for the next two or three years, sure.
> Perl6 is still a *long* ways off.
 
> And, most of what the camel and llama teach you will be perfectly
> applicable in Perl6.  Most people will probably only notice the syntax
> of references and array/hash elements changing, and some would say for
> the better and more DWIMmier.  The Perl5 team has also committed to
> sticking around for a half dozen years or so as well, maintaining the
> old code base, so there's still a lot of Perl5 life left.
 

A note of humor for you, Randal. 

When Perl 5 is no longer supported, I am certain these geeks
will say, as they do about Perl 4,

    "Perl 5 is a Flea Bitten Dead Camel Carcass and anyone
     who uses Perl 5 is a total idiot."


Godzilla!  Queen Of Perspectival


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

Date: 12 Aug 2001 08:05:31 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: Line counting in a file
Message-Id: <74f348f7.0108120705.2333d77e@posting.google.com>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<9ktis9$g9$1@mamenchi.zrz.TU-Berlin.DE>...
> Look, I'm sure I'm not only speaking for myself when I say that I
> appreciate your contributions to the group.  It is however a rule
> that code you post should be tested (unless there are compelling
> reasons not to, which should be mentioned in the text).  If you fail
> to do so, that will be noted.
> 
> Anno

Fair comment anno. I'll be more on the ball next time.

Yves


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

Date: Sun, 12 Aug 2001 11:01:22 -0700
From: "Stephen Deken" <shutupsteve@awdang.no.thanks.com>
Subject: Re: Need help with error trying to use string as ARRAY ref...
Message-Id: <tndh2qqgsnt463@corp.supernews.com>

>     Thanks for the help..  I was even able to debug one very small error.
I
> got to change bcvset to bcvsets.  :)  I also took your advice and added
the
> or die to the open file.

Ergh, that's what I get for not testing my code.  Sorry about that.

--sjd;




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

Date: Sun, 12 Aug 2001 17:18:25 GMT
From: "Ben Kennedy" <bkennedy99@Home.com>
Subject: Re: Newbie Question: Can't write file in data directory of a Win2000 server
Message-Id: <BTyd7.96427$EP6.24073759@news1.rdc2.pa.home.com>


"tonyc" <trx32@home.com> wrote in message
news:belbnt4u83civqbei8uscl5hmck9duddd8@4ax.com...
>
>
> I'm new to Perl and am trying to get a simple counter script to work.
> It seems to be able to read the counter.txt file ok (it's in the data
> directory) but I can't get it to write the new file count to the file.
> When I open the file handle and code it for a warning, I get nothing
> at all and the file isn't written with the new value. I thought I
> should have gotten a warning or something that it could not
> open the file.....

Are your warnings going the web server's error log?  Various web servers
(such as apache) will dump all text to STDEER inth the error log.  You can
try including your error directly into the returned text (via STDOUT), which
may yield better results.  You should also include the system errno
variable, e.g.

open(my $handle, ">$file") or warn "Cannot open $file for writing: $!";

--Ben Kennedy




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

Date: Sun, 12 Aug 2001 17:49:03 +0000 (UTC)
From: see-sig@from.invalid (David Efflandt)
Subject: Re: Newbie Question: Can't write file in data directory of a Win2000 server
Message-Id: <slrn9ndgcf.ls6.see-sig@typhoon.xnet.com>

On 11 Aug 2001 20:09:08 -0500, tonyc <trx32@home.com> wrote:
> 
> I'm new to Perl and am trying to get a simple counter script to work.
> It seems to be able to read the counter.txt file ok (it's in the data
> directory) but I can't get it to write the new file count to the file.
> When I open the file handle and code it for a warning, I get nothing
> at all and the file isn't written with the new value. I thought I
> should have gotten a warning or something that it could not
> open the file.....
> 
>      Anybody ever seen this happen?

Yes, but this is NOT a Perl question, the same would happen in any
programming language.  Your CGI does not have write permission for the
file, but you wouldn't know that even from server logs because the warn
message fails to include the reason for the error ($!).  Try inserting the
following near the beginning of the script if you want to see warn or die
messages in your browser instead of server logs:

use CGI::Carp qw(fatalsToBrowser);

This count would not be accurate on a busy site because more than one
instance of the script may read and increment the same count at the same
time.  It should open the file for read/write, flock it and not close it
until it has written the new count to it.  More to it than that, but 
basically it needs some work.

-- 
David Efflandt  (Reply-To is valid)  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: Sun, 12 Aug 2001 19:48:15 +0200
From: "Steven Wüthrich" <webmaster@dsxs.net>
Subject: Re: Newbie Question: Can't write file in data directory of a Win2000 server
Message-Id: <3b76c1ce$1_2@news.bluewin.ch>


"tonyc" <trx32@home.com> wrote in message
news:belbnt4u83civqbei8uscl5hmck9duddd8@4ax.com...
>
>
> I'm new to Perl and am trying to get a simple counter script to work.
> It seems to be able to read the counter.txt file ok (it's in the data
> directory) but I can't get it to write the new file count to the file.
> When I open the file handle and code it for a warning, I get nothing
> at all and the file isn't written with the new value. I thought I
> should have gotten a warning or something that it could not
> open the file.....
>
>      Anybody ever seen this happen?
>
> I am perplexed.
>
> here is the code:
>
> The input routine works fine. The graphix routines work fine.
> The counter get's incremented just fine, But I cannot get the
> darned thing to write back out to the counter.txt file with the
> new value. My file permissions seem to be ok. It reads the
> counter.txt file but will not write to it.
>
> thankx in advance.....!
>
> Duh, here is the code this time.....
>
> #!/usr/bin/perl
>
> ######################################################################
> #  BEFORE TRYING TO EDIT THIS SCRIPT, READ THE README FILE
> ######################################################################
> #
> #     The Dream Catcher's Web Free CGI Scripts
> #     Simple Counter
> #
> #     Created by Seth Leonard
> #
> #     http://dreamcatchersweb.com/scripts/
> #
> #     (c)2000 Seth Leonard
> #     All Rights Reserved
> #
> ######################################################################
> # ONLY EDIT THIS PART OF THE SCRIPT!!
>
> $number_of_digits = "4";
> $end = ".gif";
>
> $pathtocounter = "data/counter.txt";
> # images  work ok - they are in the cgi-bin directory...
> $pathtoimages = "";
>
> $graphics = "yes";
>
> # DO NOT EDIT BELOW THIS LINE!!
>
############################################################################
>
> # Tell Browser
>
> print ("Content-type: text/html\n\n");
>
> # Get Count
>
> open (COUNTER, "$pathtocounter") or  warn "Cannot open file
> $pathtocounter";
>
>
> $count = <COUNTER>;
>
>
> chop ($count) if $count =~ /\n$/;
> close (COUNTER) or warn "Cannot close file $pathtocounter";
>
> # Increase Count
>
> $count += 1;
>
>
>
>
> # write the new count back to the file:
>
> open (COUNTER, ">$pathtocounter") or  warn "Cannot open file
> $pathtocounter";
> print COUNTER  "$count" ;
> close (COUNTER);
>
> @digits = split(//, $count);
>
> if ($number_of_digits eq "") {
>         $howmany = @digits;
> } else {
>         $howmany = $number_of_digits;
> }
>
> # Give empty digits a value
>
> $spline = '%0' . $howmany . 'd';
> $count = sprintf("$spline", $count);
>
> @digitimages = split(//, $count);
>
> # Print Output Counter
>
> foreach $digitimage (@digitimages) {
> if ($graphics eq yes) {
>         $image = "<img src=$pathtoimages" . "$digitimage" . "$end>";
> print ("$image");
> } else {
>         $plain = $digitimage;
>   print ("$plain");
> }
> }
>
> exit;
>

The code seems all right to me. But try what Ben said before,
append the $! to the code, in order to see what excactely went
wong. It might be that you havent permission to write in the file?!
What OS is the serverrunning on, win UNIX etc?!!?
You might also want to try tainting your filehandles with the
appropriate switch (T) in the first line, after #!/usr.......blabla/ T.
that way there wont be any confusion in case two or more user
want to write/update the file at the same time. Consult the perldoc
for clarity on that.

Hope it helps a little, post another one if
it still doesnt work!

bye now, Steve




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

Date: 12 Aug 2001 19:30:52 +0200
From: Steve Holland <holland@origo.ifa.au.dk>
Subject: Perl -w and -W flags
Message-Id: <w47vgjttcc3.fsf@origo.ifa.au.dk>


     Could someone please tell where I can find a description of which
warnings the -w and -W flags turn on.  I've not been able to find it
in perldoc, but it is possible that I am missing the obvious.  The
only description that I have been able to find is from running perl
with the -h flag.

  -w              enable many useful warnings (RECOMMENDED)
  -W              enable all warnings

I'm running Perl5.6.0 under SunOS 5.7.

=====================================================================
               To find out who and where I am look at:
               http://www.nd.edu/~sholland/index.html
  Spammers: Please send spam to: abuse@aol.com and abuse@yahoo.com
=====================================================================



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

Date: 12 Aug 2001 21:53:28 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Perl -w and -W flags
Message-Id: <87zo955fmv.fsf@abra.ru>


SH>      Could someone please tell where I can find a description of which
SH> warnings the -w and -W flags turn on.  I've not been able to find it
SH> in perldoc, but it is possible that I am missing the obvious.  The
SH> only description that I have been able to find is from running perl
SH> with the -h flag.

SH>   -w              enable many useful warnings (RECOMMENDED)
SH>   -W              enable all warnings

It is described in 'perldoc perllexwarn' chapter 'Controlling Warnings
from the Command Line'.

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Date: 11 Aug 2001 23:09:34 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Regular expression to take HTML comments out??
Message-Id: <9l4dve$ll9$3@mamenchi.zrz.TU-Berlin.DE>

According to Carlos C. Gonzalez  <miscellaneousemail@yahoo.com>:
> Hi everyone,
> 
> Since I am relatively new at using regular expressions and Perl in 
> general I was wondering if someone could give me some feedback on the 
> following regexp.  It strips the $string of the HTML comment statement 
> and any text in between them.  
> 
> Is there a faster and / or clearer, better way to do this?  
> 
> The code:
> 
> #!/usr/bin/perl -w
> 
> use CGI::Carp qw(carpout fatalsToBrowser);
> use diagnostics;
> use strict;
> 
> my $string = "Hello<!-- BEGIN -->there!<!-- END --> How are you?";
> $string =~s/<!-- BEGIN -->.+<!-- END -->//;
> print $string;

Oh dear... regex parsing of HTML.  It won't work.

For one, your substitution will erase everything between the first
comment in a sting and the last, because the .+ in the middle is greedy.
But even if you fixed that (which is possible) there are places in HTML
where the string "<!-- BEGIN -->" can appear without introducing
a comment, which will confuse the hell out of your regex. 

The upshot of many similar discussions on this group is: If you want
to parse HTML, use HTML::Parser.

Anno



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

Date: 12 Aug 2001 09:43:12 -0700
From: brian@numenor.screaming.net (brian)
Subject: searching files from linux to Internet
Message-Id: <1b9ec5ec.0108120843.27b75c9c@posting.google.com>

hi, i've written a program which searches the text for specified words
or phrases in all of the files in specified directories. it works as
hoped when tested on my linux box but when i make a couple of small
changes to make it search folders on the internet i keep getting
server error 500.
heres the code for the one that works:

#! /usr/bin/perl

###############################################
# option 1 = match complete phrase            #
# option 2 = match all words in any order     #
# option 3 = match any word                   #
# for option 1 if entire phrase isn't matched #
# the program returns this result and then    #
# checks to see if any words are              #
# matched...                                  #
###############################################

############################################################
# get strings, set initial values etc
############################################################

$found = 0;
@directoryList = (".", ".."); ### add directories to be searched

print("Enter option: ");
$option = <STDIN>;
chomp($option);
print("Enter Search string: ");
$search = <STDIN>;
chomp($search);

if ($option == 1)
   {
    &matchEntirePhrase;
   }
if ($option == 2)
   {
    &matchAllWords;
   }
if ($option == 3)
   {
    &matchAnyWord;
   }

##############################################################
# subroutines to do the searching                 
##############################################################

sub matchEntirePhrase
{
foreach $dir (@directoryList)
   {
    opendir(DIR, $dir)||print("could not open $dir\n");
    @fileList = readdir(DIR);
    closedir(DIR);
    foreach $file (@fileList)
       {
        @temp = ($dir, $file);
        $file = join("/", @temp);
        open(FILE, $file)||print("could not open $file \n");
        @text = <FILE>;
        close(FILE);
        $text = join(" ",@text);
        if ($text =~ /$search/)
          {
           print("$search, Exact match found in $file \n");
           $found = 1;
          }
       }
   }
if (!$found)
  {
   print("Exact phrase not found\n");
   &matchAnyWord;
  }
    
}

##############################################################

sub matchAllWords
{
foreach $dir (@directoryList)
   {
    opendir(DIR, $dir)||print("could not open $dir \n");
    @fileList = readdir(DIR);
    closedir(DIR); 
    foreach $file (@fileList)
       {
        @temp = ($dir, $file);
        $file = join("/", @temp);
        open(FILE, $file)||print("could not open $file \n");
        @text = <FILE>;
        close(FILE);
        $text = join(" ", @text);
           $found = 1;
           @splitSearch = split(/ +/, $search);
           $total = @splitSearch;
           $count = 0;
           while ($count < $total)
              {
               $check = $splitSearch[$count];
               $check =~ tr/ //;
               if ($text !~ /$check/)
                 {
                  $found = 0;
                 }
               $count++;
              }
           if ($found)
             {
              $atLeastOneRecordFound = 1;
              print("All words matched in file $file \n");
             }
       }
   }
if (!$atLeastOneRecordFound)
  {
   print("$search No files contain all of those words\n");
  }
}  

#################################################################

sub matchAnyWord
{
$found = 0;
foreach $dir (@directoryList)
   {
    opendir(DIR, $dir)||print("could not open $dir \n");
    @fileList = readdir(DIR);
    closedir(DIR);
    foreach $file (@fileList)
       {
        @temp = ($dir, $file);
        $file = join("/", @temp);  
        open(FILE, $file)||print("could not open $file \n");
        @text = <FILE>;
        close(FILE);
        $text = join(" ", @text);
        @words = split(/ +/, $search);
        foreach $word (@words)
           {
            if ($text =~ /$word/)
              {
               $found = 1;
               $foundList = join(" ",@matchedFiles);
               if ($foundList !~ $file)
                 {
                  push(@matchedFiles, $file);
                 }
              }
           }
       }
   }
if ($found)
  {
   foreach $match (@matchedFiles)
      {
       print("Some words matched in $match \n");
      }
  }
else
  {
   print("no words matched in any file\n");
  }
}     

############################################################
################ end #######################################
############################################################

the second one accepts the search text and search options from an html
form:

#! /usr/bin/perl

###############################################
# option 1 = match complete phrase            #
# option 2 = match all words in any order     #
# option 3 = match any word                   #
# for option 1 if entire phrase isn't matched #
# the program returns this result and then    #
# checks to see if any words are              #
# matched...                                  #
###############################################

############################################################
# get strings, set initial values etc
############################################################
Use CGI;
$searchQuery = new CGI;
$search = $searchQuery->param('search');
$option = $searchQuery->param('option');

print "Content-type: text/html\n\n";

print qq|
<html>
<title> Search Result </title>
<body>
Search results for $search<br><br>
|;
 
$found = 0;
@directoryList = ("/home/hinkiec/www/search"); ###add directories to
be searched

#print("Enter option: ");
#$option = <STDIN>;
#chomp($option);
#print("Enter Search string: ");
#$search = <STDIN>;
#chomp($search);

if ($option == 1)
   {
    &matchEntirePhrase;
   }
if ($option == 2)
   {
    &matchAllWords;
   }
if ($option == 3)
   {
    &matchAnyWord;
   }

##############################################################
# subroutines to do the searching                 
##############################################################

sub matchEntirePhrase
{
foreach $dir (@directoryList)
   {
    opendir(DIR, $dir)||print("could not open $dir\n");
    @fileList = readdir(DIR);
    closedir(DIR);
    foreach $file (@fileList)
       {
        @temp = ($dir, $file);
        $file = join("/", @temp);
        open(FILE, $file)||print("could not open $file \n");
        @text = <FILE>;
        close(FILE);
        $text = join(" ",@text);
        if ($text =~ /$search/)
          {
           print("$search, Exact match found in $file \n");
           $found = 1;
          }
       }
   }
if (!$found)
  {
   print("Exact phrase not found\n");
   &matchAnyWord;
  }
    
}

##############################################################

sub matchAllWords
{
foreach $dir (@directoryList)
   {
    opendir(DIR, $dir)||print("could not open $dir \n");
    @fileList = readdir(DIR);
    closedir(DIR); 
    foreach $file (@fileList)
       {
        @temp = ($dir, $file);
        $file = join("/", @temp);
        open(FILE, $file)||print("could not open $file \n");
        @text = <FILE>;
        close(FILE);
        $text = join(" ", @text);
           $found = 1;
           @splitSearch = split(/ +/, $search);
           $total = @splitSearch;
           $count = 0;
           while ($count < $total)
              {
               $check = $splitSearch[$count];
               $check =~ tr/ //;
               if ($text !~ /$check/)
                 {
                  $found = 0;
                 }
               $count++;
              }
           if ($found)
             {
              $atLeastOneRecordFound = 1;
              print("All words matched in file $file \n");
             }
       }
   }
if (!$atLeastOneRecordFound)
  {
   print("$search No files contain all of those words\n");
  }
}  

#################################################################

sub matchAnyWord
{
$found = 0;
foreach $dir (@directoryList)
   {
    opendir(DIR, $dir)||print("could not open $dir \n");
    @fileList = readdir(DIR);
    closedir(DIR);
    foreach $file (@fileList)
       {
        @temp = ($dir, $file);
        $file = join("/", @temp);  
        open(FILE, $file)||print("could not open $file \n");
        @text = <FILE>;
        close(FILE);
        $text = join(" ", @text);
        @words = split(/ +/, $search);
        foreach $word (@words)
           {
            if ($text =~ /$word/)
              {
               $found = 1;
               $foundList = join(" ",@matchedFiles);
               if ($foundList !~ $file)
                 {
                  push(@matchedFiles, $file);
                 }
              }
           }
       }
   }
if ($found)
  {
   foreach $match (@matchedFiles)
      {
       print("Some words matched in $match \n");
      }
  }
else
  {
   print("no words matched in any file\n");
  }
}     

############################################################

print qq|
</body>
</html>
|;


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

Date: Sun, 12 Aug 2001 13:09:55 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: searching files from linux to Internet
Message-Id: <slrn9nde33.1ai.tadmc@tadmc26.august.net>

brian <brian@numenor.screaming.net> wrote:

>hi, i've written a program which searches the text for specified words
>or phrases in all of the files in specified directories. it works as
>hoped when tested on my linux box but when i make a couple of small
>changes to make it search folders on the internet 
                           ^^^^^^^^^^^^^^^^^^^^^^^


Huh? What do you mean by that? 

"internet" is networking. 

"folders" (directories, I assume) are file system components.

networking is not file systems. (and neither of those are the WWW)



>i keep getting
>server error 500.


   perldoc -q 500


>heres the code for the one that works:
>
>#! /usr/bin/perl


You should start every Perl program with:

   #!/usr/bin/perl -w
   use strict;

while developing it.

Perl will give you all kinds of help and clues, but you have
to ask for it. Enabling warnings and strictures is how you ask
perl to help you. Take all the help you can get.


>sub matchEntirePhrase
>{
>foreach $dir (@directoryList)
>   {
>    opendir(DIR, $dir)||print("could not open $dir\n");
>    @fileList = readdir(DIR);
>    closedir(DIR);
>    foreach $file (@fileList)
>       {
>        @temp = ($dir, $file);
>        $file = join("/", @temp);


Those 2 lines are a strange way of building the pathname:

   $file = "$dir/$file";


>        open(FILE, $file)||print("could not open $file \n");


Why are you continuing with program execution when the open() fails?

Your purpose is to search the file, right? If you cannot search
the file, then it seems you should abort, not plow ahead.

At the very least, you should not be reading from FILE if the
open() failed, you won't be reading anything anyway.

You should include the $! variable in your diag message, it will
tell you _why_ the open() failed.


   open(FILE, $file) || die("could not open '$file'  $!");

or without parens:

   open FILE, $file or die "could not open '$file'  $!";



>               $check =~ tr/ //;


That statement doesn't do anything.

If you want to "d"elete space characters, then you want:

   $check =~ tr/ //d;



>################ end #######################################
>
>the second one accepts the search text and search options from an html
>form:
>
>#! /usr/bin/perl
>

>Use CGI;
 ^
 ^

Syntax error. This will cause a 500 error.

(But that is easily diagnosed by looking at your server logs,
 which you have probably already done.
)


>@directoryList = ("/home/hinkiec/www/search"); ###add directories to


That looks like a plain pathname too.


I don't see any "folders on the internet" anywhere in your code.
So I guess I have no idea what you are talking about. Sorry.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 12 Aug 2001 16:00:08 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: Shouldn't sub foo {} be equivalent to sub foo {return} or sub foo {()} ?
Message-Id: <9l6968$7qppb$2@fu-berlin.de>

Philip Newton <pne-news-20010812@newton.digitalspace.net> wrote:
> On 12 Aug 2001 11:32:21 GMT, Tina Mueller <tinamue@zedat.fu-berlin.de>
> wrote:

>> sub using {return} returns undef always.

> Well, or the empty list (if called in list context).

oops. maybe i wanted to say something like "nothing" instead of undef.
"nothing" would be undef in scalar context and the empty
list in list context.
i'll be more careful next time =)
-- 
http://www.tinita.de \  enter__| |__the___ _ _ ___
tina's moviedatabase  \     / _` / _ \/ _ \ '_(_-< of
search & add comments  \    \ _,_\ __/\ __/_| /__/ perception
---   Warning: content of homepage hopelessly out-dated   ---


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

Date: Mon, 13 Aug 2001 02:05:19 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Shouldn't sub foo {} be equivalent to sub foo {return} or sub foo {()} ?
Message-Id: <slrn9nda9v.cq.mgjv@martien.heliotrope.home>

On 12 Aug 2001 14:07:29 GMT,
	Tina Mueller <tinamue@zedat.fu-berlin.de> wrote:
> Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
>> On Sun, 12 Aug 2001 08:29:57 -0400,
>> 	Bernie Cosell <bernie@fantasyfarm.com> wrote:
>>> mgjv@tradingpost.com.au (Martien Verbruggen) wrote:
>>> } 
>>> } just makes no more sense to me than it returning its own argument list.
>>> 
>>> Yeah, but how about only returning its argument list in list context and
>>> returning undef in scalar context.  *that* makes more sense??  :o)
> 
>> Heh, yeah, well.. No, it doesn't.
> 
>> I'd probably vote for this to be called 'unspecified behaviour' rather
>> than a bug. It's not behaving contrary to any documentation, it's just
>> behaving weirdly. And that falls under unspecified :)
> 
> there's another unspecified behaviour:
> 03:56pm tina@lux:perl 665> perl -wle'
> sub test {@_}
> @_ = (2,3,4);
> @x = &test;
> print "<@x>"'
><2 3 4>
> 03:57pm tina@lux:perl 666> perl -wle'
> sub test {}
> @_ = (2,3,4);
> @x = &test;
> print "<@x>"'
><>
> 03:57pm tina@lux:perl 667> perl -wle'
> sub test {}
> @_ = (2,3,4);
> @x = &test(@_);
> print "<@x>"'
><2 3 4>
> 
> and perlsub says:
>|        &foo;               # foo() get current args, like foo(@_) !!
> 
> but in the above example you can see that &test behaves
> different from &test(@_)

Indeed. And to make the list more complete:

martien:5.6.1/pod$ perl -wl
sub test {}
sub foo { @x = &test; print "<@x>" }
foo(2,3,4)
<>
martien:5.6.1/pod$ perl -wl
sub test {}
@x = test(2,3,4);
print "<@x>"
<2 3 4>

*sigh* hardly consistent in whichever way you like to look at it.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | This matter is best disposed of from
Commercial Dynamics Pty. Ltd.   | a great height, over water.
NSW, Australia                  | 


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

Date: 12 Aug 2001 08:30:10 -0700
From: moran-gy@actcom.co.il (Moran Goldstein)
Subject: Re: Unexplained process killing
Message-Id: <223f9ce4.0108120730.524f2d57@posting.google.com>

> When waiting at the first prompt, "top" on my system shows the perl
> process using 2212K of memory.  If I type "one", then at the second
> prompt it is using 52MB meaning that it takes 50MB to store that those
> 2^21 values in a one-dimensional array.  If I type "three", then at the
> second prompt its size grows 62MB instead, meaning it uses 60 MB to
> store those same values.  (The amount of extra memory used depends on
> the size of the individual dimensions as well.)
> 
> Actually, the most important point is that it really takes a LOT of
> memory to store these values either way you do it.  50 MB is 52428800
> bytes, and if that's used to store 2^21 values, that means that each
> value (each floating point number) is using 25 bytes.  The machine
> representation of a double normally takes only 8 bytes, so you can see
> that there's lots of overhead.
> 
> What I would suggest is that you use some of your operating system's
> tools (like maybe "top" or "ps") to watch the process and see how large
> it grows.  You may be surprised.  To get more detail, you might step
> through your program in the Perl debugger and watch the memory (using
> something like "top") at various stages.




I tried the test script you posted, and it works consistently up to
around 200x200x200. At 250x250x250 it's almost always killed.

I sent an E-mail to my hosting service asking if they have any
specific limits setup, at that point I'll know more. It's hosted on a
dedicated server, so there aren't other users on the server that might
effect server load.

Is the problem the amount and type of values, or the amount of
processes? ie - if I write something to loop 20,000,000 times through
"my $foo = 2+2", and discard the results, will it still drain
resources?

Will it help to limit the values to integers? Are there any methods to
keep the values handy, but not drain so much memory? I was referred to
the 'vec' function which stores integers, might that help?

How do image editing programs do it? Images are essentially 2D arrays
with each value containing 3 integers (RGB). Do they function
differently?

-Moran Goldstein


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

Date: Sun, 12 Aug 2001 15:05:15 GMT
From: friedman@math.utexas.edu (Chas Friedman)
Subject: Re: Warning  pragma -w
Message-Id: <3b769a14.123623369@news.itouch.net>

On 12 Aug 2001 06:22:32 -0700, circuller@yahoo.com (Nkhouri) wrote:

>I used the -w while developing my FCGI program , the program worked
>fine with
> many harmless warnnings {used of unitialized values }! now if i take
>the -w
> out , the program stop responding and logs an error " terminating
>program with  exit status 2 " to STDERR .
>
> i added the $^W=0,$^W=1 to ignore warnings , but nothing happen ,
>same error occurs !
>
> help plz !
One possibility: If you developed your script on a Windows machine and
then transferred it to Linux/Unix, there may be some extra characters
at the end of the lines. This seems to interfere with the #!/bin/perl
(or whatever) line. Putting the "-w" seems to make the extra
characters ignored. Look at you script in an editor using binary mode
(e.g.use vi -b) to see if this is the case.
                                        cf


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

Date: Sun, 12 Aug 2001 16:51:26 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: Warning  pragma -w
Message-Id: <997635086.146181741729379.gnarinn@hotmail.com>

In article <64ffc63e.0108120522.4b82587e@posting.google.com>,
Nkhouri <circuller@yahoo.com> wrote:
>I used the -w while developing my FCGI program , the program worked
>fine with
> many harmless warnnings {used of unitialized values }! now if i take
>the -w
> out , the program stop responding and logs an error " terminating
>program with  exit status 2 " to STDERR .
>
> i added the $^W=0,$^W=1 to ignore warnings , but nothing happen ,
>same error occurs !
>

maybe you edited the file on pc and uploaded it to unix in bin mode?

in that case there may be a carriage return at the end each line,
that can interfere with the correct execution of your script


gnari



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

Date: 12 Aug 2001 10:17:58 -0700
From: morebeans@hotmail.com (Glenn)
Subject: Win32::Console - reading input
Message-Id: <91179b65.0108120917.21612da6@posting.google.com>

Hi, I'm trying to write a win32 app that reads 3 characters from the
console.  However, my app so far creates a new console, writes to it,
but doesn't seem to wait for input.  Below is the app, I'm presently
using "ReadChar", as my Perl in a Nutshell book says it should read a
specified number of characters from the console but it doesn't seem to
be pausing the app for reading the input.

Thanks for any help.

Glenn
_______________________________

#!/usr/bin/perl

use Win32::Console;

$con = Win32::Console->new();

$con->Mode(ENABLE_WINDOW_INPUT,ENABLE_PROCESSED_INPUT,ENABLE_LINE_INPUT,ENABLE_ECHO_INPUT,ENABLE_PROCESSED_OUTPUT,ENABLE_WRAP_AT_EOL_OUTPUT);

$con->Display;

$con->Write("Please enter the agent ID number: "); # I want to wait
for input here, but apparently the ReadChar below doesn't do that

@info = $con->Info();

$con->Write("The cursor info is ",$info[3],",",$info[4],". \r"); #
This presently prints no cursor data

$port = ($con->ReadChar(3,$info[3],$info[4]));

$con->Write("The port number to use is ",$port);


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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 1502
***************************************


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