[14006] in Perl-Users-Digest
Perl-Users Digest, Issue: 1416 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 18 14:14:18 1999
Date: Thu, 18 Nov 1999 11:10:31 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <942952229-v9-i1416@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 18 Nov 1999 Volume: 9 Number: 1416
Today's topics:
How to sort lines of plain text db file ? <factory@factory.co.kr>
Re: How to sort lines of plain text db file ? <slanning@bu.edu>
Re: How to sort lines of plain text db file ? <factory@factory.co.kr>
Re: How to sort lines of plain text db file ? <wyzelli@yahoo.com>
Re: How to sort lines of plain text db file ? <lr@hpl.hp.com>
Re: How to sort lines of plain text db file ? <jeff@vpservices.com>
html via perl <bdoyle@wiannoassociates.com>
Javascript w/ Perl brondsem@my-deja.com
Re: Javascript w/ Perl (Kragen Sitaker)
Re: looking for a developer . . . <steve@corp.airmedia.com>
Re: looking for a developer . . . <russellm@bellsouth.net>
Re: Making http requests with extra headers <jtolley@bellatlantic.net>
Re: my ... if -- strange behavior <rick.delaney@home.com>
Re: OO question (Damian Conway)
Re: OO question (Kragen Sitaker)
Re: OO question (Damian Conway)
Re: Oracle via the web <newsposter@cthulhu.demon.nl>
Re: Oracle via the web (Dan Wilga)
Re: perl stumper <lr@hpl.hp.com>
POP3:Client <jovileung@excite.com>
Re: POP3:Client (Kragen Sitaker)
Re: problem with DBM delete <sariq@texas.net>
Re: Q: DBI.pm (odd warnings) <slanning@bu.edu>
Rephrase (Joel A. Tropp)
Re: Rephrase (Kragen Sitaker)
Save As box... printing an image to the screen" (Slim)
Re: Save As box... printing an image to the screen" (Frosty )
Split a input file with perl <huyv@usa.net>
Substitute for gethostbyaddr? (AcCeSsDeNiEd)
Re: Tying a pseudo-hash (Charles DeRykus)
Re: Use sort function with reference to subroutine? (Randal L. Schwartz)
Re: Use sort function with reference to subroutine? <uri@sysarch.com>
Using C library in Perl <dhlee@softforum.co.kr>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 18 Nov 1999 14:22:39 +0900
From: "Moltimer" <factory@factory.co.kr>
Subject: How to sort lines of plain text db file ?
Message-Id: <XjevjMYM$GA.219@news.thrunet.com>
Hi,
I'm trying to print out a html page.
and it works well with something like following code.
it prints all lines which has "sample" on second value($ex1).
How can I sort all lines according to "$ex3" and print them in a html
page with correct order ?
The data lines are in data.txt.
$category = "sample";
open(FILE1, ">$category.html") || die "I can't ....\n";
flock (FILE1, 2) or die "can't lock ...\n";
open(FILE, "data.txt") || die "I can't open ..\n";
flock (FILE, 1) or die "can't ...\n";
@lines = <FILE>;
close(FILE);
$sizelines = @lines;
open(FILE, "<data.txt") || die "I can't ..\n";
flock (FILE, 2) or die "can't lock ...\n";
chop;
for ($a = 0; $a <= $sizelines; $a++) {
$_ = $lines[$a];
$line = $_;
$line =~ s/\cM//g;
$line =~ s/\n//g;
($ex0, $ex1, $ex2, $ex3) = split(/&&/, "$line");
if($category eq "$ex1")
print FILE1 qq~ $ex0 - $ex1 - $ex2 - $ex3 ~;
}
}
close(FILE);
close(FILE1);
------------------------------
Date: 18 Nov 1999 00:28:44 -0500
From: Scott Lanning <slanning@bu.edu>
Subject: Re: How to sort lines of plain text db file ?
Message-Id: <kusbt8s74hf.fsf@strange.bu.edu>
"Moltimer" <factory@factory.co.kr> writes:
> How can I sort all lines according to "$ex3" and print them in a html
> page with correct order ?
perldoc perlfaq4
"How do I sort an array by (anything)?"
--
"One should not confuse this craving for change and novelty with the
indifference of play which is in its greatest levity at the same time
the most sublime and indeed the only true seriousness." --Georg Hegel
------------------------------
Date: Thu, 18 Nov 1999 15:10:03 +0900
From: "Moltimer" <factory@factory.co.kr>
Subject: Re: How to sort lines of plain text db file ?
Message-Id: <QiNBDnYM$GA.228@news.thrunet.com>
Dear,
I'm not talking about array but lines.
Thank you
Scott Lanning ÀÌ(°¡) ¸Þ½ÃÁö¿¡¼ ÀÛ¼ºÇÏ¿´½À´Ï´Ù...
>"Moltimer" <factory@factory.co.kr> writes:
>> How can I sort all lines according to "$ex3" and print them in a html
>> page with correct order ?
>
>perldoc perlfaq4
>"How do I sort an array by (anything)?"
>
>--
>"One should not confuse this craving for change and novelty with the
>indifference of play which is in its greatest levity at the same time
>the most sublime and indeed the only true seriousness." --Georg Hegel
------------------------------
Date: Thu, 18 Nov 1999 16:16:07 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: How to sort lines of plain text db file ?
Message-Id: <3hNY3.25$Yu4.2778@vic.nntp.telstra.net>
Moltimer <factory@factory.co.kr> wrote in message
news:XjevjMYM$GA.219@news.thrunet.com...
> Hi,
>
> I'm trying to print out a html page.
> and it works well with something like following code.
> it prints all lines which has "sample" on second value($ex1).
>
> How can I sort all lines according to "$ex3" and print them in a html
> page with correct order ?
>
> The data lines are in data.txt.
> $category = "sample";
> open(FILE1, ">$category.html") || die "I can't ....\n";
> flock (FILE1, 2) or die "can't lock ...\n";
>
> open(FILE, "data.txt") || die "I can't open ..\n";
> flock (FILE, 1) or die "can't ...\n";
> @lines = <FILE>;
> close(FILE);
> $sizelines = @lines;
>
> open(FILE, "<data.txt") || die "I can't ..\n";
> flock (FILE, 2) or die "can't lock ...\n";
> chop;
> for ($a = 0; $a <= $sizelines; $a++) {
> $_ = $lines[$a];
> $line = $_;
> $line =~ s/\cM//g;
> $line =~ s/\n//g;
> ($ex0, $ex1, $ex2, $ex3) = split(/&&/, "$line");
> if($category eq "$ex1")
>
> print FILE1 qq~ $ex0 - $ex1 - $ex2 - $ex3 ~;
> }
> }
> close(FILE);
> close(FILE1);
>
>
Which of the answers to this question you asked yesterday do you not
understand?
Wyzelli
------------------------------
Date: Wed, 17 Nov 1999 23:08:09 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: How to sort lines of plain text db file ?
Message-Id: <MPG.129d45b0b52ad56a98a22b@nntp.hpl.hp.com>
In article <XjevjMYM$GA.219@news.thrunet.com> on Thu, 18 Nov 1999
14:22:39 +0900, Moltimer <factory@factory.co.kr> says...
> Hi,
>
> I'm trying to print out a html page.
> and it works well with something like following code.
> it prints all lines which has "sample" on second value($ex1).
>
> How can I sort all lines according to "$ex3" and print them in a html
> page with correct order ?
You asked this same question yesterday, and got several answers. Is
there anything about the answers that would have caused you to post the
question again?
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 18 Nov 1999 06:28:16 GMT
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: How to sort lines of plain text db file ?
Message-Id: <38339C37.8C2B1903@vpservices.com>
Moltimer wrote:
>
> Scott Lanning ÀÌ(°¡) ¸Þ½ÃÁö¿¡¼ ÀÛ¼ºÇÏ¿´½À´Ï´Ù...
> >"Moltimer" <factory@factory.co.kr> writes:
> >> How can I sort all lines according to "$ex3" and print them in a html
> >> page with correct order ?
> >
> >perldoc perlfaq4
> >"How do I sort an array by (anything)?"
>
> Dear,
> I'm not talking about array but lines.
Yet your script has:
($ex0, $ex1, $ex2, $ex3) = split(/&&/, "$line");
It does not take a very big leap of the imagination to turn that into an
array.
--
Jeff
------------------------------
Date: Thu, 18 Nov 1999 02:42:21 -0600
From: "Bryan Doyle" <bdoyle@wiannoassociates.com>
Subject: html via perl
Message-Id: <810al6$oqt$1@autumn.news.rcn.net>
Hi,
I need to open the url which is defined by the variable $guestbookurl as a
full window in the browser (ie5), rather than in the frame that the script
is called from. The relevant area of code in question is below. Inserting
TARGET="_top" after print "<a href=\"$guestbookurl\" obviously
does not work. Any advice or reference would be truly appreciated.
Thanks!
# Redirection Option
sub no_redirection {
# Print Beginning of HTML
print "Content-Type: text/html\n\n";
print "<html><head><title>Thank You</title></head>\n";
print "<body><h1>Thank You for Registering with Us!</h1>\n";
# Print Response
print "<a href=\"$guestbookurl\">Proceed to the Registered Users'
Page!</a>";
#Print End of HTML
print "<hr>\n";
print "</body></html>\n";
exit;
}
------------------------------
Date: Thu, 18 Nov 1999 02:13:52 GMT
From: brondsem@my-deja.com
Subject: Javascript w/ Perl
Message-Id: <80vncu$r6j$1@nnrp1.deja.com>
Could anyone tell me if and how perl can work with javascript (other
than creating javascript from your perl code). Is it possible in
anyway to exchange variables or anything like this?
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 18 Nov 1999 03:22:58 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Javascript w/ Perl
Message-Id: <miKY3.24267$YI2.1056974@typ11.nn.bcandid.com>
In article <80vncu$r6j$1@nnrp1.deja.com>, <brondsem@my-deja.com> wrote:
>Could anyone tell me if and how perl can work with javascript (other
>than creating javascript from your perl code). Is it possible in
>anyway to exchange variables or anything like this?
Sure. Here are some ways:
- JavaScript can talk to an IRC server; so can Perl. They can
communicate by sending messages to each other.
- They can both read and write files. They can communicate this way too.
- JavaScript can presumably open sockets, although I don't know enough
about it to say for sure. So you could connect to a network server
written in Perl.
- Perl running on a Web server can generate JavaScript code and send it
to a browser. JavaScript code running on a browser can set form
elements that will be handled by the Web server.
Which of these ways (and there are others, too) works best for you is a
matter of your platform. But it is NOT A PERL QUESTION. So don't ask
here.
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08. Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: Thu, 18 Nov 1999 13:26:34 -0500
From: "Steve Protopapas" <steve@corp.airmedia.com>
Subject: Re: looking for a developer . . .
Message-Id: <811g8v$i8k$1@nnrp03.primenet.com>
Larry Rosler <lr@hpl.hp.com> wrote in message
news:MPG.129ce983d4598c2898a228@nntp.hpl.hp.com...
> In article <383339F5.2B196F92@bellsouth.net> on Wed, 17 Nov 1999
> 17:27:50 -0600, Mark Russell <russellm@bellsouth.net> says...
> >
> > > Coprophagous mutant.
> >
> > Coprophagous?
>
> Greek 'koprophagos', from kopr- + -phagos] : adj., feeding on dung
>
> --
> (Just Another Larry) Rosler
> Hewlett-Packard Laboratories
> http://www.hpl.hp.com/personal/Larry_Rosler/
> lr@hpl.hp.com
Don't forget "myso-" too.
------------------------------
Date: Thu, 18 Nov 1999 01:26:18 -0600
From: Mark Russell <russellm@bellsouth.net>
Subject: Re: looking for a developer . . .
Message-Id: <3833AA1A.90CA896E@bellsouth.net>
>
> > > Coprophagous mutant.
> >
> > Coprophagous?
>
> Greek 'koprophagos', from kopr- + -phagos] : adj., feeding on dung
Interesting. I'll have to try to work this into my vocabulary.
Markic
------------------------------
Date: Thu, 18 Nov 1999 03:47:08 GMT
From: James Tolley <jtolley@bellatlantic.net>
Subject: Re: Making http requests with extra headers
Message-Id: <3828EA50.862E8035@bellatlantic.net>
Eduardo Hernández Gil wrote:
>
> I want to make a request of some web pages and store then on the disk
> using perl, but I don't know how. The main problem is that, apart from
> the normal request header I have to send some extra info in the header:
> cookies and some "post" information send by a form.
>
Piece of cake:
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Response;
You can find these at
www.cpan.org
hth,
James
------------------------------
Date: Thu, 18 Nov 1999 03:26:30 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: my ... if -- strange behavior
Message-Id: <38337201.D0F4E0B@home.com>
[posted & mailed]
M.J.T. Guy wrote:
>
> Rick Delaney <rick.delaney@home.com> wrote:
> >This is a result of a feature that allows you to have static vars in
> >your subs.
>
> That's a bug, not a feature. See the thread referenced in my reply to
> John Lin.
Thanks. But notice that I didn't call it a feature, but a "result of a
feature". I thought it was a side effect of the compile/run time
difference in C<my> that allows less obfuscated statics like
> > {
> > my $static;
> > sub foo { return ++$static }
> > }
which I do consider a feature.
> >and IMHO should draw a warning.
>
> Looks like you agree with me. :-)
I do but I didn't realize there was consensus on p5p :-) so I didn't
want to use the B-word.
Next time I will be more explicit, especially since the last time I
(wrongly) cried bug I learned something anyway.
--
Rick Delaney
rick.delaney@home.com
------------------------------
Date: 18 Nov 1999 02:28:56 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: OO question
Message-Id: <80vo98$45h$1@towncrier.cc.monash.edu.au>
jamus jegier <jamus@bigfoot.com> writes:
> In the function
> called go, there will be quite a few calls to methods that are in the
> same instance, so I would like to avoid if at all possible:
> my $mystuff=sub {
> my $self=shift;
> $self->mycall1($arg1);
> $self->mycall2($arg2);
> }
Presumably you want to avoid using regular method calls because
of the performance penalty involved in multiple polymorphic look-ups.
The &can method is useful here, because it allows you to factor out
the polymorphism:
my $mystuff=sub {
my $self=shift;
# LOCATE METHODS POLYMORPHICALLY...
my $mycall1 = $self->can('mycall1');
my $mycall2 = $self->can('mycall2');
# CALL METHODS NON-POLYMORPHICALLY (VIA REFERENCE)...
$mycall1->($self,$arg1);
$mycall2->($self,$arg2);
#...etc.
}
The overhead of the calls to &can means that for less than 5 method
calls, the regular method call syntax (i.e. $self->mycall1()) is
still faster.
But asymptotically -- say, for more than 10 calls -- this approach is
within 5% of a direct subroutine call (on my machine, at least).
Damian
------------------------------
Date: Thu, 18 Nov 1999 03:52:27 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: OO question
Message-Id: <%JKY3.24340$YI2.1062617@typ11.nn.bcandid.com>
In article <80vo98$45h$1@towncrier.cc.monash.edu.au>,
Damian Conway <damian@cs.monash.edu.au> wrote:
>The overhead of the calls to &can means that for less than 5 method
>calls, the regular method call syntax (i.e. $self->mycall1()) is
>still faster.
>
>But asymptotically -- say, for more than 10 calls -- this approach is
>within 5% of a direct subroutine call (on my machine, at least).
Hmm. Something seems weird here; let me see if I can tease it out with
equations.
A simple model is that the 'can' version takes time C for the can call
and time M for each direct method call. So C+5M is the time to do five
method calls with the 'can' method. Let's say each indirect method
call takes time I, I>M. You're saying that C+4M > 4I, and C+5M < 5I.
Right?
So we know C/4 + M > I, and C/5 + M < I. So (assuming positive M)
C/4 > I - M > C/5.
Now, I'm not sure what you mean by a 'direct subroutine call' --
whether you mean just M, or something smaller.
#!/usr/bin/perl -w
use strict;
use Benchmark;
my $x;
sub foo {
$x++;
}
$::foo = \&foo;
my $n = 1_000_000;
timethis($n, 'foo()');
timethis($n, '$::foo->()')
timethis 1000000: 26 wallclock secs (23.81 usr + 0.01 sys = 23.82 CPU)
timethis 1000000: 24 wallclock secs (23.81 usr + 0.00 sys = 23.81 CPU)
Is the indirection getting lost in the overhead of the benchmark?
perl -wMBenchmark -Mstrict -e 'timethis(1_000_000, "")'
timethis 1000000: -1 wallclock secs ( 0.06 usr + 0.00 sys = 0.06 CPU)
(warning: too few iterations for a reliable count)
Hmm, I guess timethis() compensates for that overhead.
This suggests that there isn't anything smaller, at least on my machine
with 5.005_03; a direct and an indirect subroutine call are within 5%
of one another.
So your second statement says that C+11M <= 1.05 * 11M, so
C <= 1.05 * 11M - 11M, so C <= .05 * 11M, so C <= (11/20)M, so
(20/11)C <= M. So C is less than half of M.
This is a little troubling, since M represents the cost of an arbitrary
function call (through a CODE ref) and C represents the cost of a
particular function call.
So I must have done something wrong.
But if I didn't, that means I - M is less than one-eighth of M, but
more than about a tenth.
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08. Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: 18 Nov 1999 05:28:08 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: OO question
Message-Id: <8102p8$57a$1@towncrier.cc.monash.edu.au>
kragen@dnaco.net (Kragen Sitaker) writes:
>In article <80vo98$45h$1@towncrier.cc.monash.edu.au>,
>Damian Conway <damian@cs.monash.edu.au> wrote:
>>The overhead of the calls to &can means that for less than 5 method
>>calls, the regular method call syntax (i.e. $self->mycall1()) is
>>still faster.
>>
>>But asymptotically -- say, for more than 10 calls -- this approach is
>>within 5% of a direct subroutine call (on my machine, at least).
>Hmm. Something seems weird here; let me see if I can tease it out with
>equations.
I was contrasting three approaches to calling method m on an object $o
of class C:
1. Direct subroutine call:
C::m($o,@args) for (1..$N); # COST=D/call
2. "Indirect" method invocation:
$o->m(@args) for (1..$N); # COST=I/call
3. "Can-and-reference" invocation:
$m = $o->can('m'); # COST=C
$m->($o,@args) for (1..$N); # COST=M/call
>You're saying that C+4M > 4I, and C+5M < 5I. Right?
Right.
>So we know C/4 + M > I, and C/5 + M < I. So (assuming positive M)
Yes, the optimizer isn't *that* good yet ;-)
>C/4 > I - M > C/5.
Yes. I other words, the cost of a &can lookup is about 4.5 times the difference
between an method call and a subroutine call via a reference.
>Now, I'm not sure what you mean by a 'direct subroutine call' --
>whether you mean just M, or something smaller.
I mean D above, which might be marginally smaller than M.
> [Benchmarking deleted]
>
>This suggests that there isn't anything smaller, at least on my machine
>with 5.005_03; a direct and an indirect subroutine call are within 5%
>of one another.
No. It is the direct call and one via a reference that seem to be within 5%.
>So your second statement says that C+11M <= 1.05 * 11M, so
>C <= 1.05 * 11M - 11M, so C <= .05 * 11M, so C <= (11/20)M, so
>(20/11)C <= M. So C is less than half of M.
Well, technically my second statement only claims:
C+11M <= 1.05 * 11D
but lets assume M~=D, as above. That wasn't true under 5.00502, where I was
benchmarking, but I could be under 5.00503. So, tentatively: "yes".
>This is a little troubling, since M represents the cost of an arbitrary
>function call (through a CODE ref) and C represents the cost of a
>particular function call.
But C represents the cost of an invocation of &can, which may be highly
optimized, whereas M is the cost of generic call via reference. It may
also be that the actual "within-5%" mark is closer to 20 calls (the relative
cost curve is already very flat in that region and hence my guestimation is
suspect there :-), in which case C and M are about the same, as one
might expect.
Damian
------------------------------
Date: 18 Nov 1999 18:32:57 GMT
From: Erik van Roode <newsposter@cthulhu.demon.nl>
Subject: Re: Oracle via the web
Message-Id: <811gop$re0$1@internal-news.uu.net>
Chris Collins <cpcollin@wam.umd.edu> wrote:
> $dbname = 'DBNAME';
> $user = 'USERNAME';
> $password = 'PASSWORD';
> $dbd = 'Oracle';
> $dbh = DBI->connect ($dbname, $user, $password, $dbd);
Are you sure those dbname/dbd are correct? From the DBI docs:
$dbh = DBI->connect($data_source, $username, $auth, \%attr);
The $data_source value should begin with 'dbi:driver_name:'.
Eg, I use:
my $db = "dbi:Oracle:$oracle_sid";
my $dbh = DBI->connect($db, $db_user, $db_passwd, {
RaiseError => 0,
AutoCommit => 0,
PrintError => 1,
});
Erik
------------------------------
Date: Thu, 18 Nov 1999 13:35:23 -0500
From: dwilgaREMOVE@mtholyoke.edu (Dan Wilga)
Subject: Re: Oracle via the web
Message-Id: <dwilgaREMOVE-1811991335230001@wilga.mtholyoke.edu>
In article <8116m6$nq7$1@hecate.umd.edu>, "Chris Collins"
<cpcollin@wam.umd.edu> wrote:
> use DBI;
> use Env;
> use Env qw(WWW_myquery);
> use Exporter();
>
[...]
>
> $dbname = 'DBNAME';
> $user = 'USERNAME';
> $password = 'PASSWORD';
> $dbd = 'Oracle';
>
[...]
>
> $dbh = DBI->connect ($dbname, $user, $password, $dbd);
You need two things. First, you need to install a database interface.
Either DBD::Oracle or DBD::ODBC should work, but DBD::Oracle is much
easier to set up.
Next, you need to construct a valid DSN, and pass the correct arguments to
connect(). This depends on which driver you're using, but for DBD::Oracle,
this sequence should work. It assumes the Oracle database is on the same
machine as the Perl script:
$dsn = 'dbi:Oracle';
$user = 'USERNAME';
$password = 'PASSWORD';
$dbh = DBI->connect ($dsn, $user, $password);
Dan Wilga dwilgaREMOVE@mtholyoke.edu
** Remove the REMOVE in my address address to reply reply **
------------------------------
Date: Wed, 17 Nov 1999 17:59:59 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: perl stumper
Message-Id: <MPG.129cfd7aa5151f7498a22a@nntp.hpl.hp.com>
In article <0a0133f8.2f9ed36b@usw-ex0102-016.remarq.com> on Wed, 17 Nov
1999 17:23:19 -0800, toby_toby_toby
<toby_toby_tobyNOtoSPAM@hotmail.com.invalid> says...
> One of the folks in my team stumped me with this
> trivial hunk of code. It really seems like it
> should work. Unfortunately, perl says "Use of
> unitialized value..." when the second line is
> read from the file.
>
> Any clues?
> -toby
For sure!
> #!perl -w
> use strict;
Two cheers!
> open (IN, "notes.txt");
No test and diagnostic with $!, so -1 cheer!
> my($line) = <IN>;
This executes the <IN> operator in *list* context. So it reads the
entire file into a list, assigns the first list element to $line, and
throws the rest away.
> print "first line is $line";
> $line = <IN>;
So there isn't any more to read from the file at this point.
> print "second line is $line";
Don't use parentheses on the 'my($line)', as 'my $line =' establishes
*scalar* context. Then only one line will be written, and all will be
well.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 17 Nov 1999 10:05:44 +0800
From: jovi <jovileung@excite.com>
Subject: POP3:Client
Message-Id: <38320D78.FBF17BB7@excite.com>
I have experienced that my hosting provider did not support Perl-Mod. so
that i can't use pop...... for mail retrieval. Is that any other means i
can do that without writing a C program.
------------------------------
Date: Thu, 18 Nov 1999 03:14:51 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: POP3:Client
Message-Id: <LaKY3.24247$YI2.1056129@typ11.nn.bcandid.com>
In article <38320D78.FBF17BB7@excite.com>, jovi <jovileung@excite.com> wrote:
>I have experienced that my hosting provider did not support Perl-Mod. so
>that i can't use pop...... for mail retrieval. Is that any other means i
>can do that without writing a C program.
Sure. You could install the modules yourself, you could implement the
POP protocol yourself, or you could cut and paste the module into your
program. #1's your best bet.
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08. Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: Thu, 18 Nov 1999 12:34:19 -0600
From: Tom Briles <sariq@texas.net>
Subject: Re: problem with DBM delete
Message-Id: <383446AB.4A5C4D75@texas.net>
Chris Stigas wrote:
>
> Hello,
>
> I am having a problem with this small piece of code:
>
> while (($key, $value) = each(%MAILDB)) {
> if($MAILDB{$key} eq 0){
> delete $MAILDB{$key};
> }
> }
Other than the fact that you're using the wrong comparison operator,
this is covered in perlfaq4.
Read the FAQ before posting here. It saves everyone alot of time and
effort and bandwidth.
- Tom
------------------------------
Date: 18 Nov 1999 13:40:08 -0500
From: Scott Lanning <slanning@bu.edu>
Subject: Re: Q: DBI.pm (odd warnings)
Message-Id: <kushfij63uf.fsf@buphy.bu.edu>
erik_lembke@my-deja.com writes:
> I got odd warnings when I use the DBI Interface in perl.
> They look like this:
> Use of uninitialized value at (eval 21) line 18.
>
> How can I evalute such a warning?
Uhm, how can we either if you don't post the code?
> (my line 18 is empty)
Or so you claim! Hmmph!
> IMHO these warnings are created if i generate invalid sql
> statements.
That's a good start. "Use of uninitialized value" usually
means there is a variable which isn't getting....initialized,
and you tried....uhm, to use its....value. heh. <looks upwards>
From 'perldoc perldiag':
Use of uninitialized value
(W) An undefined value was used as if it were already
defined. It was interpreted as a "" or a 0, but maybe
it was a mistake. To suppress this warning assign an
initial value to your variables.
Perhaps if you generated an invalid SQL statement, then a
variable which you assumed was getting a legitimate value
assigned to it, was actually getting a "" or a 0.
See? Using the -w switch is a Good Thing.
------------------------------
Date: Wed, 17 Nov 1999 21:48:53 -0600
From: jtropp@ticam.utexas.edu (Joel A. Tropp)
Subject: Rephrase
Message-Id: <jtropp-1711992148530001@dial-83-8.ots.utexas.edu>
Why doesn't this work right?
$files{ $cat } = "feh"; # Black Magic
open( $files{ $cat }, ">$fname" );
select( $files{ $cat } );
print "Content.\n"
...
if ( $files{ $mandu } ) {
select( $files{ $mandu } );
print "More content.\n"
}
joel
------------------------------
Date: Thu, 18 Nov 1999 04:16:42 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Rephrase
Message-Id: <K4LY3.24373$YI2.1065287@typ11.nn.bcandid.com>
In article <jtropp-1711992148530001@dial-83-8.ots.utexas.edu>,
Joel A. Tropp <jtropp@ticam.utexas.edu> wrote:
>Why doesn't this work right?
>
>$files{ $cat } = "feh"; # Black Magic
>
>open( $files{ $cat }, ">$fname" );
Because filehandles and typeglobs are evil. One of these days I'll get
up the courage to delve into the stinking pit of human error and
depravity that is filehandles, and maybe I'll even like it; until then,
I use IO::Handle and put blocks around expressions to fetch filehandles
from hashes.
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08. Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: Thu, 18 Nov 1999 06:59:49 GMT
From: ShadeyGradey@linuxfreak.com (Slim)
Subject: Save As box... printing an image to the screen"
Message-Id: <3833a1be.139653222@news.inet4u.com>
Hey!
I just made a script that will get an image and print it out to the
screen...
when I choose save as to save the image the name of the image will be
the script name... is there a way to make it say the real name of the
image in the save as box"
thanks...
-Slim-
------------------------------
Date: 18 Nov 1999 16:21:52 GMT
From: sotmesc@datasync.com (Frosty )
Subject: Re: Save As box... printing an image to the screen"
Message-Id: <811930$db0$3@news.ametro.net>
Slim (ShadeyGradey@linuxfreak.com) wrote:
: Hey!
:
: I just made a script that will get an image and print it out to the
: screen...
: when I choose save as to save the image the name of the image will be
: the script name... is there a way to make it say the real name of the
: image in the save as box"
Actually, for this NG, the question should be "who can I hire to fix this?"
------------------------------
Date: Thu, 18 Nov 1999 02:21:35 -0500
From: "Huy Vu" <huyv@usa.net>
Subject: Split a input file with perl
Message-Id: <SMNY3.2708$MM.74813@newscontent-01.sprint.ca>
Hi all,
I have a file with a format as below:
^R
AAAAAA BBBBBbb CCCCCCCc
PARAGRAPH #1
^O1234 Testing 54.0
^O4566 Checking 454.0 ----------> I would like to
save 3 these lines to 'paragraph#1' file
^O3456 Decided 55.0
withoutthe ^O character control.
PARAGRAPH #2
^O5675 Moon 45.0 -----------> 2 these
lines to 'paragraph#2' file
^O7688 Sun 3434
PARAGRAPH #3
^O5692 Mars 234.00
^O7666 Venus 343.00
^O7656 Mercury 3434.00 -------------> 4 these lines to
'paragraph#3' file
^O3435 Appolo 93443.00
PARAGRAPH #1
1234 Testing 45.0 -----------> 2 these
lines appended to 'paragraph#1' file
^O3456 Decided 3434
PARAGRAPH #2
5675 Moon 45.0 -----------> Appended to
'paragraph#2' file
PARAGRAPH #3
7666 Venus 343.00
7656 Mercury 3434.00 -------------> Appended to
'paragraph#3' file
...............................................
I still trying to slit that but still not successful.
Thanks in advance for any help.
H.V
------------------------------
Date: Thu, 18 Nov 1999 07:22:54 GMT
From: dillon_rm@magix.com.sg (AcCeSsDeNiEd)
Subject: Substitute for gethostbyaddr?
Message-Id: <3833a614.3579288@news.magix.com.sg>
Hi folks,
Firstly, thanks for all the help I got from you guys (Thread: Can't
get hostname with gethostbyaddr).
Also, sorry for the repeated post for that thread. I was having
problems with my news server.
The perl ver on the webhost machine (SCO Unix) has been upgraded to
5.005_03. But I still can't use "gethostbyaddr".
I think the problem running "gethostbyaddr" has been found out:-
This is what the Webhost System Administrator has to say:
"The function which you are trying to implement can only be run as
root,
"gethostbyaddr" needs to be run as root or superuser. You need to use
functions which don't need superuser as it might compromise system
securities".
The question is, the problem with "gethostbyadd" or is it just the
config of the server? That means I suppose there is no way to retrieve
hostname from an IP on this machine with any method/s unless I'm the
root/superuser acc?
Or is there any substitute for gethostbyaddr?
Thanks.
To e-mail me, remove "_rm"
------------------------------
Date: Thu, 18 Nov 1999 02:41:19 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: Tying a pseudo-hash
Message-Id: <FLDGsv.K8z@news.boeing.com>
In article <80cpu2$i3f$1@nnrp1.deja.com>, Mark Lofdahl <mel@disc.com> wrote:
>Is there a way to tie a psuedo-hash as a hash instead of an array?
>
>my $k = {"a" => 1, "b" => 2};
>my $psuedohash = [$k];
>
>I can treat $pseudohash as a hash like this
> $pseudohash->{a} = 5;
> printf("%d\n", scalar(keys(%$pseudohash)));
>but not like this
> tie(%$pseudohash, "Tie::StdHash");
> error -- Can't locate object method "TIEARRAY" via package
>"Tie::StdHash"
>
>Is there any way to do this?
>
You have to use the underlying hash
rather than the pseudohash ref, e.g.,
package My_Tie;
use Tie::Hash;
@ISA = qw( Tie::StdHash);
sub FETCH {
my ($self, $key) = @_;
warn "fetched $key\n";
}
package main;
my $k = {"a" => 1, "b" => 2};
my $pseudo_hash = [$k];
tie( %{$k}, 'My_Tie') or die "can't tie\n";
my $var = $pseudo_hash->{a}; #--> "fetched a"
__END__
--
Charles DeRykus
------------------------------
Date: 17 Nov 1999 19:36:30 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Use sort function with reference to subroutine?
Message-Id: <m1yabwxygx.fsf@halfdome.holdit.com>
>>>>> "Uri" == Uri Guttman <uri@sysarch.com> writes:
Uri> simple fix (which is documented in perldoc -f sort):
Uri> *sortglob = $subref ;
Uri> or
Uri> *sortglob = \&sortsub ;
Uri> @sorted = sort sortglob @array ;
Uri> that will allow sort to call any arbitrary sub.
Nicer to be local there:
@sorted = do {
local *SORTFUNC = $subref;
sort SORTFUNC @array;
};
print "Just another Perl hacker,"
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: 17 Nov 1999 22:59:51 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Use sort function with reference to subroutine?
Message-Id: <x7ln7wsb48.fsf@home.sysarch.com>
>>>>> "RLS" == Randal L Schwartz <merlyn@stonehenge.com> writes:
>>>>> "Uri" == Uri Guttman <uri@sysarch.com> writes:
Uri> *sortglob = \&sortsub ;
Uri> @sorted = sort sortglob @array ;
RLS> Nicer to be local there:
RLS> @sorted = do {
RLS> local *SORTFUNC = $subref;
RLS> sort SORTFUNC @array;
RLS> };
that's been posted here before but i forgot it. and since i use 5.005_03
i don't have to think about that hack anymore.
to the original poster: upgrade, tell your isp to upgrade or gett a
better isp. i even installed my own perl and modules since my web host
hasn't yet upgraded perl for a good long while.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Thu, 18 Nov 1999 04:41:51 GMT
From: "À̵¿È£" <dhlee@softforum.co.kr>
Subject: Using C library in Perl
Message-Id: <jsLY3.340$J5.11323@news2.bora.net>
I have C version program and want to make Perl version.
Can I use C libX.a and includes files in Perl ?
I've read how to use XS.
I followed that instruction.
But, I've encountered this error message
Can't load './TEST.so' for module TEST: ld.so.1: perl: fatal: relocation
error: symbol not found: earth: referenced in ./libhanul.so at
/usr/local/lib/perl5/sun4-solaris/5.00404/DynaLoader.pm line 166.
Any one who has any solution for this, pleas mail me..
mail to : dhlee@softforum.co.kr
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V9 Issue 1416
**************************************