[31278] in Perl-Users-Digest
Perl-Users Digest, Issue: 2523 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 20 06:09:46 2009
Date: Mon, 20 Jul 2009 03:09:05 -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 Mon, 20 Jul 2009 Volume: 11 Number: 2523
Today's topics:
Re: FAQ 5.28 How can I read in an entire file all at on <brian.helterline@hp.com>
Re: FAQ 5.28 How can I read in an entire file all at on <brian.d.foy@gmail.com>
Re: FAQ 5.28 How can I read in an entire file all at on <uri@stemsystems.com>
Re: FAQ 5.41 How do I delete a directory tree? <brian.d.foy@gmail.com>
Re: FAQ 6.7 How can I make "\w" match national characte <brian.d.foy@gmail.com>
Re: Perl Fails To List All The Multiple Matches In The <kst-u@mib.org>
Re: RegEx - finding the innermost block <m@rtij.nl.invlalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 17 Jul 2009 21:59:13 -0700
From: Brian Helterline <brian.helterline@hp.com>
Subject: Re: FAQ 5.28 How can I read in an entire file all at once?
Message-Id: <h3rkr2$783$1@usenet01.boi.hp.com>
PerlFAQ Server wrote:
>
> --------------------------------------------------------------------
>
> 5.28: How can I read in an entire file all at once?
>
> The customary Perl approach for processing all the lines in a file is to
> do so one line at a time:
>
> open (INPUT, $file) || die "can't open $file: $!";
> while (<INPUT>) {
> chomp;
> # do something with $_
> }
> close(INPUT) || die "can't close $file: $!";
>
since most advise it to use the 3 argument version of open along with
lexical filehandles, why doesn't this example follow best practices?
--
-brian
------------------------------
Date: Sat, 18 Jul 2009 01:18:54 -0500
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 5.28 How can I read in an entire file all at once?
Message-Id: <180720090118547076%brian.d.foy@gmail.com>
In article <h3rkr2$783$1@usenet01.boi.hp.com>, Brian Helterline
<brian.helterline@hp.com> wrote:
> PerlFAQ Server wrote:
> >
> > --------------------------------------------------------------------
> >
> > 5.28: How can I read in an entire file all at once?
> since most advise it to use the 3 argument version of open along with
> lexical filehandles, why doesn't this example follow best practices?
... because no one has updated it yet.
------------------------------
Date: Sat, 18 Jul 2009 02:48:43 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: FAQ 5.28 How can I read in an entire file all at once?
Message-Id: <871voe5vw4.fsf@quad.sysarch.com>
>>>>> "bdf" == brian d foy <brian.d.foy@gmail.com> writes:
bdf> In article <h3rkr2$783$1@usenet01.boi.hp.com>, Brian Helterline
bdf> <brian.helterline@hp.com> wrote:
>> PerlFAQ Server wrote:
>> >
>> > --------------------------------------------------------------------
>> >
>> > 5.28: How can I read in an entire file all at once?
>> since most advise it to use the 3 argument version of open along with
>> lexical filehandles, why doesn't this example follow best practices?
bdf> ... because no one has updated it yet.
and i want to comment on the note there that says slurping is not
efficient. it may be true with line oriented stuff but slurping in a
file into a scalar and then processing it can be much more efficient
than line oriented processing. you can do multiline regexes to grab
sections or do /g global ones on all the lines at one time. the bias
against slurping stems from the high cost of ram in the goode olde
dayes. few normal text files are that large today compared to the ram
available. 1mb text was huge back then but is tiny compared to 1gb of
ram which is very common now. i don't want the faq entry to be much
longer but maybe another entry would be on ways to process slurped
files. my fave is slurping and parsing a simple key: value config file
in one line:
my %config = read_file( 'config' ) =~ /^(\w+):\s*(.+)$/gm ;
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Sat, 18 Jul 2009 01:33:38 -0500
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 5.41 How do I delete a directory tree?
Message-Id: <180720090133380131%brian.d.foy@gmail.com>
In article <170720091701081307%jimsgibson@gmail.com>, Jim Gibson
<jimsgibson@gmail.com> wrote:
> > If you have an empty directory, you can use Perl's built-in "rmdir". If
> > the directory is not empty (so, no files or subdirectories), you either
> > have to empty it yourself (a lot of work) or use a module to help you.
>
> I can't really figure out what "(so, no files or subdirectories)" means
> here. It seems contradictory to me.
It's contradictory because it's a mistake. I've fixed it. Thanks,
------------------------------
Date: Sat, 18 Jul 2009 01:09:52 -0500
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 6.7 How can I make "\w" match national character sets?
Message-Id: <180720090109524561%brian.d.foy@gmail.com>
In article <slrnh5rcbb.cik.hjp-usenet2@hrunkner.hjp.at>, Peter J.
Holzer <hjp-usenet2@hjp.at> wrote:
> Here is a more radical rewrite:
I've updated the answer with your version. Thanks, :)
------------------------------
Date: Fri, 17 Jul 2009 20:11:46 -0700
From: Keith Thompson <kst-u@mib.org>
Subject: Re: Perl Fails To List All The Multiple Matches In The Same Line?
Message-Id: <lnskguu1l9.fsf@nuthaus.mib.org>
l v <veatchla@yahoo.com> writes:
[...]
> Windows uses back slashes while unix uses forward slashes. A
> mainframe uses periods (.).
That depends on the mainframe, and which OS it's running.
> Therefore unix's /dir/dir/dir/not_dir
> is windows c:\dir\dir\dir\file
>
> In your Perl code you should use forward slashed even when on
> windows. For example:
>
> open FH, '<', 'c:/dir/dir/dir/file') or die ........
Why? I mean, I'm aware that it will work, but what's the real
advantage of using '/' rather than '\' on Windows?
One *small* advantage is that you don't have worry about escaping
backslashes in double-quoted strings. (The solution: Remember to
escape the backslashes.)
But I can think of two disadvantages. One is that the string might be
passed to the command processor at some point. Another is that it
might be displayed to the user, and most Windows users probably don't
know that '/' is a valid directory delimiter.
If you're hardwiring file paths like C:\dir\file.txt, you're writing
Windows-specific code anyway. Why not use the form that's most
natural for Windows? (Or, better yet, don't hardwire paths in your
script.)
[...]
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
------------------------------
Date: Sat, 18 Jul 2009 22:27:41 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: RegEx - finding the innermost block
Message-Id: <tqn9j6-9mn.ln1@news.rtij.nl>
On Thu, 16 Jul 2009 03:51:05 -0700, msciwoj wrote:
> Does any one have an idea is it possible to catch the block that has no
> nested blocks of its type using regular expressions? In other words how
> to catch
> <blockbeginmark>.....-NO <blockbeginmark> until <blockendmark>
>
> For instance, can
> <div> ..... </div>
> block can be caught with the condition it has no nested <div> blocks in
> it?
Yes, use a html parser. There are many on CPAN and they work much better
that any regex you can come up with.
M4
------------------------------
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 2523
***************************************