[30605] in Perl-Users-Digest
Perl-Users Digest, Issue: 1848 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 11 09:09:58 2008
Date: Thu, 11 Sep 2008 06:09:10 -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 Thu, 11 Sep 2008 Volume: 11 Number: 1848
Today's topics:
=?GB2312?B?zMy7rQ==?= srnp8atognoicl9m9eecafg@gmail.com
Extract Numeric values from string <v3gupta@gmail.com>
Re: Extract Numeric values from string <tomislav.novak@gmail.com>
Re: Extract Numeric values from string <ben@morrow.me.uk>
Re: Extract Numeric values from string <cartercc@gmail.com>
Re: Extract Numeric values from string <rvtol+news@isolution.nl>
new CPAN modules on Thu Sep 11 2008 (Randal Schwartz)
perl upgrade - make test error "Can't locate Config_hea <me2@privacy.net>
Re: perl upgrade - make test error "Can't locate Config <sisyphus359@gmail.com>
simple perl script for file uploads ? <jack_posemsky@yahoo.com>
Re: simple perl script for file uploads ? <xemoth@gmail.com>
Re: simple perl script for file uploads ? <joost@zeekat.nl>
Re: simple perl script for file uploads ? <spamtrap@dot-app.org>
standard modules? <bugbear@trim_papermule.co.uk_trim>
Re: standard modules? <spamtrap@dot-app.org>
Re: standard modules? <ben@morrow.me.uk>
Re: using 2-arg open to open to a scalar xhoster@gmail.com
Re: using 2-arg open to open to a scalar <ced@blv-sam-01.ca.boeing.com>
Re: using 2-arg open to open to a scalar <ben@morrow.me.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 10 Sep 2008 19:26:47 -0700 (PDT)
From: srnp8atognoicl9m9eecafg@gmail.com
Subject: =?GB2312?B?zMy7rQ==?=
Message-Id: <c20088e4-eec4-4d25-b1a9-83f87407cfba@s9g2000prg.googlegroups.com>
zMy7rdeovNIt0+/A8tHH06G7qCjMzLutKdPQz965q8u+ysfSu7zSvK/IyNeq06HMzLut0dC3oqGi
yfqy+rrNz/rK286q0rvM5bXE16jStczMu63WxtTsycyho9PvwPLRx8zMu63PtcHQsvrGty2/wsq9
zMy7raGiusXC68zMu62hosnMserPtMuuDQrf6czMu62horjfta/TvtewzMy7raGi3+nNt8zMu62h
otbpueLMzLutoaK3tLnizMy7raGiycG00MzMu62horeixd3MzLutoaLJ/buqzMy7raGi1rLI3szM
u62hotDCuaTS1czMu621yKOssqLM4bmpuPfA4MzMu63WvbrNzMy7rbv6oaMNCg0Kss6/vM341b6j
umh0dHA6Ly93d3cuZWxlLWFydC5jb20vY2hpbmVzZS90YW5naHVhLmh0bWw=
------------------------------
Date: Thu, 11 Sep 2008 01:46:08 -0700 (PDT)
From: Vishal G <v3gupta@gmail.com>
Subject: Extract Numeric values from string
Message-Id: <3517e672-f5c5-4b9e-938d-f74aaeaac5d9@v16g2000prc.googlegroups.com>
Hi there,
I have searched the whole group looking for solution to my problem.
Actually, I dont understand the perl regular expression properly...
working on it...
Here is the problem..
I have string which contain numbers...
$str = "30 574 454 67 59 298928 74 4875 8 934"; # in actual string
there are 112 million values
I would like to extract numveric values from specific position till
some position using regular expression.. I dont want to use split caue
it uses lot of memory..
for example:
offset = 3; length = 4;
so the result string should be $str = "454 67 59 298928";
Thanks in advance
Vishal
------------------------------
Date: Thu, 11 Sep 2008 11:21:19 +0200
From: Tomislav Novak <tomislav.novak@gmail.com>
Subject: Re: Extract Numeric values from string
Message-Id: <87wshjavhs.fsf@gmail.com>
Vishal G <v3gupta@gmail.com> writes:
> I have string which contain numbers...
>
> $str = "30 574 454 67 59 298928 74 4875 8 934"; # in actual string
> there are 112 million values
>
> I would like to extract numveric values from specific position till
> some position using regular expression.. I dont want to use split caue
> it uses lot of memory..
>
> for example:
>
> offset = 3; length = 4;
>
> so the result string should be $str = "454 67 59 298928";
Well, you could always do something like:
my $regex =
qr/
^
(?:\d+\s*) {$offset}
((?:\d+\s*){$length})
/x;
my ($result) = $str =~ /$regex/;
--
T.
------------------------------
Date: Thu, 11 Sep 2008 12:41:50 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Extract Numeric values from string
Message-Id: <uocnp5-r52.ln1@osiris.mauzo.dyndns.org>
Quoth Tomislav Novak <tomislav.novak@gmail.com>:
> Vishal G <v3gupta@gmail.com> writes:
>
> > I have string which contain numbers...
> >
> > $str = "30 574 454 67 59 298928 74 4875 8 934"; # in actual string
> > there are 112 million values
> >
> > I would like to extract numveric values from specific position till
> > some position using regular expression.. I dont want to use split caue
> > it uses lot of memory..
> >
> > for example:
> >
> > offset = 3; length = 4;
> >
> > so the result string should be $str = "454 67 59 298928";
>
> Well, you could always do something like:
>
> my $regex =
> qr/
> ^
> (?:\d+\s*) {$offset}
> ((?:\d+\s*){$length})
> /x;
The string apparently contains 112M values. {} quantifiers in Perl cannot
be larger than 32766.
I would suggest running through the string using substr to check each
character at a time. Count the number of spaces, and collect up the
digits as needed. This will be slow, but will avoid copying the string.
In general, perl has a policy of trading memory for speed. If you are
short of memory, I would suggest using a different language with more
appropriate tradeoffs.
Ben
--
Raise your hand if you're invulnerable.
[ben@morrow.me.uk]
------------------------------
Date: Thu, 11 Sep 2008 05:47:26 -0700 (PDT)
From: cartercc <cartercc@gmail.com>
Subject: Re: Extract Numeric values from string
Message-Id: <f4da120f-6f99-470b-9714-abb3eb6925b5@e39g2000hsf.googlegroups.com>
On Sep 11, 4:46=A0am, Vishal G <v3gu...@gmail.com> wrote:
> I have string which contain numbers...
>
> $str =3D "30 574 454 67 59 298928 74 4875 8 934"; # in actual string
> there are 112 million values
>
> I would like to extract numveric values from specific position till
> some position using regular expression.. I dont want to use split caue
> it uses lot of memory..
>
> for example:
>
> offset =3D 3; length =3D 4;
>
> so the result string should be $str =3D "454 67 59 298928";
Is your string already in memory, or does it come from storage? If the
latter, you might consider replacing the spaces with new lines and
then using a counter to iterate through the file with something like
this:
while (<INFILE>)
{ $counter++;
if ($counter < $offset) { next; }
elsif ($counter >=3D $offset and $counter < $length)
{ print OUTFILE; }
elsif ($counter > ($length + $offset)) { last; }
else { print "ERROR"; }
}
If your string is already in memory, I would use the C trick of getc()
and test each character, again using a counter for the white space.
Using inline C would probably be faster and you could discard all the
characters you don't need.
while ((char c =3D getc()) !=3D EOF)
{ //test c, count whitespace, and save what you need
}
CC
------------------------------
Date: Thu, 11 Sep 2008 14:46:43 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Extract Numeric values from string
Message-Id: <gabb0v.1ko.1@news.isolution.nl>
Vishal G schreef:
> I have string which contain numbers...
>
> $str = "30 574 454 67 59 298928 74 4875 8 934"; # in actual string
> there are 112 million values
>
> I would like to extract numveric values from specific position till
> some position using regular expression.. I dont want to use split caue
> it uses lot of memory..
>
> for example:
>
> offset = 3; length = 4;
>
> so the result string should be $str = "454 67 59 298928";
Maybe you are looking for something like this:
$ perl -Mstrict -Mwarnings -le '
print scalar localtime;
my $s; $s .= "$_ " for 1..10_000_000;
print scalar localtime;
my $offset = 9_999_903;
my $count = 4;
while ($s =~ m/([0-9]+)/g) {
$count or last;
--$offset > 0 and next;
$count-- and print $1;
}
print scalar localtime;
'
Thu Sep 11 14:42:40 2008
Thu Sep 11 14:42:47 2008
9999903
9999904
9999905
9999906
Thu Sep 11 14:42:53 2008
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Thu, 11 Sep 2008 04:42:21 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Thu Sep 11 2008
Message-Id: <K70L2L.Ezu@zorch.sf-bay.org>
The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN). You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.
Acme-MetaSyntactic-daleks-1.03
http://search.cpan.org/~saper/Acme-MetaSyntactic-daleks-1.03/
EXTERMINATE! EXTERMINATE! EXTERMINATE!
----
Apache-AuthTicket-0.90_01
http://search.cpan.org/~mschout/Apache-AuthTicket-0.90_01/
Cookie based access module.
----
Apache-AuthTicket-0.90_02
http://search.cpan.org/~mschout/Apache-AuthTicket-0.90_02/
Cookie based access module.
----
App-CLI-Toolkit-0.03
http://search.cpan.org/~swhitaker/App-CLI-Toolkit-0.03/
a helper module for generating command-line utilities
----
App-Cache-0.35
http://search.cpan.org/~lbrocard/App-Cache-0.35/
Easy application-level caching
----
Archive-Peek-0.34
http://search.cpan.org/~lbrocard/Archive-Peek-0.34/
Peek into archives without extracting them
----
CGI-Application-Plugin-ActionDispatch-0.95
http://search.cpan.org/~jaywhy/CGI-Application-Plugin-ActionDispatch-0.95/
Perl extension
----
CGI-Cookie-XS-0.14
http://search.cpan.org/~agent/CGI-Cookie-XS-0.14/
HTTP Cookie parser in pure C
----
Catalyst-Authentication-Store-LDAP-0.1003
http://search.cpan.org/~karman/Catalyst-Authentication-Store-LDAP-0.1003/
Authentication from an LDAP Directory.
----
Catalyst-Plugin-CookiedSession-0.34
http://search.cpan.org/~lbrocard/Catalyst-Plugin-CookiedSession-0.34/
Store sessions in a browser cookie
----
Catalyst-Plugin-SimpleAuth-0.32
http://search.cpan.org/~lbrocard/Catalyst-Plugin-SimpleAuth-0.32/
Simple authentication for Catalyst
----
Compress-LZF_PP-0.33
http://search.cpan.org/~lbrocard/Compress-LZF_PP-0.33/
A pure-Perl LZF decompressor
----
Compress-LZMA-External-0.35
http://search.cpan.org/~lbrocard/Compress-LZMA-External-0.35/
Compress and decompress using LZMA
----
Config-Extend-MySQL-0.04
http://search.cpan.org/~saper/Config-Extend-MySQL-0.04/
Extend your favourite .INI parser module to read MySQL configuration file
----
DB-CouchDB-Schema-0.3
http://search.cpan.org/~zaphar/DB-CouchDB-Schema-0.3/
A Schema driven CouchDB module
----
DBIx-Class-DynamicDefault-0.02
http://search.cpan.org/~flora/DBIx-Class-DynamicDefault-0.02/
Automatically set and update fields
----
Devel-FindBlessedRefs-1.25
http://search.cpan.org/~jettero/Devel-FindBlessedRefs-1.25/
find all refs blessed under a package
----
Geo-IP-PurePerl-1.21
http://search.cpan.org/~borisz/Geo-IP-PurePerl-1.21/
Look up country by IP Address
----
GoferTransport-http-1.016
http://search.cpan.org/~timb/GoferTransport-http-1.016/
----
Google-Chart-0.05005
http://search.cpan.org/~dmaki/Google-Chart-0.05005/
Interface to Google Charts API
----
HTTP-Server-Multiplex-0.10
http://search.cpan.org/~markov/HTTP-Server-Multiplex-0.10/
single process multi serve HTTP daemon
----
HiSQuotes-MICEX-1.00
http://search.cpan.org/~novikov/HiSQuotes-MICEX-1.00/
Site-specific class for retrieving historical stock quotes via Moscow Interbank Currency Exchange (MICEX) - Russia.
----
LCFG-Build-Skeleton-0.0.4
http://search.cpan.org/~sjquinney/LCFG-Build-Skeleton-0.0.4/
LCFG software package generator
----
LCFG-Build-Skeleton-0.0.5
http://search.cpan.org/~sjquinney/LCFG-Build-Skeleton-0.0.5/
LCFG software package generator
----
LCFG-Build-VCS-0.0.20
http://search.cpan.org/~sjquinney/LCFG-Build-VCS-0.0.20/
LCFG version-control infrastructure
----
MooseX-TheSchwartz-0.03
http://search.cpan.org/~fayland/MooseX-TheSchwartz-0.03/
TheSchwartz based on Moose!
----
OpenGL-PLG-0.02
http://search.cpan.org/~garu/OpenGL-PLG-0.02/
Create, manipulate and render PoLyGon objects and files
----
POE-Component-Client-NNTP-2.10
http://search.cpan.org/~bingos/POE-Component-Client-NNTP-2.10/
A POE component that implements an RFC 977 NNTP client.
----
Parse-Marpa-0.215001
http://search.cpan.org/~jkegl/Parse-Marpa-0.215001/
Generate Parsers from any BNF grammar
----
Parse-Marpa-0.215_002
http://search.cpan.org/~jkegl/Parse-Marpa-0.215_002/
Generate Parsers from any BNF grammar
----
Parse-Syslog-Mail-0.17
http://search.cpan.org/~saper/Parse-Syslog-Mail-0.17/
Parse mailer logs from syslog
----
Perlwikipedia-1.3.2_01
http://search.cpan.org/~dcollins/Perlwikipedia-1.3.2_01/
a Wikipedia bot framework written in Perl
----
Perlwikipedia-1.3.3
http://search.cpan.org/~dcollins/Perlwikipedia-1.3.3/
a Wikipedia bot framework written in Perl
----
Rose-DBx-Object-Renderer-0.29
http://search.cpan.org/~danny/Rose-DBx-Object-Renderer-0.29/
Web UI Rendering for Rose::DB::Object
----
Search-QueryParser-SQL-0.004
http://search.cpan.org/~karman/Search-QueryParser-SQL-0.004/
turn free-text queries into SQL WHERE clauses
----
Sub-Uplevel-0.2001
http://search.cpan.org/~dagolden/Sub-Uplevel-0.2001/
apparently run a function in a higher stack frame
----
Text-Template-Simple-0.54_04
http://search.cpan.org/~burak/Text-Template-Simple-0.54_04/
Simple text template engine
----
Text-Tmpl-0.32
http://search.cpan.org/~dlowe/Text-Tmpl-0.32/
Templating system perl library
----
WWW-ColiPoste-0.02
http://search.cpan.org/~saper/WWW-ColiPoste-0.02/
Fetch shipping status from ColiPoste
----
WWW-Mechanize-Plugin-Ajax-0.03
http://search.cpan.org/~sprout/WWW-Mechanize-Plugin-Ajax-0.03/
WWW::Mechanize plugin that provides the XMLHttpRequest object
----
WWW-Myspace-0.86
http://search.cpan.org/~stevenc/WWW-Myspace-0.86/
Access MySpace.com profile information from Perl
----
ZipTie-Client-1.3
http://search.cpan.org/~lbayer/ZipTie-Client-1.3/
Webservice client for the ZipTie server
----
warnings-compat-0.07
http://search.cpan.org/~saper/warnings-compat-0.07/
warnings.pm emulation for pre-5.6 Perls
If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.
This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
http://www.stonehenge.com/merlyn/LinuxMag/col82.html
print "Just another Perl hacker," # the original
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
------------------------------
Date: Thu, 11 Sep 2008 00:47:11 +0100
From: "Lee Stone" <me2@privacy.net>
Subject: perl upgrade - make test error "Can't locate Config_heavy.pl"
Message-Id: <48c85c7f$0$26088$db0fefd9@news.zen.co.uk>
Hello
Although I have seen a couple of other people with similar errors, I cannot
find any solutions. I hope someone can point me in the right direction.
I am trying to upgrade from Perl 5.6.1 to Perl 5.8.8 on an older Suse Linux
2.4.18 i686 box.
Make completed OK but Make Test is showing the following error:
"
t/op/filetest.............................Can't locate Config_heavy.pl in
@INC (@INC contains: ../lib) at ../lib/Config.pm line 66.
# Looks like you planned 10 tests but ran 5.
FAILED--expected 10 tests, saw 5
"
Config_heavy.pl exists within /lib and appears to be intact. I have checked
and rechecked my configuration and all appears to be correct. I have run
Make Clean and re-run from scratch. I do not understand why Config_heavy.pl
is not found during Make Test.
Unfortunately I am not experienced enough to know if this is important to
fix or whether I should just go ahead and force the install.
Any guidance much appreciated.
Thanks
Lee
------------------------------
Date: Thu, 11 Sep 2008 02:50:21 -0700 (PDT)
From: sisyphus <sisyphus359@gmail.com>
Subject: Re: perl upgrade - make test error "Can't locate Config_heavy.pl"
Message-Id: <00aaab18-b1af-4608-812a-b61b8d809554@a18g2000pra.googlegroups.com>
On Sep 11, 9:47=A0am, "Lee Stone" <m...@privacy.net> wrote:
> Hello
>
> Although I have seen a couple of other people with similar errors, I cann=
ot
> find any solutions.
Looks like some sort of bug in the test suite.
See http://www.nntp.perl.org/group/perl.perl5.porters/2008/04/msg135950.htm=
l
. Assuming that fix results in all t/op/filetest.t tests passing, then
you've got nothing to worry about.
Mind you, having read that post, I still don't see why it should be
necessary to go to that trouble to get filetest.t to run properly.
Afaict, things should work perfectly well the way they are ... but
they obviously don't. (I don't have access to a machine that can
reproduce your problem.)
Cheers,
Rob
------------------------------
Date: Wed, 10 Sep 2008 22:32:19 -0700 (PDT)
From: Jack <jack_posemsky@yahoo.com>
Subject: simple perl script for file uploads ?
Message-Id: <2a8d9718-325f-46d0-8c01-2ba894563917@r15g2000prh.googlegroups.com>
Hi I am looking for a NON form based simple script that handles a file
upload on the server side.. does anyone have a pointer or an example
of how to do this ? I am working in HTML/Perl/Javascript ASP on IIS
and looking ideally to do without doing a "form post".
Thank you,
Jack
------------------------------
Date: Thu, 11 Sep 2008 01:49:40 -0700 (PDT)
From: Owen <xemoth@gmail.com>
Subject: Re: simple perl script for file uploads ?
Message-Id: <39cd50e2-d78a-490b-8b00-57361d1a2e03@l33g2000pri.googlegroups.com>
On Sep 11, 3:32=A0pm, Jack <jack_posem...@yahoo.com> wrote:
> Hi I am looking for a NON form based simple script that handles a file
> upload on the server side.. does anyone have a pointer or an example
> of how to do this ? =A0I am working in HTML/Perl/Javascript ASP on IIS
> and looking ideally to do without doing a "form post".
Have a look at http://search.cpan.org/~gunnar/CGI-UploadEasy-0.11/
It has many good features.
Owen
------------------------------
Date: Thu, 11 Sep 2008 10:56:27 +0200
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: simple perl script for file uploads ?
Message-Id: <87tzcnawn8.fsf@zeekat.nl>
Jack <jack_posemsky@yahoo.com> writes:
> Hi I am looking for a NON form based simple script that handles a file
> upload on the server side.. does anyone have a pointer or an example
> of how to do this ? I am working in HTML/Perl/Javascript ASP on IIS
> and looking ideally to do without doing a "form post".
You seem to be talking about browsers. What is a "form post"? You can't
portably upload anything without using <FORM>s.
See CGI's upload() method. This section of the manual seems to describe
more or less the whole process:
http://search.cpan.org/~lds/CGI.pm-3.42/CGI.pm#CREATING_A_FILE_UPLOAD_FIELD
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
------------------------------
Date: Thu, 11 Sep 2008 07:13:50 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: simple perl script for file uploads ?
Message-Id: <m1ljxzx7dd.fsf@dot-app.org>
Jack <jack_posemsky@yahoo.com> writes:
> Hi I am looking for a NON form based simple script that handles a file
> upload on the server side..
Not possible as far as I know, since the only way to trigger a file
upload from a browser is with an HTML form. There's nothing you can
put on the server to get around that limitation.
sherm--
--
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Thu, 11 Sep 2008 11:53:28 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: standard modules?
Message-Id: <fpydnZ3Xd9s0ZVXVRVnyvQA@posted.plusnet>
Is there a definitive list of the modules
that are part of perl, and ALWAYS installed,
as opposed to modules that are "very handy"
and OFTEN installed?
BugBear
------------------------------
Date: Thu, 11 Sep 2008 07:21:18 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: standard modules?
Message-Id: <m1hc8nx70x.fsf@dot-app.org>
bugbear <bugbear@trim_papermule.co.uk_trim> writes:
> Is there a definitive list of the modules
> that are part of perl, and ALWAYS installed,
> as opposed to modules that are "very handy"
> and OFTEN installed?
perldoc perlmodlib
If you want to support multiple versions of Perl, just check the
perlmodlib from the oldest version you care about.
sherm--
--
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Thu, 11 Sep 2008 12:43:45 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: standard modules?
Message-Id: <hscnp5-r52.ln1@osiris.mauzo.dyndns.org>
Quoth bugbear <bugbear@trim_papermule.co.uk_trim>:
> Is there a definitive list of the modules
> that are part of perl, and ALWAYS installed,
> as opposed to modules that are "very handy"
> and OFTEN installed?
Module::CoreList, which was itself not core until 5.9.2 so you may need
to install it from CPAN :).
Ben
--
I've seen things you people wouldn't believe: attack ships on fire off
the shoulder of Orion; I watched C-beams glitter in the dark near the
Tannhauser Gate. All these moments will be lost, in time, like tears in rain.
Time to die. ben@morrow.me.uk
------------------------------
Date: 10 Sep 2008 10:20:57 GMT
From: xhoster@gmail.com
Subject: Re: using 2-arg open to open to a scalar
Message-Id: <20080910062057.682$IN@newsreader.com>
"C.DeRykus" <ced@blv-sam-01.ca.boeing.com> wrote:
> On Sep 9, 11:27 am, Ben Morrow <b...@morrow.me.uk> wrote:
> > Quoth xhos...@gmail.com:
> >
> >
> >
> > > By the way, what do people consider the "best practice" for detecting
> > > whether the thing passed in is a file-handle, rather than a filename?
> >
> > > if (ref $_[0]) { #...
> >
> > > Seems to be good enough to me. It works with lexicals and with
> > > foo(\*FH), but it fails with foo(*FH). I'm willing to live with
> > > that, but if there is something better which isn't overly complicated
> > > it would be better yet.
> >
> > use Scalar::Util qw/openhandle/;
> >
> > if (openhandle $_[0]) {
> >
> > is what I'd use. It doesn't catch \*FOO where FOO is not an open
> > handle, nor cases like
> >
> > open my $x, "<", "foo";
> > close $x;
> > if (openhandle $x) {
> >
> > but that's probably what you wanted anyway.
> >
>
> Hm... Scalar::Util 1.18 seems to catch both cases:
>
> perl -lM"Scalar::Util 'openhandle'"
> open my $h,"<","/dev/null" or die;
> close $h or die;
> print openhandle $h ? "yes" : "no";
> ^D
> no
>
> perl -lM"Scalar::Util 'openhandle'"
> print openhandle \*FOO ? "yes"
> : "no";
> ^D
> no
Catch in the wrong sense. If the method is being given something
that is either a handle or a filename, and it is supposed to detect
the difference, then one would not want to try to open a stringified handle
as if it were a filename when given something that is a handle but not
an open one. (Especially if it will be for output)
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Wed, 10 Sep 2008 21:44:21 -0700 (PDT)
From: "C.DeRykus" <ced@blv-sam-01.ca.boeing.com>
Subject: Re: using 2-arg open to open to a scalar
Message-Id: <6c479d52-484a-4511-aedb-189f3d4d3544@k36g2000pri.googlegroups.com>
On Sep 10, 3:20 am, xhos...@gmail.com wrote:
> "C.DeRykus" <c...@blv-sam-01.ca.boeing.com> wrote:
> > On Sep 9, 11:27 am, Ben Morrow <b...@morrow.me.uk> wrote:
> > > Quoth xhos...@gmail.com:
>
> > > > By the way, what do people consider the "best practice" for detecting
> > > > whether the thing passed in is a file-handle, rather than a filename?
>
> > > > if (ref $_[0]) { #...
>
> > > > Seems to be good enough to me. It works with lexicals and with
> > > > foo(\*FH), but it fails with foo(*FH). I'm willing to live with
> > > > that, but if there is something better which isn't overly complicated
> > > > it would be better yet.
>
> > > use Scalar::Util qw/openhandle/;
>
> > > if (openhandle $_[0]) {
>
> > > is what I'd use. It doesn't catch \*FOO where FOO is not an open
> > > handle, nor cases like
>
> > > open my $x, "<", "foo";
> > > close $x;
> > > if (openhandle $x) {
>
> > > but that's probably what you wanted anyway.
>
> > Hm... Scalar::Util 1.18 seems to catch both cases:
>
> > perl -lM"Scalar::Util 'openhandle'"
> > open my $h,"<","/dev/null" or die;
> > close $h or die;
> > print openhandle $h ? "yes" : "no";
> > ^D
> > no
>
> > perl -lM"Scalar::Util 'openhandle'"
> > print openhandle \*FOO ? "yes"
> > : "no";
> > ^D
> > no
>
> Catch in the wrong sense. If the method is being given something
> that is either a handle or a filename, and it is supposed to detect
> the difference, then one would not want to try to open a stringified handle
> as if it were a filename when given something that is a handle but not
> an open one. (Especially if it will be for output)
>
Unless I'm missing the boat again
though, wouldn't some combo of
ref, openhandle, and arg inspection
get even closer:
> if (ref $_[0]) { #...
> Seems to be good enough to me.
> It works with lexicals and with
> foo(\*FH),
> but it fails with foo(*FH).
Maybe something along these lines..
if( not ref $_[0]
and not defined openhandle $_[0]
and substr($_[0],0,1) ne '*' )
# filename...
}
--
Charles DeRykus
------------------------------
Date: Thu, 11 Sep 2008 12:36:12 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: using 2-arg open to open to a scalar
Message-Id: <cecnp5-r52.ln1@osiris.mauzo.dyndns.org>
Quoth "C.DeRykus" <ced@blv-sam-01.ca.boeing.com>:
>
> Maybe something along these lines..
>
> if( not ref $_[0]
> and not defined openhandle $_[0]
> and substr($_[0],0,1) ne '*' )
Better would be
ref \$_[0] ne 'GLOB'
or maybe even
ref \$_[0] eq 'SCALAR'
as otherwise you can't use files whose names begin with '*'...
Ben
--
Every twenty-four hours about 34k children die from the effects of poverty.
Meanwhile, the latest estimate is that 2800 people died on 9/11, so it's like
that image, that ghastly, grey-billowing, double-barrelled fall, repeated
twelve times every day. Full of children. [Iain Banks] ben@morrow.me.uk
------------------------------
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 1848
***************************************