[29346] in Perl-Users-Digest
Perl-Users Digest, Issue: 590 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 27 14:14:39 2007
Date: Wed, 27 Jun 2007 11:14:13 -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 Wed, 27 Jun 2007 Volume: 11 Number: 590
Today's topics:
skip first N lines when reading file <jiehuang001@gmail.com>
Re: skip first N lines when reading file <noreply@gunnar.cc>
Re: skip first N lines when reading file <peter@makholm.net>
Re: skip first N lines when reading file <wahab@chemie.uni-halle.de>
Re: skip first N lines when reading file <jiehuang001@gmail.com>
Re: strings with formatted characters in %ARGV <savagebeaste@yahoo.com>
Re: The Modernization of Emacs: terminology buffer and <borud-news@borud.no>
Re: The Modernization of Emacs: terminology buffer and <twisted0n3@gmail.com>
Re: The Modernization of Emacs: terminology buffer and <mkb@incubus.de>
Re: The Modernization of Emacs: terminology buffer and (Joel J. Adamson)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 27 Jun 2007 08:59:22 -0700
From: Jie <jiehuang001@gmail.com>
Subject: skip first N lines when reading file
Message-Id: <1182959962.668605.163690@q75g2000hsh.googlegroups.com>
Hi,
can someone please let me know how to skip first N lines when reading
a file in perl? I know that I can write something like below, but too
much coding and computing is involved.
also, can someone please let me know if there is a master pdf file
that has all the perl documentation content. right now, from
perldoc.per.org i found it is divided into many many files..
======my code to skip first N lines======
$line = 0;
while(<IN>) {
if ($line <= N) {
} else {
do something
}
}
------------------------------
Date: Wed, 27 Jun 2007 18:34:00 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: skip first N lines when reading file
Message-Id: <5efi1bF38bqcgU1@mid.individual.net>
Jie wrote:
> can someone please let me know how to skip first N lines when reading
> a file in perl?
One way:
use Tie::File;
my $skip = 3;
tie my @file, 'Tie::File', 'myfile' or die $!;
print "$_\n" for @file[ $skip..$#file ];
untie @file;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 27 Jun 2007 17:07:17 +0000
From: Peter Makholm <peter@makholm.net>
Subject: Re: skip first N lines when reading file
Message-Id: <87y7i5uy0q.fsf@makholm.net>
Jie <jiehuang001@gmail.com> writes:
> ======my code to skip first N lines======
>
> $line = 0;
> while(<IN>) {
> if ($line <= N) {
> } else {
> do something
> }
> }
My take:
while(<IN>) {
next if 1 .. N;
do something;
}
if N is a constant expression or else you have to use at little less
magic:
my $N = lines_to_skip();
while(<IN>) {
next if 1 .. $N==$.;
do something;
}
Read 'perldoc perlop' look for the 'Range Operators' section.
//Makholm
------------------------------
Date: Wed, 27 Jun 2007 19:15:02 +0200
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: skip first N lines when reading file
Message-Id: <f5u5us$24ff$1@nserver.hrz.tu-freiberg.de>
Gunnar Hjalmarsson wrote:
> Jie wrote:
>> can someone please let me know how to skip first N lines when reading
>> a file in perl?
>
> One way:
>
> use Tie::File;
> my $skip = 3;
> tie my @file, 'Tie::File', 'myfile' or die $!;
> print "$_\n" for @file[ $skip..$#file ];
> untie @file;
This might be sometimes a good, sometimes a bad idea.
example: file w/110000 lines (4.xMB)
The tie-solution
...
use Tie::File;
my ($skip, $len) = (30, 0);
tie my @file, 'Tie::File', 'myfile.txt' or die $!; # invoke file
print $file[$skip], "\n"; # skip n lines, print this line (validity)
$len += length for @file[ $skip..$#file ]; # compute lentgh of remaining lines
print scalar @file, " => $len\n"; # output: length and number of lines
untie @file;
...
would need around 16 seconds to (user) complete (588/Linux/2.5GHz AthlonXP),
whereas the straight thing:
...
my ($skip, $len) = (30, 0);
open my $fh, '<', 'myfile.txt' or die $!; # invoke file
1 while $skip-- && <$fh>; # skip n lines
print scalar <$fh>, "\n"; # print this line (validity)
$len += (length)-1 while <$fh>; # compute lentgh of remaining lines
# (remove newline!)
print "$. => $len\n"; # output: length and number of lines
...
passes through in far below 0.15 (!) seconds on the same machine
(several runs checked)
Regards
M.
------------------------------
Date: Wed, 27 Jun 2007 10:58:41 -0700
From: Jie <jiehuang001@gmail.com>
Subject: Re: skip first N lines when reading file
Message-Id: <1182967121.916071.313450@q69g2000hsb.googlegroups.com>
Hi, Makholm:
Thank you so much!! "next if 1 .. N" works great!!
I am going to post another question here, regarding an "out of memory"
issue which has troubled me for a long while. Hope I can get it
resoved here.
Thank you again!!
Jie
------------------------------
Date: Wed, 27 Jun 2007 08:39:22 -0700
From: "Clenna Lumina" <savagebeaste@yahoo.com>
Subject: Re: strings with formatted characters in %ARGV
Message-Id: <5efelgF383a41U1@mid.individual.net>
Michele Dondi wrote:
> On Tue, 26 Jun 2007 14:12:55 -0700, "Clenna Lumina"
> <savagebeaste@yahoo.com> wrote:
>
>> Note, I noticed that if I passed the arguements without any quoting
>> (./foo.pl 1 2\n3) the "\" would get stripped (I'm guessing my the
>> shell - linux, bash) so perl only sees '1 2n3'... why does the slash
>> get
>
> Yes, it's the shell.
>
>> stripped?
>
> Because the shell does so. It has it's own backslash quoting, e.g. to
> quote a bare single quote. But it doesn't handle special charachters.
> We have to live with that.
I had some how forgot the shell handles foward slashes like that. It
seems youy can simply escape them too as an alternative to quoting
(./foo.pl 1 2\\n3), if one really wanted to.
--
CL
------------------------------
Date: 27 Jun 2007 15:09:34 +0200
From: Bjorn Borud <borud-news@borud.no>
Subject: Re: The Modernization of Emacs: terminology buffer and keybinding
Message-Id: <m3ir99wnld.fsf@borud.not>
["Kjetil S. Matheussen" <k.s.matheussen@notam02.no>]
|
| Things have probably changed a little, but the stuff in SISC isn't
| specific for scheme, although a schemish language is used in the book.
well, those are really two separate discussions: Scheme and whether
SICP is an important book or not.
-Bjørn
------------------------------
Date: Wed, 27 Jun 2007 14:43:02 -0000
From: Twisted <twisted0n3@gmail.com>
Subject: Re: The Modernization of Emacs: terminology buffer and keybinding
Message-Id: <1182955382.783515.167290@n60g2000hse.googlegroups.com>
On Jun 27, 8:26 am, g...@mail.ru (Timofei Shatrov) wrote:
> >For which you need an interpreter. Such as Ghostscript. Which is a
> >pain to install and a bigger one to configure, even on Windoze.
>
> Lie. Ghostscript works out of the box on Windows.
You're joking. First of all I am not a liar, and secondly, Ghostscript
and Ghostview are tricky to set up correctly. I know -- I've done it a
time or three. There's an arcane GUI configurator that isn't
exceptionally well designed, and once it's working it still wonks out
on maybe 1 in 10 .ps and .eps files you come across ... which is still
better than being able to view none of them, mind you. Nonetheless
there's a world of difference between the GS tools and say Adobe
Acrobat Reader in terms of setup and use; the latter you just run an
installer and then find a pdf to double-click; no other steps
necessary and it works every time. Of course, Adobe stuff is
proprietary, and acrord supports some types of evil DRM...
------------------------------
Date: Wed, 27 Jun 2007 18:05:38 +0200
From: Matthias Buelow <mkb@incubus.de>
Subject: Re: The Modernization of Emacs: terminology buffer and keybinding
Message-Id: <5efg6iF38nuukU1@mid.dfncis.de>
Bjorn Borud wrote:
> I was told by a lot of people I consider to be intelligent that this
> book would change how I think about writing software. it didn't. I
> didn't really know what to expect, but after reading it I did feel
> that its importance was greatly exaggerated.
I think it's basically a course book, for some CS courses at MIT that it
was originally used with, and that's it. It's not superb but ok, as far
as "lecture notes" go, a bit pretentious and a bit idiosyncratic,
probably due to being targeted mainly at students visiting a particular
course of lectures. I don't think it's supposed to be a general "how to
learn good programming"-style book although I don't think you've wasted
time reading it.
F'up-to: c.l.lisp.
------------------------------
Date: Wed, 27 Jun 2007 13:32:45 -0400
From: jadamson@partners.org (Joel J. Adamson)
Subject: Re: The Modernization of Emacs: terminology buffer and keybinding
Message-Id: <87odj1joaq.fsf@W0053328.mgh.harvard.edu>
Twisted <twisted0n3@gmail.com> writes:
> On Jun 27, 8:26 am, g...@mail.ru (Timofei Shatrov) wrote:
>> >For which you need an interpreter. Such as Ghostscript. Which is a
>> >pain to install and a bigger one to configure, even on Windoze.
>>
>> Lie. Ghostscript works out of the box on Windows.
>
> You're joking. First of all I am not a liar, and secondly, Ghostscript
> and Ghostview are tricky to set up correctly. I know -- I've done it a
> time or three. There's an arcane GUI configurator that isn't
> exceptionally well designed, and once it's working it still wonks out
> on maybe 1 in 10 .ps and .eps files you come across ...
It's become clear that you have a different conception of what
consitutes "working" software.
> better than being able to view none of them, mind you. Nonetheless
> there's a world of difference between the GS tools and say Adobe
> Acrobat Reader in terms of setup and use; the latter you just run an
> installer and then find a pdf to double-click; no other steps
> necessary and it works every time. Of course, Adobe stuff is
> proprietary, and acrord supports some types of evil DRM...
It's also become clear that you have a different conception of what
constitutes using a computer.
Joel
--
Joel J. Adamson
Biostatistician
Pediatric Psychopharmacology Research Unit
Massachusetts General Hospital
Boston, MA 02114
(617) 643-1432
(303) 880-3109
*Joel's guide to sending attachments:
1. put all the files you want to send in a folder and archive the
folder using tar, then compress it with gzip or bzip2
2. please send me .pdf, .html, or text in place of Word documents:
http://www.gnu.org/philosophy/sylvester-response.html
*Did you know there's a FREE alternative to using word processors?
http://www.edafe.org/latex/
http://en.wikipedia.org/wiki/LaTeX
http://nitens.org/taraborelli/latex
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 V11 Issue 590
**************************************