[28268] in Perl-Users-Digest
Perl-Users Digest, Issue: 9632 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 21 14:05:56 2006
Date: Mon, 21 Aug 2006 11:05:11 -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, 21 Aug 2006 Volume: 10 Number: 9632
Today's topics:
Re: -multiposted- <someone@example.com>
Re: -multiposted- <cwilbur@mithril.chromatico.net>
Re: -multiposted- usenet@DavidFilmer.com
File Creation Problem with CGI Scripts in Apache cgi-bi <fozlul@gmail.com>
Re: File Creation Problem with CGI Scripts in Apache cg <jurgenex@hotmail.com>
Re: File Creation Problem with CGI Scripts in Apache cg xhoster@gmail.com
Re: File Creation Problem with CGI Scripts in Apache cg <David.Squire@no.spam.from.here.au>
Re: hiw do i perform this extraction <redgrittybrick@spamweary.foo>
Re: hiw do i perform this extraction <tadmc@augustmail.com>
Re: HOW to rename a NPH script ? anno4000@radom.zrz.tu-berlin.de
Re: Printing to a file Or STDOUT xhoster@gmail.com
Re: References - problem understanding them <rvtol+news@isolution.nl>
Re: References - problem understanding them <mgarrish@gmail.com>
Re: References - problem understanding them <juergenherz@gmail.com>
Re: References - problem understanding them <juergenherz@gmail.com>
Re: References - problem understanding them <juergenherz@gmail.com>
Re: References - problem understanding them <juergenherz@gmail.com>
Re: References - problem understanding them <rvtol+news@isolution.nl>
Re: References - problem understanding them <klaus03@gmail.com>
Re: References - problem understanding them anno4000@radom.zrz.tu-berlin.de
Re: References - problem understanding them <jurgenex@hotmail.com>
Re: References - problem understanding them xhoster@gmail.com
Re: References - problem understanding them <juergenherz@gmail.com>
Re: References - problem understanding them <David.Squire@no.spam.from.here.au>
Re: References - problem understanding them <uri@stemsystems.com>
Re: The DEBUG constant? <not-for-replies@zombie.org.uk>
Re: The DEBUG constant? <rvtol+news@isolution.nl>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 21 Aug 2006 14:07:08 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: -multiposted-
Message-Id: <g6jGg.12045$Nz6.11022@edtnps82>
me@davidfilmer.net wrote:
> "kitcha" <kitcha315@gmail.com> wrote:
>>>[ snip multiposted message ]
>
> This message has been posted more than once as separate articles:
> comp.lang.perl.misc
> <news:1156147939.176160.48680@h48g2000cwc.googlegroups.com>
>
> perl.beginners
> <news:1156147886.554906.43800@h48g2000cwc.googlegroups.com>
>
>
> This practice, known as multiposting, is generally considered
> impolite in Usenet newsgroups. For an explanation, please see:
>
> http://www.cs.tut.fi/~jkorpela/usenet/xpost.html
*THIS* message has been posted more than once as separate articles:
comp.lang.perl.misc
<news:QMKdndcoPr3b8HTZnZ2dnUVZ_76dnZ2d@giganews.com>
comp.lang.perl.misc
<news:LdKdnVOD5-va8HTZRVn_vA@giganews.com>
This practice, known as multiposting, is pissing some of us off.
------------------------------
Date: 21 Aug 2006 10:43:13 -0400
From: Charlton Wilbur <cwilbur@mithril.chromatico.net>
Subject: Re: -multiposted-
Message-Id: <87bqqeb14u.fsf@mithril.chromatico.net>
"John W. Krahn" <someone@example.com> writes:
> *THIS* message has been posted more than once as separate articles:
>
> comp.lang.perl.misc
> <news:QMKdndcoPr3b8HTZnZ2dnUVZ_76dnZ2d@giganews.com>
>
> comp.lang.perl.misc
> <news:LdKdnVOD5-va8HTZRVn_vA@giganews.com>
>
>
> This practice, known as multiposting, is pissing some of us off.
ESPECIALLY as some of us have filtered out the offending multiposts in
the first place -- now we also need to filter out the multiposted
messages nagging the newsgroup at large about multiposting?
Charlton
--
Charlton Wilbur
cwilbur@chromatico.net
------------------------------
Date: 21 Aug 2006 09:55:17 -0700
From: usenet@DavidFilmer.com
Subject: Re: -multiposted-
Message-Id: <1156179317.017180.319270@74g2000cwt.googlegroups.com>
John W. Krahn wrote:
> This practice, known as multiposting, is pissing some of us off.
Sheesh - I tested this damn thing with over 100 test posts and I never
saw this.
OK, OK - I'm turning off the bot. I gotta figure out how to do
effective "real world" testing without actually posting back to usenet.
Maybe I'll have the bot send me an e-mail or something...
--
David Filmer (http://DavidFilmer.com)
------------------------------
Date: 21 Aug 2006 08:00:28 -0700
From: "BestFriend" <fozlul@gmail.com>
Subject: File Creation Problem with CGI Scripts in Apache cgi-bin (Fedora Core 3)
Message-Id: <1156172428.345923.199920@m79g2000cwm.googlegroups.com>
Can Anyone Help me?
I have an Online quiz test Program. I have written this program in C++.
It creates a CGI Script that I use with Apache server putting it in
cgi-bin directory and I was using this script in Linux 7.1, 7.3 and 9.0
but now I load Fedora Core 3 in my server and configure all the things
needed for my program.
Now the script is running and doing all the work except creating file
in cgi-bin directory.
Note: I have give write permission of (html) /var/www/html and
(cgi-bin) /var/www/cgi-bin directory to all.
But My script can't create any file in cgi-bin directory.
Please if you have any information help me.
fozlul
------------------------------
Date: Mon, 21 Aug 2006 15:08:37 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: File Creation Problem with CGI Scripts in Apache cgi-bin (Fedora Core 3)
Message-Id: <V%jGg.10713$RQ5.1161@trnddc03>
BestFriend wrote:
> Can Anyone Help me?
>
> I have an Online quiz test Program. I have written this program in
> C++. [...]
I am sure there is a reason why you posted this to a Perl NG. Unfortunately
my limited intellect fails to see the reason. Would you mind to enlighten
me, please?
jue
------------------------------
Date: 21 Aug 2006 16:02:39 GMT
From: xhoster@gmail.com
Subject: Re: File Creation Problem with CGI Scripts in Apache cgi-bin (Fedora Core 3)
Message-Id: <20060821120246.873$s1@newsreader.com>
"BestFriend" <fozlul@gmail.com> wrote:
> But My script can't create any file in cgi-bin directory.
Presumably this is a Perl script which is created by C++, right?
>
> Please if you have any information help me.
I don't, but $! probably does.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Mon, 21 Aug 2006 16:08:38 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: File Creation Problem with CGI Scripts in Apache cgi-bin (Fedora Core 3)
Message-Id: <ecci9n$5s7$1@gemini.csx.cam.ac.uk>
BestFriend wrote:
> Can Anyone Help me?
>
> I have an Online quiz test Program. I have written this program in C++.
> It creates a CGI Script that I use with Apache server putting it in
> cgi-bin directory and I was using this script in Linux 7.1, 7.3 and 9.0
??? Linux 7.1 etc? Do you mean RedHat?
> but now I load Fedora Core 3 in my server and configure all the things
> needed for my program.
>
> Now the script is running and doing all the work except creating file
> in cgi-bin directory.
>
> Note: I have give write permission of (html) /var/www/html and
> (cgi-bin) /var/www/cgi-bin directory to all.
>
> But My script can't create any file in cgi-bin directory.
>
> Please if you have any information help me.
First, you have posted this question in the wrong place. Your question
has zero Perl content. It is a webserver/OS configuration question.
Please post such questions in an appropriate group, such as:
comp.infosystems.www.servers.unix
I have set follow-ups to that group.
Still, I am feeling generous today. I reckon it's a good bet that your
problem is the "secure linux" layer that is on by default in FC3.
DS
------------------------------
Date: Mon, 21 Aug 2006 12:50:31 +0100
From: RedGrittyBrick <redgrittybrick@spamweary.foo>
Subject: Re: hiw do i perform this extraction
Message-Id: <5Mmdnaf17YKUA3TZRVnygg@bt.com>
kitcha wrote:
> i have a file of this format..
>
> ModelGen Info, Time 63425843 ps, Instance Device/Device_core
> 00000084 E5810000 STR r0,[r1,#0]
>
> i want the script to print an output like this
>
> Time 63425843 ps
>
> 00000084 E5810000 STR r0,[r1,#0]
>
>
> wht cmds shud i use?
>
I thk ul hv mr lck f u us ths 1s:
/!perl
use strict;
use warnings;
while (<$posting>) {
s/wht/what/;
s/cmds/commands/;
s/shud/should/;
s/i/I/;
print;
}
bcz ts hrd 2 tl wt ppl rly mn whn ty us txt spk on usnt so i wdnt rcmnd t.
------------------------------
Date: Mon, 21 Aug 2006 06:22:42 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: hiw do i perform this extraction
Message-Id: <slrneej5s2.6ol.tadmc@magna.augustmail.com>
kitcha <kitcha315@gmail.com> wrote:
> wht cmds shud i use?
-------------------------
#!/usr/bin/perl
use warnings;
use strict;
while ( <DATA> ) {
if ( s/^\s\s+/ / ) {
print;
next;
}
s/^[^,]+,\s*//;
s/,[^,]+$//;
print "$_\n";
}
__DATA__
ModelGen Info, Time 63425843 ps, Instance Device/Device_core
00000084 E5810000 STR r0,[r1,#0]
-------------------------
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 21 Aug 2006 10:43:39 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: HOW to rename a NPH script ?
Message-Id: <4kth2rFdmeujU1@news.dfncis.de>
Ulrich Mueller <umu@hrz.tu-chemnitz.de> wrote in comp.lang.perl.misc:
>
>
> let's shortly analyze this communication process:
>
> 1. I POSE A QUESTION
> 2. YOU ADVICE ME TO ASK SOMEWHERE ELSE (STILL KINDLY)
> 3. I TELL YOU I VE DONE SO ALREADY WITH NO LUCK, SO TRYING HERE (KINDLY)
> 4. YOU JUST REPEAT 2. WITHOUT ANY CONSIDERATION OF 3.
Don't shout!
What's to consider about 3? The fact that you got no replies elsewhere
doesn't make it topical here. When the baker is closed, do you go to the
butcher next door to get your breakfast rolls?
Anno
------------------------------
Date: 21 Aug 2006 16:06:50 GMT
From: xhoster@gmail.com
Subject: Re: Printing to a file Or STDOUT
Message-Id: <20060821120657.874$fu@newsreader.com>
Hal Vaughan <hal@thresholddigital.com> wrote:
> I thought this was a FAQ, but I can't find it, which means it either
> isn't as obvious as I think or I'm just using the wrong search terms.
>
> I want to be able to print to either STDOUT or to a file, so if I have a
> series of print statements like:
>
> print $fh "This is a line of text\n";
>
> I'd like to be able to have $fh be able to refer to STDOUT so a command
> line option for my program could specify to either save the output to a
> file or print it to the console. I know I can just open the file, but
> how to I set $fh equal to the actual STDOUT stream?
$ perl -wle 'use strict; my $fh=*STDOUT; print $fh "foo"'
foo
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Mon, 21 Aug 2006 12:06:54 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: References - problem understanding them
Message-Id: <ecc7tc.17k.1@news.isolution.nl>
xhoster: schreef:
> Jürgen_Herz:
>> currently I'm trying to understand references.
>> I've read perltut.pod and
>
> AFAIK, there is no perltut.
ISHM perlreftut.
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: 21 Aug 2006 03:39:41 -0700
From: "Matt Garrish" <mgarrish@gmail.com>
Subject: Re: References - problem understanding them
Message-Id: <1156156781.745271.233870@h48g2000cwc.googlegroups.com>
Dr.Ruud wrote:
> xhoster: schreef:
> > J=FCrgen_Herz:
>
> >> currently I'm trying to understand references.
> >> I've read perltut.pod and
> >
> > AFAIK, there is no perltut.
>
> ISHM perlreftut.
>
ITYM ITHM? Or is this some concoction of "I'm Sure He Meant", which is
just a guess after staring at for some time. It would be so much easier
to just write what is intended.
(Not to single you out on this particular pet peeve of mine except for
the fact I couldn't decipher this one, but it is annoying in general to
have to look these things up when one isn't hip to the comings and
goings of acronyms.)
Matt
------------------------------
Date: Mon, 21 Aug 2006 13:30:59 +0200
From: =?ISO-8859-1?Q?J=FCrgen_Herz?= <juergenherz@gmail.com>
Subject: Re: References - problem understanding them
Message-Id: <ecc5dv$8r9$1@news1.nefonline.de>
xhoster@gmail.com wrote:
> Jürgen_Herz <juergenherz@gmail.com> wrote:
>> currently I'm trying to understand references. I've read perltut.pod and
>
> AFAIK, there is no perltut. Have you read perlref?
I meant perlref. Yes, I've read it, but not really understood - as I fear.
>> I'd expect accessing the hash in main doesn't work because it doesn't
>> exist anymore outside of test(), just the pointer to that gone hash.
>
> Garbage collection is explained in the 2nd paragraph (v.5.8.8) of
> the "description" section of perlref.
Hm, explained - yes and no. Now I know how it works, I understand that
paragraph - but not before. And still I think "automatically freeing the
thing referred to when its reference count goes to zero" doesn't
implicate it's *not* freed as long a reference to it exists.
Thank you,
Jürgen
------------------------------
Date: Mon, 21 Aug 2006 13:49:13 +0200
From: =?ISO-8859-1?Q?J=FCrgen_Herz?= <juergenherz@gmail.com>
Subject: Re: References - problem understanding them
Message-Id: <ecc6d9$95t$1@news1.nefonline.de>
David Squire wrote:
> Jürgen Herz wrote:
>> Hi,
>>
>> currently I'm trying to understand references. I've read perltut.pod and
>> perlreftut.pod but still don't know why does this works:
>
> missing:
>
> use strict;
> use warnings;
No, not missing. I just let them out here in order to make the example
shorter. I guess that was to well-meant.
> OK. I take it you were expecting this code *not* to work, and are
> surprised that it did? That's a change from most questions around here :)
:-)
Yes, you're right. I often go the way of writing code that I'd expect
not to work in order to be sure I've understood all aspects. Which I
didn't here.
> The reason that your example works is that Perl is a garbage-collected
> language (unlike C), and many garbage-collected languages maintain
> counts of references to chunks of memory that are allocated. The memory
> is only freed when the reference count goes to zero. Since your sub
> returns a reference to the hash created within it, that hash sticks
> around so long as the reference exists.
Thank you, now I see why it works like it does.
Regards,
Jürgen
------------------------------
Date: Mon, 21 Aug 2006 13:59:11 +0200
From: =?ISO-8859-1?Q?J=FCrgen_Herz?= <juergenherz@gmail.com>
Subject: Re: References - problem understanding them
Message-Id: <ecc6uc$9ed$1@news1.nefonline.de>
Klaus wrote:
> There is some explanation in perlsub (although it is not obvious to
> find)
>
> [...]
Uh yes, that's the answer to why that works.
But I still have a bad feeling doing that. So is it considered good (or
bad) style relying on this behaviour? Though it seems to be guaranteed
and should always work, maybe it's on some "List of things better not to
do" because of something like code comprehensibility.
Thank you,
Jürgen
------------------------------
Date: Mon, 21 Aug 2006 14:06:29 +0200
From: =?ISO-8859-1?Q?J=FCrgen_Herz?= <juergenherz@gmail.com>
Subject: Re: References - problem understanding them
Message-Id: <ecc7ar$b08$1@news1.nefonline.de>
Aaron Sherman wrote:
> In reality they're the same thing, but what you should not do is
> confuse lexically scoped variables with stack-allocated variables in C.
> You essentially have no access to the stack at all in Perl. The "Perl
> stack" is malloced memory, and items allocated on it are freed when
> they are no longer referenced. By creating a reference to your
> lexically scoped hash, you asked Perl not to release it.
>
> Hope that helps, one C programmer to another.
Indeed that helped. Not references itself are different but the system
of variable allocation in Perl at all.
Thanks,
Jürgen
------------------------------
Date: Mon, 21 Aug 2006 14:34:47 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: References - problem understanding them
Message-Id: <eccgjk.1f8.1@news.isolution.nl>
Matt Garrish schreef:
> Dr.Ruud:
>> xhoster:
>>> Jürgen_Herz:
>>>> currently I'm trying to understand references.
>>>> I've read perltut.pod and
>>>
>>> AFAIK, there is no perltut.
>>
>> ISHM perlreftut.
>
> ITYM ITHM? Or is this some concoction of "I'm Sure He Meant", which is
> just a guess after staring at for some time. It would be so much
> easier to just write what is intended.
It was meant as funny. Not everybody knows even what 'AFAIK' means. My
'S' was 'suppose(d)'.
> (Not to single you out on this particular pet peeve of mine except for
> the fact I couldn't decipher this one, but it is annoying in general
> to have to look these things up when one isn't hip to the comings and
> goings of acronyms.)
It's OK. (old knowledge?)
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: 21 Aug 2006 05:44:51 -0700
From: "Klaus" <klaus03@gmail.com>
Subject: Re: References - problem understanding them
Message-Id: <1156164291.787151.197720@75g2000cwc.googlegroups.com>
J=FCrgen Herz wrote:
> Klaus wrote:
>
> > There is some explanation in perlsub (although it is not obvious to
> > find)
> >
> > [...]
>
> Uh yes, that's the answer to why that works.
>
> But I still have a bad feeling doing that.
I can understand this, I had the same bad feeling when I started perl
programming. But after several years, I now have a good feeling about
that.
> So is it considered good (or bad) style relying on this behaviour?
Personally, I consider this a good style.
> Though it seems to be guaranteed and should always work,
There are thousands of CPAN modules which rely heavily on garbage
collection, and they work fine...
.=2E.but yes, the garbage collector itself is written by humans, and
humans can make mistakes, but I believe that the human who wrote the
garbage collector makes much less mistakes than I would make, if I
wrote my own code to collect garbage.
> maybe it's on some "List of things better not to do" because of
> something like code comprehensibility.
Not having to worry about garbage collection in the actual code
improves code comprehensibility.
------------------------------
Date: 21 Aug 2006 13:24:49 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: References - problem understanding them
Message-Id: <4ktqh1Fdqsu4U1@news.dfncis.de>
Klaus <klaus03@gmail.com> wrote in comp.lang.perl.misc:
> Jürgen Herz wrote:
[...]
> ...but yes, the garbage collector itself is written by humans, and
> humans can make mistakes, but I believe that the human who wrote the
> garbage collector makes much less mistakes than I would make, if I
> wrote my own code to collect garbage.
The garbage collector proper is relatively safe, it's a compact bit
of code that's well debugged. It's rather the maintenance of the
refcount that's error-prone. That happens all over the perl code
(and in XS modules) whenever the default behavior isn't good enough,
which is often. Symptoms are memory leaks when the refcount is too
high and segfaults or entirely bizarre behavior when it is too low.
This must be carefully debugged if perl is to keep its promise that
references are automatically collected and never dangle.
Anno
------------------------------
Date: Mon, 21 Aug 2006 14:11:40 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: References - problem understanding them
Message-Id: <wajGg.19539$uV.13666@trnddc08>
Jürgen Herz wrote:
> Aaron Sherman wrote:
>
>> In reality they're the same thing, but what you should not do is
>> confuse lexically scoped variables with stack-allocated variables in
>> C. You essentially have no access to the stack at all in Perl. The
>> "Perl stack" is malloced memory, and items allocated on it are freed
>> when they are no longer referenced. By creating a reference to your
>> lexically scoped hash, you asked Perl not to release it.
>>
>> Hope that helps, one C programmer to another.
>
> Indeed that helped. Not references itself are different
Sorry, but I strongly disagree. Pointers in C are memory addresses,
something that otherwise you find in assembler. You can manipulate them, you
can add or subtract to the address, etc, etc.
A reference in Perl is an _abstract_, well, reference to one concrete
object. You cannot change it, you cannot manipulate it, you cannot create it
or destroy it. On an implementation level it may be implemented as a C
pointer, but it could just as well be an index into some variable list or
whatever. As a Perl programmer you don't know and you don't care.
> but the system
> of variable allocation in Perl at all.
Not really. Perl and C are actually quite similar. Had you said that
_memory_ allocation and management is different, then yes, because C forces
the programmer to implement memory management manually while Perl does it
automatically. There is not new(), malloc(), or free() in Perl.
jue
------------------------------
Date: 21 Aug 2006 16:12:30 GMT
From: xhoster@gmail.com
Subject: Re: References - problem understanding them
Message-Id: <20060821121237.993$WA@newsreader.com>
Jürgen_Herz <juergenherz@gmail.com> wrote:
> Klaus wrote:
>
> > There is some explanation in perlsub (although it is not obvious to
> > find)
> >
> > [...]
>
> Uh yes, that's the answer to why that works.
>
> But I still have a bad feeling doing that. So is it considered good (or
> bad) style relying on this behaviour?
It is excellent style to rely on it. And it isn't like there is a choice.
Pure Perl has no user-accessible malloc or free.
> Though it seems to be guaranteed
> and should always work, maybe it's on some "List of things better not to
> do" because of something like code comprehensibility.
What alternative would you propose?
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Mon, 21 Aug 2006 18:38:50 +0200
From: =?ISO-8859-1?Q?J=FCrgen_Herz?= <juergenherz@gmail.com>
Subject: Re: References - problem understanding them
Message-Id: <eccnhf$i94$1@news1.nefonline.de>
xhoster@gmail.com wrote:
>> Though it seems to be guaranteed
>> and should always work, maybe it's on some "List of things better not to
>> do" because of something like code comprehensibility.
>
> What alternative would you propose?
I'm far from proposing anything. But using plain hash would also work at
least in my example:
my %content2 = test2();
for (keys %content2)
{ print "$_: ",$content2{$_},"\n" }
sub test2
{
my %content2 = (one => "eins", two => "zwei");
return %content2;
}
Jürgen
------------------------------
Date: Mon, 21 Aug 2006 17:47:42 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: References - problem understanding them
Message-Id: <ecco3e$h93$1@gemini.csx.cam.ac.uk>
Jürgen Herz wrote:
> xhoster@gmail.com wrote:
>
>>> Though it seems to be guaranteed
>>> and should always work, maybe it's on some "List of things better not to
>>> do" because of something like code comprehensibility.
>> What alternative would you propose?
>
> I'm far from proposing anything. But using plain hash would also work at
> least in my example:
>
> my %content2 = test2();
> for (keys %content2)
> { print "$_: ",$content2{$_},"\n" }
>
> sub test2
> {
> my %content2 = (one => "eins", two => "zwei");
> return %content2;
> }
Sure, this will work, but the entire hash gets copied when the sub
returns. For large data structures this can be very inefficient. Passing
around references is much more memory and time efficient for large and
complex data structures.
DS
------------------------------
Date: Mon, 21 Aug 2006 13:45:54 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: References - problem understanding them
Message-Id: <x78xlinfsd.fsf@mail.sysarch.com>
>>>>> "x" == xhoster <xhoster@gmail.com> writes:
>> But I still have a bad feeling doing that. So is it considered good (or
>> bad) style relying on this behaviour?
x> It is excellent style to rely on it. And it isn't like there is a choice.
x> Pure Perl has no user-accessible malloc or free.
>> Though it seems to be guaranteed
>> and should always work, maybe it's on some "List of things better not to
>> do" because of something like code comprehensibility.
x> What alternative would you propose?
there is another style choice. returning a ref to a lexical array/hash
may be confusing but returning an anon array/hash could be less
confusing. so instead of
my @array ;
return \@array ;
do
my $aref = [] ;
return $aref ;
they do the exact same thing but it is clearer code IMO to explicitly
create and return an anon array (or hash). not that i haven't done the
former in some cases but i lean to doing the latter.
the only downside to the $aref version would be how you stuff it. you
have to deref it with ->[] or @{} where in the former case you can do
the slightly simpler direct access to the array.
so here is the choice: cleaner looking return of a ref vs cleaner
access to the array in the sub.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Mon, 21 Aug 2006 10:17:07 GMT
From: Brian Greenfield <not-for-replies@zombie.org.uk>
Subject: Re: The DEBUG constant?
Message-Id: <o61je256gpt163st64r9kmpqucog999m45@4ax.com>
On 21 Aug 2006 02:16:04 -0700, "ska" <skg@mail.inf.fh-brs.de> wrote:
>anno4000@radom.zrz.tu-berlin.de wrote:
>
>> One point about the the approach using constants is that a statement
>> qualified by "if DEBUG" will not even be compiled when debugging
>> is off. Thus code with "DEBUG => 0" will be the same as if no
>> assertions were present at all.
>
>I always wondered:
>
>Can you, for instance, write
>
>assert( condition );
>
>in the code, but let have perl ignore the statement, or let have perl
>_not_ evaluate the arguments, unless a $debug (non-constant) is true?
not quite. Consider x.pl:
#!/usr/bin/perl
use constant DEBUG => 0;
assert( 1 == 0 );
sub assert { die "bad thing happened" if DEBUG && ! $_[0] }
and then deparse it:
~/scripts$ perl -MO=Deparse x.pl # letter O, not digit
use constant ('DEBUG', 0);
assert(!1);
sub assert {
0;
}
you can see the sub call is still compiled, but the contents of the
sub aren't
>With a preprocessor one could write, e.g.:
>
>#define assert(a) if(debug) _assert(a)
>
>Is something like this possible in plain perl, too?
No, but I wish it was!
------------------------------
Date: Mon, 21 Aug 2006 13:08:21 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: The DEBUG constant?
Message-Id: <eccbe9.1bs.1@news.isolution.nl>
ska schreef:
> Can you, for instance, write
> assert( condition );
> in the code, but let have perl ignore the statement, or let have perl
> _not_ evaluate the arguments, unless a $debug (non-constant) is true?
You can "use Sub::Assert", but the statement is not fullly ignored when
assertions are turned of.
See also "use constant", after which you could write "assert ... if
DEBUG" to let the assert-line get optimized away.
There is also Carp::Assert. And Perl 5.9.
http://search.cpan.org/search?m=module&q=assert&n=50
`perldoc constant`
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
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 9632
***************************************