[12917] in Perl-Users-Digest
Perl-Users Digest, Issue: 327 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 1 20:17:34 1999
Date: Sun, 1 Aug 1999 17:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sun, 1 Aug 1999 Volume: 9 Number: 327
Today's topics:
Re: <<END_OF_TEXT function <flavell@mail.cern.ch>
Re: [Summary] Korn Shell or Perl? (Eric Bohlman)
Re: [Summary] Korn Shell or Perl? (Michael Wang)
Re: [Summary] Korn Shell or Perl? (Ken Pizzini)
Re: [Summary] Korn Shell or Perl? (Ken Pizzini)
Re: Confusion with the Schwartzian Transform used in so <twade@nobmispam.net>
Re: Confusion with the Schwartzian Transform used in so (Eric Bohlman)
Re: defconfaq - Q&A on arguments against the hypothetic <gt7202e@prism.gatech.edu>
Re: defconfaq - Q&A on arguments against the hypothetic <tchrist@mox.perl.com>
Re: external file access (Eric Bohlman)
Re: external file access makarand_kulkarni@my-deja.com
How do i append the beginning of a HTML file? <nfs@ukonline.co.uk>
Re: How do i append the beginning of a HTML file? (Mike Bristow)
Re: is process still running? (Martien Verbruggen)
Re: LINUX APACHE PERL <alex@kawo2.rwth-aachen.de>
Re: mail check via web <alex@kawo2.rwth-aachen.de>
newbie - fill array w/ contents of a file <ssd@bc.sympatico.ca>
Re: newbie - fill array w/ contents of a file (Garth Sainio)
Re: newbie - fill array w/ contents of a file makarand_kulkarni@my-deja.com
Re: newbie - fill array w/ contents of a file (Michael Wang)
Re: newbie - fill array w/ contents of a file (Martien Verbruggen)
Re: Paasing Arguments to System Function (Eric Bohlman)
Re: perl 2 c converter/compiler/translater ? (Tad McClellan)
Re: Q: perl driver for window nt and oracle 8 ? (Martien Verbruggen)
Running scrips on own pc <paulreid@cableinet.co.uk>
Re: VERY,VERY URGENT: I need help with the Net::FTP mod <alex@kawo2.rwth-aachen.de>
Re: VERY,VERY URGENT: I need help with the Net::FTP mod <flavell@mail.cern.ch>
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 1 Aug 1999 23:23:30 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: <<END_OF_TEXT function
Message-Id: <Pine.HPP.3.95a.990801231903.6130D-100000@hpplus03.cern.ch>
On 1 Aug 1999, Kai Henningsen wrote:
> > OK, das stimmt, but it was already discussed about trying scripts from
> > the shell first, and that kind of problem would surely show up at _that_
> > stage.
>
> Richtig, except the guy claimed to have no shell access.
Well, then I'd say the first priority is to get the appropriate access,
for example on one's own machine. Trying to develop CGI scripts when
the only option is to install them onto a remote web server to which one
has no shell access, seems about as productive as pushing water uphill.
> > "Bei dreibegriffigen mechanischen Vorsignalen ohne
> > Doppelstellerhebel steuern zwei Fluegelkupplungen"
>
> SBB?
I'm sorry, I spotted it as part of an explanation in a de. group and
it just kind'a appealed to me. I don't understand the details.
Is that honest enough for you?
Gruesse
------------------------------
Date: 1 Aug 1999 21:41:56 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: [Summary] Korn Shell or Perl?
Message-Id: <7o2ev4$7nl@dfw-ixnews11.ix.netcom.com>
Michael Wang (mwang@tech.cicg.ml.com) wrote:
: brian d foy <brian@pm.org> wrote:
: >
: > i told you to use tie(), but you don't seem to have
: >done any homework on what tie() does. you should have seen that it
: >allows you to abstract the notions of FETCHing and STOREing a value.
: >this allows you to abstract your stream. the perltie man page will
: >probably not be read by you though.
:
: I think I know what tie() does.
:
: It declares a variable a class object, and then you use the
^^^
: class member function such as FETCH and STORE on the object.
No. *Not* "you." *perl* calls the FETCH and STORE methods (that's the
Perl term for "member functions") on the tied object *automatically*
whenever the variable is used in a way that requires it to be fetched from
(e.g. as a term in an expression) or stored to (e.g. as the LHS of an
assignment). You, the programmer, do *not* need to write code that calls
these methods explicitly, and normally *should not* do so.
------------------------------
Date: 1 Aug 1999 23:01:22 GMT
From: mwang@tech.cicg.ml.com (Michael Wang)
Subject: Re: [Summary] Korn Shell or Perl?
Message-Id: <7o2jk2$mk3$1@news.ml.com>
Eric Bohlman <ebohlman@netcom.com> wrote:
>: It declares a variable a class object, and then you use the
> ^^^
>: class member function such as FETCH and STORE on the object.
>
>No. *Not* "you." *perl* calls the FETCH and STORE methods (that's the
>Perl term for "member functions") on the tied object *automatically*
>whenever the variable is used in a way that requires it to be fetched from
>(e.g. as a term in an expression) or stored to (e.g. as the LHS of an
>assignment). You, the programmer, do *not* need to write code that calls
>these methods explicitly, and normally *should not* do so.
To me, it is kind of "=" operator overloading. Perl uses member function
FETCH if the object is on the RHS, and uses STORE if the object on the
LHS. It is an interesting idea to use FETCH and STORE to do shell pipelines.
What is the difference between that you "store" stuff to a @list, and that
you STORE something, or Perl STORE something to, er, I guess, an object
in terms of memory usage? Thanks.
--
Michael Wang
http://www.mindspring.com/~mwang
------------------------------
Date: 1 Aug 1999 23:19:21 GMT
From: ken@halcyon.com (Ken Pizzini)
Subject: Re: [Summary] Korn Shell or Perl?
Message-Id: <slrn7q9lcp.8sq.ken@pulsar.halcyon.com>
On 1 Aug 1999 20:17:10 GMT, Michael Wang <mwang@tech.cicg.ml.com> wrote:
>The difference between Perl and Shell, as I see it, in dealing with
>this kind of problem, is that in Perl I have to handle this manually
>with the code, in Shell it is handled by the interpreter.
Well... kinda. Here is a fairly literal translation of your
shell code to perl. Like the shell code it forks off a copy
of the interpreter and has them talking via a pipeline:
my $pid = open(P, "-|);
defined $pid || die "cannot fork: $!\n";
if ($pid == 0) {
if ($opt_d eq "all") {
for my $i (split /\s*[ ,]\s*/) {
if ($i eq "local") {
for my $k (keys %beeper_byname) { print $k, "\n" }
} elsif ($i eq "yp") {
system qw(ypcat -k beeper.byname);
}
}
} else {
print $opt_d;
}
exit;
}
while (<P>) {
chomp;
s/ .*//;
/YP_/ || print $_, "\n";
}
Here is another perl approach (TMTOWTDI), using only one process
(excepting calls to ypcat) and making use of closures. There
is some administrative overhead making this longer than the above
shell-like solution, but if you look carefully you'll see the
importat parts are still quite straightforward to modify; the
more complicated the guts the less relevant the overhead code
becomes.
use Symbol;
my $nextline;
if ($opt_d eq "all") {
my @parts = split /\s*[ ,]\s*/, $opt_b;
my $subline = undef;
$nextline = sub {
for (;;) {
if (defined $subline) {
my $result = &$subline;
defined $result && return $result;
$subline = undef;
}
my $i = shift @parts || return undef;
if ($i eq "local") {
my @k = keys %beeper_byname;
$subline = sub { return shift @k };
} elsif ($i eq "yp") {
my $f = gensym;
open($f, "ypcat -k beeper.byname |")
|| warn "Cannot start ypcat: $!\n";
$subline = sub { return scalar <$f> };
}
}
}
} else {
my @k = split /\s*[ ,]\s*/, $opt_d;
$nextline = sub { return shift @k };
}
while (defined($_ = &$nextline)) {
chomp;
s/ .*//;
/YP_/ || print $_, "\n";
}
With perl you get to choose your tradeoffs with much more freedom
than you can with the shell.
--Ken Pizzini
------------------------------
Date: 1 Aug 1999 23:29:10 GMT
From: ken@halcyon.com (Ken Pizzini)
Subject: Re: [Summary] Korn Shell or Perl?
Message-Id: <slrn7q9m3v.94c.ken@pulsar.halcyon.com>
On 1 Aug 1999 23:01:22 GMT, Michael Wang <mwang@tech.cicg.ml.com> wrote:
>What is the difference between that you "store" stuff to a @list, and that
>you STORE something, or Perl STORE something to, er, I guess, an object
>in terms of memory usage? Thanks.
Well, for the situation that you're playing with you'd have
a null (or an error) STORE sub and the memory requirements
of your FETCH are entirely dependent on how you write the
FETCH. You could implement the FETCH by caching the entire
input in an array (high usage), or you could implement the
FETCH by reading in one line at a time (low usage). For your
"pseudo-pipe" application you'd have the FETCH routine maintain
state (probably some shared "my" variables in the package)
to determine where the next result should be coming from,
and to step to the next source when one source is exhausted.
Another way to look at tied variables is that these are
objects which syntatically look like variables, but their
contents are generated programmatically on an as-needed
basis rather than being stored in memory (though it is
possible that the method's implementation might actually
store the data in memory).
--Ken Pizzini
------------------------------
Date: Sun, 1 Aug 1999 14:12:20 -0700
From: "meteorman" <twade@nobmispam.net>
Subject: Re: Confusion with the Schwartzian Transform used in sorting
Message-Id: <rq9e1m4i501cq6@corp.supernews.com>
Anno and others,
I really appreciate all the comments and suggestions. I still don't have
these transforms down pat yet, but I'm getting there. Here is my version so
far. Is it correct now? I am still having a difficult time trying to
figure out what is going on internally. I understand the concept but do
not know how map is storing the data internally. This is where I am getting
lost. Would anyone be willing to explain it in detail?
///////////////// here is a sample of the data file
Iron Mountain,spot1.html
Badger Butte,spot2.html
Anthony Lakes,spot3.html
Badger Butte Lake,spot4.html
/////////////////// here is the script
open LIST, ">c:\\temp\\fws_list" || die "Couldn't open file. $!\n";
@by_spotname =
map { $_->[0] }
sort { $a->[0] cmp $b->[0] }
map { [$_, (split /,/)[0]] }
<LIST>;
close LIST;
This version compiles without any problems on the command line us '-w',
unlike the previous attempt. However, I am still unsure how to "see" if the
data is correct. Several of you mentioned renaming the file and then
storing to the original file. Since I am just starting perl, probably
obvious, I have not used this technique. Could some one show me an example.
Thanks again for all your time and help,
...Wade...
------------------------------
Date: 1 Aug 1999 22:24:11 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Confusion with the Schwartzian Transform used in sorting
Message-Id: <7o2heb$7nl@dfw-ixnews11.ix.netcom.com>
brian d foy (brian@pm.org) wrote:
: In article <MPG.120e2c2bc92de9ff989d8a@nntp.hpl.hp.com>, lr@hpl.hp.com
: (Larry Rosler) wrote:
:
: >In article <7o1uia$6a2$1@lublin.zrz.tu-berlin.de> on 1 Aug 1999 17:02:02
: >-0000, Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> says...
: >> meteorman <twade@nobmispam.net> wrote in comp.lang.perl.misc:
: >...
: >> ># file needing sorted alphabetically
: >> >Iron Mountain,spot1.html
: >> >Badger Butte,spot2.html
: >> >Anthony Lakes,spot3.html
: >>
: >> With these data you don't need a Schwartzian. Just sort the strings
: >> as they come.
: >
: >That is just happenstance. But if we added another line, for example:
: >
: > Badger Butte Lake,spot4.html
: >
: >this sort would fail, because 'comma' sorts lexicographically higher
: >than 'space'. Unless the field separator is guaranteed to sort below
: >any character in the data, the fields *must* be separated for sorting.
:
:
: you don't really need to separate the fields. you could write
: your own sort subroutine in which the field separator sorts higher
: than everything. that's not a better solution than separating the
: fields though. ;)
You mean "sorts *lower* than everything else." If it sorted higher, then
if one initial field was a prefix of another, the longer field would come
out first after sorting. Even if the data were guaranteed not to contain
spaces, sorting without extracting would work if the file was
comma-separated, but would suddenly break if the specification was changed
to make the file pipe-separated. That sort of buried dependency is a real
maintenance nightmare.
If the first field were *fixed-length*, then you could simply sort the
entire records directly.
------------------------------
Date: Sun, 01 Aug 1999 18:07:37 -0400
From: andy barfoot <gt7202e@prism.gatech.edu>
Subject: Re: defconfaq - Q&A on arguments against the hypothetical ?? operator
Message-Id: <37A4C529.4E20B02C@prism.gatech.edu>
Reini Urban wrote:
> [Tom] forgot the mention that the only case is
> if the null value (0, "") is meant to be valid and true,
> in contrary to C. (0 and NULL pointer)
>
> in those rare cases gsar's
> defined(EXPR1)
> or defined(EXPR1 = EXPR2)
> or defined(EXPR1 = EXPR3)
> or defined(EXPR1 = EXPR4);
> or your
> first {defined} $foo, $bar, $baz
> is really much better than any new weird operator.
Who suggested that 0 or '' ever be "meant to be valid and true"? Also,
since use of ?? would be functionally equivalent to both Gurusamy's code
and Tom's code, what do you mean by "really much better"?
It isn't "weird". Most code using || would be more safely written with
??, excluding the uses of || for control (as in open() || die) for which
most people would use 'or' anyway. And can you think of a use for ||=
that shouldn't really be ??= for safety?
There's a simple equivalent in ksh:
#!/bin/ksh
param=
a=${param:-default}
b=${param-default}
echo a=$a b=$b
I once spent too long finding two bugs in a short program:
sub foo(;$) {
# Should have been local $_ = @_? shift: $_;
local $_ = shift || $_;
...
$cache[$_] ||= recursive stuff;
# Needed ... unless defined $cache[$_];
}
One of Tom's good arguments against ?? is that uses for it don't turn up
often enough to justify making Perl more complicated. And typing
'defined' a few times instead is pretty painless.
I like Tom's essay, though I think it goes on too much about:
T> if ($a ?? $b) { } # if either is defined
T> while ($a ?? $b) { } # so long as either is defined
since one would hardly ever want to do that. (Actually, I can't think of
any reason why one would do that.) Also, the section on ugliness should
be omitted since it's just an assertion of opinion. These distract from
his convincing (to me) argument about unnecessary complexity.
--
andy barfoot
20! seconds ago predates life on Earth. By a lot.
------------------------------
Date: 1 Aug 1999 17:36:53 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: defconfaq - Q&A on arguments against the hypothetical ?? operator
Message-Id: <37a4da15@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc, andy barfoot <gt7202e@prism.gatech.edu> writes:
: # Should have been local $_ = @_? shift: $_;
: local $_ = shift || $_;
No, converting that to ?? is still wrong in the general case.
You always need ?: to distinguish being passed an explicit
undef there are not.
:I like Tom's essay, though I think it goes on too much about:
:
:T> if ($a ?? $b) { } # if either is defined
:T> while ($a ?? $b) { } # so long as either is defined
People already use "or" wherever they use "||", to their peril. And as
you yourself have just done here, the mantra of "don't use ||, use ??" is
repeated until it becomes misunderstood.
:any reason why one would do that.) Also, the section on ugliness should
:be omitted since it's just an assertion of opinion.
Ugliness counts. Readability counts. Try to list the operators in Perl
that do not in any fashion derive from another programming language and
are thus completely unable to be inferred based on prior experience of
any sort. There are very few.
It's as though people grew so weary of writing
if (charptr != 0 && *charptr != 0)
or
if (charptr != NULL && *charptr != '\0')
that they lobbied Dennis for a special new operator that had that built
into it, arguing that often people want one case and write the other,
or become tired of typing out the full thing, and then decide that,
oh my, wouldn't it be much more legible to invent a brand new operator
that implicitely handles those cases and looks like nothing else --
more than TEN YEARS into the history of the language? Can you say,
"unlikely in the extreme"? :-)
This whole thing is a tempest in a tea cup. I'll let others infer from
reading Sarathy's and Larry's statements how likely its deploymeet is.
--tom
--
Unix never says `please.' -- Rob Pike
------------------------------
Date: 1 Aug 1999 22:38:06 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: external file access
Message-Id: <7o2i8e$7nl@dfw-ixnews11.ix.netcom.com>
PerlLinux (perllinux@aol.com) wrote:
: I am trying to write a program module that opens an external file, reads all
: entried in that file, until there are no more to read. from there, i want a
: user to enter input and want to check the user's input against what i have read
: in. if what the user has entered does not match anything i have read in, i
: want the list of entries read in from the external file to print. then i want
: the user to be prompted to enter another value. i want this to continue until
: the user enters a valid choice. i have tried doing this a few different way,
: but i whatever i do i cannot seem to get to work. any help would be
: appreciated.
Since you haven't shown us any of the few different ways you've tried,
nor have you told us exactly how they're failing, we can only guess at
what you need to do. Offhand, it sounds like you want to use a hash
somewhere, since a hash lookup is almost always the best way to answer
the question "have I seen the same stuff before?"
------------------------------
Date: Sun, 01 Aug 1999 23:46:36 GMT
From: makarand_kulkarni@my-deja.com
Subject: Re: external file access
Message-Id: <7o2m8r$jcj$1@nnrp1.deja.com>
Let us assume that you have
the valid options in entries.txt
( one option on each line..)
Code -- something like this..
Also let us assume that
the user will either type
a valid option or "end"
to indicate that he is ending his
interactive 'session'.
#!/usr/local/bin/perl5 -w
open ( F, "entries.txt" ) || die ;
@entries = <F> ;
chomp @entries ;
while ( 1)
{
$response= <STDIN> ;
chop $response ;
next if ( length ( $response ) < 1 ) ;
last if ( $response eq "end" ) ;
last if ( grep ( $_ eq $response , @entries) ) ;
# else tell user what the valid options are..
print " your valid options are " . join ( " ", @entries ). "\n" ;
}
print "You got yourselves a good entry..\n" ;
~
continue here.
Hope this helps.
==
Makarand Kulkarni
~
In article <19990801162741.18763.00004448@ng-ba1.aol.com>,
perllinux@aol.com (PerlLinux) wrote:
> I am trying to write a program module that opens an external file,
reads all
> entried in that file, until there are no more to read. from there, i
want a
> user to enter input and want to check the user's input against what i
have read
> in. if what the user has entered does not match anything i have read
in, i
> want the list of entries read in from the external file to print.
then i want
> the user to be prompted to enter another value. i want this to
continue until
> the user enters a valid choice. i have tried doing this a few
different way,
> but i whatever i do i cannot seem to get to work. any help would be
> appreciated.
>
> fwi: this is perl script that is running in a unix shell...it is not
a cgi
> script.
>
> Thank you,
> PerlLinux@aol.com
>
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Mon, 2 Aug 1999 00:31:08 +0100
From: "matt saunders" <nfs@ukonline.co.uk>
Subject: How do i append the beginning of a HTML file?
Message-Id: <7o2lfn$3v1$1@apple.news.easynet.net>
I've not been using perl for long at all and i've been desperately seeking
the source code for a CGI to append the beginning of a file. I was
wondering if any of you (obviously knowledgable) people could reply with the
source code. I'd be eternally grateful.
Thank in advance.
Matt Saunders
------------------------------
Date: Sun, 01 Aug 1999 23:46:50 GMT
From: mike@fat.dotat.at (Mike Bristow)
Subject: Re: How do i append the beginning of a HTML file?
Message-Id: <slrn7q9n3a.66c.mike@lindt.fat.dotat.at>
On Mon, 2 Aug 1999 00:31:08 +0100, matt saunders <nfs@ukonline.co.uk> wrote:
>I've not been using perl for long at all and i've been desperately seeking
>the source code for a CGI to append the beginning of a file. I was
>wondering if any of you (obviously knowledgable) people could reply with the
>source code. I'd be eternally grateful.
If you have perl on your computer, you should have the documentation.
Which includes the FAQ. Which include perlfaq5. Which includes:
=head1 Found in /usr/lib/perl5/5.00503/pod/perlfaq5.pod
=head2 How do I change one line in a file/delete a line in a
file/insert a line in the middle of a file/append to the beginning of
a file?
Which includes a bette written answer to your question than you are
likely to find here.
(perldoc -q is your friend)
--
Mike Bristow, Geek-At-Large. GK/RT0038
one tequila - two tequila - three tequila - FLOOR !!!
------------------------------
Date: Sun, 01 Aug 1999 23:27:48 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: is process still running?
Message-Id: <UJ4p3.59$yJ1.3115@nsw.nnrp.telstra.net>
In article <37a1f34e@cs.colorado.edu>,
Tom Christiansen <tchrist@mox.perl.com> writes:
> [courtesy cc of this posting mailed to cited author]
>
> In comp.lang.perl.misc, mrduane@my-deja.com writes:
>:Thanks for the info. I was aware that kill($pid) just calls the unix
>:kill command.
>
> No, it doesn't. It performs the kill(2) system call directly.
> The kill(1) command is certainly not invoked.
An important distinction.
Just an addition: kill(2) will only be called if it's available.
Sometimes killpg() will be called (probably on most BSD systems),
sometimes the system's equivalent function or set of functions (VMS?).
Martien
--
Martien Verbruggen |
Interactive Media Division | Never hire a poor lawyer. Never buy
Commercial Dynamics Pty. Ltd. | from a rich salesperson.
NSW, Australia |
------------------------------
Date: Mon, 02 Aug 1999 00:56:30 +0200
From: Alex Farber <alex@kawo2.rwth-aachen.de>
To: chris18@my-deja.com
Subject: Re: LINUX APACHE PERL
Message-Id: <37A4D09E.E31D6BB3@kawo2.rwth-aachen.de>
Hi Chris,
chris18@my-deja.com wrote:
> I want to know about the complete administration of a webserver running
> on LINUX , APACHE using cgi-perl.
>
> can anyone tell me where I can find faqs , docs etc
maybe http://www.modperl.com
Regards
Alex
--
Ich studiere Elektrotechnik (Technische Informatik) an der RWTH Aachen
und bin ein guter Perl-Programmierer (arbeite seit 4 Jahren als Intranet-
Entwickler). Kann auch C, Java, SQL, JavaScript und HTML, CGI und TCP/IP.
Ich suche eine gut bezahlte Diplomstelle in Aachen, Koeln oder Umgebung.
------------------------------
Date: Mon, 02 Aug 1999 00:55:13 +0200
From: Alex Farber <alex@kawo2.rwth-aachen.de>
To: Graziano Poretti <tdm@dmw.it>
Subject: Re: mail check via web
Message-Id: <37A4D051.86ECB3F@kawo2.rwth-aachen.de>
Hi Graziano,
Graziano Poretti wrote:
> I'm looking for a freeware perl script allowing me to check emails from
> a webpage (see objects, senders ... and the possibility to delete them
> before dnload the messages). Useful to avoid spam, loooong not requested
> attachment and so on
>
> do you know where to find it on the Net?
maybe at http://freshmeat.net or at http://cpan.org ?
Regards
Alex
--
Ich studiere Elektrotechnik (Technische Informatik) an der RWTH Aachen
und bin ein guter Perl-Programmierer (arbeite seit 4 Jahren als Intranet-
Entwickler). Kann auch C, Java, SQL, JavaScript und HTML, CGI und TCP/IP.
Ich suche eine gut bezahlte Diplomstelle in Aachen, Koeln oder Umgebung.
------------------------------
Date: Sun, 1 Aug 1999 15:02:01 -0700
From: "Steve S" <ssd@bc.sympatico.ca>
Subject: newbie - fill array w/ contents of a file
Message-Id: <vj3p3.75$jO.334472@news.bctel.net>
Can anybody help?
I am trying to fill an array with the contents of a file but seem to be only
getting the last record. This is what I am doing:
open (READFILE, "c:\test\log.txt");
while (<READFILE>)
{
@fileList= $_;
}
To check my array contents I am doing the following:
foreach $line(@fileList)
{
print $line . "\n";
}
Am I totally missing something or should this work?
Regards,
Steve.
------------------------------
Date: Sun, 01 Aug 1999 18:36:28 -0400
From: modred@shore.net (Garth Sainio)
Subject: Re: newbie - fill array w/ contents of a file
Message-Id: <modred-0108991836290001@gniqncy-s03-150.port.shore.net>
In article <vj3p3.75$jO.334472@news.bctel.net>, "Steve S"
<ssd@bc.sympatico.ca> wrote:
!! Can anybody help?
!!
!! I am trying to fill an array with the contents of a file but seem to be only
!! getting the last record. This is what I am doing:
!!
!! open (READFILE, "c:\test\log.txt");
!! while (<READFILE>)
!! {
!! @fileList= $_;
$_ is the current line in the file, so the last thing put into the array
is the last line. If you are absolutely, positively sure you want to read
the whole thing into an array you can say @fileList = <READFILE>; but you
had better have a really, really good reason for doing it. Generally, you
want to read the file line by line and do the processing as necessary
rather than slurp the whole thing into an array. Reading the whole thing
in an array uses a lot of memory and generally unnecessary.
Garth
--
Garth Sainio "Finishing second just means you were the
modred@shore.net first to lose" - anonymous
------------------------------
Date: Sun, 01 Aug 1999 23:15:07 GMT
From: makarand_kulkarni@my-deja.com
Subject: Re: newbie - fill array w/ contents of a file
Message-Id: <7o2kdm$i16$1@nnrp1.deja.com>
Instead of
while (<READFILE>)
{
@fileList= $_;
}
do this
while ( <READFILE> )
{
push ( @fileList, $_) ;
}
==
Makarand
In article <vj3p3.75$jO.334472@news.bctel.net>,
"Steve S" <ssd@bc.sympatico.ca> wrote:
> Can anybody help?
>
> I am trying to fill an array with the contents of a file but seem to
be only
> getting the last record. This is what I am doing:
>
> open (READFILE, "c:\test\log.txt");
> while (<READFILE>)
> {
> @fileList= $_;
> }
>
> To check my array contents I am doing the following:
>
> foreach $line(@fileList)
> {
> print $line . "\n";
> }
>
> Am I totally missing something or should this work?
>
> Regards,
> Steve.
>
>
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: 1 Aug 1999 23:11:41 GMT
From: mwang@tech.cicg.ml.com (Michael Wang)
Subject: Re: newbie - fill array w/ contents of a file
Message-Id: <7o2k7d$mlj$1@news.ml.com>
Steve S <ssd@bc.sympatico.ca> wrote:
> open (READFILE, "c:\test\log.txt");
> while (<READFILE>)
> {
> @fileList= $_; => push(@fileList, $_);
> }
>
> foreach $line(@fileList)
> {
> print $line . "\n";
> }
@fileList is overwritten everytime in the while loop.
By changing it to push(@fileList, $_) as indicated above
you will be fine. Posted and Emailed.
--
Michael Wang
http://www.mindspring.com/~mwang
------------------------------
Date: Sun, 01 Aug 1999 23:49:18 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: newbie - fill array w/ contents of a file
Message-Id: <225p3.65$yJ1.3896@nsw.nnrp.telstra.net>
In article <vj3p3.75$jO.334472@news.bctel.net>,
"Steve S" <ssd@bc.sympatico.ca> writes:
> Can anybody help?
>
> I am trying to fill an array with the contents of a file but seem to be only
> getting the last record. This is what I am doing:
I'm amazed that you get even that:
> open (READFILE, "c:\test\log.txt");
You don't check for errors. And you obviously don't know what happens
with backslashes in a double-quoted string:
# perl -w
use strict ;
my $foo = "c:\test\log.txt";
print $foo, "\n";
c: estog.txt
^ That's a tab
So.. You're trying to open the file "c:<tab>estog.txt" for reading.
Does that file exist? You would have found out with something like:
my $file = "c:\test\log.txt";
open(READFILE, $file) || die "Cannot open $file for reading: $!";
> while (<READFILE>)
> {
> @fileList= $_;
This probably doesn't do what you think it does..
> Am I totally missing something or should this work?
No... It shouldn't.
Maybe something like this will work, depending on what you want:
# Note the _single_ quotes
my $file = 'c:\test\log.txt';
open(READFILE, $file) || die "Cannot open $file for reading: $!";
my @lines = <READFILE>;
close(READFILE);
Suggested reading:
# perldoc perlfunc
(Section on open)
or
# perldoc -f open
# perldoc perlop
(Section I/O Operators)
(Section on Quote and Quotelike Operators)
# perldoc perldata
(Sections on arrays)
(Sections on quoting)
Martien
--
Martien Verbruggen |
Interactive Media Division | You can't have everything, where would
Commercial Dynamics Pty. Ltd. | you put it?
NSW, Australia |
------------------------------
Date: 1 Aug 1999 22:31:35 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Paasing Arguments to System Function
Message-Id: <7o2hs7$7nl@dfw-ixnews11.ix.netcom.com>
paul (paul@balans.net) wrote:
: I'm getting a bit angry avout this one because i do not see the
: mistake i'm making.
:
: $test = 'perl \\query\\query1.cgi';
: $uitkomst = `$test "FileNaam=test.txt"`;
:
: I'm trying to run query1.cgi with the the variable FileNaam filled
: with test.txt.
CGI programs don't expect to get their input as command-line arguments.
Read up on the CGI spec until you're familiar with the two possible ways
that CGI programs can get their input, examine query1.cgi to find out
which way it's using (if it was written using CGI.pm, either way will
work, but unfortunately many CGI programs use a cargo-cult parameter
decoder instead), and then pass the input the proper way.
------------------------------
Date: Sun, 1 Aug 1999 13:33:31 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: perl 2 c converter/compiler/translater ?
Message-Id: <bd02o7.kv2.ln@magna.metronet.com>
markus (drbrain@ziemlich.org) wrote:
: Hello, i was wondering if there is an perl to c converter/
: compiler/translater/whatsoever available.
: Any resources,
Can you spell F-A-Q ?
: hints,
That Question is Asked Frequently.
: url ?
What for? It is already on your hard disk.
Perl FAQ, part 3:
"How can I compile my Perl program into byte code or C?"
: thanks in advice,
Uh huh.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 01 Aug 1999 23:59:22 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Q: perl driver for window nt and oracle 8 ?
Message-Id: <ub5p3.67$yJ1.3896@nsw.nnrp.telstra.net>
In article <7o28u0$agl$1@nnrp1.deja.com>,
tedchyn@yahoo.com writes:
> Sir, Is there perl drivers (dbd,dbi) for window nt and oracle 8 out
> somewhere ?
DBD::Oracle is the standard Oracle driver for DBI.
# perl -MCPAN -e shell
[snip]
cpan> readme DBD::Oracle
DBD::Oracle -- an Oracle 7 and Oracle 8 interface for Perl 5.
[snip]
Looks like it does support Oracle 8.
The source for all things perl-win32:
http://www.activestate.com/
Their perl comes with a thing called PPM. Use that to find and install
DBI and DBD-Oracle.
Martien
--
Martien Verbruggen |
Interactive Media Division | Never hire a poor lawyer. Never buy
Commercial Dynamics Pty. Ltd. | from a rich salesperson.
NSW, Australia |
------------------------------
Date: Sun, 01 Aug 1999 23:01:44 +0100
From: Paul Christopher Reid <paulreid@cableinet.co.uk>
Subject: Running scrips on own pc
Message-Id: <37A4C3C8.79E011F5@cableinet.co.uk>
When i try to run a script on my pc I get a message box asking if I want
to save or open the file. Is there something I can do so that the script
executes?
------------------------------
Date: Mon, 02 Aug 1999 00:53:56 +0200
From: Alex Farber <alex@kawo2.rwth-aachen.de>
To: bernie <b.schindlholzer@tirol.com>
Subject: Re: VERY,VERY URGENT: I need help with the Net::FTP module and ActiveStates Perl!!!
Message-Id: <37A4D004.5BE53520@kawo2.rwth-aachen.de>
Hi Bernie,
bernie wrote:
> What do I have to do in WinNT so that i can use this moduls in my
> scripts??
have you set PERL5LIB (see "perldoc perlrun") or
use lib qw (/path/to/that/module/dir); ?
Regards
Alex
--
Ich studiere Elektrotechnik (Technische Informatik) an der RWTH Aachen
und bin ein guter Perl-Programmierer (arbeite seit 4 Jahren als Intranet-
Entwickler). Kann auch C, Java, SQL, JavaScript und HTML, CGI und TCP/IP.
Ich suche eine gut bezahlte Diplomstelle in Aachen, Koeln oder Umgebung.
------------------------------
Date: Mon, 2 Aug 1999 01:27:08 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: VERY,VERY URGENT: I need help with the Net::FTP module and ActiveStates Perl!!!
Message-Id: <Pine.HPP.3.95a.990802012406.18666B-100000@hpplus03.cern.ch>
On Sun, 1 Aug 1999, bernie wrote:
> VERY,VERY URGENT:
I love this kind of posting. As the new users FAQs explain, if it's
true then you're already dead before the answer can get back to you, so
it doesn't matter what I say. And if it's false, then I don't care what
I say either.
As I'm in a good mood, however, I won't bother to say it.
------------------------------
Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 1 Jul 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.
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 V9 Issue 327
*************************************