[27098] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 8981 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 22 03:06:03 2006

Date: Wed, 22 Feb 2006 00:05:03 -0800 (PST)
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, 22 Feb 2006     Volume: 10 Number: 8981

Today's topics:
    Re: Reading Mac / Unix / DOS text files (Rick Scott)
        save output to array <a@mail.com>
    Re: save output to array <jurgenex@hotmail.com>
    Re: save output to array <a@mail.com>
    Re: XS - Variable creation <nospam-abuse@ilyaz.org>
    Re: XS - Variable creation <nospam-abuse@ilyaz.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 22 Feb 2006 05:11:41 -0000
From: rick@shadowspar.dyndns.org (Rick Scott)
Subject: Re: Reading Mac / Unix / DOS text files
Message-Id: <2d76.43fbf28d.ed825@shadowspar>

(thrill5 <nospam@comcast.net> uttered:)
> I don't know why you had to stare at "while (<IF>)" for anything
> longer than about a tenth of second.  Pretty obvious what the code
> does to me.  

Your filehandle `IF' collides with Perl's conditional `if' in the
mental hash-bucket of the programmers who have to read your code. 
Given that it reduces the comprehensibility of your program and that
you could have used any number of more legible identifiers, I'd call
use of `IF' poor style, if not an outright error. 


> Whitespace  and using barewords for file handles is a matter of
> programming style.  Just because that's not the way you do it does
> not mean that it is incorrect or wrong.

On the contrary -- I would posit that any coding practice that makes
it easier to inadvertently introduce bugs into your program is a 
poor one.  By using a bareword filehandle, you're essentially using
a package variable (*IF).  If some other piece of code in the same
package namespace touches that bareword while you're using it to read
from a file, your filehandle will get stomped and your code will break
without you even having changed it.  That's why it's a bad idea.

Pick up a copy of Damian Conway's "Perl Best Practices" -- he explains
why this and about a thousand other `harmless style preferences' aren't
harmless, aren't stylish, and definitely aren't preferable. 




Rick
-- 
key CF8F8A75 / print C5C1 F87D 5056 D2C0 D5CE  D58F 970F 04D1 CF8F 8A75 
A: Because the response should come after the question.
Q: Why is top-posting so annoying?
     :Mike Andrews


------------------------------

Date: Wed, 22 Feb 2006 05:53:10 GMT
From: "a" <a@mail.com>
Subject: save output to array
Message-Id: <a%SKf.61366$B94.36465@pd7tw3no>

Hi,
For example,
If I want to save the output of system("ls") to an array, what should I do?
Thanks a lot




------------------------------

Date: Wed, 22 Feb 2006 06:05:08 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: save output to array
Message-Id: <oaTKf.10641$GQ.5906@trnddc03>

a wrote:
> If I want to save the output of system("ls") to an array, what should
> I do?

I would follow the advise that is given in the man page and the FAQ about of 
system().
Like e.g. the fourth sentence in the third paragraph of "perldoc -f system".
Or the answer to "perldoc -q system": "Why can't I get the output of a 
command with system()?"
Or any of the gazillion previous threads about this topic.

Having said that, why do you want to capture the output of 'ls' in the first 
place?
There are several Perl builtin functions that provide the same 
functionality, no need to shell out an external process.

jue 




------------------------------

Date: Wed, 22 Feb 2006 06:17:06 GMT
From: "a" <a@mail.com>
Subject: Re: save output to array
Message-Id: <ClTKf.61395$B94.44395@pd7tw3no>

Thanks for you reply.
Actually, I need to look for the file path of the given file name.
Do perl have support for this?
Thanks a lot.

"Jürgen Exner" <jurgenex@hotmail.com> ¼¶¼g©ó¶l¥ó·s»D
:oaTKf.10641$GQ.5906@trnddc03...
> a wrote:
> > If I want to save the output of system("ls") to an array, what should
> > I do?
>
> I would follow the advise that is given in the man page and the FAQ about
of
> system().
> Like e.g. the fourth sentence in the third paragraph of "perldoc -f
system".
> Or the answer to "perldoc -q system": "Why can't I get the output of a
> command with system()?"
> Or any of the gazillion previous threads about this topic.
>
> Having said that, why do you want to capture the output of 'ls' in the
first
> place?
> There are several Perl builtin functions that provide the same
> functionality, no need to shell out an external process.
>
> jue
>
>





------------------------------

Date: Wed, 22 Feb 2006 07:52:09 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: XS - Variable creation
Message-Id: <dth579$12bn$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Ferry Bolhar
<bol@adv.magwien.gv.at>], who wrote in article <1140438870.621665@proxy.dienste.wien.at>:
> BTW can someone explain me the difference in marking a SV as "not longer
> needed" by doing a
> 
> sv_2mortal(mysv)         and

Please REFCNT_dec() some time later.

> SvREFCNT_dec(mysv)?

Please REFCNT_dec() now.

The first call is not appropriate for things "not longer needed".  The
purpose of this call is to fight with the fact that some parts of Perl
data structures are not refcounted; e.g., the Perl subroutine call
stack, and return values.  So the values put "there" should have
"eventual refcount" 0; but they should still survive "for a short
time"; so you make REFCNT=1, and arrange for the count to be
decremented when the caller/callee had a chance to inspect the value.


> > I would do it like this: return a reference from XS.  Do the
> > assignment in Perl code wrapper (via *name = reference).  (Not hard to
> > do from XS, but somebody spent some time to make it *especially
> > simple* from Perl code; why not use it?)
> 
> Sorry, I can't understand what you mean. Could you post an example, please?

sub Perl_wrapper (args) {
  *MyModule::Values::This = XS_Workhorse(args);
}

Make XS_Workhorse() return a reference to the created value.

  RETVAL = newRV_noinc(RETVAL);	       /* sp? */

Hope this helps,
Ilya




------------------------------

Date: Wed, 22 Feb 2006 07:56:24 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: XS - Variable creation
Message-Id: <dth5f8$12cl$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Anno Siegel
<anno4000@lublin.zrz.tu-berlin.de>], who wrote in article <dtcffo$icp$1@mamenchi.zrz.TU-Berlin.DE>:
> > BTW can someone explain me the difference in marking a SV as "not longer
> > needed" by doing a
> > 
> > sv_2mortal(mysv)         and
> > SvREFCNT_dec(mysv)?
> 
> SvREFCNT_dec counts the refcount down immediately.  If the sv had
> a refcount of 1, it will be gone after the operation.

> sv_2mortal arranges for a delayed SvREFCNT_dec.  The sv will continue
> to exist until the next call to FREETMPS.  FREETMPS is usually called
> implicitly at statement boundaries.

Better make this "next call to FREETMPS upward in the call tree".

Hope this helps,
Ilya


------------------------------

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 V10 Issue 8981
***************************************


home help back first fref pref prev next nref lref last post