[11925] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5525 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 30 06:07:18 1999

Date: Fri, 30 Apr 99 03:00:19 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 30 Apr 1999     Volume: 8 Number: 5525

Today's topics:
    Re: a better way??? <uri@sysarch.com>
    Re: FreeBSD 3.0 pw -h (Pedro J. Lobo)
    Re: how to use require? <Mathias-Henry.Weber@de.heidelberg.com>
    Re: how to use require? (Larry Rosler)
    Re: how to use require? (Bart Lateur)
        HTML Parsing problem. <m3thod@cyberspace.org>
    Re: Impythonating PERL? (Avery Andrews)
        is there a switch statement in perl <mario@alamar.net>
    Re: is there a switch statement in perl <olivier.henrot@alcatel.fr>
    Re: is there a switch statement in perl <Michael.Cameron@no.spam.technologist.com>
        NT Shutdown <"Pep Mico"@hp.com>
    Re: NT Shutdown <tim@timbury.com>
        Perl calling exe program problem!!!!!!!!!!!!!! <U903506@ntu.edu.sg>
    Re: Python and Perl <gellyfish@gellyfish.com>
        Regexp help needed <s@undersea.net>
    Re: Regexp help needed <vroquencourt@businessobjects.com>
    Re: single quotation " erases REST OF TEXT <gellyfish@gellyfish.com>
        Speeding up text search of flatfile database? (Brett Tabke)
    Re: Speeding up text search of flatfile database? <ebohlman@netcom.com>
    Re: Transactions not working with ODBC module <rhardicr@hotmail.com>
        unlink - why doesn't it work <mario@alamar.net>
    Re: unlink - why doesn't it work <moe@blackhole.vision.net.au>
    Re: unlink - why doesn't it work <ebohlman@netcom.com>
    Re: unlink - why doesn't it work (Bart Lateur)
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: 30 Apr 1999 02:08:39 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: a better way???
Message-Id: <x7hfpy7i8o.fsf@home.sysarch.com>

>>>>> "MM" == Meling Mudin <mudin@expert.cc.purdue.edu> writes:

  MM> When the program runs, it's suppose to look for user(s) that is/are
  MM> connected from different hosts. I have initialization error
  MM> pointing to the line:
  MM>   if (exists ($hash{$user}{$from}))

  MM> my @myline = ();
  MM> my %hash = ();

no need to initialize hashes and arrays to ().

  MM> 	@myline = split /[((\t)+)((\s)+)]+/; 

where did that ugliness come from? what do you think it is doing?  []
defines a characater class, a set of characters to match so that
actually reduces to /[()\s+]+/ which is not what you want. it probably
split who ok so you can't tell but if anyone had a + in their name it
would break. read perlre and buy mastering regular expressions. what you
probably want is just /s+/ and that can be simplified to / / as a
special case.

  MM> 	$user = $myline[0];
  MM> 	$from = $myline[5];

  MM> 	# store the stuff into a hash 
	
  MM> 	if (exists ($hash{$user}{$from})) {
  MM> 		$hash{$user}{$from}++;
  MM> 	}
  MM> 	else {
  MM> 		$hash{$user}{$from} = 0;
  MM> 	}
  MM> }

no need for all that stuff. just do

$hash{$user}{$from}++;

perl will create the anon hash and increment it to 1 the first time a
$name and $from are found.

are you sure $from always exists? if a user is logged in locally they
will not show a remote host field in who. so maybe you are using undef for a
key which will trigger the warning.

so try this:

$hash{$user}{$from}++ if defined $from ;

  MM> foreach $user (sort keys %hash) {
  MM> 	$count = 0;
  MM> 	$from_here = "";
  MM>     foreach $from (sort keys %{$hash{$user}}) {
  MM> 		$count++;
  MM> 		$from_here.="$from ";
  MM> 	 	# print "$user==>$from \n";
  MM> 	}
  MM> 	# print $count."\n";
  MM> 	if ($count > 1) {
  MM> 		print "$user : $from_here\n";
  MM> 	}
  MM> }

this code is very confusing. to count the number of keys in a hash, just
use keys %hash. also to get the keys of a hash just use keys %hash. this
will do the same stuff:

foreach $user (sort keys %hash) {

	@hosts_from = sort keys %{$hash{$user}} ;

	if ( @hosts_from > 1) {
		print "$user : @hosts_from\n";
	}
}

isn't that a lot clearer?

so the complete program might look like this (not fully tested since i
don't have any remote logins right now):

foreach ( `/bin/who` ) {

	( $user, $from ) = (split)[0,5] ;

	$hash{$user}{$from}++ if defined $from ;
}

foreach $user (sort keys %hash) {

	@hosts_from = sort keys %{$hash{$user}} ;

	if ( @hosts_from > 1) {
		print "$user : @hosts_from\n";
	}
}


hth,

uri


-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: 30 Apr 1999 11:49:49 +0100
From: pjlobo@euitt.upm.es (Pedro J. Lobo)
Subject: Re: FreeBSD 3.0 pw -h
Message-Id: <37297cbd.0@ntred.ccupm.upm.es>

Fredrick DeQuan Lee (flee@theshop.net) wrote:
: Can someone either post or email me an example of a script that uses the
: 'pw' command to set passwords or add users. The man page has thoroughly
: confused me. I've tried opening pipes to it in perl by:
: open(PW,"|pw -h");
: and
: open(PW,"pw-h|);
: with no success. Any help out there? TIA.

Try this:

open (PW, "|/usr/sbin/pw <put your options here> -h 0"); # Tell pw to use stdin
print PW "password\n";
close PW;

It worked for me.


--
-------------------------------------------------------------------
Pedro Josi Lobo Perea                   Tel:    +34 91 336 78 19
Centro de Calculo                       Fax:    +34 91 331 92 29
E.U.I.T. Telecomunicacisn               e-mail: pjlobo@euitt.upm.es
Universidad Politicnica de Madrid
Ctra. de Valencia, Km. 7                E-28031 Madrid - Espaqa / Spain


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

Date: Fri, 30 Apr 1999 08:37:37 +0200
From: "Mathias-H. Weber" <Mathias-Henry.Weber@de.heidelberg.com>
Subject: Re: how to use require?
Message-Id: <37294FB1.6B6515B@de.heidelberg.com>

judak wrote:
> 
> Hi, I try to do this simple thing.  I typed up this predefined html
> header and footer so every time when I want to draw a web page it'll
> save me a little trouble.  I put the subroutines header and footer in a
> file called html.pl
> and try to use it by typing "   require "html.pl"   "  and the error I
> get is
> 
> "html.pl did not return a true value at test.pl line 2."
> 
> here is actual codes:
> #html.pl
> #makes the header and footer of a html document
> 
> #header part
> sub html_header
> {
>  print "Content-type: text/html", "\n\n";
>  print "<HTML>", "\n\n";
>  print "<HEAD>", "\n\n";
>  print "<TITLE>", "@_", "</TITLE>", "\n\n";
>  print "</HEAD>", "\n\n";
> }
> 
> #footer part
> sub html_footer
> {
>  print "\n", "</BODY>", "\n\n";
>  print "</HTML>", "\n\n";
> }
> 
The last line (i.e. statement) of your required file should be:
1; # <- This is a "one" not an "ell"!

This is just what the perl interpreter complained about. Every "used" or
"required" module must return a true value to indicate successful
loading.

> Here is how I called the file:
> #test.pl
> require "html.pl";
> &html_header;
> print "Content-type: text/html", "\n\n";
> print "<BODY>", "\n";
> print "<H1><center>HAHAHAHAHA</center></H1>", "\n";
> print "<br><hr>", "\n";
> &html_footer;
> 
> Would someone please help me out?  I did what the book told me to and it
> did not work out.  Thanks a lot!!!

Mathias
-- 
Mathias-H.Weber                        mailto:weber.m@gmx.de


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

Date: Thu, 29 Apr 1999 23:48:30 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: how to use require?
Message-Id: <MPG.1192f216e2f19c30989982@nntp.hpl.hp.com>

[Posted and a courtesy copy sent.]

In article <37294375.D389A7E2@yahoo.com> on Thu, 29 Apr 1999 22:45:25 -
0700, judak <judak@yahoo.com> says...
+ Hi, I try to do this simple thing.  I typed up this predefined html
+ header and footer so every time when I want to draw a web page it'll
+ save me a little trouble.  I put the subroutines header and footer in
+ a file called html.pl
+ and try to use it by typing "   require "html.pl"   "  and the error I
+ get is
+ 
+ "html.pl did not return a true value at test.pl line 2."
+ 
+ here is actual codes:
+ #html.pl
+ #makes the header and footer of a html document
+ 
+ #header part
+ sub html_header
+ {
+  print "Content-type: text/html", "\n\n";
+  print "<HTML>", "\n\n";
+  print "<HEAD>", "\n\n";
+  print "<TITLE>", "@_", "</TITLE>", "\n\n";
+  print "</HEAD>", "\n\n";
+ }
+ 
+ #footer part
+ sub html_footer
+ {
+  print "\n", "</BODY>", "\n\n";
+  print "</HTML>", "\n\n";
+ }
+ 
+ 
+ Here is how I called the file:
+ #test.pl
+ require "html.pl";
+ &html_header;
+ print "Content-type: text/html", "\n\n";
+ print "<BODY>", "\n";
+ print "<H1><center>HAHAHAHAHA</center></H1>", "\n";
+ print "<br><hr>", "\n";
+ &html_footer;
+ 
+ Would someone please help me out?  I did what the book told me to and
+ it did not work out.  Thanks a lot!!!

Perl comes with a file nameed perldiag that lists all the error 
messages, with further explanations.  Here is what it says:

%s did not return a true value
 
(F) A required (or used) file must return a true value to indicate that 
it compiled correctly and ran its initialization code correctly. It's 
traditional to end such a file with a ``1;'', though any true value 
would do. See perlfunc. 



A few other observations:

Why are you printing the 'Content-type' header twice?  And what are all 
those double newlines for?  You need them only on the 'Content-type' 
header.

Where are the arguments that constitute the TITLE?

To improve your coding style, you should learn about 'here-docs' to 
reduce the need for all those print statements.

And, as you are cross-posting this in the modules group, you should
start to use the module CGI.pm which does a lot of these things for
you more cleanly.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Fri, 30 Apr 1999 09:07:44 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: how to use require?
Message-Id: <372b6913.6908741@news.skynet.be>

judak wrote:

>Hi, I try to do this simple thing.  I typed up this predefined html
>header and footer so every time when I want to draw a web page it'll
>save me a little trouble.  I put the subroutines header and footer in a
>file called html.pl
>and try to use it by typing "   require "html.pl"   "  and the error I
>get is
>
>"html.pl did not return a true value at test.pl line 2."

Add a line 

	1;

at the bottom of your "html.pl" file. A "required" file can not only
contain sub definitions, but bare code too, that is executed at the time
it is loaded (the first time it's "required"). Typical use is for
initialisation of data structures as used by the subs.

The last code executed in a "required" file must return a TRUE value.
"1;" will do. This is a sanity check, to see that for example the
library file isn't completely empty.

>Here is how I called the file:
>#test.pl
>require "html.pl";
>&html_header;
>print "Content-type: text/html", "\n\n";
>print "<BODY>", "\n";

Do you realize you now have emitted TWO content-type headers? One inside
the sub html_header, and on the line just below that sub call.

	Bart.


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

Date: Fri, 30 Apr 1999 02:12:33 -0700
From: "Method Man" <m3thod@cyberspace.org>
Subject: HTML Parsing problem.
Message-Id: <7gbs67$gkk$1@fir.prod.itd.earthlink.net>

I am trying to parse an HTML table that's in the following format:

<TABLE>
<TR><TH BGCOLOR=#000077>COL1</TH>
<TH BGCOLOR=#000077>COL2</TH></TR>
<TR VALIGN=TOP ALIGN=CENTER><TD NOWRAP><FONT SIZE=-1>
<BR>AAA1
<BR>AAA2
<BR>AAA3
<BR><FONT COLOR="#99FFBB">AAA4</FONT>
</TD><TD ALIGN=RIGHT NOWRAP BGCOLOR=#000055><FONT SIZE=-1>
<BR>BBB1
<BR>BBB2
<BR>BBB3
<BR>BBB4
</TD></TR>
</TABLE>

I want as output:------------------------------------

COL1, COL2

AAA1, BBB1
AAA2, BBB2

I have the following script:----------------------------

#!/usr/local/bin/perl -l

use HTML::Parser;

my ($in_table,$in_td,$in_br,$txtbuf,$colcnt,@columns);

package myParser;
@ISA = qw/HTML::Parser/;

sub start {
  my ($self,$tag,$attr,$attrseq,$text) = @_;

 if ($tag eq 'table') {
  $in_table = 1;
 } elsif ($tag eq 'tr') {
  $colcnt = 0;
 } elsif ($tag eq 'td') {
  $in_td = 1;
  $txtbuf = '';
 } elsif ($tag eq 'br') {
  $in_br = 1;
 }
# print "\n" if $tag eq "tr";
# print "|" if $tag eq "td";
}

sub text {
 my ($self,$text) = @_;
 $txtbuf.=$text if ($in_table && $in_td);
}

sub end {
 my ($self,$tag,$text) = @_;
 if ($tag eq 'td') {
  push @{$columns[$colcnt++]}, $txtbuf;
  $in_td = 0;
 } elsif ($tag eq 'table') {
  $in_table = 0;
 }
}

{ local $/; $content=<>; }

my $p = myParser->new;
$p->parse($content);
$p->eof();

foreach my $col (@columns) {
 foreach my $row (@$col) {
  print "$row";
 }
}

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

My problem is, the parsing is done flawlessly (except for the 'tr' tags
because I haven't worried about them yet).  But it doesn't really get
displayed correctly because of the <BR> tags, or rather the lack of <TD>
tags around the column text.

What is an easy way to get my desired output using the script above.  It's
very close to doing what I want it to, but I'm not sure what to add and
where.

Any help/advice would be greatly appreciated.

Thanks in advance.





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

Date: 29 Apr 1999 23:22:46 -0700
From: andrews@Turing.Stanford.EDU (Avery Andrews)
Subject: Re: Impythonating PERL?
Message-Id: <7gbi7m$c0q@Turing.Stanford.EDU>

In <37288D73.B52B4E8F@mail.cor.epa.gov> David Cassell
<cassell@mail.cor.epa.gov> writes:

>> .....
>> 
>> Anyway, since you have to lay code out that way to make it readable
>> later, what's so dumb about using the whitespace to lose the
>> punctuation?

>Avery, I don't have any experience with this sort of code-munging in
>Perl, but I've seen it done a number of ways in C.  It usually leads to
>one of several problems.  The code becomes unmaintainable, except by 
>the user.  If the user changes programming styles or has style
>mandates put upon him by PHB's, havoc ensues.  If the coder learns
>new language features or wants to move to more advanced programming
>in that language, the code-munging often gets in the way.  And the
>user gets used to code looking a certain way, so that texts and
>other programs don't help as much as they might.

>I would strongly advise against it.

That makes sense, so perhaps a better version of the idea would be as
a whitespace-driven syntax checker, no too hard to derive from Damian
Conways code.

  Avery Andrews



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

Date: Fri, 30 Apr 1999 08:30:52 +0100
From: "Mario Anthony Thomas" <mario@alamar.net>
Subject: is there a switch statement in perl
Message-Id: <7gbm8s$7s5$1@lure.pipex.net>

Is there a switch or case statement in perl or do I need to use blocks of if
elsif else?

My code looks really untidy because I've got about 15 if statements one
after the other.
I'd like a more elegant solution.

Thanks in advance

Mario




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

Date: Fri, 30 Apr 1999 10:40:31 +0200
From: Olivier Henrot <olivier.henrot@alcatel.fr>
To: Mario Anthony Thomas <mario@alamar.net>
Subject: Re: is there a switch statement in perl
Message-Id: <37296C7F.62455614@alcatel.fr>

Mario Anthony Thomas wrote:
> 
> Is there a switch or case statement in perl or do I need to use blocks of if
> elsif else?
> 

perldoc -q switch
Found in c:\local\perl\lib/pod/perlfaq7.pod
  How do I create a switch or case statement?

            This is explained in more depth in the the perlsyn
            manpage. Briefly, there's no official case statement,
            because of the variety of tests possible in Perl
            (numeric comparison, string comparison, glob comparison,
            regexp matching, overloaded comparisons, ...). Larry
            couldn't decide how best to do this, so he left it out,
            even though it's been on the wish list since perl1.

            The general answer is to write a construct like this:

                for ($variable_to_test) {
                    if    (/pat1/)  { }     # do something
                    elsif (/pat2/)  { }     # do something else
                    elsif (/pat3/)  { }     # do something else
                    else            { }     # default
                } 

            Here's a simple example of a switch based on pattern
            matching, this time lined up in a way to make it look
            more like a switch statement. We'll do a multi-way
            conditional based on the type of reference stored in
            $whatchamacallit:

                SWITCH: for (ref $whatchamacallit) {

                    /^$/            && die "not a reference";

                    /SCALAR/        && do {
                                            print_scalar($$ref);
                                            last SWITCH;
                                    };

                    /ARRAY/         && do {
                                            print_array(@$ref);
                                            last SWITCH;
                                    };

                    /HASH/          && do {
                                            print_hash(%$ref);
                                            last SWITCH;
                                    };

                    /CODE/          && do {
                                            warn "can't print function
ref";
                                            last SWITCH;
                                    };

                    # DEFAULT

                    warn "User defined type skipped";

                }

            See `perlsyn/"Basic BLOCKs and Switch Statements"' for
            many other examples in this style.

            Sometimes you should change the positions of the
            constant and the variable. For example, let's say you
            wanted to test which of many answers you were given, but
            in a case-insensitive way that also allows
            abbreviations. You can use the following technique if
            the strings all start with different characters, or if
            you want to arrange the matches so that one takes
            precedence over another, as `"SEND"' has precedence over
            `"STOP"' here:

                chomp($answer = <>);
                if    ("SEND"  =~ /^\Q$answer/i) { print "Action is
send\n"  }
                elsif ("STOP"  =~ /^\Q$answer/i) { print "Action is
stop\n"  }
                elsif ("ABORT" =~ /^\Q$answer/i) { print "Action is
abort\n" }
                elsif ("LIST"  =~ /^\Q$answer/i) { print "Action is
list\n"  }
                elsif ("EDIT"  =~ /^\Q$answer/i) { print "Action is
edit\n"  }

            A totally different approach is to create a hash of
            function references.

                my %commands = (
                    "happy" => \&joy,
                    "sad",  => \&sullen,
                    "done"  => sub { die "See ya!" },
                    "mad"   => \&angry,
                );

                print "How are you? ";
                chomp($string = <STDIN>);
                if ($commands{$string}) {
                    $commands{$string}->();
                } else {
                    print "No such command: $string\n";
                }


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

Date: Fri, 30 Apr 1999 09:03:34 +0000
From: Michael Cameron <Michael.Cameron@no.spam.technologist.com>
To: Mario Anthony Thomas <mario@alamar.net>
Subject: Re: is there a switch statement in perl
Message-Id: <372971E6.29FA331F@no.spam.technologist.com>

Mario Anthony Thomas wrote:
> 
> Is there a switch or case statement in perl or do I need to use blocks of if
> elsif else?
> 
> My code looks really untidy because I've got about 15 if statements one
> after the other.
> I'd like a more elegant solution.
> 
> Thanks in advance
> 
> Mario
man perlsyn

especially the section labelled "Basic BLOCKs and Switch Statements"

You had the answers at your fingertips all the time...

Michael


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

Date: Fri, 30 Apr 1999 09:55:57 +0200
From: Pep Mico <"Pep Mico"@hp.com>
Subject: NT Shutdown
Message-Id: <3729620D.3626632@hp.com>

Hello,

I'm using ActivePerl (5.005_03), build 515. And I'd like to program an
Script for NT Shutdown.

What Is the module that I should Invoque to use the function
"initiateSystemShutdown"?

Please give me a short example, I'm trying to use it and I don't know
how.

Thanks in advance
pep_mico@hp.com




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

Date: Fri, 30 Apr 1999 05:20:32 -0400
From: "Tim" <tim@timbury.com>
Subject: Re: NT Shutdown
Message-Id: <925464015.505.65@news.remarQ.com>

You might try :
    system ("c:\\shutdown.exe") or die "Couldn't Shutdown.  $!";
The shutdown.exe is part of the NT Resource Kit.  I suggest running
shutdown /? first to see the parameters.  :-)    The only shutdown
function I'm aware of in Perl is used to shutdown a socket.


Pep Mico <"Pep Mico"@hp.com> > wrote in message <3729620D.3626632@hp.com>...
>Hello,
>
>I'm using ActivePerl (5.005_03), build 515. And I'd like to program an
>Script for NT Shutdown.
>
>What Is the module that I should Invoque to use the function
>"initiateSystemShutdown"?
>
>Please give me a short example, I'm trying to use it and I don't know
>how.
>
>Thanks in advance
>pep_mico@hp.com
>
>




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

Date: Fri, 30 Apr 1999 12:29:00 +0800
From: #VIKRAM BALKRISHNAN NATARAJAN# <U903506@ntu.edu.sg>
Subject: Perl calling exe program problem!!!!!!!!!!!!!!
Message-Id: <D0BE198B1C7ED111AD1808002BA613F80CF6D328@mail1.ntu.edu.sg>

This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01BE92C1.F8231146
Content-Type: text/plain

Hi
  This time there is a slightly different problem...
 I am able to run simple perl scripts on my server when i call it form
the client....say just return a simple web page...
  now in my perl script i want to call an exe program(vfp)
  when i run the perl script from the server using command window the
script is able to execute the exe program...
  however if i use a browser to call the perl script which in turn calls
the exe program the execution does not take place .....
   anybody can help??
   is there some problem in the path?? but then  why does it work from
the command window and not from the client browser when i am able to run
other simple perl scripts from the client browser???
   thanks 
vikram
  

------_=_NextPart_001_01BE92C1.F8231146
Content-Type: text/html
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Dus-ascii">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2232.0">
<TITLE>Perl calling exe program problem!!!!!!!!!!!!!!</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=3D2>Hi</FONT>
<BR><FONT SIZE=3D2>&nbsp; This time there is a slightly different =
problem...</FONT>
<BR><FONT SIZE=3D2>&nbsp;I am able to run simple perl scripts on my =
server when i call it form the client....say just return a simple web =
page...</FONT></P>

<P><FONT SIZE=3D2>&nbsp; now in my perl script i want to call an exe =
program(vfp)</FONT>
<BR><FONT SIZE=3D2>&nbsp; when i run the perl script from the server =
using command window the script is able to execute the exe =
program...</FONT>
<BR><FONT SIZE=3D2>&nbsp; however if i use a browser to call the perl =
script which in turn calls the exe program the execution does not take =
place .....</FONT></P>

<P><FONT SIZE=3D2>&nbsp;&nbsp; anybody can help??</FONT>
<BR><FONT SIZE=3D2>&nbsp;&nbsp; is there some problem in the path?? but =
then&nbsp; why does it work from the command window and not from the =
client browser when i am able to run other simple perl scripts from the =
client browser???</FONT></P>

<P><FONT SIZE=3D2>&nbsp;&nbsp; thanks </FONT>
<BR><FONT SIZE=3D2>vikram</FONT>
<BR><FONT SIZE=3D2>&nbsp;</FONT>=20
</P>

</BODY>
</HTML>
------_=_NextPart_001_01BE92C1.F8231146--



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

Date: 30 Apr 1999 09:54:32 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Python and Perl
Message-Id: <37296fc8@newsread3.dircon.co.uk>

In comp.lang.perl.misc Ben Caradoc-Davies <bmcd@es.co.nz> wrote:
> [This is not intended to start another pointless language war. Well, at least
> not between Perlers and Pythonistas.  :-)  ]
> 

<Snip pointless language war inflaming followup to a post in another group>

Then why did you cross-post it then ?

*plonk*

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>



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

Date: Fri, 30 Apr 1999 00:25:51 -0500
From: Sean <s@undersea.net>
Subject: Regexp help needed
Message-Id: <37293EDF.2B4F5878@undersea.net>

Hi,
	I've got a real quick question.  What is the correct regular expression
for matching ever character from the beginning of a string up to a
comma?  I'm using  /^.*,/ right now which matches the entire line which
is not what I want.  Any help is greatly appreciated.  ThanX!!!   

--Sean


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

Date: Fri, 30 Apr 1999 11:27:38 +0200
From: vincent <vroquencourt@businessobjects.com>
To: Sean <s@undersea.net>
Subject: Re: Regexp help needed
Message-Id: <3729778A.B4073221@businessobjects.com>



Sean wrote:

> Hi,
>         I've got a real quick question.  What is the correct regular expression
> for matching ever character from the beginning of a string up to a
> comma?  I'm using  /^.*,/ right now which matches the entire line which
> is not what I want.  Any help is greatly appreciated.  ThanX!!!
>
> --Sean

Use a greedy expression :     /^.*?,/




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

Date: 30 Apr 1999 09:44:51 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: single quotation " erases REST OF TEXT
Message-Id: <37296d83@newsread3.dircon.co.uk>

crstlblu@planet.eon.net wrote:
> 
> again:
> 
> (a) a dbm file has a text string INSIDE it that reads:
> 		I am 5'10" tall
> 
> (b) ONE script extracts this into a $variable then passes it
>      in a hidden form field to a SECOND script
> 

Except of course you are missing some stages here:

   (B) A script extracts data from the dbm and then generates HTML
       without do any entity conversion and the sends it to a browser.

   (C) The browser parses the HTML as per the standard.

   (D) Browser sends *its* understanding of the values of the form fields
       back to the server.

> (c) the SECOND script parses values and then saves the
>      value into a NEW DBM file!
> 
> now if you VIEW the actual contents of this NEW dbm file,
> you will see that the ONLY THING THAT GOT SAVED is:
> 		I am 5'10
> 
> EVERYTHING after the quotation mark in the middle got LOST!
> 
> Don't do ANY HTML codeing in the scipts - to keep the flamers away -
> don't worry about trying to "print" to the browser any values this is
> 100% strictly PERL programming!
> 

I've seen nematodes with better logic than that.  OK. Lets looks at a
simpler scenario with only one program - you are obviously getting
confused.

Make the *single* program extract data from your first dbm and then insert
it into the second dbm.  One program no 'hidden fields' no HTML no browser
just out of one dbm into another.  Now view your data.  Lordy !! the whole
string is in there.  What I wonder is the reason for the difference.

You are trying to get us to ignore the fact that is plainly obvious to
everyone apart from you - if in your stage 'b' you do a 'View Source'
in your browser and your hidden field doesnt look something like:

<INPUT TYPE="hidden" 
       NAME="name" 
       VALUE="I am 5'10&quot; Tall but I know whats going to happen">

Then yes the value of the hidden field that might get sent to some other
script will be truncated at the second double quote.  The
value attribute of the hidden field is terminated where the browser
believes the string ends which is with the second double quote - that is
why any embedded quotes must be converted to entities as above.

Of course all of this would have been unnecessary if you had been using
the module CGI.pm and created the hidden field like:

  print hidden('name',$hidden_value);

Then this thread would never have happened as it will automatically convert
any characters necessary to the correct entities (and param() will convert
back ).

Now go away and use CGI.pm.

*plonk*

/J\ 
-- 
Jonathan Stowe <jns@gellyfish.com>



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

Date: Thu, 29 Apr 1999 21:49:45 -0400
From: invalid-see-sig@nope.joefarmer.com (Brett Tabke)
Subject: Speeding up text search of flatfile database?
Message-Id: <5wQK3k+hDorN092yn@joefarmer.com>


I run a modest site directory (9000 sites).  I use a flat file database to
store site info and an occasional full site spider/indexing.  As the db has
grown, search response times have naturally also grown.  I have mysql
online but that is unsatisfactory for a text search system (too much post
processing makes it slower than a pure perl flatfile).

So, I'm back to trying to tweak the last scraps of speed out of my
current search routine until a better solution is found.

Any thoughts on making the following main search routine faster?
The three arrays (rejects,includes,querywords) are an array of what
the user entered in the search form.  (-rejects, +includes,
querywords) in altavista style syntax.

--
Thank you
Brett Tabke howdy -at_ netlane.com http://www.joefarmer.com


----------------------------------------------------------- import

foreach $LINE (<FILE1>)	{			#grab line of database
chomp($LINE);

($linkserial,$s,$s,$linktitle,$linkdescrip,$linkwords,$linkemail,$s,$s,
$linkstatus,$URL,$s,$s,$linkcrank,$s,$linknote) = split(/\s*\|\s*/,$LINE);

$ss = " $linktitle $linkdescrip $linkwords $URL ";	   #search string

if ($Suser) {$ss .= "$linkserial $linkstatus $linknote $linkemail";}

($weight,$dead) = (0,0);
							#main compare loops

	foreach (@rejects)	{  # check for "not" or -words in query string
		if (($ss =~ /$_/i) && ($_ !~ /[A-Z]/))	{
			$dead++;
			last;
			}
		elsif ($ss =~ /$_/ig)	{
			$dead++;
			last;
			}
		}
	next if ($dead);

	foreach (@includes)	{	#array of all "+" required included words
		if (($ss =~ /$_/) && ($_ =~ /[A-Z]/))	{
			$weight += (($ss =~ s/$_/$_/og) + 20);	#score the match
			}
		elsif (($ss =~ /$_/i) && ($_ !~ /[A-Z]/))	{
			$weight += (($ss =~ s/$_/$_/oig) + 10);
			}
		else	{
			$dead++;
			last;
			}
		}
	next if ($dead);

	foreach (@querywords)	{	#check for standard user querywords
		if (($ss =~ /$_/) && ($_ =~ /[A-Z]/))	{
			$weight += ($ss =~ s/$_/$_/og);
			}
		elsif (($ss =~ /$_/i) && ($_ !~ /[A-Z]/))	{
			$weight += ($ss =~ s/$_/$_/oig);	#score the match
			}
		}
					#score the match (weight it for listing purposes)
	if ($weight) {  #add up count
		$weight = ($weight + $linkcrank) if ($linkcrank > 1);
		$weight = 100000 if ($weight > 100000);
		$weight = sprintf("%.5f",($weight/100000));

					#stuff the match in hash for cheap quick sorting later
		$HITS{"$weight$URL"} = $LINE;
		$hitcount++;
		}

}
---- end import




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

Date: Fri, 30 Apr 1999 07:53:54 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Speeding up text search of flatfile database?
Message-Id: <ebohlmanFAzsLu.EG1@netcom.com>

Brett Tabke <invalid-see-sig@nope.joefarmer.com> wrote:
: Any thoughts on making the following main search routine faster?
: The three arrays (rejects,includes,querywords) are an array of what
: the user entered in the search form.  (-rejects, +includes,
: querywords) in altavista style syntax.

Rather than having several separate loops for each class of words, and 
rather than using 's/$_/$_/g' simply to get a count of the occurrence of 
a word, I'd suggest doing a little more processing up front.  One of the 
outputs of this processing should be a single regex that matches the OR 
of all the words in the query.  Use the (?i) or (?-i) construct within 
the regex to specify whether certain words should be matched exactly or 
case-insensitively.  Stick the regex in, say, $matchexp.  Additionally 
build up some hashes or other data structures containing the properties 
for each word (whether to reject, require, or just count; any special 
weights; etc.).

Then slurp in the file, and do one loop along the lines of:

while ($filecontents =~ /$matchexp/ogs) {
  look up word matched;
  last if (word was excluded);
  do appropriate stuff;
}


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

Date: Fri, 30 Apr 1999 08:06:58 +0100
From: Richard H <rhardicr@hotmail.com>
Subject: Re: Transactions not working with ODBC module
Message-Id: <37295692.DCB2EB3B@hotmail.com>

Hi,

> 
> $sql = "insert into MyTable(name) values ('Sanjiv')";
> #$sql ="delete * from Sanjiv";
> if ($db->sql($sql)) {
>    die "Died on $sql: " . $db->Error();

If youre expecting the delete statement to remove the line inserted by
your INSERT statement, and these lines are straight from your code, then
the SQL is wrong for the delete isnt it?

Insert into MyTable(name) values 'Sanjiv'
Delete * from MyTable(name) where value = 'Sanjiv'

Richard H


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

Date: Fri, 30 Apr 1999 08:15:16 +0100
From: "Mario Anthony Thomas" <mario@alamar.net>
Subject: unlink - why doesn't it work
Message-Id: <7gblbj$757$1@lure.pipex.net>

I've noticed that the unlink function sometimes fails to delete a particular
file - even when I know its trying to delete the correct file.

Why does unlink fail? Are there a list of reasons why it doesn't work
sometimes?

Thanks in advance

mario




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

Date: Fri, 30 Apr 1999 09:50:55 +0100
From: "John" <moe@blackhole.vision.net.au>
Subject: Re: unlink - why doesn't it work
Message-Id: <37296ef4@newsread3.dircon.co.uk>

Check the file permissions of the file and see if that's the problem?!

Mario Anthony Thomas <mario@alamar.net> wrote in message
news:7gblbj$757$1@lure.pipex.net...
> I've noticed that the unlink function sometimes fails to delete a
particular
> file - even when I know its trying to delete the correct file.
>
> Why does unlink fail? Are there a list of reasons why it doesn't work
> sometimes?
>
> Thanks in advance
>
> mario
>
>




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

Date: Fri, 30 Apr 1999 09:12:06 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: unlink - why doesn't it work
Message-Id: <ebohlmanFAzw86.Jq4@netcom.com>

Mario Anthony Thomas <mario@alamar.net> wrote:
: I've noticed that the unlink function sometimes fails to delete a particular
: file - even when I know its trying to delete the correct file.

: Why does unlink fail? Are there a list of reasons why it doesn't work
: sometimes?

perl will tell you why unlink fails, if only you ask...

unlink($file) or die "Couldn't unlink $file: $!";



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

Date: Fri, 30 Apr 1999 09:13:06 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: unlink - why doesn't it work
Message-Id: <372c7376.9567825@news.skynet.be>

Mario Anthony Thomas wrote:

>I've noticed that the unlink function sometimes fails to delete a particular
>file - even when I know its trying to delete the correct file.
>
>Why does unlink fail? Are there a list of reasons why it doesn't work
>sometimes?

Have you printed out $! when it fails? 

	unlink $thatfile or die "Couldn't unlink $thatfile: $!";

See also perlfunc.pod for unlink.

	Bart.


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

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


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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

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