[25106] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7356 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 3 21:05:45 2004

Date: Wed, 3 Nov 2004 18:05:05 -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, 3 Nov 2004     Volume: 10 Number: 7356

Today's topics:
    Re: Check POP3 E-mail <dsgSPAMFILTER@alum.dartmouth.org>
    Re: Check POP3 E-mail <noreply@gunnar.cc>
    Re: Check POP3 E-mail <ioneabu@yahoo.com>
    Re: Check POP3 E-mail <noreply@gunnar.cc>
        deleting empty lines from a variable containing \n's (machoq)
    Re: deleting empty lines from a variable containing \n' <tadmc@augustmail.com>
        FAQ 9.18: How do I decode a MIME/BASE64 string? <comdog@panix.com>
    Re: Jumping to machine code <nospam@example.com>
        nntp.perl.org posting problem <soundz@techie.com>
    Re: nntp.perl.org posting problem <1usa@llenroc.ude.invalid>
    Re: nntp.perl.org posting problem <comdog@panix.com>
    Re: number of characters in a string <mritty@gmail.com>
    Re: Performance: longest prefix length <nospam-abuse@ilyaz.org>
    Re: perl self generating program <lwt0301@bellsouth.net>
    Re: perl self generating program (Anno Siegel)
    Re: Q: re Inline and Benchmark <abigail@abigail.nl>
    Re: Q: re Inline and Benchmark <nospam-abuse@ilyaz.org>
    Re: Q: re Inline and Benchmark <nospam-abuse@ilyaz.org>
    Re: Rlogin client? <abigail@abigail.nl>
    Re: The most perfect beginning <tim@vegeta.ath.cx>
    Re: The most perfect beginning (Anno Siegel)
    Re: The most perfect beginning <ioneabu@yahoo.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 3 Nov 2004 15:01:46 -0500
From: "David Gale" <dsgSPAMFILTER@alum.dartmouth.org>
Subject: Re: Check POP3 E-mail
Message-Id: <2usrufF2dtjcdU1@uni-berlin.de>

Quoth A. Sinan Unur <1usa@llenroc.ude.invalid>:
> wana <ioneabu@yahoo.com> wrote:
>> my @message = ();
>
> There is no need to explictly initialize my variables.

Nor does it hurt to do so, and is a good habit to get into, in case you're
ever in an environment when you can't choose which language to program in,
and have to use something (say, C) which does not implicitly initialize
variables.

Of course, I always initialize my variables (in any language) simply because
I'm a control freak, and want to be darn certain I know what's in there.
;-)

-D.




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

Date: Wed, 03 Nov 2004 21:59:07 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Check POP3 E-mail
Message-Id: <2usv6cF2ebk78U1@uni-berlin.de>

David Gale wrote:
> Quoth A. Sinan Unur:
>> wana wrote:
>>> 
>>> my @message = ();
>> 
>> There is no need to explictly initialize my variables.
> 
> Nor does it hurt to do so, and is a good habit to get into, in case
> you're ever in an environment when you can't choose which language to
> program in, and have to use something (say, C) which does not
> implicitly initialize variables.
> 
> Of course, I always initialize my variables (in any language) simply
> because I'm a control freak, and want to be darn certain I know
> what's in there. ;-)

Not sure what you guys are talking about now. :)

Does anything really get *initialized* by saying

     my @array = ();

or

     my %hash = ();

? I thought that was only in order to ensure that the array or hash is
*empty* (which isn't necessary since my() takes care of it).

Do you actually initialize anything but scalars?

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Wed, 03 Nov 2004 17:27:14 -0500
From: wana <ioneabu@yahoo.com>
Subject: Re: Check POP3 E-mail
Message-Id: <10oijfnrfvm4358@news.supernews.com>

Gunnar Hjalmarsson wrote:

> David Gale wrote:
>> Quoth A. Sinan Unur:
>>> wana wrote:
>>>> 
>>>> my @message = ();
>>> 
>>> There is no need to explictly initialize my variables.
>> 
>> Nor does it hurt to do so, and is a good habit to get into, in case
>> you're ever in an environment when you can't choose which language to
>> program in, and have to use something (say, C) which does not
>> implicitly initialize variables.
>> 
>> Of course, I always initialize my variables (in any language) simply
>> because I'm a control freak, and want to be darn certain I know
>> what's in there. ;-)
> 
> Not sure what you guys are talking about now. :)
> 
> Does anything really get *initialized* by saying
> 
>      my @array = ();
> 
> or
> 
>      my %hash = ();
> 
> ? I thought that was only in order to ensure that the array or hash is
> *empty* (which isn't necessary since my() takes care of it).
> 
> Do you actually initialize anything but scalars?
> 

I have a lot of habits that carry over from C and C++ and also from being
unsure of things like precedence (extra parentheses) and variable
initialization, like in this case.

One thing I especially like about Perl, as I am learning, is that everything
has a definite defined action or meaning.  For example, the list of things
that will resolve to false like '', 0, undef etc...  I believe that
declaring a scalar in Perl automatically sets it to a false value.  I don't
know if it is '' or 0 but it will become the appropriate one when you use
it. Anyway, the point is that there are no undefined things like in C where
you don't know what value you will find in an uninitialized variable and
the defined action may vary from system to system.

Also, I did have the mod_perl thing in mind too.  Apparently mod_perl
scripts will stay loaded in memory after running and variables may retain
their values, requiring the implicit initialization.

I have found that doing most of my Perl programming on a shared system which
does not use mod_perl due to security risks, I have not really had to worry
about it.  I think that mod_perl is only safely used on a dedicated server. 
The book I have on Perl and MySQL for the Web goes to great lengths to get
readers to install and use mod_perl and then explains later that it can not
be used safely on shared systems.  A shared web server is the only
practical and affordable way I can write Perl CGI programs and keep them
online 24/7.

By the way, the module support for e-mail in Perl is really cool.  I have
some great automation things going on that I never thought were possible. 
My family is getting sick of receiving an e-mail every 24 hours with a
randomly generated directory link to my family photos.  They think my
security measures are a little excessive.

wana


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

Date: Wed, 03 Nov 2004 23:01:47 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Check POP3 E-mail
Message-Id: <2ut2ruF2eo0qqU1@uni-berlin.de>

wana wrote:
> I believe that declaring a scalar in Perl automatically sets it to a
> false value.

Yes...

> I don't know if it is '' or 0

Neither. It's undef.

> but it will become the appropriate one when you use it.

Well, you will get an uninitialized warning if you for instance print
the undefined value or do

     if ($num < 1) {
         # do something;
     }

> Also, I did have the mod_perl thing in mind too.  Apparently mod_perl
> scripts will stay loaded in memory after running and variables may
> retain their values, requiring the implicit initialization.

Global variables retain their values in mod_perl, but I don't think
that's true for lexically scoped variables.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: 3 Nov 2004 14:59:42 -0800
From: spamsaket@yahoo.com (machoq)
Subject: deleting empty lines from a variable containing \n's
Message-Id: <e715de76.0411031459.6f7d2f10@posting.google.com>

I read a file and store it in a scalar variable...the file contains
lines with ### i need to delete those lines. When i substitute them i
get an empty line but not a deletedline. How do i achieve this ?

Code

undef $/;
open(FILE,"someFile");
$file = <FILE>;
$file =~ s/^#+$//mg;
print $file;

Result
If someFileContained
1) myCode
2) ###
3) furtherCode

The output is 
1) myCode

2) furtherCode

I want output like
1) myCode
2) furtherCode

regards
-Machoq


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

Date: Wed, 3 Nov 2004 16:48:50 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: deleting empty lines from a variable containing \n's
Message-Id: <slrncoio2i.7jd.tadmc@magna.augustmail.com>

machoq <spamsaket@yahoo.com> wrote:
> I read a file and store it in a scalar variable...the file contains
> lines with ### i need to delete those lines. When i substitute them i
> get an empty line but not a deletedline. How do i achieve this ?


By deleting the newline character too.


> open(FILE,"someFile");


You should always, yes *always*, check the return value from open():

   open(FILE, 'someFile') or die "could not open 'someFile'  $!";


> $file =~ s/^#+$//mg;


   $file =~ s/^#+\n//mg;


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Wed, 3 Nov 2004 23:03:02 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 9.18: How do I decode a MIME/BASE64 string?
Message-Id: <cmbo36$g2$1@reader1.panix.com>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.

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

9.18: How do I decode a MIME/BASE64 string?

    The MIME-Base64 package (available from CPAN) handles this as well as
    the MIME/QP encoding. Decoding BASE64 becomes as simple as:

        use MIME::Base64;
        $decoded = decode_base64($encoded);

    The MIME-Tools package (available from CPAN) supports extraction with
    decoding of BASE64 encoded attachments and content directly from email
    messages.

    If the string to decode is short (less than 84 bytes long) a more direct
    approach is to use the unpack() function's "u" format after minor
    transliterations:

        tr#A-Za-z0-9+/##cd;                   # remove non-base64 chars
        tr#A-Za-z0-9+/# -_#;                  # convert to uuencoded format
        $len = pack("c", 32 + 0.75*length);   # compute length byte
        print unpack("u", $len . $_);         # uudecode and print



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

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-2002 Tom Christiansen and Nathan
    Torkington, and other contributors as noted. All rights 
    reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.


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

Date: Thu, 04 Nov 2004 09:17:30 +0800
From: Derek Fountain <nospam@example.com>
Subject: Re: Jumping to machine code
Message-Id: <4189821f$0$6565$5a62ac22@per-qv1-newsreader-01.iinet.net.au>

> First, there is no such thing as "cross platform machine code."

I know that, but I can put the right flavour of machine code into the string
dynamically.

> Second, a Perl script must do an awful lot of disk access to get
> started, so what's the problem?

Perl scripts start with a lot of disk *reading*, I don't have easy write
access.

> Third, if you are so concerned about speed, WTF are you doing running it
> from within Perl?

The usual balance of convenience and speed; writing a file to disk might tip
the balance the wrong way.

> Fourth, this sounds like an attempt at injecting a virus in Perl code.

It might sound like it, but no. Close though, I'm working with the
metasploit framework and want to test some payloads.

> Could you please tell us what this marvelous piece of machine code is
> going to do, and given that Perl is SOOO slow compared to machine code,
> what benefit you think you're going to get from this approach?

Since your attitude is that of an idiot, and you clearly have no intention
of helping me with my genuine, legitimate problem, no.


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

Date: Wed, 03 Nov 2004 17:49:01 -0800
From: Mark Day <soundz@techie.com>
Subject: nntp.perl.org posting problem
Message-Id: <41898A8D.5030305@techie.com>

Wondering if anyone knows of an email address of the admin to contact 
about nntp.perl.org posting problems i'm having, articles not showing 
up. Thanks.



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

Date: 4 Nov 2004 01:55:50 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: nntp.perl.org posting problem
Message-Id: <Xns9596D4EA44FE7asu1cornelledu@132.236.56.8>

Mark Day <soundz@techie.com> wrote in news:41898A8D.5030305@techie.com:

> Wondering if anyone knows of an email address of the admin to contact 
> about nntp.perl.org posting problems i'm having, articles not showing 
> up. 

See http://www.nntp.perl.org/

Sinan.


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

Date: Wed, 03 Nov 2004 19:57:39 -0600
From: brian d foy <comdog@panix.com>
Subject: Re: nntp.perl.org posting problem
Message-Id: <031120041957398148%comdog@panix.com>

In article <41898A8D.5030305@techie.com>, Mark Day <soundz@techie.com>
wrote:

> Wondering if anyone knows of an email address of the admin to contact 
> about nntp.perl.org posting problems i'm having, articles not showing 
> up. Thanks.

See http://www.nntp.perl.org/

-- 
brian d foy, comdog@panix.com
Subscribe to The Perl Review: http://www.theperlreview.com


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

Date: Wed, 03 Nov 2004 19:08:51 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: number of characters in a string
Message-Id: <71aid.11722$a24.5138@trndny07>

"Xevo" <x3v0-usenet@yahoo.com> wrote in message
news:359b5621.0411031003.306966b1@posting.google.com...
> spamsaket@yahoo.com (machoq) wrote in message
news:<e715de76.0411011551.3fb201c7@posting.google.com>...
> > I have reading a line from a text file
> > the line is like
> >
> > abc\"123
>
> Well if the line is "abc\"123", then the \ would be counted as a
> backreference for the " character. Therefore, \" is only counted as
> one character. This is only a guess though since you didn't post the
> exact code.

If the line is being read from a text file, as the OP claimed, than this
is not true.  The \ will be a literal \.  \ is only treated 'special'
within literal code, not within data.

Paul Lalli




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

Date: Wed, 3 Nov 2004 22:11:27 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Performance: longest prefix length
Message-Id: <cmbl2f$1ild$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Ryan Thompson 
<a@ry.ca>], who wrote in article <20041102221355.I71781@localhost.my.domain>:

> I need to find the length of the largest common prefix between two short
> strings (1-80 chars). This wouldn't be so bad, if I didn't have to do it
> hundreds of millions of times (cross-checking large sets of strings).
> Performance is an issue.

The last time I saw a similar question raised, the performance of
Text::Trie (or maybe of a code taken from Text::Trie?) was found the
best.  Google for it.

Hope this helps,
Ilya


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

Date: Wed, 03 Nov 2004 15:50:29 -0500
From: Laura <lwt0301@bellsouth.net>
Subject: Re: perl self generating program
Message-Id: <10oidq96pie5b27@news.supernews.com>

Bernard El-Hagin wrote:

> yahavbaryosef@hotmail.com (Yahav Bar yosef) wrote:
> 
>> Tad McClellan <tadmc@augustmail.com> wrote in message
>> news:<slrncocqvs.q0m.tadmc@magna.augustmail.com>...
>>> Yahav Bar yosef <yahavbaryosef@hotmail.com> wrote:
>>> 
>>> > Anyone has something shorter than this ?
>>> > 
>>> > ****************************************
>>> > 
>>> > #!/usr/bin/perl
>>> > open(F,$0);print<F>
>>> 
>>> 
>>> Sure, an empty file is a shorter "quine" than that one is.
>>> 
>>> :-)
>> 
>> Hi Tad,
>> what excactly do you mean by "empty file" ?
> 
> 
> How is "empty file" confusing you?
> 
> 

How about a non-existent file that was never created and then deleted 10
times in a row?


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

Date: 3 Nov 2004 21:42:16 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: perl self generating program
Message-Id: <cmbjbo$naf$3@mamenchi.zrz.TU-Berlin.DE>

Laura  <lwt0301@bellsouth.net> wrote in comp.lang.perl.misc:
> Bernard El-Hagin wrote:
> 
> > yahavbaryosef@hotmail.com (Yahav Bar yosef) wrote:
> > 
> >> Tad McClellan <tadmc@augustmail.com> wrote in message
> >> news:<slrncocqvs.q0m.tadmc@magna.augustmail.com>...
> >>> Yahav Bar yosef <yahavbaryosef@hotmail.com> wrote:
> >>> 
> >>> > Anyone has something shorter than this ?
> >>> > 
> >>> > ****************************************
> >>> > 
> >>> > #!/usr/bin/perl
> >>> > open(F,$0);print<F>
> >>> 
> >>> 
> >>> Sure, an empty file is a shorter "quine" than that one is.
> >>> 
> >>> :-)
> >> 
> >> Hi Tad,
> >> what excactly do you mean by "empty file" ?
> > 
> > 
> > How is "empty file" confusing you?
> > 
> > 
> 
> How about a non-existent file that was never created and then deleted 10
> times in a row?

An empty file can't be mistaken for that.

Anno


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

Date: 03 Nov 2004 20:18:11 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Q: re Inline and Benchmark
Message-Id: <slrncoif83.d9i.abigail@alexandra.abigail.nl>

Michele Dondi (bik.mido@tiscalinet.it) wrote on MMMMLXXXII September
MCMXCIII in <URL:news:o4lho0tmiinq1ee8fpg7enb4ma1qvdqcp3@4ax.com>:
-:  On 03 Nov 2004 00:22:54 GMT, Abigail <abigail@abigail.nl> wrote:
-:  
-: >    use Inline C => <<'--';
-:  [snip code]
-:  
-: >    cmpthese 500 => {
-: >        C     =>  'r_string',
-: >        Loop1 => \&Loop1,
-: >        Loop2 => \&Loop2,
-: >        ...
-: >    }
-:  
-:  TY! However... I apologize for my fussiness, but would this be fair?

YES! 

-:  Some quick tests showed that, in a general situation, there are
-:  different performance responses with coderefs and strings: I think
-:  that in one case dereferencing and sub calls are involved whereas in
-:  the other an eval() takes place:
-:  
-:    # perl -MBenchmark=:all -e 'sub a { $|++ }\
-:    cmpthese 20_000_000, { str => "a", code => \&a }'
-:              Rate  str code
-:    str   922084/s   -- -46%
-:    code 1693480/s  84%   --
-:  
-:  I don't know if things are different with Inline subs, but I doubt
-:  that...


Indeed. So, \&Loop1 calls one sub per iteration (the sub "Loop1"), and
'r_string' calls one sub per iteration (the sub "r_string").

I did it this way to be sure it's fair - all the benchmarks now call
the same number of subs.


Abigail
-- 
perl -we '$| = 1; $_ = "Just another Perl Hacker\n";  print
          substr  $_ => 0, 1 => "" while $_ && sleep 1 => 1'


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

Date: Wed, 3 Nov 2004 22:04:24 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Q: re Inline and Benchmark
Message-Id: <cmbkl8$1ifd$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Tassilo v. Parseval
<tassilo.von.parseval@rwth-aachen.de>], who wrote in article <slrncoh12r.qs.tassilo.von.parseval@localhost.localdomain>:
> >               outsv = newSVpv(outstr, l)
> >               Safefree(str);
> >               return outsv;
> 
> That will leak, too. 'outsv' must be made mortal in order to get freed on
> block boundaries:
  ^^^^^^^^^^^^^^^^

Actually, "Beginning of the next statement".

> Allocating a string, then copy it into an SV after which the string is
> freed is also a bit wasteful. A better solution:
> 
>     New(1, str, l, char);
>     ...
>     outsv = sv_newmortal();
>     sv_usepvn(outsv, str, l);
>     return outsv;

This is also wasteful, since usepvn() calls realloc() to add \0 at the
end.  I would use something like

   outsv = sv_newmortal();
   SvGROW(outsv, l);
   str = SvPV_nolen(outsv);
   ...
   return outsv;

Hope this helps,
Ilya


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

Date: Wed, 3 Nov 2004 22:07:29 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Q: re Inline and Benchmark
Message-Id: <cmbkr1$1ikc$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Sisyphus 
<kalinaubears@iinet.net.au>], who wrote in article <4188959f$0$564$5a62ac22@per-qv1-newsreader-01.iinet.net.au>:

> I don't have to worry - it's as I thought. The C code reveals that 
> returning an SV as I did (in Inline C) pushes the SV onto the stack, 
> where it is made mortal and then returned to perl. My code does *not* 
> leak memory and returning an 'sv_2mortal' in this case is simply redundant.

sv_mortal() can never be "redundant".  It must be called *exactly* a
particular number of times (just like free()): if you call it less,
you get a memory leak.  If you call it more, you get a crash soon.

Hope this helps,
Ilya

P.S.  Probably you mean "approach of replacing char* with a mortal
SV*" is redundant...



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

Date: 03 Nov 2004 20:33:02 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Rlogin client?
Message-Id: <slrncoig3u.d9i.abigail@alexandra.abigail.nl>

Jean-Louis Leroy (jll@soundobjectlogic.com) wrote on MMMMLXXXII September
MCMXCIII in <URL:news:lzk6t2sxl4.fsf@toots.sol>:
}}  Anybody knows of a rlogin client-in-a-module? Surprisingly I don't
}}  find one on CPAN.
}}  
}}  N.B. 1: I'm aware of the security issues - that's no the issue ;-)
}}  N.B. 2: I'd like to avoid Expect and spawning a rlogin process.


You might want to try Net::Telnet.



Abigail
-- 
 :;$:=~s:
-:;another Perl Hacker
 :;chop
$:;$:=~y:;::d;print+Just.$:


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

Date: Wed, 03 Nov 2004 21:29:56 -0000
From: Tim Hammerquist <tim@vegeta.ath.cx>
Subject: Re: The most perfect beginning
Message-Id: <slrncoij8o.jdv.tim@vegeta.saiyix>

wana <ioneabu@yahoo.com> wrote:
>  I was looking at the Perl t-shirts at
>  http://www.thinkgeek.com/tshirts/coder/321a/ and I noticed that the
>  shirt says:
>  
>  #!/usr/bin/perl -w
>  use strict;
>  
>  I was told that:
>  
>  #!/usr/bin/perl
>  
>  use strict;
>  use warnings;
>  
>  is better.

The 'warnings' pragma did not exist in early versions of perl5.  The -w
turns warnings on regardless of which version of perl you're running.

>  Also, I was told that I should use -T, especially in cases
>  like CGI where many users may run a program, which I found out was not
>  as simple as adding the -T to the first line.

-T is definitely a good idea for CGI, or in any context where outside
input/data needs to be treated like toxic waste that must be purified
before it is used.  That doesn't mean it's necessary, or even the best
option, in all cases, though.

>  I was wondering what people think is the most perfect general
>  beginning to a Perl program that could be used in most or all
>  programs.  This would include whatever flags, pragmas and modules
>  might be useful and important.

You're question doesn't make much sense. I frequently use the Getopt::*
modules in a lot of my scripts, but they don't make sense in all of my
apps, so I wouldn't recommend them as a standard "opening" to a program.
Most modules work this way.  Use the modules that make your program
better.

Even using the -wTMstrict in your scripts isn't as valuable as knowing
*exactly* *why* you *should* be using them.  Doing things just because
you saw someone else do them is, to resurrect a cliche', cargo cult
programming.

HTH,
Tim Hammerquist


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

Date: 3 Nov 2004 21:40:03 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: The most perfect beginning
Message-Id: <cmbj7j$naf$2@mamenchi.zrz.TU-Berlin.DE>

wana <ioneabu@yahoo.com> wrote in comp.lang.perl.misc:

[...]

> I was wondering what people think is the most perfect general
> beginning to a Perl program that could be used in most or all
> programs.  This would include whatever flags, pragmas and modules
> might be useful and important.

Here is my current template for a Perl program:

    #!/usr/local/bin/perl
    use strict; use warnings; $| = 1;
    use Vi::QuickFix;

    exit; #########################################################

    __END__

Comments:

Setting $| in the main program helps keeping the visible stdout and
stderr in sync.  If you do mass output on stdout, switch it off.

Vi::QuickFix is a module that helps Vim users such as yours truly
find the locations of Perl errors and warnings (including those from
modules loaded by your program) -- that is, Vim finds them with the
aid of a file Vi::QuickFix leaves around.  Available on CPAN.

Filling in the form, everything executable comes before "exit" (duh),
sub definitions go below the "###########..." (slightly shortened for
usenet). "BEGIN" (including "use") "END" and possibly "CHECK" and
"INIT" can go anywhere, preferably right on top, or near the place
that motivates them.  If you must know :)

Anno



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

Date: Wed, 03 Nov 2004 17:59:05 -0500
From: wana <ioneabu@yahoo.com>
Subject: Re: The most perfect beginning
Message-Id: <10oilbeli2ho71e@news.supernews.com>

Tim Hammerquist wrote:

> wana <ioneabu@yahoo.com> wrote:
>>  I was looking at the Perl t-shirts at
>>  http://www.thinkgeek.com/tshirts/coder/321a/ and I noticed that the
>>  shirt says:
>>  
>>  #!/usr/bin/perl -w
>>  use strict;
>>  
>>  I was told that:
>>  
>>  #!/usr/bin/perl
>>  
>>  use strict;
>>  use warnings;
>>  
>>  is better.
> 
> The 'warnings' pragma did not exist in early versions of perl5.  The -w
> turns warnings on regardless of which version of perl you're running.
> 
>>  Also, I was told that I should use -T, especially in cases
>>  like CGI where many users may run a program, which I found out was not
>>  as simple as adding the -T to the first line.
> 
> -T is definitely a good idea for CGI, or in any context where outside
> input/data needs to be treated like toxic waste that must be purified
> before it is used.  That doesn't mean it's necessary, or even the best
> option, in all cases, though.
> 
>>  I was wondering what people think is the most perfect general
>>  beginning to a Perl program that could be used in most or all
>>  programs.  This would include whatever flags, pragmas and modules
>>  might be useful and important.
> 
> You're question doesn't make much sense. I frequently use the Getopt::*
> modules in a lot of my scripts, but they don't make sense in all of my
> apps, so I wouldn't recommend them as a standard "opening" to a program.
> Most modules work this way.  Use the modules that make your program
> better.

That's true.  I guess my question would have been better stated as asking
people for standard templates that they use to start off most programs.  I
am really enjoying reading the responses.  At least everyone can agree on:

#!/usr/bin/perl
use strict;
use warnings;

I have a module I wrote for self use that I include in every single program
because it encapsulates some common actions that would normally take 3 or 4
lines of code.

> 
> Even using the -wTMstrict in your scripts isn't as valuable as knowing
> *exactly* *why* you *should* be using them.  Doing things just because
> you saw someone else do them is, to resurrect a cliche', cargo cult
> programming.

The chapter in 'Programming Perl' describes writing a module like filling
out a contract.  You don't have to fully understand everything in it to
write one, just fill in the details.

writing Visual C++ programs is the worst extreme.  I used to write my little
pockets of code surrounded by a sea of incomprehensible Microsoft code.  As
long as I stayed on the path, I was usually safe.

> 
> HTH,
> Tim Hammerquist



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

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 7356
***************************************


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