[17201] in Perl-Users-Digest
Perl-Users Digest, Issue: 4613 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 14 00:05:27 2000
Date: Fri, 13 Oct 2000 21: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)
Message-Id: <971496307-v9-i4613@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 13 Oct 2000 Volume: 9 Number: 4613
Today's topics:
Re: *hex editing* in perl <tomp@sci.fi>
Re: *hex editing* in perl (Mark-Jason Dominus)
Re: *hex editing* in perl <uri@sysarch.com>
Re: [Q] "pass along" in AUTOLOAD ? (Mark-Jason Dominus)
Re: [Q] "pass along" in AUTOLOAD ? (Mark-Jason Dominus)
Re: Cannot find the error <ah@datapharm.de>
Re: Cannot find the error (Martien Verbruggen)
Re: execute in the background in Windows <bwalton@rochester.rr.com>
Re: I need a DB solution <bwalton@rochester.rr.com>
Re: I need a DB solution <jeff@vpservices.com>
Re: Multiple fork()s? (Martien Verbruggen)
Re: Multiple fork()s? (Mark-Jason Dominus)
Re: Multiple fork()s? eric@on-e.com
Re: Need help converting lots of Unix times (Mark-Jason Dominus)
Re: Plz help - Perl Q <mikecook@cigarpool.com>
Re: question <wyzelli@yahoo.com>
Re: question <c.gersch@iglusoft.com>
Re: question <joe+usenet@sunstarsys.com>
Re: question <c.gersch@iglusoft.com>
Re: question <joe+usenet@sunstarsys.com>
Re: question <jeff@vpservices.com>
Re: question <uri@sysarch.com>
Re: question <juex@my-deja.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 14 Oct 2000 05:01:31 +0300
From: tomp at sci fi <tomp@sci.fi>
Subject: Re: *hex editing* in perl
Message-Id: <39E7BE7B.79FC8D95@sci.fi>
How do I convert the bytes to characters ? :) Or I just didn't get it how to
write those properly because now the '0xFF' goes as ascii in the file.
Uri Guttman wrote:
> perldoc -f seek
> perldoc -f sysread
> perldoc -f syswrite
> perldoc -f open
> perldoc opentut
> perldoc binmode
>
> it's all there and not difficult.
>
> uri
------------------------------
Date: Sat, 14 Oct 2000 02:29:38 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: *hex editing* in perl
Message-Id: <39e7c4f8.5909$152@news.op.net>
In article <39E7BE7B.79FC8D95@sci.fi>, tomp at sci fi <tomp@sci.fi> wrote:
>How do I convert the bytes to characters ? :) Or I just didn't get it how to
>write those properly because now the '0xFF' goes as ascii in the
file.
$character_number_255 = chr(hex("0xFF"));
------------------------------
Date: Sat, 14 Oct 2000 02:51:32 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: *hex editing* in perl
Message-Id: <x7d7h4w2x7.fsf@home.sysarch.com>
>>>>> "MD" == Mark-Jason Dominus <mjd@plover.com> writes:
MD> In article <39E7BE7B.79FC8D95@sci.fi>, tomp at sci fi
MD> <tomp@sci.fi> wrote:
>> How do I convert the bytes to characters ? :) Or I just didn't get
>> it how to write those properly because now the '0xFF' goes as ascii
>> in the file.
MD> $character_number_255 = chr(hex("0xFF"));
or use pack which is better for multiple sequential bytes which the OP
seems to want.
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: Sat, 14 Oct 2000 02:21:04 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: [Q] "pass along" in AUTOLOAD ?
Message-Id: <39e7c310.58d2$381@news.op.net>
Keywords: Bach, cotton, humble, persona
In article <Pine.GSO.4.21.0010131856260.14163-100000@crusoe.crusoe.net>,
Jeff Pinyan <japhy@pobox.com> wrote:
>This works for me:
> if ($meth =~ /\A[A-Z]+\z/) { goto &{ $SUPER::{$meth} } }
I'm totally boggled here. I first thought that this was a mistake,
but you said that it works for you, so that can't be right. What does
$SUPER::{$meth} doing? Is it documented anywhere?
------------------------------
Date: Sat, 14 Oct 2000 02:25:21 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: [Q] "pass along" in AUTOLOAD ?
Message-Id: <39e7c410.58f3$3c7@news.op.net>
Keywords: Elmira, added, anthropomorphic, nebulous
In article <8s7tj7$4kr$1@panix3.panix.com>, kj0 <kj0@mailcity.com> wrote:
>I'm writing AUTOLOAD in a base class to handle some common methods,
>but I want it to pass along (to the superclass, typically UNIVERSAL)
>all calls to methods whose names are all-caps (e.g. DESTROY).
I don't think that makes sense. Either the method is defined in a
superclass, or it isn't.
If the method *is* defined in a superclass, then your AUTOLOAD will
not be called at all, because Perl searches the inheritance tree for
methods *before* it calls AUTOLOAD.
If the method is *not* defined in a superclass, then AUTOLOAD has
nowhere to 'pass along' the call to.
So what exactly did you want it do? If AUTOLOAD gets invoked, it's
because the method does not exist; but then you want it to call the
method that doesn't exist.
Maybe the right answer for your question is "You don't need an
AUTOLOAD at all"?
------------------------------
Date: Thu, 12 Oct 2000 18:22:29 +0200
From: Andreas Huber <ah@datapharm.de>
Subject: Re: Cannot find the error
Message-Id: <39E5E545.FB05500C@datapharm.de>
Oliver Soeder schrieb:
> Can anybody help me out? I don't find the problem.
>
> print "Bitte geben Sie eine Ziffernfolge ein:\n";
> $zahl=<STDIN>;
> chomp $zahl;
> @feld=split(//,$zahl);
> $i=1;
>
> #1. Schritt
>
> while (defined($feld[$i]))
> {
> $j=0;
> $mal2[$j]=$feld[$i]*2;
> j++; #THERE SEEMS TO
> BE AN ERROR HERE BUT I CAN'T FIND
> i=i+2;
> }
> foreach $quer (@mal2)
> {
> if ($quer<10)
> {
> $n=0;$o=0;
> while(defined($mal2[$n]))
> {
> $smallerten[$o]=$mal2[$n];
> n++; o++;
> }
Hi,
try chop in line 3; not chomp
--
Andreas Huber
Produktion & Entwicklung
Datapharm Netsystems AG
E-Mail: ah@datapharm.de
Tel.: (+49) 89 85 68 4 -202
Fax: (+49) 89 85 68 4 -100
------------------------------
Date: Sat, 14 Oct 2000 13:59:51 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Cannot find the error
Message-Id: <slrn8ufj17.294.mgjv@martien.heliotrope.home>
On Thu, 12 Oct 2000 18:22:29 +0200,
Andreas Huber <ah@datapharm.de> wrote:
> Oliver Soeder schrieb:
>
> > Can anybody help me out? I don't find the problem.
> >
> > print "Bitte geben Sie eine Ziffernfolge ein:\n";
> > $zahl=<STDIN>;
> > chomp $zahl;
>
> try chop in line 3; not chomp
Why?
What is going to be the difference? Do you know what chomp and chop do?
I believe that chomp is actually the correct call to use here, and chop
is not.
If you feel otherwise, please, enlighten me.
Martien
--
Martien Verbruggen |
Interactive Media Division | In the fight between you and the
Commercial Dynamics Pty. Ltd. | world, back the world - Franz Kafka
NSW, Australia |
------------------------------
Date: Sat, 14 Oct 2000 03:37:00 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: execute in the background in Windows
Message-Id: <39E7D4D9.1356476D@rochester.rr.com>
John wrote:
>
> Hello:
>
> How to let perl program started from Windows(95/98/NT/2000) command line to
> return immediatly and keep running in the background?
>
> John Hsieh
> john@imining.com.tw
Try the start command. You might have better luck with DOS questions in
a DOS newsgroup.
--
Bob Walton
------------------------------
Date: Sat, 14 Oct 2000 03:34:23 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: I need a DB solution
Message-Id: <39E7D43C.C486E542@rochester.rr.com>
Neb wrote:
...
> I don't have anymore choice, I need a DB for my web site (which now has more
> than 600 members).
>
> Here are the facts: my web site "engine" is in Perl, that I develop on my PC
> (Windows 98). My site is hosted by a "free" server on the internet (so, I
> don't have the control on the server) which is running some flavor of Unix.
>
> Since I entend for my site to have one day thousands of members, I need a DB
> that I could change for something like SQL Server using ODBC. But for now,
> I would maybe like to use Access, since I have it, plus it's easy to
> manipulate the data in it.
>
> But if I don't have much access to my internet server, plus it's Unix, is it
> a good idea to use Access (and how)?!
>
> Or is there an other DB I can use that I don't need some kind of DB server
> to access it (not like MySql which needs to install a server to access a DB)
> ? Some DB that can be used under Windows and Unix ?
...
> neb
Have you considered the standard Perl facility involving tie'ing a Perl
hash to a DBM-style database? It isn't a fancy SQL-based database, but
it does the basic job of making a hash persistent. On your PC, DB_File
would be a good choice (probably the only choice that will actually work
under Windoze 98). On you ISP's computer, whatever you get with dbmopen
is probably the best choice. Note that there are limitations on key and
value size in many DBM-type setups -- read the man pages carefully to be
sure you fully understand these before making use of them. Also note
that you cannot use DBM-style tie'd hashes to store anything but strings
in the keys and values. Specifically, attempts to store references
won't work too well.
Using the tie'd-hash facility has the advantage of being portable (but
note that the resulting binary files are not portable) across most any
platforms. And it comes with every Perl installation, so it should
already be installed and ready for your use on your ISP's computer.
Don't forget to perform locking in your CGI application every time the
hash is tied.
--
Bob Walton
------------------------------
Date: Fri, 13 Oct 2000 20:47:12 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: I need a DB solution
Message-Id: <39E7D740.870F0F7C@vpservices.com>
Neb wrote:
>
> Or is there an other DB I can use that I don't need some kind of DB server
> to access it (not like MySql which needs to install a server to access a DB)
> ? Some DB that can be used under Windows and Unix ?
DBD::RAM, DBD::CSV, and DBD::Sprite all fit that description. They will
let you use DBI and (some) SQL without needing to install a database
server. You'd use either flat comma separated values file with DBD::CSV
and DBD::Sprite or comma separated values, fixed width records, XML, or
other formats with DBD::RAM. All three would be easily upgraded to
MySQL or something else later since they use DBI. The first two I know
work on both Win and *nix and Sprite may as well.
--
Jeff
------------------------------
Date: Sat, 14 Oct 2000 13:17:21 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Multiple fork()s?
Message-Id: <slrn8ufghh.294.mgjv@martien.heliotrope.home>
On Fri, 13 Oct 2000 23:49:23 GMT,
eric@on-e.com <eric@on-e.com> wrote:
> I've exhaustedly searched the Net looking for some basic code to
> handle multiple forks in Perl to no success. The following code snippet
> I put together doesn't work as I want it to:
I've posted this code snippet to this group before, but here it is
again. It's extracted from some module I wrote a long time ago, and
probably borrows heavily from stuff in the perlipc man page.
#!/usr/local/bin/perl -w
use strict;
use Carp;
my $num_children = 3;
my $waitedpid = 0;
sub REAPER
{
$waitedpid = wait;
$SIG{CHLD} = \&REAPER; # SYSV reinstall
print "Reaped $waitedpid" . ($? ? " with exit $?" : '') . "\n";
}
$SIG{CHLD} = \&REAPER;
# Spawn children
for (my $i = 0; $i < $num_children; $i++)
{
spawn(\&childproc, $i);
}
# Wait for all the children to finish
wait;
# Do post processing here
exit 0;
# Child procedure wrapper
sub childproc
{
# This is what the children will actually do
print "Child $$: Executing child proc: @_\n";
return 0;
}
# This is how we spawn
sub spawn
{
my $coderef = shift;
confess "USAGE: spawn CODEREF"
unless ($coderef && ref($coderef) eq 'CODE');
my $pid = fork;
die "cannot fork: $!" unless defined $pid;
if ($pid)
{
print "Parent: spawned pid $pid\n";
return; # Parent
}
# Child
exit &$coderef;
}
Note that this still potentially duplicates some stuff that gets sent to
STDOUT. See perlipc for ways of dealing with this
Martien
--
Martien Verbruggen |
Interactive Media Division | That's not a lie, it's a
Commercial Dynamics Pty. Ltd. | terminological inexactitude.
NSW, Australia |
------------------------------
Date: Sat, 14 Oct 2000 02:12:23 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Multiple fork()s?
Message-Id: <39e7c106.58a8$2c1@news.op.net>
Keywords: biddable, mart, mudguard, subjectivity
In article <7cNF5.1172$_o5.4496@typhoon.san.rr.com>, <eric@on-e.com> wrote:
>I've exhaustedly searched the Net looking for some basic code to
>handle multiple forks in Perl to no success.
That's a little puzzling, because the code should be exactly the same
in Perl as it is in C.
>print "parent - pid $$\n";
>foreach my $i (1..3) {
> my $pid;
> defined($pid = fork) || die "unable to fork: $!\n";
> if (!$pid) { print "child $i - pid $pid\n" }
> else { wait }
>}
>I'd like the output (indicating that the children are only forking
>additional children, with everyone outputing one print() statement):
Sorry, I cannot understand this, or at least I cannot make it match up
with the output you say you want, which suggests to me that maybe you
don't understand fork. But I don't have a good guess about what it is
you don't understand.
I'll note that in the code you showed, you are creating *eight*
processes. The first time through the loop, your initial process
forks. There are now two processes. Then both processes start the
second iteration of the loop, and each of the two processes forks
again, yielding four processes: The two original ones, and two new
children. This is why your output includes two lines that say
>child 2 - pid 0
Finally, each of your four processes enters the loop for the third
time and each one calls fork(); this creates four new children, each
of which prints out
>child 3 - pid 0
That is why you get seven lines of output: One for each new process.
You say you want this output:
>$ ./test_fork
>parent - pid 991
>child 1 - pid 0
>child 2 - pid 0
>child 3 - pid 0
A program, similar to yours, that will deliver this output is:
print "parent - pid $$\n";
foreach my $i (1..3) {
my $pid;
defined($pid = fork) || die "unable to fork: $!\n";
if (!$pid) { print "child $i - pid $pid\n";
last } # ***
else { wait }
}
The only change is on the line marked with ***. After a child prints
its message, it exits the loop immediately, rather than going back to
do more forks.
But that is different from what you said you wanted to do:
>I'd like the output (indicating that the children are only forking
>additional children, with everyone outputing one print() statement):
because in the program I just showed, the children are *not* forking
additional children; they exit the loop after they are created, and
only the initial process forks.
So I'm not sure that this will be helpful.
>I know it's something simple.. :-/
Could be.
------------------------------
Date: Sat, 14 Oct 2000 03:58:24 GMT
From: eric@on-e.com
Subject: Re: Multiple fork()s?
Message-Id: <ARQF5.9343$46.85576@typhoon.san.rr.com>
Mark-Jason Dominus <mjd@plover.com> wrote:
> print "parent - pid $$\n";
> foreach my $i (1..3) {
> my $pid;
> defined($pid = fork) || die "unable to fork: $!\n";
> if (!$pid) { print "child $i - pid $pid\n";
> last } # ***
> else { wait }
> }
> The only change is on the line marked with ***. After a child prints
> its message, it exits the loop immediately, rather than going back to
> do more forks.
Ahh.. that's what I needed - I knew it was simple. Much appreciated.
> But that is different from what you said you wanted to do:
>>I'd like the output (indicating that the children are only forking
>>additional children, with everyone outputing one print() statement):
> because in the program I just showed, the children are *not* forking
> additional children; they exit the loop after they are created, and
> only the initial process forks.
> So I'm not sure that this will be helpful.
>>I know it's something simple.. :-/
> Could be.
Well, I see now that I was being vague - my apologies. I'm completely
satisfied with the proposed solution. Thank you again! =)
Eric
------------------------------
Date: Sat, 14 Oct 2000 02:43:17 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Need help converting lots of Unix times
Message-Id: <39e7c845.59dc$140@news.op.net>
Keywords: Hickman, belate, cohosh, generate
In article <39E762D1.3C31B91F@pacbell.net>, <alphathk@pacbell.net> wrote:
>Could someone plase point me in the right direction?
I frequently use something like this:
perl -pe 's/\d{9}/localtime $&/ge' thefile
Applied to the sample data you showed, that produces:
Wed Aug 16 16:17:58 2000 Wed Aug 16 16:18:58 2000 459.483
Wed Aug 16 16:18:58 2000 Wed Aug 16 16:19:58 2000 49.35
Wed Aug 16 16:19:58 2000 Wed Aug 16 16:20:58 2000 17.5637
Wed Aug 16 16:20:58 2000 Wed Aug 16 16:21:58 2000 696.7
Wed Aug 16 16:21:58 2000 Wed Aug 16 16:22:58 2000 682.067
Wed Aug 16 16:22:58 2000 Wed Aug 16 16:23:58 2000 137.967
------------------------------
Date: Fri, 13 Oct 2000 20:56:58 -0700
From: "Michael Cook" <mikecook@cigarpool.com>
Subject: Re: Plz help - Perl Q
Message-Id: <FRQF5.1113$yP.512296@news.uswest.net>
Thanks for the tips Bart!!!
I don't have 2 open at the same time. I open one, read some stuff, then
close it, then open another & write to it based on the info from the first.
Should I redefine $OFH between these, use another variable, or do I only
need to flush it once for the whole script?
Thanks!
Michael
--
== CigarPool ==
http://www.cigarpool.com
"Bart Lateur" <bart.lateur@skynet.be> wrote in message
news:s0nduschlcfpshpd7sueki19o7l275rbea@4ax.com...
> Michael Cook wrote:
>
> > My question is: If I have to lock more than 1 file in a script,
should I
> >undefine $OFH after each use? Or maybe use a different scalar designator
for
> >the flush each use? Or do I need to only flush once per script?
>
> >$OFH=select(MEMBERS); $| = 1; select($OFH);
>
> $OFH is only used to temporarily store the current handle. There's no
> reason not to reuse this variable for other purposes. Well, personally,
> I would make it a localized variable:
>
> {
> my $ofh = select MEMBERS;
> $| = 1;
> select $ofh;
> }
>
> But, coming back to this:
>
> >If I have to lock more than 1 file in a script
>
> At the same time? Be careful for avoiding deadlock. If program A grabs X
> and then Y, and program B grabs Y and then X, well, if this happens
> simulataniously, and A has X and B has Y, they'll wait for each other
> forever. That is called "deadlock". But actually, that's not a Perl
> specific problem.
>
> --
> Bart.
------------------------------
Date: Sat, 14 Oct 2000 10:36:29 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: question
Message-Id: <ckOF5.4$DL4.2576@vic.nntp.telstra.net>
"Christian Gersch" <c.gersch@iglusoft.com> wrote in message
news:8s8avr$sun$1@news.online.de...
> Hi there!
>
> I'm a really Perl-newbie. Perhaps you can answer my stupid question:
>
> I have got a textfile that incluedes 7 lines of text. The variable $text
> should just include the 4th line of my textfile.
> Please help me!
>
Read the whole file nto an array and then assign the 4th element to $text.
or
Read the file line by line and assign the 4th line to $text, then exit the
read loop.
What have you got so far?
Wyzelli
--
#Modified from the original by Jim Menard
for(reverse(1..100)){$s=($_==1)? '':'s';print"$_ bottle$s of beer on the
wall,\n";
print"$_ bottle$s of beer,\nTake one down, pass it around,\n";
$_--;$s=($_==1)?'':'s';print"$_ bottle$s of beer on the
wall\n\n";}print'*burp*';
------------------------------
Date: Sat, 14 Oct 2000 03:08:35 +0200
From: "Christian Gersch" <c.gersch@iglusoft.com>
Subject: Re: question
Message-Id: <8s8bs3$t6h$1@news.online.de>
Here's my script: (-;
open(DATEI, "<file.txt");
while(<DATEI>)
If ($. = 4) $text = $_;
close(DATEI);
...but I just gen an error message. What's wrong?
-Chris
--
...................................
IgluSoft, Bad Homburg
service24@de.isneurope.com
+49 700 IGLUSOFT / www.isneu.com
Geld für Ihre Startseite: www.myISN.de
------------------------------
Date: 13 Oct 2000 21:22:32 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: question
Message-Id: <m3em1k2p47.fsf@mumonkan.sunstarsys.com>
"Christian Gersch" <c.gersch@iglusoft.com> writes:
> Hi there!
> I have got a textfile that incluedes 7 lines of text. The variable $text
> should just include the 4th line of my textfile.
> Please help me!
#! /usr/bin/perl -wT
open FILE, "< /my/text/file";
<FILE>,<FILE>,<FILE>; #reads the first 3 lines
my $text = <FILE>; # read 4th line into $text
close FILE;
--
Joe Schaefer
------------------------------
Date: Sat, 14 Oct 2000 03:24:42 +0200
From: "Christian Gersch" <c.gersch@iglusoft.com>
Subject: Re: question
Message-Id: <8s8csi$tfn$1@news.online.de>
Thanks! (-;
--
...................................
IgluSoft, Bad Homburg
service24@de.isneurope.com
+49 700 IGLUSOFT / www.isneu.com
Geld für Ihre Startseite: www.myISN.de
------------------------------
Date: 13 Oct 2000 21:40:01 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: question
Message-Id: <m3aec82ob2.fsf@mumonkan.sunstarsys.com>
"Christian Gersch" <c.gersch@iglusoft.com> writes:
> If ($. = 4) $text = $_;
this should read
if ($. == 4) { $text = $_; } #GOOD
or you could do the whole loop in one line:
$text = <FILE> while ($. <= 4); #BAD
but using $. really isn't a good idea
since it makes your code difficult to
read (most perlies don't know what $.
does- I had to look it up myself). Put
your own line counter variable in, and
name it as such, and break your code up
so each line does one thing.
Remember, code is for humans (especially
you) to read, so keep simplicity and
clarity higher values than cleverness and
obscurity.
HTH
--
Joe Schaefer
------------------------------
Date: Fri, 13 Oct 2000 18:59:21 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: question
Message-Id: <39E7BDF9.7A891693@vpservices.com>
Christian Gersch wrote:
>
> Here's my script: (-;
No need for a frownie, gotta start somewhere.
> open(DATEI, "<file.txt");
Whenever you open a file or do something with the file system *always*
check to see if what you are trying is successful:
open(DATEI, '<file.txt') or die "Can't open file.txt: $!";
The "$!" will give a specific error message, the only way you can find
out what is wrong.
> while(<DATEI>)
> If ($. = 4) $text = $_;
"if" in Perl is not spelled with an "I", but an "i".
comparison in Perl is done with "==", not "=". (Perl is picky, picky,
picky, but in a good way)
> ...but I just gen an error message. What's wrong?
That's what error messages are for: to tell you what's wrong. What did
yours say?
--
Jeff
------------------------------
Date: Sat, 14 Oct 2000 02:54:39 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: question
Message-Id: <x7aec8w2s0.fsf@home.sysarch.com>
>>>>> "JS" == Joe Schaefer <joe+usenet@sunstarsys.com> writes:
JS> "Christian Gersch" <c.gersch@iglusoft.com> writes:
>> If ($. = 4) $text = $_;
JS> this should read
JS> if ($. == 4) { $text = $_; } #GOOD
JS> or you could do the whole loop in one line:
JS> $text = <FILE> while ($. <= 4); #BAD
JS> but using $. really isn't a good idea
JS> since it makes your code difficult to
JS> read (most perlies don't know what $.
JS> does- I had to look it up myself). Put
JS> your own line counter variable in, and
JS> name it as such, and break your code up
JS> so each line does one thing.
that is bogus. $. is the better way to do it as it is simpler than
making an extra counter. most perl hacker DO know it.
JS> Remember, code is for humans (especially you) to read, so keep
JS> simplicity and clarity higher values than cleverness and
JS> obscurity.
then where do you draw the line? might as well not use perl if you have
that attitude. obscurity and brevity for its own sake is for obsfucated
contests and golf. but using a well documented perl variable for its
intended purpose is neither.
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: Fri, 13 Oct 2000 20:16:32 -0700
From: "Jürgen Exner" <juex@my-deja.com>
Subject: Re: question
Message-Id: <39e7d011@news.microsoft.com>
"Christian Gersch" <c.gersch@iglusoft.com> wrote in message
news:8s8bs3$t6h$1@news.online.de...
Two problems:
> open(DATEI, "<file.txt");
> while(<DATEI>)
> If ($. = 4) $text = $_;
a) Perl is case sensitive, you may want to try "if" instead of "If"
b) you are assigning the value 4 to $., try a compare operator "==" instead
> close(DATEI);
jue
------------------------------
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 4613
**************************************