[10859] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4460 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Dec 19 11:07:19 1998

Date: Sat, 19 Dec 98 08:00:59 -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           Sat, 19 Dec 1998     Volume: 8 Number: 4460

Today's topics:
    Re: $&, $', and $` and parens.... (Bart Lateur)
    Re: ? (question mark) not recognised. <due@murray.fordham.edu>
    Re: [Q] How do I connect to a irc server using telnet f <gellyfish@btinternet.com>
        ANNOUNCE: Pod::Html patch providing relative URLs <rbs@lm.com>
    Re: Anyone have a workaround for crippled ActiveState p <newspost@morlock.net>
        Avoiding Editor Holy War (was Re: Favourite Editor for  <gellyfish@btinternet.com>
    Re: bless Perl objects or references <jipes@ispchannel.com>
    Re: help with system() or `` <gellyfish@btinternet.com>
    Re: how do I do this common text import task? <gellyfish@btinternet.com>
    Re: Installing pm files for Perl Win32 <pep_mico@hp.com>
    Re: need Sun Solaris 2.6 sun4u gcc binaires <gellyfish@btinternet.com>
    Re: numbers in base 36 (Matthew Bafford)
        Print only the first 50 characters <mark.givens@iname.com>
    Re: Print only the first 50 characters <gellyfish@btinternet.com>
    Re: Problem with script "... cgi-bin\signup.pl' script  <gellyfish@btinternet.com>
    Re: Problems when requesting documents from Apacheserve <gellyfish@btinternet.com>
    Re: Reading in data from a text file <due@murray.fordham.edu>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Sat, 19 Dec 1998 12:08:33 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: $&, $', and $` and parens....
Message-Id: <367d93e3.1657801@news.skynet.be>

Lary Rosler wrote:

>My conclusions (based on these limited tests):

>2.  Using the special variables has a *small* negative impact on 
>performance when they are not used.

That isn't clear.  The mere existence of these variables in the total
source, has a small negative impact in the regex code, even where they
aren't used.

Well, the results are pretty much what *I* would have expected.

They said it gave SOME loss of speed, for every regex. It does.

But somehow, things got a bit blown out of proportion. It reminds me of
the story of the assembler programmer who was really proud of a code
optimization he had dopne, which resulted in a speed gain of 10
microseconds, every time it was run. Somehow, he had overlooked the fact
that it ran at most once every few minutes made this optimization
totally irrelevant. Even if it would have run once every few seconds.

Look, if you really want to get rid of $&, $4 and $', here's one way to
do it:

	$_ = '123#abc@456!';
	$\ = "\n";
	if(/([a-zA-Z]+)/g) { # "pos" doesn't work without "//g"
		print "pos = ",pos;
		print "Before: ", substr($_,,0,(pos)-length($1));
		print "Match: ", $1;
		print "After: ", substr($_,pos);
	}
Result:
	pos = 7
	Before: 123#
	Match: abc
	After: @456!

That is all that these variables need done. Essentially it's very simple
code, so this should not take long. It is extremely simple when compared
to a matching a  regex. So it should never have taken a relatively large
amount of time. Never. Not even in Perl 4.

The only loss of speed is because this assignment happens every time if
any of these variables is used once, even if you don't need them. But
don't blow it out of proportion.

>3.  Using the special variables has a *big* positive impact on 
>performace when they are used.

That's because the regex is much simpler in the code where they are
used, than in your substitute.

	Bart.


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

Date: 19 Dec 1998 15:40:35 GMT
From: "Allan M. Due" <due@murray.fordham.edu>
Subject: Re: ? (question mark) not recognised.
Message-Id: <75ghdj$71s$0@206.165.165.145>

Jason Q. wrote in message <367d04cd.1388248@news.cyberway.com.sg>...
|>Of course, on reading the code, it's not clear to me why you're using
|>the regex engine at all: you could just as well use index, or maybe
|>string comparison (if you're looking for lines that exactly match
|>$RSTRING1 rather than lines that contain $RSTRING1).  Also, what is $i
|>used for -- why are you even using a foreach loop, if you increment a
|>counter each time through?
|
|The reason why I added the $found++ was so as to be able to find the
|line number with $halt=$found and then use that number to splice.
|
|I'm sure there's an easier way to do it but I'm still new to Perl and
|am using whatever little commands I know to build something. :)
|
|>In fact your whole algorithm seems awfully clunky to me.  I'll assume
|>you're looking for lines that *match* $RSTRING1 rather than *contain*
|>it; I would rewrite everything in between the read-file and write-file
|>steps as follows:
|>
|>  foreach (@array)
|>  {
|>    $_ = $RSTRING2 if $_ eq $RSTRING1;
|>  }
|
|I tried your method but when I print @array back to the file, the
|change wasn't reflected. Is there any other command I must include to
|properly print the modified @array back?


Although I like Ala's solutions a bit better (except that map in the void
context <g>) Greg's works fine and nothing else needs to be done (I just don't
like assigning to $_, to my way of thinking it is asking for trouble).  Your
script is going awry somewhere else.
quick example:

#!/usr/local/bin/perl -w
use strict;
my @array = qw(dog cat mouse);
my $RSTRING2 = 'elephant';
my $RSTRING1 = 'mouse';
print join "\n",@array,"-----\n";
foreach (@array)  {
    $_ = $RSTRING2 if $_ eq $RSTRING1;
}
print join "\n",@array;

gives:

dog
cat
mouse
-----
dog
cat
elephant


HTH

AmD




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

Date: 19 Dec 1998 15:29:21 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: [Q] How do I connect to a irc server using telnet from perl?
Message-Id: <75ggoh$16u$1@gellyfish.btinternet.com>

On 19 Dec 1998 11:48:33 +0100 Andreas Gustafsson <ante@Zeke.Update.UU.SE> wrote:
> Hi!
> 
> I'm trying to connect to my own irc-server (thus no ban
> on multiple connections) using perl. How do I do it?

You might try the Net::IRC module that is available from :

<URL:http://www.perl.com/CPAN/authors/FIMM/Net-IRC-0.54.tar.gz>

I havent had call to use it myself but its worth a try.

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Sat, 19 Dec 1998 08:57:38 -0500
From: Barrie Slaymaker <rbs@lm.com>
Subject: ANNOUNCE: Pod::Html patch providing relative URLs
Message-Id: <367BB0D2.732C3C4F@lm.com>

(resend since it looks like the first post didn't propagate)

I've posted an experimental patch that allows Pod::Html 
(and installhtml) to generate HTML docs with true relative URLs.  
The patch is for perl5.005_02, but the 2 patched files are also 
included and may give you some leeway...  This was done as a test
platform for File:PathConvert that might be useful for it's own
sake.

This means that the docs can be browsed coherently
no matter where they are rooted, so file: and http: access
methods both work, and they can be moved to a new
location without a rebuild.  It seems to work on my linux box, 
but your mileage may vary.  Let me know :-).

It's in

        patch-Pod-Html-relative-0.001_01.tar

This archive includes both patch files and patched files, as 
well as a Makefile to apply the patch and run installhtml.

You should be able to get it from:

http://www.telerama.com/~rbs/perl/
http://www.perl.com/CPAN/authors/id/R/RB/RBS/

(CPAN will take a bit to mirror everywhere).

You'll also need File::PathConvert, v0.84 or later, available
from the same place.  DON'T BOTHER WITH 0.83: IT WON'T HELP!

Feel free to contact me with any updates, questions, etc.

- Barrie


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

Date: Sat, 19 Dec 1998 08:27:34 -0500
From: "Steven Morlock" <newspost@morlock.net>
Subject: Re: Anyone have a workaround for crippled ActiveState perl -- fork()
Message-Id: <zSNe2.1703$qF5.5090054@lwnws01.ne.mediaone.net>


I understand that versions of Perl build with the Cygwin Win32 ports
of the GNU development tools support fork().  There appears to be support
for using this compiler in the standard Perl source archive - see the
README.cygwin32 in the archive.  The Cygwin tools can be found
at http://sourceware.cygnus.com/cygwin/

If any of you have had experience building and running Perl using
this development environment, I'd like to hear about it.

Steve

--
Foliage Software Systems
aka The Nerd Farm
http://www.foliage.com

hutchiss@my-dejanews.com wrote in message <75brrb$bnc$1@nnrp1.dejanews.com>...
>In the time-honored tradition of not re-inventing the wheel,
>I'm looking for hints or examples of ways to get around the
>gaping hole in Active State Perl...
>
>$main::whinge=1;
>Is there a reason why these guys didn't bother to implement
>a feature that NT supports and that even the 16-bit Windows
>API had ways to approximate?
>$main::whinge=0;
>
>I'm looking at different ways to do a fork equivalent. If I'm
>forced to use Tcl to do this part of things it will be high irony.
>
>I'm going to be using perlTk to do the GUI part of the project
>and it needs to be able to spawn off a number of different
>pieces that have to be able to run concurrently (this app can be
>run on Unix or NT) ... without the use of 'fork' I'm not sure
>just how I'll be able to do this.
>
>Hints?  Pointers?  Derisive laughter?  Anything?
>
>-----------== Posted via Deja News, The Discussion Network ==----------
>http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own




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

Date: 19 Dec 1998 14:40:21 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Avoiding Editor Holy War (was Re: Favourite Editor for NT Perl)
Message-Id: <75gdsl$sd$1@gellyfish.btinternet.com>

On Sat, 19 Dec 1998 03:13:36 GMT Peter L. Berghold <peter@berghold.net> wrote:
> 
> You are about to touch off a "holy war" with that question.  Everyone
> has a preference for what editor to use. 


I think under the circumstances the standard response should be to point the
questioner to the Editors section at <URL:http://reference.perl.com> thus
avoiding any provocative editor advocacy ...

Now I know I have been as guilty as anybody over this.

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Sat, 19 Dec 1998 09:33:01 -0600
From: "BenJamin Prater" <jipes@ispchannel.com>
Subject: Re: bless Perl objects or references
Message-Id: <367bc6c5.0@news.mediacity.com>

Rakesh,

Blessing an object simly means that Perl now knows where it belongs.

It's like giving (or blessing) the object with an additional knowledge of
where it comes from.

My name is BenJamin, and suppose I was blessed a Catholic. Whenever you run
BenJamin, you know that you should use the Catholic module, because in this
instance, that's the faith I belong to. (I feel compeled to note that I'm
not Catholic). That's what blessing does.

Ref simply tells you how the bless worked out.

BenJamin




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

Date: 19 Dec 1998 13:45:23 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: help with system() or ``
Message-Id: <75galj$s0$1@gellyfish.btinternet.com>

On Sat, 19 Dec 1998 11:58:01 GMT Nikolaus Nikoll <nikolaus.nikoll@wu-wien.ac.at> wrote:
> hi
> 
> i am writing a nph cgi script, which calls sqlplus to push the
> contents of some oracle db tables to another host, which takes about
> 2,3 minutes. i do it like this: 
> 
> @output = `sqlplus foo/bar@www.foo.at @script`;
> foreach $_ (@output) {
> 	print;
> }
> 
> this way, someone who executes this cgi script, has to wait until
> sqlplus is finished, and then gets loads of sqlplus output. 
> 
> is there any way to get and print the output from sqlplus (or any
> other command executed from within perl) while it is still running,
> which would be much more nicer for the user?
> 

I'm not sure how the output from sqlplus is buffered - and not having it
here I cant test it but you might try one of:

$| = 1;
print `sqlplus foo/bar@www.foo.at @script`;

or

$| = 1;
open(QUERY,"sqlplus foo/bar@www.foo.at @script |") || die "run failed - $!\n";
while(<QUERY>)
  {
    print;
  }
close(QUERY) || die "Error in sqlplus - $!\n";

You might want to check out the perlvar manpage to read about $| 


/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: 19 Dec 1998 12:44:48 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: how do I do this common text import task?
Message-Id: <75g740$pd$1@gellyfish.btinternet.com>

On Tue, 15 Dec 1998 02:28:24 -0800 Terry Haroldson <tharold@portal.ca> wrote:
> I'm new at this and am sure this is a easy question.  I have data in a
> text file similar to the following (retrieved from a Informix d/b).  I
> would like to transpose it into a csv format, so I can stick it into
> Excel.  (I don't care about the field names.)  This must be a common
> task.  Any ideas.
> 
> I would like to get this:
> 
> 11,1,876,1,909576453,7,0,0,7
> 2,CT003A,76,1,912859221,0,0,0,0
> 2,CT003A,51,1,912859221,0,0,0,0
> etc.
> 

Hate to go against the orthodoxy but why dont you just do :

UNLOAD TO "blah.csv" DELIMITER ","
SELECT * FROM <blah> ....

when you export the data from Informix.  Yeah I know it aint Perl but its
sensible I would have thought ...

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Sat, 19 Dec 1998 14:25:24 +0100
From: Pep Mico <pep_mico@hp.com>
To: Bob Stickel <bstickel@dot.state.oh.us>
Subject: Re: Installing pm files for Perl Win32
Message-Id: <367BA944.B9164F2A@hp.com>

To answer your e-mail question about wich books are available. Well it depends
of your knowledge about perl. If you want an entry level you could check some
books that are available at http://www.mcp.com, you must register (free) and
you will have access to a personal bookshelf where from you could read several
books about perl + cgi.

Or you have the option with the typical books of Perl  from "O'Really"
http://www.oreilly.com/


Hope this helps
pep_mico@hp.com





Bob Stickel wrote:

> I just got started with ActiveState's version 5.005_02 under 95 and NT with
> no particular problems. Now I would like to install some modules but can't
> figure out exactly what I need to do. I understand the make commands from
> previous Linux experience but I don't have a C compiler installed on my
> Win32 platforms. Do I need to get the GNU DOS version and compile the
> modules before they can be installed or do I need to have a Win32 C
> compiler? I have Borland and Msoft available for installation but really
> don't want to install them unless absolutely necesssary.
>
> Thanks
>
> Bob





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

Date: 19 Dec 1998 13:52:25 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: need Sun Solaris 2.6 sun4u gcc binaires
Message-Id: <75gb2p$s3$1@gellyfish.btinternet.com>

On Tue, 15 Dec 1998 19:58:29 -0800 euclid <euclid@crl.com> wrote:
> I desparately need Sun Solaris 2.6 sun4u gcc binaires in order to build
> Perl and Apache..(uh... right)  I am wondering if this will even work..
> any Perl/Apache on Sun Solaris 2.6 sun4u??

I and many others have Perl and Apache running on Solaris - You wont need
to use gcc if you have Sun Workshop and/or the c89 compiler ...

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Sat, 19 Dec 1998 10:27:41 -0500
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: numbers in base 36
Message-Id: <MPG.10e58ff4bce8d13d989767@news.scescape.net>

In article <x7iuf8mye3.fsf@sysarch.com>, uri@sysarch.com says...
=> >>>>> "MB" == Matthew Bafford <dragons@scescape.net> writes:
=> 
=>   MB> Well, I looked back through my old *ha* scripts, and dug up:
=>   MB> (minus the error checking)
=> 
=> and minus the bug fixes! did you ever test this with a 3 digit number?  :-)

I did say it was from one of my older scripts! :)  Anyway, it works fine 
with a 3 digit number.

*scratch head*

=>   MB> sub base2dec {
=>   MB> 	my %chars;
=>   MB> 	@chars{(0..9, 'A'..'Z')} = (0..35);
=> 		
=>   MB> 	my $base   = shift;
=>   MB> 	my $number = reverse(shift);
=>   MB> 	my $ret;
=>   MB> 	my $multi = 1;
=> 
=>   MB> 	for ( split //, $number ) {
=>   MB> 		$ret   += $chars{$_} * $multi;
=> 
=>   MB> 		if   ( $multi == 1 ) { $multi  = $base }
=>   MB> 		else                 { $multi *= 2     }
=>                                                  ^^^
=>                                                  $multi

Um, no.  That's not how this works.

The multiplier doubles every position, not squares.

=>   MB> 	}
=>   MB> 	return $ret;
=>   MB> }
=> 
=>   MB> I probably would have written it differently now, but it does work. :)
=> 
=> no it doesn't!

eh?

=> it also is slower than it has to be.

That may be.

=>                                       i didn't benchmark the changes but
=> i would wager that removing the reverse and using chop will beat the
=> split. 

Maybe.

=>        also the if looks suspect. 

Yeah, I don't like it, but that's what I came up with when I wrote it.

[snip]

=>        this also handles lower case input. i wonder if ucfirst is faster
=> than uc for a single character value?

I did say adding lowercase support would be trivial. :)

=>                                        i am too tired to hack up a
=> benchmark for that or my other changes. help me larry? :-)
=> 
=> hth,

Well...

Regarding your code.  I'm sure it's much faster, but it has one major 
flaw.  It doesn't work.

Say base is 16:

0  == 0
1  == 1
2  == 2
3  == 3
4  == 4
5  == 5
6  == 6
7  == 7
8  == 8
9  == 9
A  == 10
B  == 11
C  == 12
D  == 13
E  == 14
F  == 15
11 == 2     # Should be 16
12 == 3     # Should be 17
 .. == ..


You do see why that's happening, don't you?

=> sub base2dec {
=> 	my %chars;
=> 	@chars{(0..9, 'A'..'Z')} = (0..35);
=> 		
=> 	my $base   = shift;
=> #	my $number = reverse(shift);
=> 	my $number = shift;
=> 	my $ret;
=> 	my $multi = 1;
=> 
=> #	for ( split //, $number ) {
=> 	while( $c = chop $number, length( $c ) ) {
=> 		$ret   += $chars{ uc $c} * $multi;

                                     * 1     ;

=> 		$multi *= $multi ;

            1      *= 1      ;

=> 	}
=> 
=> 	return $ret;
=> }

I'm not sure why you were so bothered by efficiency in this case, but I 
did benchmark them (the if check added back into yours so it would work), 
and got:

Benchmark: timing 32768 iterations of MB, URI...
        MB: 48 wallclock secs (49.10 usr +  0.00 sys = 49.10 CPU)
       URI: 44 wallclock secs (43.45 usr +  0.00 sys = 43.45 CPU)

So yours is faster... :-)

Thanks!

=> uri

--Matthew


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

Date: Sat, 19 Dec 1998 08:12:17 -0600
From: "Mark Givens" <mark.givens@iname.com>
Subject: Print only the first 50 characters
Message-Id: <75gc87$2e@dfw-ixnews5.ix.netcom.com>

Hello, I am trying to figure out how to print the first 50 characters of a
string that may have up to 500 characters.  Basically, I want to give a
preview and let the user read and decide if they want to view the entire
string.

ie. shorten this which is $bookdesc and is a field in a "," delimited
database
  this is my book and it is really interesting and fun to read.  please feel
free to buy it now and blah blah blah

so it displays on a web page like this:
  this is my book and it is really interesting and fun to ...



Thanks in advance for your all your God like PERL powers!
--
Mark
mark.givens@iname.com
PERL God wannabe




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

Date: 19 Dec 1998 15:10:45 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Print only the first 50 characters
Message-Id: <75gfll$11i$1@gellyfish.btinternet.com>

On Sat, 19 Dec 1998 08:12:17 -0600 Mark Givens <mark.givens@iname.com> wrote:
> Hello, I am trying to figure out how to print the first 50 characters of a
> string that may have up to 500 characters.  Basically, I want to give a
> preview and let the user read and decide if they want to view the entire
> string.
> 
Assuming you want only to split on whitespace (and not get part of some word)
you might try something like this:


#!/usr/bin/perl
$longstring =  "this is my book and it is really interesting and fun 
to read.  please feel free to buy it now and blah blah blah";

($shortstring) = ( $longstring =~ /(.{1,50}) / );

print $shortstring, " ... \n";

read the perlop and perlre manpages for more on what is going on here.

> 
> 
> Thanks in advance for your all your God like PERL powers!

That'll be Dog and Perl at 8 and 10 respectively ;-}

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: 19 Dec 1998 14:05:41 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Problem with script "... cgi-bin\signup.pl' script produced no output "
Message-Id: <75gbrl$s9$1@gellyfish.btinternet.com>

On 16 Dec 1998 03:50:36 GMT Worldmall <worldmall@aol.com> wrote:
> 
> p.s. Here's the code:
> 
> print "HTTP/1.0 200 OK\n";
> ###########################################################
> # Pull in system configuration
> #
> $lib = "/cgi-bin";
> require "d:/inetpub/users/leads/config.pl";
> 
> #
> # Pull in required libraries
> #
> require "d:/inetpub/users/leads/cgi-bin/mail.pl";
> require "d:/inetpub/users/leads/cgi-bin/dbmember.pl";
> require "d:/inetpub/users/leads/cgi-bin/dbcompany.pl";
> require "d:/inetpub/users/leads/cgi-bin/ez_html.pl";
> require "d:/inetpub/users/leads/cgi-bin/web_basic.pl";
> 

<snip code>

I really would recommend using the CGI.pm module - it is designed to handle
platform specific stuff and makes it very easy to get the CGI and HTTP
things right so you can get on with making your script do the real
processing correctly. 

Your problem is unrelated to any platform issues - the message you get 
simply means that your program failed to make any output after it had sent
the headers.

The proper place to ask about general CGI issues (as your question is) 
rather than Perl specific one is at:

comp.infosystems.www.authoring.cgi

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: 19 Dec 1998 13:35:50 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Problems when requesting documents from Apacheservers
Message-Id: <75ga3m$rs$1@gellyfish.btinternet.com>

On Wed, 16 Dec 1998 19:59:05 +0100 Jesper Rautell Balle <jesper@rautell.dk> wrote:
> Hi..
> I picked up the following snip of code. I wan't to fetch certain
> html-document from other servers.
> When I request on MS-IIS there are no problems. But when I request a
> document from an Apache-server, I get a message that "the requested
> document could not  be found." Has anyone got an idea, what could be
> wrong?

<snip a bunch of code reinventing LWP::Simple>

> $s=getpage("www.rautell.dk","/index.htm");

Are you sure that the there is a file called "index.htm" in the document root
of your apache server - on mine there is one called index.html - it works 
fine if I use that or indeed '/' in lieu of a full file name.

Despite the fact that this code does work I would suggest that you use one
of the LWP::* modules available from CPAN in general.

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: 19 Dec 1998 13:36:29 GMT
From: "Allan M. Due" <due@murray.fordham.edu>
Subject: Re: Reading in data from a text file
Message-Id: <75ga4t$mt7$0@206.165.165.142>

mikej wrote in message <367AFEB3.D2592358@1185design.com>...
|Hi everyone,
|I have a script that opens a flat file database (LOG filehandle) and
|attempts to read in information on each line. The information in the log
|file looks like this:
|17|12-18-98|mj|logo.gif|one
|17|12-18-98|mj|home.gif|two
|17|12-18-98|mj|employ_top.jpg|three
|18|12-18-98|dp|image.jpg|image
|18|12-18-98|dp|image_2.jpg|image_two
|I have a form that prompts the user to type in a reference number, and
|the script is supposed to search each line of the log file to see if it
|matches the reference number to the number on the left to each line.
|Then I try to get the data on each line that matches the reference
|number they typed. It works for reading the data off the first line, but
|it wont get to the second, third, fourth lines down etc. even though I
|have it in a for each loop. Anyone know how to get it to search the
|entire list instead of only looking at the first line only? Heres the
|code in question:

|#open the log file and put the data into an array
|open(LOG, "post.log") || &error("Couldn't open log file \n\n$!");
|@indata = <LOG>;
|close(LOG);
|
| #supposed to assign each line's data to these 5 variables
|foreach $line (@indata)
|   {
|    chop($line);


This is probably not the problem but you should be using chomp there.

|    ($ID, $date, $initials, $file, $description) = split(/\|/, $line);
|
|# note that $referenceID is set earlier in the script to what the user
|typed in the form

I am guessing that the above is where things are going awry.

|#if it finds a match, do stuff, the problem is it wont check past the
|first line of the log file
|
so you are getting only error messages?


|if ($ID eq $referenceID) {
|    $unlink "../$clientname/$jobnumber/$date/$initials/$file" ||
|&error("I can't delete these files!");

Your problem may be the above.  First, I am not sure why there is a $ in front
of unlink, typo?  Also, eq is a string test and you may be interested in a
numeric test in which case  you should be using == .
Otherwise I can't see the error.  Below is an example of your code (slightly
modified, that shows that the loop is working and how the eq sign might be
causing problems.  Change eq to == below and the matches will be found.
Otherwise you might want to check whatever you are doing there with unlink.
My  last thought is the nature of the data file.  If you data is really on one
long line you only have one element in @indata. Oh, and watch that else
statement, I don't think it says what you mean it gets printed every time
there is no match.

HTH

AmD
[posted and mailed]
---------------
@indata = <DATA>;
$referenceID = "17.0";
foreach $line (@indata)
   {
    chomp($line);
    ($ID, $date, $initials, $file, $description) = split(/\|/, $line);
    print "$ID, $date, $initials, $file, $description\n";

    if ($ID eq $referenceID) {
      #  unlink "../$clientname/$jobnumber/$date/$initials/$file" || &error("I
can't delete these files!");
        print "matched $ID\n";
    }
        else {print("$Found no matches in the log file.\n\n")};
}

__DATA__
17|12-18-98|mj|logo.gif|one
17|12-18-98|mj|home.gif|two
17|12-18-98|mj|employ_top.jpg|three
18|12-18-98|dp|image.jpg|image
18|12-18-98|dp|image_2.jpg|image_two





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

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

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