[11571] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5171 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 18 21:07:24 1999

Date: Thu, 18 Mar 99 18:00:22 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 18 Mar 1999     Volume: 8 Number: 5171

Today's topics:
        & in a filename <zzhao@execulink.com>
        Commercial use of Perl ?'s (Krusty276)
    Re: DBF Format (Alastair)
    Re: deleting an array of words from a string (Bart Lateur)
    Re: Determining GIf and JPG's dimensions (Alastair)
    Re: Editing array content <cassell@mail.cor.epa.gov>
        Executing another SCRIPT on a different SERVER <dales@enhanced-performance.com>
    Re: foo bar (Laurence Leider)
        foreach loop question (IGuthrie)
    Re: getline equivalent in Perl? (Alastair)
    Re: Here 's a good one !!! (Larry Rosler)
    Re: How to dup a $fh_ref ? <rick.delaney@home.com>
    Re: How to redirect Output? (Sam Holden)
    Re: incrementation with undef results in definition. <rick.delaney@home.com>
        installation error <scott.ranzal@mci.com>
    Re: List of Lists (Larry Rosler)
    Re: Ms-Mail from perl <sugalskd@netserve.ous.edu>
    Re: Mysterious Perl Bug <cassell@mail.cor.epa.gov>
    Re: Perl 4 to Perl 5 Question <cassell@mail.cor.epa.gov>
        PERL Text Handling jtreyes@mindspring.com
    Re: PERL Text Handling (Bart Lateur)
    Re: PERL Text Handling (David Jacoby)
    Re: Perl/Daemon (Alastair)
    Re: searching a flat file database (Larry Rosler)
    Re: Speeding up Multi Word Searches (Boolean OR) <cassell@mail.cor.epa.gov>
    Re: unlink problem (Charles DeRykus)
    Re: Variables in QUERY_STRING jt@enterprise.net
    Re: Why can't i create a file with >>$file? (Bart Lateur)
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Thu, 18 Mar 1999 20:47:05 -0500
From: "Jerry Zhao" <zzhao@execulink.com>
Subject: & in a filename
Message-Id: <7csafo$d9n$1@demon.uunet.ca>

It seems to me that Perl doesn't like & in a filename (as in B&W.data). Why?
How does one get arround that?





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

Date: 19 Mar 1999 01:43:51 GMT
From: krusty276@aol.com (Krusty276)
Subject: Commercial use of Perl ?'s
Message-Id: <19990318204351.15302.00000281@ng-fq1.aol.com>

Hey our company is using ActivePerl to develop some software, there is no
licencing fee you need to pay for commercially selling our software that was
developed in active Perl 5 is there ?


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

Date: Fri, 19 Mar 1999 00:00:34 GMT
From: alastair@calliope.demon.co.uk (Alastair)
Subject: Re: DBF Format
Message-Id: <slrn7f350u.5j.alastair@calliope.demon.co.uk>

mtcorey@my-dejanews.com <mtcorey@my-dejanews.com> wrote:
>I was told that it was possible to use the DBD::xBase module to write data
>out in DBF format.  I have never used the DBD::xBase module, so I am totally
>lost.

Why don't you have a look at the docs that are, no doubt, part of this module?


-- 

Alastair
work  : alastair@psoft.co.uk
home  : alastair@calliope.demon.co.uk


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

Date: Fri, 19 Mar 1999 00:21:38 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: deleting an array of words from a string
Message-Id: <36f39796.714848@news.skynet.be>

Larry Rosler wrote:

>@ignore = qw(i am a);
>
>> $string = "a boy am i";
 ..
>  $string =~ s/\b(?:i|am|a)\b//g;

Indeed. And if you're interested, it's quite easy to build the regex on
the fly from the list of words. Somebody once suggested:

	{
		local $" = '|';
		s/\b(@ignore)\b//o;
	}

which will probably work alright, provided that the "words" are
garanteed to be constructed properly. Otherwise, if any contain non-word
characters, not only should those be quoted, (backslash), but "\b" will
no longer do what was desired, either.

	Bart.


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

Date: Fri, 19 Mar 1999 00:11:53 GMT
From: alastair@calliope.demon.co.uk (Alastair)
Subject: Re: Determining GIf and JPG's dimensions
Message-Id: <slrn7f35m5.5j.alastair@calliope.demon.co.uk>

John Swainston <John.Swainston@iclweb.com> wrote:
>Hi all,
>	I want to write a PERL script to determine the dimensions of
>an image, so that I can restrict the size of images uploaded to a
>site.	

Have you tried the Image::Size module on CPAN? 

http://www.cpan.org

-- 

Alastair
work  : alastair@psoft.co.uk
home  : alastair@calliope.demon.co.uk


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

Date: Thu, 18 Mar 1999 16:53:13 -0800
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: Editing array content
Message-Id: <36F19FF9.3BC0E795@mail.cor.epa.gov>

Larry Rosler wrote:
> 
> In article <JnYG2.726$AI1.23@weber.videotron.net> on Sun, 14 Mar 1999
> 19:20:58 -0500, u4ia <u4ia@nospam.videotron.ca.nospam >says...
> ...
> > So how I can remove the last line? The array have a static lenght, the empty
> > line is the line 34.
> 
> perldoc -f pop
> 
> > I tried $chomp($ra[34]) since the last line is a carriage return but it
> > didn't work and I can't see any other operators to remove array content.
> > *sigh* :o) (did I already said that I'm coding Perl for two days only? :P ).
> 
> perldoc -f splice
> 
> 'splice' can be used to delete an arbitrary hunk of an array.  'pop' is
> a special case to delete the last element.

And in case [1] Larry's explanation was not enough verbiage for you, and
[2] you don't have perldoc because you're running ActivePerl on a Win-box,
look in the html documentation under perlfunc, and find the entries for
'pop' and 'splice'.

David
-- 
David L. Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Thu, 18 Mar 1999 16:00:18 -0800
From: Dale Sutcliffe <dales@enhanced-performance.com>
Subject: Executing another SCRIPT on a different SERVER
Message-Id: <36F19392.B5309942@enhanced-performance.com>

How would I execute and pass information to another script on different
server?
I need to do this without doing a post or get.
Thanks.

--
PLEASE NOTE: comp.infosystems.www.authoring.cgi is a
SELF-MODERATED newsgroup. aa.net and boutell.com are
NOT the originators of the articles and are NOT responsible
for their content. You can SELF-APPROVE your first posting
by writing the word 'passme' on a line by itself.



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

Date: Fri, 19 Mar 1999 00:43:25 GMT
From: lleider@tiny.net (Laurence Leider)
Subject: Re: foo bar
Message-Id: <36f19cd0.2007155@news.visi.com>

Seems like nobody remembers FUBAR being explained in Tango & Cash many
years ago.  Even after the explanation, Cash (Sylvester Stallone) did
not really understand FUBAR until Tango (Mark Russell) stuffed a
grenade down the bad guy's pants and well, the guy was FUBAR shortly
thereafter.


On Mon, 14 Dec 1998 09:34:50 -0800, Marc <metalmd@earthlink.net>
wrote:

>It's fubar, if you're referring to the Private Ryan movie.  Not sure if it
>is the same thing here, but it probably is. And it means  f#$%^ up beyond
>all recognition.  You can add it the first word.
>
>Marc
>
>Todd Smith wrote:
>
>> where's this foo-bar stuff come from? I heard it in that "Search for
>> Private Ryan" movie. What's it mean?, and what's it got to do with Perl?
>>
>> --
>> _______________
>> Todd Smith
>> Perl Programmer
>> ITC^Deltacom
>



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

Date: 19 Mar 1999 01:59:57 GMT
From: iguthrie@aol.com (IGuthrie)
Subject: foreach loop question
Message-Id: <19990318205957.06675.00000081@ng-fr1.aol.com>

Hello I am have a small piece of code and a question. Here is the code:

foreach $a (0 .. 2)  {
     $a="a$a";
      print"a: $a\n";
     foreach $b (0 .. 2)  {
           $b="b$b"; 
           print "b: $b\n";
     }
}

If you run it it prints something like:
a: 0
b: b0
b: b1
b: b2
a: 1
b: bb0
b: bb1
etc .....

Question is why does $b retain the "b" character that was added onto $b from
the previous run of the foreach loop? I thought that $b would go out of scope
when its foreach loop exited and that $b was reset to the value of the next
item returned by the list given to the foreach loop? I know it may not be a
good idea to mess with iteration variables and is easliy fixable but I just
thought this was interesting and would like to know why it is happening.

Thanks


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

Date: Fri, 19 Mar 1999 00:02:49 GMT
From: alastair@calliope.demon.co.uk (Alastair)
Subject: Re: getline equivalent in Perl?
Message-Id: <slrn7f3555.5j.alastair@calliope.demon.co.uk>

Aaron Ginn <rp2885@email.sps.mot.com> wrote:
><HTML>
>Never mind, I answered my own question.&nbsp; I&nbsp;forgot all about a2p!&nbsp;
>If anyone is interested, I&nbsp;ran a2p on the following awk file:

I'm glad you fixed the problem. One thing though - can you configure your news
client to post plain text and not all this HTML please?

Thanks.

-- 

Alastair
work  : alastair@psoft.co.uk
home  : alastair@calliope.demon.co.uk


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

Date: Sun, 14 Mar 1999 19:47:02 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Here 's a good one !!!
Message-Id: <MPG.1156228fc7ba86b7989749@nntp.hpl.hp.com>

In article <comdog-ya02408000R1403991724100001@news.panix.com> on Sun, 
14 Mar 1999 17:24:10 -0500, brian d foy <comdog@computerdog.com >says...
> In article <7chaap$7da$1@ionews.ionet.net>, "Travis" <Travis@wildboysnet.com> posted:
> > when using the -w on code I often get a screen full of errors due to the
> > fact that I forgot an
> > quotation mark somewhere ( on a print statement ) .  Anyone know how the
> > errors can be saved to a file so
> > you can read the first offending error ?
> 
> why save it to a file?
> 
>    perl -cw script_name | more

Doesn't this pipe STDOUT to 'more'?  The perl diagnostics are written to 
STDERR, which goes straight to the terminal unless redirected.

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


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

Date: Fri, 19 Mar 1999 00:42:21 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: How to dup a $fh_ref ?
Message-Id: <36F19F62.9133A913@home.com>

[posted & mailed]

Phil R Lawrence wrote:
> 
> OK, I want to redirect STDERR.  The following test script works fine 
> if I redirect to LOG, but dies if I try to redirect to $fh_log.  How 
> should I do it?
> _______________________
> #!/usr/local/bin/perl -w
> use diagnostics;
> 
> open LOG, ">test.log" or die "Couldn't open log!";
> $fh = \*LOG;
> open SAVERR, ">&STDERR";
> open STDERR, ">&$fh" or die "Couldn't redirect STDERR!";
                                                       ^
Don't just exclaim, explain!

    open STDERR, ">&$fh" or die "Couldn't redirect STDERR:  $!";
                                                            ^^
>From the entry for open in perlfunc:

    You may also, in the Bourne shell tradition, specify an EXPR 
    beginning with '>&', in which case the rest of the string is
    interpreted as the name of a filehandle (or file descriptor, if 
                       ^^^^^^^^^^^^^^^^^^^^
    numeric) to be duped and opened.

$fh will obviously not return the name of the filehandle.  But you can
get the file descriptor.

    my $fd = fileno($fh);

Then you would have

    open STDERR, ">&$fd" or die "Couldn't dup STDERR: $!";

Of course, if you're just redirecting stderr (as opposed to dup'ing it),
you could just do

    open STDERR, '>test.log' or die "Can't redirect STDERR:  $!\n";

-- 
Rick Delaney
rick.delaney@home.com


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

Date: 19 Mar 1999 00:59:28 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: How to redirect Output?
Message-Id: <slrn7f38bg.c5p.sholden@pgrad.cs.usyd.edu.au>

On Thu, 18 Mar 1999 08:03:27 -0500, Allan M. Due <Allan@due.net> wrote:
>Pep Mico wrote in message <36F0C2AB.D37B932A@hp.com>...
>:Hello,
>:I'm Using Activestate perl (perl for win32). And I'm trying to redirect
>:the output of my scripts using the simply MS-DOS redirecting like this.
>:myscript.pl > output.txt
>:But output.txt doesn't receive anything it has the lengh of "0" zero
>:bytes.
>:My "sophisticated" script is only this line
>:print "hello\n";
>:Why It doesn't work? How can i redirect the output of my Script?
>
>Something else must be goint on. If, at the prompt, I type
>
>perl myscript.pl > output.txt
>, and myscript.pl contains
>print "hello\n";
>
>then output.txt contains hello.  Are you sure your script actually runs?

Windows seems to break redirections when associations are used in 
running a program. Since the original post said they used
'myscript.pl > output.txt', that is probably the reason.

I don't know the solution (I suspect it's some tweaking of the association),
but searching on dejanews, or a win32/perl place somewhere should turn
something up.

-- 
Sam

If your language is flexible and forgiving enough, you can prototype
your belief system without too many core dumps.
	--Larry Wall


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

Date: Fri, 19 Mar 1999 01:53:36 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: incrementation with undef results in definition.
Message-Id: <36F1B016.F8DC67DC@home.com>

[posted & mailed]

jon@amxstudios.com wrote:
> 
>   DB<17> $x .= undef($y)
> 
>   DB<18> print 'defined' if defined($x)
> defined
>   DB<19>
> 
> This seems odd to me. A similar effect occurs with the += operator.
> 
> Likewise, if you start with an undefined $x and do:
> $x = ((undef) + (undef))
> 
> $x will be defined.
> 
> Is this a bug, or am I missing something?

Are you missing -w?  Your examples will surely produce 'use of
uninitialized value' warnings.  If you 'use diagnostics' it will even
tell you that the values are interpreted as "".

Many Perl operators expect to get defined operands and if they don't
then perl will try to supply something useful (such as "" or 0).  Then
the operator will return a defined value.

Do addition and concatenation really make sense on undefined operands? 
I don't think so.  Perl is just trying to DWYM.

> 
> The reason this is getting in my way, is that I want to error check a 
> sequence of function calls like this:
> undef ($error);
> $error .= func1();
> $error .= func2();
> 
> print "Something failed" if defined $error.

I don't understand why you would check them like that.  Why the
concatenation?  Do you mean func1 returns undef on success?  If so then
why not

    if (defined ($error = func1())) {
        die $error;
    }

?

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Fri, 19 Mar 1999 01:31:22 GMT
From: "Scott Ranzal" <scott.ranzal@mci.com>
Subject: installation error
Message-Id: <KNhI2.120$zG2.751@PM01NEWS>

all

trying to install perl5.005_02 on AIX4.3.1 machine(rs6000).  make generates
the following error.

"/usr/include/arpa/inet.h" the type "struct_ether_address" was introduced in
a parameter list, and will go out of scope at the end of the function
declaration or definition.

I think it means the install program is unable to find something it needs.
my question is does anyone know what that is or how i would be able to
figure it out ?

several test failed on running make test:
pragma/overload
lib/tie-push

if that is any help in discovering the errors cause.

thanks

scott ranzal
scott.ranzal@mci.com
415-544-0508





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

Date: Sun, 14 Mar 1999 19:55:14 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: List of Lists
Message-Id: <MPG.1156247e12dfdd1898974a@nntp.hpl.hp.com>

[Posted and a courtesy copy sent.]

In article <01be6e90$e1d15150$2bbe10ac@amipnet> on 15 Mar 1999 03:07:47 
GMT, Sheila  Eugenio <seugenio@man.amis.com >says...
 ...
> @data = ( [09, 10, 11],
> 	   [7.5,6.8,5.6]);
> Can the array keep the data so that the next combination will be added at
> end?

  push @{$data[0]}, 12;
  push @{$data[1]}, 4.2;

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


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

Date: 19 Mar 1999 00:53:58 GMT
From: Dan Sugalski <sugalskd@netserve.ous.edu>
Subject: Re: Ms-Mail from perl
Message-Id: <7cs776$d0i$1@news.NERO.NET>

massimobalestra@my-dejanews.com wrote:
: Hi, Does somebody knows if there is a way to send a mail Through a server
: Microsoft Mail (Ms-Mail) without having a gateway? Or  (Off Topic) does
: exists there a (freeware) gateway from unix to ms-mail?

: I know perl and unix but not ms-mail server.

Does the MSMail server do SMTP? If so, you can always connect to it and
send mail directly. If not, you could always see about sneaking a linux
box in there somewhere... :)

					Dan


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

Date: Thu, 18 Mar 1999 16:28:33 -0800
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: Mysterious Perl Bug
Message-Id: <36F19A31.5743C206@mail.cor.epa.gov>

Craig wrote:
> 
> I have a large script about 200k running on Perl 5.00502. It gives an
> Internal Server Error when it comes to the second line listed below:
> 
> open(FILE,"$path");
> @lines = <FILE>;
> close(FILE);
> 
> The file located at $path does exist by the way. When I take the same
> three lines of code and run them in a smaller script, they work fine.
> Does anyone know why the second line of code causes a larger script to
> error out but not a smaller script?

The error you sort of quoted is not a Perl error.  Are you running
this on a web server?  When you tested the small chunk of code did 
verify that it was using the same environment?  I assume that your
$path variable is actually a $path/$file combo, or else you should
have had a problem with the smaller script.  But still, you're going
to have to give us more info.  Can you tell us exactly where this
is running?  Which version of Perl?  Can you make a small [10 - 40]
line program which duplicates the error?

And BTW, always check open() and close() for errors:
    open(FILE,"$path/$filname") or die "couldn't open $filname: $!";
 
David
-- 
David L. Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Thu, 18 Mar 1999 16:19:21 -0800
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: Perl 4 to Perl 5 Question
Message-Id: <36F19809.BAD27D76@mail.cor.epa.gov>

Andrew Weiss wrote:
> 
> I'm kinda new to Perl.  Got the camel and the llama books.  Nowhere near
> proficient in it, just dangerous.

Don't worry aobut that.  People have said that about me too.  :-)
The camel and llama books are an *excellent* start.  Make sure they're
the turquoise [Perl 5] ones.
 
> I've recently become responsible for maintaining a legacy "application"
> written in Perl.  When last modified, the application was targeted for Perl
> 4, and it ran fine.  Oh, Perl4 on OS/2, that is.

Perl 4, and porting to a different OS.  You have my deepest sympathies.
Let me see if there's some way I can help.
 
> Now I must take that application, and port it to Windows 95/98.  The first
> place I started was to download Perl for Windows.  The perl.com site allowed
> me to download version 5.005_02.  Unfortunately, the application blows sky
> high, producing many errors, when run with that version of Perl.  I can also
> download version 5.004_04, but I doubt that it will work either.  I tried
> ActivePerl, and the same errors came when I ran the application.
> 
> Here are my questions:
> 
> (1) Should I find a Perl4 and build it for W95/98?  If so, where would I
> begin?

No.  Umm, let me re-phrase that.  NNNOOOOO!!!!  Perl 4 has known bugs, and
is no longer supported.  Tom Christiansen has suggested the following
substitution:
    s/Perl 4/dead flea-bitten camel carcasses/g

> (2) Or, should I put the time in to find out why the application won't work
> under Perl5 (already spent a day at this, and getting frustrated) ?

I hate to say it, but this is the way to go.  Really.  You have the Camel
book.  Assuming it's the turquoise one, turn to Chapter 8 and read the section
entitled 'Previous Perl Traps'.  There are four pages of traps for the unwary.
Many of these can be caught just by using the -w flag.  Try adding -wc to the
end of the shebang line of the program [the first line, which starts '#!' ].
The -w gives you warnings.  The -c checks the syntax and exits without 
executing the whole program.  If you get an armada of errors on your screen,
just redirect them to an error file to peruse at your discretion.

Another thing to consider: now that there are huge numbers of Perl modules
available at CPAN, check the code for ugly re-inventions of the wheel.
That is, are there massive chunks of code written just to [do cgi programming |
do socket programming | etc., etc., etc.]?  Because you might want to
excise the clunky code and replace it with working code from CPAN.

> (3) Or, does anybody know of a program which can translate Perl4 to Perl5,
> or can point out what portions of the source may not work under Perl5?

The -wc flags should do a lot of that for you.
 
> An email in addition to your reply post would also be appreciated.

Done.  Good luck.

David
-- 
David L. Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Thu, 18 Mar 1999 23:47:40 GMT
From: jtreyes@mindspring.com
Subject: PERL Text Handling
Message-Id: <7cs3ao$ii2$1@nnrp1.dejanews.com>

Hello,

I'm need some advice with basic Perl test manipulation. I'm unable to detemine
how to concatenate strings. For instance, I'm using the command
"$line+=$onechar;", but the result is a number not two characters. Any help
would be appreciated.

Thanks,

 .joe



#!/usr/bin/perl

$INFILE="input.txt";
$OUTFILE="output.txt";


open (IN, "< $INFILE");
open (OUT, "> $OUTFILE");

while (!eof(IN)){
$charascii=0;
$line="";
$onechar="";

while ($charascii!=10) {
	$line+=$onechar;
	$onechar=getc(IN);
	$charascii=ord($onechar);

}

$header=substr($line,1,1);

if ($header="=" or $header="-") {
	print OUT "$line\n";
	print "$line\n";
}

}

close 1;
close 2;

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Fri, 19 Mar 1999 00:15:41 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: PERL Text Handling
Message-Id: <36f2971e.594782@news.skynet.be>

jtreyes@mindspring.com wrote:

> I'm unable to detemine
>how to concatenate strings. 

Look up . and .=

	Bart.


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

Date: 19 Mar 1999 00:12:36 GMT
From: jacoby@pier.ecn.purdue.edu (David Jacoby)
Subject: Re: PERL Text Handling
Message-Id: <7cs4pk$4p4$1@mozo.cc.purdue.edu>

In article <7cs3ao$ii2$1@nnrp1.dejanews.com>,  <jtreyes@mindspring.com> wrote:
>Hello,

>I'm need some advice with basic Perl test manipulation. I'm unable to detemine
>how to concatenate strings. For instance, I'm using the command
>"$line+=$onechar;", but the result is a number not two characters. Any help
>would be appreciated.

Perl has parallel operators for character strings and numbers.

$line .= $onechar ;

>Thanks,
>
>.joe
>
>
>
>#!/usr/bin/perl
>
>$INFILE="input.txt";
>$OUTFILE="output.txt";
>
>
>open (IN, "< $INFILE");
>open (OUT, "> $OUTFILE");
>
>while (!eof(IN)){
>$charascii=0;
>$line="";
>$onechar="";
>
>while ($charascii!=10) {
>	$line+=$onechar;
>	$onechar=getc(IN);
>	$charascii=ord($onechar);
>
>}
>
>$header=substr($line,1,1);
>
>if ($header="=" or $header="-") {
>	print OUT "$line\n";
>	print "$line\n";
>}
>
>}
>
>close 1;
>close 2;
>
>-----------== Posted via Deja News, The Discussion Network ==----------
>http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


-- 
 David Jacoby                            mailto:jacoby@ecn.purdue.edu
 Lead Web Technician, ECE          http://www.ecn.purdue.edu/~jacoby/
Can surgery and multiplayer Doom coexist on a network? -- Stephen Wolff
-----------------------------------------------------------------------


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

Date: Fri, 19 Mar 1999 00:05:15 GMT
From: alastair@calliope.demon.co.uk (Alastair)
Subject: Re: Perl/Daemon
Message-Id: <slrn7f359n.5j.alastair@calliope.demon.co.uk>

wweng@ei.org <wweng@ei.org> wrote:
>Can I write a perl script and run it as a daemon?

Yes.

There are good examples of this in the Perl Cookbook for example (O'Reilly). It
is well worth buying.

-- 

Alastair
work  : alastair@psoft.co.uk
home  : alastair@calliope.demon.co.uk


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

Date: Sun, 14 Mar 1999 20:30:35 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: searching a flat file database
Message-Id: <MPG.11562cc4b1fd12b198974b@nntp.hpl.hp.com>

[Posted and a courtesy copy sent.]

In article <7ch1n6$b0c$1@camel15.mindspring.com> on Sun, 14 Mar 1999 
14:15:44 -0500, Winfield Henry <winfieldh@mindspring.com >says...
 ... 
> The input search string would be
> 
> '1990 ford explorer'
> 
> I need to break up the search string into '1990' 'ford' 'explorer' and (I
> think) loop through each record however many times there are items in the
> search string to match them all/partial. Its the breaking up of the search
> string that I'm having difficulties with.

As your search string comes from the users, you have to make defensive 
assumptions.  Assuming you want only literal matches, you should use the 
quotemeta function on the string before creating the search pattern.

  $search = '\b(?:' . join('|', split ' ', quotemeta $string) . ')\b';

 ...
> sub Do_Search{
>      open(DATAFILE,"$datafile");

The quotes are superfluous and misleading.  What happens if the 'open' 
fails?  ALWAYS test, and do something intelligent on failure.

>      while(<DATAFILE>){
>        if(/$search/i){

Because this is a CGI program with only one set of input data, the 
contents of $search will not change during execution, so you should add 
the '/o' suffix, which will give a significant performance boost.

>          push @matches, $_;
>        } # End of if.
>      } # End of while.
>      close(DATAFILE);
>      return;
> } # End of Do_Search subroutine.

A different approach to this problem is to populate a hash with the 
(lower-cased) individual search terms as keys, then split the (lower-
cased) input lines into 'words' and look them up in the hash.

UNTESTED:

       my %hash;
       @hash{split ' ', lc $search} = ();
       while (<DATAFILE>) {
         for my $word (split ' ', lc) {
           if (exists $hash{$word}) {
             push @matches, $_;
             last;
           } # End of if.
         } # End of for.
       } # End of while.

These approaches aren't exactly the same, because \b word boundaries and 
\s word boundaries are not the same.  But that may not matter.  If it 
does, one might replace the two \b's in the regex above by (?:\s|^) and 
(?:\s|$) respectively.  Or one could replace the two splits on ' ' by 
splits on /\b/.

Ultimately a benchmark would be needed to decide which approach is 
better.

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


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

Date: Thu, 18 Mar 1999 16:47:41 -0800
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: Speeding up Multi Word Searches (Boolean OR)
Message-Id: <36F19EAD.1EBB2BBF@mail.cor.epa.gov>

regnery@ix.netcom.com wrote:
> 
> Hello,
> 
> I currently have a PERL Script that allows searching of a flat text file.
> Users can select either a boolean AND or a boolean OR search.  Then the
> script reads each line in the flat file, parses it, and searches for the
> terms in the relevant field.
> 
> Many people do boolean OR searches.  The variable pulled from the database is
> called $coname, and the terms that the user typed in are in @terms.  Right
> now, when there is an OR search, I have to look for every term in @terms as
> follows:
> 
>         foreach $term (@terms) {
>               if ($coname =~ /$term/i) {
>                             $termhits[$termcounter]++;
>                             $key = 'yes';
>                             $orhits++;
>               }
>                         $termcounter++;
>         }
> 
>

Take a look in perlfaq6: How do I efficiently match many regular expressions
at once?  It points out that your approach "is super-inefficient".  Tom's
words, not mine.  And it has code to do it better.  For more regex info,
check out Jeffrey Friedl's book "Mastering Regular Expressions".

David
-- 
David L. Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Fri, 19 Mar 1999 01:03:11 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: unlink problem
Message-Id: <F8tHLB.1xK@news.boeing.com>

In article <36effdf6.64473147@news.ionet.net>, Mark P. <mag@imchat.com> wrote:
>	I've used unlink several times and never had a problem, but
>now I can't seem to get this to work even though it should. Anyone see
>what I'm not seeing? This is simple code.
>
>sub delete 	{
>&ReadParse;
>	if ($in{'delete'} eq 'yes'){
>unlink("$htmldir/$file");
>}
>
>	The only thing I can think of is that the file resides in a
>totally different directory, but that shouldn't make a difference. It
>is on a server with ugh! FrontPage extensions installed and is in a
>password protected directory. I tested this on my own server and it
>didn't work there also.
>

Have you checked the usual: linefeed on end of $file, file permissions...

hth,
--
Charles DeRykus


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

Date: Fri, 19 Mar 1999 00:11:22 GMT
From: jt@enterprise.net
Subject: Re: Variables in QUERY_STRING
Message-Id: <36f39626.51916743@news.enterprise.net>

On Thu, 18 Mar 1999 22:26:54 GMT, Scratchie <upsetter@ziplink.net>
wrote:

>
>jt@enterprise.net wrote:
>: Oh, for goodness sakes!  Are you two so new to this list that you
>: can't realise the PERL implications of the simplest query?
>
>: If there's anyone with the slightest PERL experience, perhaps you
>: would help me - it's a perfectly reasonable request which doesn't
>: warrant the indifference of tin gods.
>
>Well, since you asked so nicely: 
>
>What you need to do is find the portion of your script where it
>IOUdsf*&(###77978*JHf**$*&$&*&&*&**&*&*&*&
>
>NO CARRIER
>


You colonials - so funny!


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

Date: Fri, 19 Mar 1999 00:13:48 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Why can't i create a file with >>$file?
Message-Id: <36f1963a.366075@news.skynet.be>

Harold Bamford wrote:

>If you are executing this as a CGI script, then remember that the
>web server is executing the script as somebody other than you. Such
>as 'nobody'.
>
>>I am trying to append to a file and it won't append nor will it create the
>>file if it isn't there.  Why?  I am using:

Indeed. ">>" creates fiels as well. But it's a quite bizarre thing on
Unix: you need EXECUTE permissions on the directory to be allowed to
create files, while you only need WRITE permissions to overwrite an
existing file. Hmm... the reverse might have made more sense. But,
that's life.

   HTH,
   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 5171
**************************************

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