[11916] in Perl-Users-Digest
Perl-Users Digest, Issue: 5516 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 29 09:07:14 1999
Date: Thu, 29 Apr 99 06:00:18 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 29 Apr 1999 Volume: 8 Number: 5516
Today's topics:
[Perl] How to find the Perl FAQ <rootbeer&pfaq*finding*@redcat.com>
A simpler way to do this? (Steve Vertigan)
Re: CGI testing <nospam.newton@gmx.net>
Does "progress bar" exist in Tk? <patrick.renaud@transport.alstom.com>
How to convert perl to C program id903@iname.com
Is this the best way to get a substring? badbob01@my-dejanews.com
Re: Need help on "hex($1)" <nospam.newton@gmx.net>
Re: Need help on "hex($1)" <droby@copyright.com>
Re: Net::NNTP help? <Michael.Cameron@no.spam.technologist.com>
Re: PERL & Y2K <droby@copyright.com>
Re: PERL & Y2K <gellyfish@gellyfish.com>
Re: PERL & Y2K (Larry Rosler)
Re: PERL & Y2K <bill@fccj.org>
Re: perldoc HELP, Was How to use Net::FTP in perl?? <e.h.bogart@larc.nasa.gov>
Re: perldoc HELP, Was How to use Net::FTP in perl?? <e.h.bogart@larc.nasa.gov>
Re: pow() ? to the power of ? <bill@fccj.org>
Re: Question: Opening and closing files. <tony@blackstar.co.uk>
Re: test please ignore <nospam.newton@gmx.net>
why doesn't redeclaring $i give warning/errors? sstarre@my-dejanews.com
Re: Why paranthesis change logical expression (Bart Lateur)
Re: Why paranthesis change logical expression <droby@copyright.com>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 29 Apr 1999 10:24:01 GMT
From: Tom Phoenix <rootbeer&pfaq*finding*@redcat.com>
Subject: [Perl] How to find the Perl FAQ
Message-Id: <pfaqmessage925381441.8469@news.teleport.com>
Archive-name: perl-faq/finding-perl-faq
Posting-Frequency: weekly
Last-modified: 10 Sep 1998
[ That "Last-modified:" date above refers to this document, not to the
Perl FAQ itself! The last major update of the Perl FAQ was in Summer of
1998; of course, ongoing updates are made as needed. ]
For most people, this URL should be all you need in order to find Perl's
Frequently Asked Questions (and answers).
http://cpan.perl.org/doc/FAQs/
Please look over (but never overlook!) the FAQ and related docs before
posting anything to the comp.lang.perl.* family of newsgroups.
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Beginning with Perl version 5.004, the Perl distribution itself includes
the Perl FAQ. If everything is pro-Perl-y installed on your system, the
FAQ will be stored alongside the rest of Perl's documentation, and one
of these commands (or your local equivalents) should let you read the FAQ.
perldoc perlfaq
man perlfaq
If a recent version of Perl is not properly installed on your system,
you should ask your system administrator or local expert to help. If you
find that a recent Perl distribution is lacking the FAQ or other important
documentation, be sure to complain to that distribution's author.
If you have a web connection, the first and foremost source for all things
Perl, including the FAQ, is the Comprehensive Perl Archive Network (CPAN).
CPAN also includes the Perl source code, pre-compiled binaries for many
platforms, and a large collection of freely usable modules, among its
560_986_526 bytes (give or take a little) of super-cool (give or take
a little) Perl resources.
http://cpan.perl.org/
http://www.perl.com/CPAN/
http://cpan.perl.org/doc/FAQs/FAQ/html/
http://www.perl.com/CPAN/doc/FAQs/FAQ/html/
You may wish or need to access CPAN via anonymous FTP. (Within CPAN,
you will find the FAQ in the /doc/FAQs/FAQ directory. If none of these
selected FTP sites is especially good for you, a full list of CPAN sites
is in the SITES file within CPAN.)
California ftp://ftp.cdrom.com/pub/perl/CPAN/
Texas ftp://ftp.metronet.com/pub/perl/
South Africa ftp://ftp.is.co.za/programming/perl/CPAN/
Japan ftp://ftp.dti.ad.jp/pub/lang/CPAN/
Australia ftp://cpan.topend.com.au/pub/CPAN/
Netherlands ftp://ftp.cs.ruu.nl/pub/PERL/CPAN/
Switzerland ftp://sunsite.cnlab-switch.ch/mirror/CPAN/
Chile ftp://ftp.ing.puc.cl/pub/unix/perl/CPAN/
If you have no connection to the Internet at all (so sad!) you may wish
to purchase one of the commercial Perl distributions on CD-Rom or other
media. Your local bookstore should be able to help you to find one.
Another possibility is to use one of the FTP-via-email services; for
more information on doing that, send mail to <mail-server@rtfm.mit.edu>
(not to me!) with these lines in the body of the message, flush left:
setdir usenet-by-group/news.announce.newusers
send Anonymous_FTP:_Frequently_Asked_Questions_(FAQ)_List
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Comments and suggestions on the contents of this document
are always welcome. Please send them to the author at
<pfaq&finding*comments*@redcat.com>. Of course, comments on
the docs and FAQs mentioned here should go to their respective
maintainers.
Have fun with Perl!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Thu, 29 Apr 1999 12:05:34 GMT
From: vertigan@bigfoot.com (Steve Vertigan)
Subject: A simpler way to do this?
Message-Id: <3728487e.276025703@news.aurum.net.au>
I'm trying load parse an array for the existence of variables so that the
following text..
Dear %firstname %lastname
Thank you for your message regarding <b>%problem</b>...
would create the following hash
$DEFINED{'firstname'} = 1; # or true
$DEFINED{'lastname'} = 1;
$DEFINED{'problem'} = 1;
I'm sure there must be a way to do this with a regexp but after reading the
man pages on m and s and perlre I'm still lost. At the moment I do the
following.
for (@_) {
s/\n/ /g; s/\r//g;
my @foo = split;
my @bar = grep(/\%(\w+)/, @foo);
for (@bar) { s/%//g; $DEFINED{$_} = 1; }
}
This works but it seems awful messy. Also it needs any "variable" to be
surrounded by whitespace or I get things like $DEFINED{'problem</B>'}.
Ideally I'd like to stop on any non alphanumeric character. Does anyone
have a better way?
On another note does anyone know why system("rm -rf $directory") doesn't
work? I can do a rm -f on a file but not a -rf on a directory. This is
happening in a suid cgi script if that makes a difference.
Thanks,
--Steve
------------------------------
Date: Thu, 29 Apr 1999 13:38:29 +0200
From: "Philip 'Yes, that's my address' Newton" <nospam.newton@gmx.net>
Subject: Re: CGI testing
Message-Id: <372844B5.17F88E89@gmx.net>
Jeremy Gurney wrote:
>
> Don't get put off because it's not a dedicated perl news group - there
> are an awful lot of perl questions asked there.
Might one add: please do get put off because comp.lang.perl.misc isn't a
dedicated CGI group, even though there are an awful lot of CGI questions
asked there. Go straight to comp.infosystems.www.authoring.cgi with your
CGI questions and do not pass comp.lang.perl.misc, do not collect $200.
Cheers,
Philip
------------------------------
Date: Thu, 29 Apr 1999 14:25:21 +0200
From: Patrick Renaud <patrick.renaud@transport.alstom.com>
Subject: Does "progress bar" exist in Tk?
Message-Id: <37284FB1.83A37C12@transport.alstom.com>
Hi all,
In my Tk application, I want to display a progress bar during a dowload
operation but I don't see such object in the Tk documentation.
Is it an omission in the Tk docs ?
If not, how can I display the progress time with a visual representation
(not only with a percentage information) ?
Thanks for your valuable help.
--
_____________________________________
/ \
| Patrick RENAUD |
| |
| patrick.renaud@transport.alstom.com |
\_______________________________________/
------------------------------
Date: 29 Apr 1999 19:22:26 +0800
From: id903@iname.com
Subject: How to convert perl to C program
Message-Id: <372840f2.0@news01.imsbiz.com>
Could anyone tell me how to convert perl program to C program ? I know it cannot get a good converted C program. I want to do this for security reason.
Thx 1st.
------------------------------
Date: Thu, 29 Apr 1999 12:26:07 GMT
From: badbob01@my-dejanews.com
Subject: Is this the best way to get a substring?
Message-Id: <7g9j4t$9au$1@nnrp1.dejanews.com>
I'm trying to extract a pattern from a string. At first, I substituted out
what I *didn't* want and what was left is what I want:
$bigstr = "12abcd";
($substr = $bigstr) =~ s/[a-z]+//;
# so $substr is "12"
But this method is indirect and gets tricky when the undesired part doesn't
fit into an easy pattern.
Then when browsing the newsgroups, I discovered heaven:
$_ = "12abcd";
/[0-9]+/;
$substr = $&;
# so $substr is "12"!!!
So is this the best/only way to get a specific substring matching a pattern?
Is there a way to get around using $_ ?
Thanks!
-bobby
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Thu, 29 Apr 1999 13:40:06 +0200
From: "Philip 'Yes, that's my address' Newton" <nospam.newton@gmx.net>
Subject: Re: Need help on "hex($1)"
Message-Id: <37284516.E35A4936@gmx.net>
Jens Engelbrecht wrote:
>
> What have I missed ?
You missed what hex() really does. perldoc -f hex should tell you that.
perldoc -f sprintf may help you, as well.
Cheers,
Philip
------------------------------
Date: Thu, 29 Apr 1999 11:37:19 GMT
From: Don Roby <droby@copyright.com>
Subject: Re: Need help on "hex($1)"
Message-Id: <7g9g9f$6vp$1@nnrp1.dejanews.com>
In article <37282ADC.E77EDE02@dachs.de>,
redaktion@dachs.de wrote:
> Hello,
>
> the following problem occurs by trying to encode an url.
>
> (...)
> $part_of_url =~ s/[^A-Za-z0-9\s]/"%".hex($1)/eg;
> (...)
>
> => "Use of uninitialized value at the line above"
>
> What have I missed ?
>
You've missed getting anything assigned to $1 before using it. You've
misinterpreted what the hex function does. If you're trying to encode
something into a valid url, you've used the wrong character class. And
you're reinventing the wheel.
The line
$part_of_url =~ s/([^a-zA-Z0-9_.-])/uc sprintf("%%%02x",ord($1))/eg;
will probably do what you think you're doing here, but you're probably better
off using one of the modules that deal with such things. In fact, that line,
aside from the use of your variable name, is straight from the escape function
in CGI.pm.
The CGI.pm module is included with recent distributions of Perl.
--
Don Roby
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Thu, 29 Apr 1999 12:11:31 +0000
From: Michael Cameron <Michael.Cameron@no.spam.technologist.com>
To: Darren Bentham <darren@netline.net.uk>
Subject: Re: Net::NNTP help?
Message-Id: <37284C73.9B276DBF@no.spam.technologist.com>
Darren Bentham wrote:
>
> Could someone please tell me how to use the list method in the NNTP client
> class. The documentation say "The result is a reference to a hash where the
> key is a group name and each value is a reference to an array. The elements
> in this array are :- the first article number in the group, the last article
> number in the group and any information flags about the group." I would
> ideally like an example of this method in use.
>
> Many thanks in advance
Chapter 18 section 4 of the Perl Cookbook has a very short example which
may (or may not) help but I would highly recommend the book in any case.
$server=Net::NNTP->new("news.mycompany.com") or die "Can't connect:
$@\n";
$grouplist=$server->list() or die "Can't get list\n";
foreach $group (keys %grouplist) {
if ($grouplist->{$group}->[2] eq 'y') {
# Can post
}
}
Regards,
Michael
PS An intersting combination of professions! A cookbook sounds ideal!
> * Internet Content Developer & Chef
------------------------------
Date: Thu, 29 Apr 1999 10:53:32 GMT
From: Don Roby <droby@copyright.com>
Subject: Re: PERL & Y2K
Message-Id: <7g9dnc$4s1$1@nnrp1.dejanews.com>
In article <7g7s15$i0b$1@news1.rmi.net>,
Jonesy <jonesy@rmi.nospam.net> wrote:
> Abigail <abigail@fnx.com> wrote:
>
> : I think you're confused. Are you saying there's nothing to be fixed in:
>
> : printf "The year is 19%d\n", (localtime) [5];
>
> Only the logically challenged would be confused.
> That there is a *programmer* problem, *not* a language problem.
> Idiots can be most inventive when it comes to writing bad code,
> in any language.
>
If you've watched this group much, you must know that Abigail is far from
being logically challenged. In this thread it would appear that you and Sam
are suffering from slight logic impairment.
That there original poster was looking for tools to help deal with
*programmer* problems, not questioning whether the language was Y2K
compliant. Abigail's proffered line of bad code is a fine example of the
sort of thing such a script should catch.
--
Don Roby
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 29 Apr 1999 12:07:46 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: PERL & Y2K
Message-Id: <37283d82@newsread3.dircon.co.uk>
Jonesy <jonesy@rmi.nospam.net> wrote:
> Abigail <abigail@fnx.com> wrote:
>
> : I think you're confused. Are you saying there's nothing to be fixed in:
>
> : printf "The year is 19%d\n", (localtime) [5];
>
> Only the logically challenged would be confused.
> That there is a *programmer* problem, *not* a language problem.
> Idiots can be most inventive when it comes to writing bad code,
> in any language.
>
Yes and that is precisely what the original poster was talking about.
/J\
--
Jonathan Stowe <jns@gellyfish.com>
------------------------------
Date: Thu, 29 Apr 1999 04:16:02 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: PERL & Y2K
Message-Id: <MPG.1191df496fc0f9a2989973@nntp.hpl.hp.com>
In article <372927a5.249785572@news.insnet.net> on Thu, 29 Apr 1999
09:37:11 GMT, David Cantrell <NukeEmUp@ThePentagon.com> says...
> On Thu, 29 Apr 1999 02:40:33 GMT, Eric Bohlman <ebohlman@netcom.com>
> enlightened us thusly:
>
> >Actually, it's possible to have non-compliant code that never gets the
> >system date. For example, code that gets dates with 2-digit years as some
> >sort of user input and sorts or compares them.
>
> Indeed. When I checked some of the older code sitting around here, I
> simply searched for /19[^0]/. Turned up a few 'false positives' but
> not many. After finding them it was simply a matter of reading the
> code.
You say 'indeed' to a problem involving bugs such as subtraction of two-
digit years, then discuss a grep that finds a different problem.
How might one automatically locate the problems Eric identifies? A grep
for /time/ might not help, and /\$y[er]/ seems like casting a rather
wide net which still has many holes for this bug to slip through (even
assuming variables are named in English).
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 28 Apr 1999 21:36:25 -0400
From: "Bill Jones" <bill@fccj.org>
Subject: Re: PERL & Y2K
Message-Id: <3727b7a5.0@usenet.fccj.cc.fl.us>
In article <slrn7iebl0.k8d.fl_aggie@stat.fsu.edu>, fl_aggie@thepentagon.com
(I R A Aggie) wrote:
> On 28 Apr 1999 15:03:11 GMT, Abigail
> <abigail@fnx.com>, in <7g77vf$4f7$3@client2.news.psi.net> wrote:
> + Sam Holden (sholden@pgrad.cs.usyd.edu.au) wrote on MMLXVI September
>
> + ^^ If you don't know how to read documentation, or even th recent posts that
> + ^^ have Y2K in there subject then you won't be able to fix anything it
> + ^^ find anyway. So what does it matter.
>
> + I think you're confused. Are you saying there's nothing to be fixed in:
>
> + printf "The year is 19%d\n", (localtime) [5];
>
> I think Sam is saying that if you don't know what localtime() provides
> you, you will be hard pressed to fix the problem. First instinct might
> be to "fix" your example like this:
>
> printf "The year is %d\n", (localtime) [5]; # we don't like 19's
>
> when what you *might* want is:
>
> printf "The year is %d\n", 1900+(localtime) [5];
>
> Someone who hasn't read the documentation would be puzzled. "1900? why
> add 1900? isn't that going to be *just* 1900 next year? doesn't localtime
> return a 2 digit year? isn't _that_ the root problem in Y2K??"
>
> If you don't know where you're at, its hard to arrive at your desired
> destination.
>
> James
What is REALLY scary is that I got e-mailed 'spam' from
some company (unravel.com, I believe) saying they had
a perl code scanner which helps you fix all perl Y2k issues.
They charge a $3,000 if I remember correctly.
I e-mailed them back and asked "So, it is a programmer mind reader?"
The guy mailed me back and said people are buying it.
Sadly true,
-Sneex- :]
_________________________________________________________________________
Bill Jones | Data Security Specialist | http://www.fccj.org/cgi/mail?dss
FCCJ | 501 W State St | Jacksonville, FL 32202 | 1 (904) 632-3089
Mentoring: http://tesla.fccj.cc.fl.us/cgi-bin/mentors.pl?cmd=show&uid=24
Jacksonville Perl Mongers
http://jacksonville.pm.org/Letter.cgi
jax@jacksonville.pm.org
------------------------------
Date: Thu, 29 Apr 1999 08:26:25 -0400
From: Ed Bogart <e.h.bogart@larc.nasa.gov>
Subject: Re: perldoc HELP, Was How to use Net::FTP in perl??
Message-Id: <37284FF1.3540D78F@larc.nasa.gov>
Tony Curtis wrote:
>
> Re: perldoc HELP, Was How to use Net::FTP in perl??,
> Ed <e.h.bogart@larc.nasa.gov> said:
>
> Ed> I have asked this before with no answers so here
> Ed> goes again. I am using perl version 5.004_04
> Ed> built for IP19-irix on an SGI 02 and have not
> Ed> been able to get perldoc to work with any
> Ed> modules. Trying the above, using all 3 forms
> Ed> from perldoc perldoc, I get;
>
> Maybe this version of perl was built with no
> documentation installed (you can do this during the
> configuration with the reply "none" at the
> appropriate point)?
>
As I explained in response to the IRA Aggie's post, it looks like all
the modules are installed and perldoc works fine when used in the
'perldoc -f somefunction' form. It only returns an error when I as for
_module_ information.
I could understand in no docs were included in the build but can some be
there and not others?
Ed
------------------------------
Date: Thu, 29 Apr 1999 08:21:02 -0400
From: Ed Bogart <e.h.bogart@larc.nasa.gov>
Subject: Re: perldoc HELP, Was How to use Net::FTP in perl??
Message-Id: <37284EAE.6867207@larc.nasa.gov>
I R A Aggie wrote:
>
> On Wed, 28 Apr 1999 12:45:24 -0400, Tim
> <tim@timbury.com>, in <925317921.333.58@news.remarQ.com> wrote:
>
> + This may seem like a silly question, but has the module been installed?
>
> Not silly, but rather a good one. Here's one way to test it. From a command
> line:
>
> $ perl
> use Net::FTP;
> <control>-D
>
> If you get a complaint, it isn't installed. If you get nothing, it is.
>
> James
I guess I should have been more thorough in my original post. The
Net::FTP _module_ has been installed, as have all the others I have
tried. The problem is that when I try to Read The Documentation(tm)
using the 'perldoc PageName|ModuleName|ProgramName' form I get an error
msg. The 'perldoc -f perlterm' works fine. I hope that is clearer.
Ed
------------------------------
Date: Wed, 28 Apr 1999 21:14:00 -0400
From: "Bill Jones" <bill@fccj.org>
Subject: Re: pow() ? to the power of ?
Message-Id: <3727b262.0@usenet.fccj.cc.fl.us>
In article <372727c6.64949187@news1.mi.home.net>, sweet@enterpriseusa.com
(Rob Sweet) wrote:
>
>
>
> $x = 2 ;
> $y = 3 ;
>
> print $x ** $y ;
>
> Rob Sweet
>
Interesting, I haven't been able to find what the ^ is for?
In math is means: X raised to power y...
But, in perl, 4 ^ 2 = 6 (not 16...)
Curious,
-Sneex- :]
_________________________________________________________________________
Bill Jones | Data Security Specialist | http://www.fccj.org/cgi/mail?dss
FCCJ | 501 W State St | Jacksonville, FL 32202 | 1 (904) 632-3089
Mentoring: http://tesla.fccj.cc.fl.us/cgi-bin/mentors.pl?cmd=show&uid=24
Jacksonville Perl Mongers
http://jacksonville.pm.org/Letter.cgi
jax@jacksonville.pm.org
------------------------------
Date: 29 Apr 1999 12:43:25 GMT
From: Tony Bowden <tony@blackstar.co.uk>
Subject: Re: Question: Opening and closing files.
Message-Id: <7g9k5d$732$1@nclient3-gui.server.ntli.net>
Abigail <abigail@fnx.com> wrote:
> David Cassell (cassell@mail.cor.epa.gov) wrote on MMLXII September
> MCMXCIII in <URL:news:37210A44.47C2D26A@mail.cor.epa.gov>:
The 2562nd of September 1993?
Tony
--
-----------------------------------------------------------------------------
Tony Bowden | Belfast, NI | tb@tmtm.com | www.tmtm.com | www.blackstar.co.uk
we barely have time to react in this world let alone rehearse
-----------------------------------------------------------------------------
------------------------------
Date: Thu, 29 Apr 1999 13:25:21 +0200
From: "Philip 'Yes, that's my address' Newton" <nospam.newton@gmx.net>
Subject: Re: test please ignore
Message-Id: <372841A1.3179B41@gmx.net>
Steven T. Hatton wrote:
>
> So you didn't listen
So you should have been posting your testing junk elsewhere, such as
misc.test
Cheers,
Philip
------------------------------
Date: Thu, 29 Apr 1999 12:29:19 GMT
From: sstarre@my-dejanews.com
Subject: why doesn't redeclaring $i give warning/errors?
Message-Id: <7g9jas$9c6$1@nnrp1.dejanews.com>
If I try:
#!/usr/local/bin/perl -w
my $i=0;
my $i=1;
perl correctly identifies the redeclaration of $i and reports:
"my" variable $i masks earlier declaration in same scope at x.pl line 3.
however, I can use this without errors or warnings:
#!/usr/local/bin/perl -w
my $j=0;
while ($j<5)
{my $i+=++$j;
print "$i\n";
}
perl x.pl
1
2
3
4
5
In which I redeclare $i 5 times. "my" declares the variable scoped for the
enclosing brackets; in this case the while loop brackets. So why am I allowed
to declare it 5 times in the same scope? It seems like the same case as in
the first trial. Also, its a subtle bug as $i is invariant- its redeclared as
0 each pass.
What I really want of course is more like:
my $j=0;
my $i=0;
while ($j<5)
{$j++;
$i+=$j;
print "$i\n";
}
perl x.pl
1
3
6
10
15
But in this case, now I have $i scoped for the entire remainder of the
program, which is also not quite what I want, but at least the results are
correct.
Anyhow, this seems inconsistent. If it warns in trial 1 it should warn in
trial 2.
HUG,
S
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Thu, 29 Apr 1999 11:02:25 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Why paranthesis change logical expression
Message-Id: <37293ae5.13908822@news.skynet.be>
Georg Raming wrote:
>while ($line = <Fin>)
> {
> print Fout $line;
> }
Are you using Perl5.005? Perl5.004 would complain about this line, at
least if warnings are enabled. Please do.
>and this worked quite fine. No I want to read in 5 line at once, trying
>this example for 2 lines:
>
>while (($line[0],$line[1]) = <Fin>)
> {
> print Fout $line[0] $line[1]
#forgot a comma
> }
You're reading all lines, and keeping two.
What I have done already, is something like this:
while(($line[0],$line[1])=(scalar <Fin>, scalar <Fin>),
defined $line[1]) {
print Fout @line;
}
but it gets pretty ugly, fast, for larger amounts of lines.
Bart.
------------------------------
Date: Thu, 29 Apr 1999 12:22:41 GMT
From: Don Roby <droby@copyright.com>
Subject: Re: Why paranthesis change logical expression
Message-Id: <7g9iuf$906$1@nnrp1.dejanews.com>
In article <37282805.5F18055B@ewh.uni-hannover.de>,
Georg Raming <raming@ewh.uni-hannover.de> wrote:
> Hi, everybody!
>
> I want to read a texfile and format in a different way. For reading I
> used:
>
> while ($line = <Fin>)
> {
> print Fout $line;
> }
>
> and this worked quite fine. No I want to read in 5 line at once, trying
> this example for 2 lines:
>
> while (($line[0],$line[1]) = <Fin>)
> {
> print Fout $line[0] $line[1]
> }
>
> and my problem is, that this reads in only once, and then the expression
> after while gets false due to the paranthesis around $line[0...
>
> Why? What is a better way?
>
<> in scalar context reads one line at a time.
<> in list context reads the entire file into a list.
Your ($line[0], $line[1]) = <Fin> is reading the entire file, putting the
first two lines in your array, and discarding the rest. And hitting
end-of-file on the next iteration.
You can either read the entire file into an array and process the array 5
entries at a time, or you can read a line at a time and have a counter inside
your loop that controls the processing. I would do the second, as the first
will use a lot of memory when you deal with a large file.
Something like:
$line_count = 0;
$line = '';
$group_count = 0;
while ($in = <Fin>) {
$line .= $in;
$line_count++;
if ($line_count == 5) {
print Fout $line;
$line_count = 0;
$line = '';
}
}
if ($line_count) {
print Fout $line;
}
--
Don Roby
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 5516
**************************************