[17750] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5170 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 21 09:05:33 2000

Date: Thu, 21 Dec 2000 06:05:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <977407511-v9-i5170@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 21 Dec 2000     Volume: 9 Number: 5170

Today's topics:
    Re: assign to array of references <trwww@my-deja.com>
    Re: assign to array of references <trwww@my-deja.com>
    Re: critisism wanted of script style - mail scripts (Martien Verbruggen)
    Re: getting data <ubl@schaffhausen.de>
    Re: heredoc within heredoc (Martien Verbruggen)
    Re: how to invalidate a hash value during a foreach loo <info@jjmackay.ca>
    Re: IDE for development in perl <juha.manninen@datex-ohmeda.com>
        If I don't want to 'goto' <johnlin@chttl.com.tw>
    Re: If I don't want to 'goto' (Abigail)
    Re: If I don't want to 'goto' <trwww@my-deja.com>
    Re: Is Perl dying? (Anno Siegel)
    Re: Language evolution C->Perl->C++->Java->Python (Is P <jason@harlequin.com>
    Re: overriding 'print' (Anno Siegel)
    Re: perl DBI <ubl@schaffhausen.de>
    Re: perl DBI <a.v.a@home.nl>
    Re: Perl newbie question nobull@mail.com
        Range operator with incremental (step size) <johnlin@chttl.com.tw>
    Re: switch/case in Perl? <trwww@my-deja.com>
    Re: switch/case in Perl? <flavell@mail.cern.ch>
    Re: switch/case in Perl? <cleon42@my-deja.com>
    Re: switch/case in Perl? <cleon42@my-deja.com>
    Re: trying to count words - not working <trwww@my-deja.com>
    Re: Understanding interpolation <abe@ztreet.demon.nl>
    Re: Understanding interpolation <trwww@my-deja.com>
        very strange thing with closures patrick_k6801@my-deja.com
    Re: very strange thing with closures (Martien Verbruggen)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 21 Dec 2000 11:47:28 GMT
From: trwww <trwww@my-deja.com>
Subject: Re: assign to array of references
Message-Id: <91sqkf$u65$1@nnrp1.deja.com>

In article <91shu0$h3s@netnews.hinet.net>,
  "John Lin" <johnlin@chttl.com.tw> wrote:
Hi John,

>
>     my @a = ('A'..'Z');
>     my @refs = \@a[7..10];
>     ${$refs[0]} = 'h';
>     ${$refs[1]} = 'i';
>     ${$refs[2]} = 'j';
>     ${$refs[3]} = 'k';
>     print @a;
> __END__
> ABCDEFGhijkLMNOPQRSTUVWXYZ
>
> Could I replace line 3~6 with one assignment?  Such as

sure if all you want is a reference... do:

$a = [ ('A' .. 'Z') ];
@$a[7 .. 10] = ('h' .. 'k');
print @$a;

if you already had @a:

$a = \@a
@$a[7 .. 10] = ('h' .. 'k');
print @$a;


be sure to check out perldoc perllol
the section on slices
--
trwww


Sent via Deja.com
http://www.deja.com/


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

Date: Thu, 21 Dec 2000 13:31:17 GMT
From: trwww <trwww@my-deja.com>
Subject: Re: assign to array of references
Message-Id: <91t0n6$2g3$1@nnrp1.deja.com>


> be sure to check out perldoc perllol
> the section on slices

sorry bout that, its perlref, not perllol

--
trwww


Sent via Deja.com
http://www.deja.com/


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

Date: Thu, 21 Dec 2000 23:51:36 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: critisism wanted of script style - mail scripts
Message-Id: <slrn943v6o.8i7.mgjv@martien.heliotrope.home>

On Thu, 21 Dec 2000 09:51:06 GMT,
	mike_solomon@lineone.net <mike_solomon@lineone.net> wrote:
> I am trying to improve the style of my Perl scripts as others are
> trying to learn from my scripts and I don't want to start them with any
> bad habits I have picked up

You seem to have some old-fashioned habits.

> #mailsend.pl
> #Wed 20/12/00 Mike Solomon
> #send mail from command line
> 
> use strict;

Good, you use strict.

But, BAD, you get around it by declaring all variables at the top of
your program, as globals. You need to learn about lexical scoping, and
name spaces, and about the fact that you can pass arguments to
subroutines. One good exercise is to have a look at some of the modules
on CPAN, and the ones that ship with Perl.

> use vars
> ('$ADDRESS','$BODY','$CC','$SUBJECT','$FROM','$IN_FILE','$OUT_FILE','$op
> t_a','$opt_b','$opt_c','$opt_f','$opt_s','$opt_i','$opt_o');

It's easier to use qw():

use vars qw( $ADDRESS $BODY $CC etc.... );

But nowdays, in 5.60 and up, we use our, instead of use vars.

I'm also a bit suspect about the use of global variables that probably
aren't necessary, and maybe should be stuffed in a hash, or even an
object.

Have you seen the Mailtools package on CPAN?

> #call libary
> require("\\\\neptune\\tech_dept\\scripts\\3slib.pl");

I probably would have used 'use lib' before, and just simply the file
name after require, but that's a minor one.

> #test for input
> if ( @ARGV == 0 ) {
> 	print "

If you use here-docs, you don't need to backwhack all those quotes. The
perldata documentation talks about them.

print <<EO_USAGE;
Usage:
	$0 -a "ADDRESSES" etc...

EO_USAGE


> #set command line switches
> require "getopts.pl";

Nowadays, since perl 5 we tend to use modules instead of these old
libraries. Perl ships with Getopt::Std and Getopt::Long. I prefer Long,
but you should be able to use Getopt::Std without changing your code too
much.

The modules also allow you to not use global variables for the options,
but instead store the result in a hash. Much neater.

> &Getopts('i:o:a:s:c:b:f:');

The & is unnecessary in this case (and almost any other case). Don't use
it unless you know why you need to use it.

> $IN_FILE		= $opt_i;
> $OUT_FILE		= $opt_o;
> $opt_a			=~ s/  *$//;
> 	#strip trailing 0's

That doesn't strip trailing zeroes. Depending on what exactly you mean
by zeroes:

s/0+$//;

or

s/\0+$//;

> $ADDRESS		= $opt_a;
> $SUBJECT		= $opt_s;
> $CC				= $opt_c;
> $BODY			= $opt_b;
> $FROM			= $opt_f;

And here I would put in some serious check to make sure that all the
addresses are correct, and that all the arguments that are required were
actually given. Also, I'd check that there aren't any nasty surprises
waiting in any of those variables.

But you probably will do that in the required module code.

I would not have made these globals, but instead I would have passed
them into the next subroutine as arguments.

> &MAIL;

Again, don't use the &. Instead use MAIL(). Or even just MAIL is the sub
has already been defined.

Style nit: You should also not use all uppercase letters for variables
and subs. 

> #3slib.pl

Change this to a module. 

> #Thu 17 Feb 09:50:02 2000 Mike Solomon
> 
> #3S Perl LIBARY
> #send mail
> #debug
> 
> #use 99 on back of internal variables to avoid confusion

Better: Use packages, and there won't be confusion. Don't use globals,
unless you really have to. This sort of 'confusion' is exactly why it is
such a mantra in computing to avoid globals as much as possible. name
spaces and lexical scoping are good things. 

I'll just cut the rest of the stuff that has to do with globals, and
comment on anything else I see. It is really too much to go into it too
deeply.

> sub main'MAIL {

You shouldn't declare these things in main anymore. This all looks like
a perl4 program to me. All the things that perl 5 solved are still
present here. You should have a look at the perlmod, perlsub
documentation, and at the documentaiton for package, use and require.
Have a look at my and our as well.

> 	my @error 		= ();	#array to hold errors

So, you do know about lexical scope :)

I must say that your program is an odd mix of almost obsolete perl 4
syntax and idiom, and perl 5.

> 	use MIME::Lite;

You can use modules at the spot you need them, but you'll more often
find them at the top of a file (or just after the package declaration).

> 
> 	################################################################
> ###########

Make sure your lines wrap correctly when posting code.

> 		}
> 	else {
> 		#test if addreses are valid

Do you know what the Perl FAQ, part 9 has to say about this sort of
test?

> 		for (@add) {
> 
> 			if (/^[a-z0-9\.\-\_]+@[a-z0-9][a-z0-9\-\.]*\.[a-
> z]+/i){

This is much, much, much too limited.

> 	my $msg = new MIME::Lite
> 		From    =>  $FROM,
> 		To   	=>	$add_good,
> 		Subject	=>	$SUBJECT,
> 		Data	=>	"$BODY",
> 		Cc		=>	$CC;

Since you have to set up this hash from all your global variables
anyway, wouldn't it be a good idea to construct this hash in the main
program, and pass it in to here as arguments? 

My time is now up. 

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | If at first you don't succeed, try
Commercial Dynamics Pty. Ltd.   | again. Then quit; there's no use
NSW, Australia                  | being a damn fool about it.


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

Date: Thu, 21 Dec 2000 13:30:17 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: getting data
Message-Id: <3A41F7D9.5F9408AE@schaffhausen.de>

Sven Franke schrieb:
> 
> Hi,
> 
> I wonder hoe I can read data out an Excel -sheet.
> I heard about a DBI/DBD module, but I can't find info about excel.
> 
> How can this be done?
> (I thought of DBI because I need to store the exceldata in a database...)

DBI is the right choice to store/read data to and from a database.
Excel is not a database, so DBI is not the right module (Correct me, maybe
there is a way to do this with the ODBC DBD). I dont think there is a perl
parser for the ever changing excel file format, but you can probably access
the data via OLE, so look for the WIN32::OLE modules.

You can find all of that at cpan.org

->malte


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

Date: Thu, 21 Dec 2000 23:18:19 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: heredoc within heredoc
Message-Id: <slrn943t8b.8i7.mgjv@martien.heliotrope.home>

On Thu, 21 Dec 2000 10:36:17 +0800,
	John Lin <johnlin@chttl.com.tw> wrote:
> Dear all,
> 
> Could you help me find out what's wrong with my code here?
> 
> print <<OUTSIDE;
> This heredoc within heredoc @{[<<INSIDE;]} needs
> OUTSIDE
> some correction to make it work.
> INSIDE

Incorrect nesting. 

Martien
-- 
Martien Verbruggen              | Since light travels faster than
Interactive Media Division      | sound, isn't that why some people
Commercial Dynamics Pty. Ltd.   | appear bright until you hear them
NSW, Australia                  | speak?


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

Date: Thu, 21 Dec 2000 12:21:48 GMT
From: "Olwynn" <info@jjmackay.ca>
Subject: Re: how to invalidate a hash value during a foreach loop?
Message-Id: <wBm06.64$Mg7.2691@sapphire.mtt.net>

Thanks to everyone that responded.  This is closest to what I was planning
to try and recover from the garbled line of code.  The number of entries in
the text boxes (there are actually 8) for addresses was less important than
testing to see if there was any data in the value for the hash (the key was
holding the field name - holdover from before I'd read the CGI security docs
and was going to provide a place to put a from address ... better leave that
for my second of theird script ;-))   In being able to populate the array
with only fields that are flul, I can then step through that to accomplish
my task.

Thanks,
Richard

Bart Lateur <bart.lateur@skynet.be> wrote in message
news:m5n14tkhrvg2fpjifvoedut04nb98vgdi7@4ax.com...

<snip>
> What you probablty want, is something along the lines of grep(). I'm
> just not sure just *what*. I supposing you have, say, 5 text boxes that
> can be used for addresses. You do your own custom form decoding, which
> makes it mpossible to use the same name for every text box. So, assuming
> their name starts with "to_", followed by, say, a number, so it's "to_1"
> till "to_5", then we can do:
>
> @to = grep length, @form{grep /^to_\d/, keys %form_results};
>
> Now, if two of these five are not empty, then @to will contain their
> contents, and nothing else. And:
>
> unless(@to) {
>     ...
>     # at least one recipient
> }
>
> p.s. Please do proper taint checking on the entered addresses. You never
> know what garbage people might fill in for an e-mail address.
>
> --
> Bart.




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

Date: Thu, 21 Dec 2000 13:34:11 +0200
From: Juha Manninen <juha.manninen@datex-ohmeda.com>
Subject: Re: IDE for development in perl
Message-Id: <3A41EAB3.F7AD09AE@datex-ohmeda.com>


Otto Wyss wrote:

> Is there any useful IDE for development in perl (platform WindowsNT) or
> does everyone just use a simple text editor?

There is Komodo from ActiveState:
http://www.activestate.com/Products/Komodo/index.html

It is in Beta stage, but already usable. Supports other languages, too.

Juha Manninen




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

Date: Thu, 21 Dec 2000 15:55:13 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: If I don't want to 'goto'
Message-Id: <91sd5b$ab3@netnews.hinet.net>

Dear all,

In "perldoc -f goto" it proudly says

    The author of Perl has never felt the need to use this
    form of `goto' (in Perl, that is--C is another matter).

Really?  Recently I tried to modify the structure of a program
to avoid using 'goto'.

    for my $file (<*>) {
        ...
        if($fail_condition1) { warn "message 1"; goto fail }
        ...
        if($fail_condition2) { warn "message 2"; goto fail }
        ...
        if($fail_condition3) { warn "message 3"; goto fail }

        next;
    fail:
        rename $file => "fail/$file";  # move to fail/ sub directory
        ... and many other statements
    }

Whenever there is an failure condition, I want to move the file
to fail/ directory as well as doing some other cleanups.

I couldn't think of a better structure to avoid the 'goto'.

For example, constructing the block after  fail:  as a sub

    if($fail_condition1) { warn "message 1";  fail;  next }

    sub fail { ... }

is not suitable because many "my" variables are involved,
they would either be invisible or need to be passed as arguments
which is ugly.

Could you give me some suggestions?

Thank you.

John Lin

P.S.  I would propose Perl to invent a fail{} block in addition
to continue{} block.  Like this:

while($loop) {
    next if $successful;   # next = goto continue{}
    skip if $failure;      # skip = goto fail{}
}
fail {
    warn "something wrong in the loop\n";
}
continue {
    $i = $i + 1;
}

What do you think about it?





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

Date: 21 Dec 2000 12:11:18 GMT
From: abigail@foad.org (Abigail)
Subject: Re: If I don't want to 'goto'
Message-Id: <slrn943sr6.54f.abigail@tsathoggua.rlyeh.net>

John Lin (johnlin@chttl.com.tw) wrote on MMDCLXIX September MCMXCIII in
<URL:news:91sd5b$ab3@netnews.hinet.net>:
`` Dear all,
`` 
`` In "perldoc -f goto" it proudly says
`` 
``     The author of Perl has never felt the need to use this
``     form of `goto' (in Perl, that is--C is another matter).
`` 
`` Really?  Recently I tried to modify the structure of a program
`` to avoid using 'goto'.
`` 
``     for my $file (<*>) {
``         ...
``         if($fail_condition1) { warn "message 1"; goto fail }
``         ...
``         if($fail_condition2) { warn "message 2"; goto fail }
``         ...
``         if($fail_condition3) { warn "message 3"; goto fail }
`` 
``         next;
``     fail:
``         rename $file => "fail/$file";  # move to fail/ sub directory
``         ... and many other statements
``     }
`` 
`` Whenever there is an failure condition, I want to move the file
`` to fail/ directory as well as doing some other cleanups.
`` 
`` I couldn't think of a better structure to avoid the 'goto'.
`` 
`` For example, constructing the block after  fail:  as a sub
`` 
``     if($fail_condition1) { warn "message 1";  fail;  next }
`` 
``     sub fail { ... }
`` 
`` is not suitable because many "my" variables are involved,
`` they would either be invisible or need to be passed as arguments
`` which is ugly.
`` 
`` Could you give me some suggestions?


Well, if you really want to get rid of goto:


    for my $file (<*>) {
	local $SIG {__WARN__} = sub {
	    if ($_ [0] =~ s/^>>//) {
		rename $file => "fail/$file";
		...
	    }
	    warn @_;
	}

	if ($fail_condition1) {warn ">>message 1"; next}
	if ($fail_condition2) {warn ">>message 2"; next}
	if ($fail_condition3) {warn ">>message 3"; next}
    }


Or use a closure $fail, and do:

        if ($fail_condition1) {warn "message 1"; $fail -> (); next}



Abigail
-- 
tie $" => A; $, = " "; $\ = "\n"; @a = ("") x 2; print map {"@a"} 1 .. 4;
sub A::TIESCALAR {bless \my $A => A} #  Yet Another silly JAPH by Abigail
sub A::FETCH     {@q = qw /Just Another Perl Hacker/ unless @q; shift @q}


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

Date: Thu, 21 Dec 2000 12:44:40 GMT
From: trwww <trwww@my-deja.com>
Subject: Re: If I don't want to 'goto'
Message-Id: <91stvn$b8$1@nnrp1.deja.com>

In article <91sd5b$ab3@netnews.hinet.net>,
  "John Lin" <johnlin@chttl.com.tw> wrote:

Hello John,

> Really?  Recently I tried to modify the structure of a program
> to avoid using 'goto'.
>
>     for my $file (<*>) {
>         ...
>         if($fail_condition1) { warn "message 1"; goto fail }
>         ...
>         if($fail_condition2) { warn "message 2"; goto fail }
>         ...
>         if($fail_condition3) { warn "message 3"; goto fail }
>
>         next;
>     fail:
>         rename $file => "fail/$file";  # move to fail/ sub directory
>         ... and many other statements
>     }

I would probably make the error checking its very own sub:

sub validate_data {
  my($foo, $bar) = @_
  work;
  if ($fail_condition1) {
    work;
  } elsif {
  if ($fail_condition1) {
    work;
  } elsif {
  if ($fail_condition1) {
    work;
  }
}

> is not suitable because many "my" variables are involved,
> they would either be invisible or need to be passed as arguments
> which is ugly.
>

I pretty much consider myself a newbie (a newbie that has read LOTS of
documentation) but I belive it is a very perllike thing to call subs
and move variables around as arguments. I think it keeps the code
readable and looks good. Arguments are how we use perl itslef. Builtin
functions are just subs.

open(ARGUMENT_1, $argument_2) or die("ARGUMENT: $!");
my($arg_to_my_1, $arg_to_my_2) = split(regex_arg, $arg_string_to_split);
validate_data($another_arg, $yet_another);
print($more, $args, $still);
close(ARGUMENT_1);

my advice is to use my() and pass variables around as arguments to
subroutines which do their own job.

--
trwww


Sent via Deja.com
http://www.deja.com/


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

Date: 21 Dec 2000 12:13:38 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Is Perl dying?
Message-Id: <91ss5i$ova$1@lublin.zrz.tu-berlin.de>

Bart Lateur  <bart.lateur@skynet.be> wrote in comp.lang.perl.misc:
>John Hunter wrote:
>
>>Quick BASIC
>>Thus I embarked on writing a full
>>application, including a real time digital oscilloscope and every
>>other goddam feature in the world in a language with no libraries and
>>little language support.  I had to write my own max functions
>
>Oh yeah. Perl is much better in that regard.
>
>    ;-)

Perl's built-in max function?  Sure, and it's a pretty one too:

   [ $x => $y ] -> [ $x <= $y ];

Anno


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

Date: Thu, 21 Dec 2000 13:32:55 +0000
From: Jason Trenouth <jason@harlequin.com>
Subject: Re: Language evolution C->Perl->C++->Java->Python (Is Python the    ULTIMATE oflanguages??)
Message-Id: <vb144t0rpj1efb1m2rtkoobptmpdru24n7@4ax.com>

On Wed, 20 Dec 2000 20:24:29 +0100, Just Me <just_me@nowhere.com> wrote:

 ...

> ...into Smalltalk:
> 
>   allEmployees do: [:eachEmployee |
>      eachEmployee
>         firstMethod;
>         secondMethod ].
> 
> In Smalltalk it's simple, elegant and easy to read whereas in Java one can get
> headaches from all these braces. I mean what are braces for anyway if a
> method has no arguments?
> 
> And as you can see, no types mean less typing!

Or in Dylan:

	for ( eachEmployee in allEmployees )
	  firstMethod( eachEmployee );
	  secondMethod( eachEmployee );
	end;

__Jason


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

Date: 21 Dec 2000 12:00:25 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: overriding 'print'
Message-Id: <91srcp$ou1$1@lublin.zrz.tu-berlin.de>

Abigail <abigail@foad.org> wrote in comp.lang.perl.misc:
>Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMDCLXVIII
>September MCMXCIII in <URL:news:91qlpi$mtu$1@lublin.zrz.tu-berlin.de>:
>-: 
>-: Aha.  Thanks for that bit.  The prototype part even makes sense: If
>-: the parameters cannot be described by a prototype there's no way
>-: to replace the functionality with a Perl function.
>
>
>Well, yeah, that's true, but the prototypes of shift and pop can
>be described; their functionality can be replaced by a Perl function;
>yet prototype() won't give a prototype for them.

Well, so apparently someone decided that overriding shift and pop
is undesirable.  As Ilya once inimitably put it: "This would rub
Camel hair the wrong way".  Not returning a prototype for these
functions is one sensible way of informing the user of this decision.

As you rightly point out, it does not mean that a suitable prototype
can't be given, or that the builtin can't be imitated using other
Perl functions.

Anno


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

Date: Thu, 21 Dec 2000 13:26:28 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: perl DBI
Message-Id: <3A41F6F3.87133244@schaffhausen.de>

Rafael Garcia-Suarez schrieb:

> 
> Ensure proper disconnection even if the select failed:
> 
>   END { $dbh->disconnect if $dbh }

Is this really neccessary? Doesn't DBI provide for this in it's
DESTROY method?

->malte


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

Date: Thu, 21 Dec 2000 13:06:09 GMT
From: AvA <a.v.a@home.nl>
Subject: Re: perl DBI
Message-Id: <3A4200A7.6BF29116@home.nl>

Bart Lateur wrote:

> The WebDragon wrote:
>
> > |  print table( map { Tr( map { td(escape_HTML($_)) } @$_ ) } @$two_d );
> >
> >is it possible to embed formatting subroutines into a line such as this
> >to ensure that for some td()'s I can set the bgcolor of the table cell
> >depending on the value of the variable to be inserted in the cell?
>
> Of course it is. There's nothing in there but code. The cell contents is
> in $_ between the "{" and the "}" (where the "td(escape_HTML($_))" is)
> for the second map(). All you have to do is let the parameters for the
> sub td() depend on the value of $_. You may even put more than one
> statement, separated by semicolons, in a map block.
>
> If, however, you'd like do certain things differently per column, for
> example align the first column to the right, you'll have to manually
> keep track on the column number. There's no implicit loop counter
> (yet?). Put "my $i = 0;" before the "Tr", and be sure to do a $i++
> somewhere in the inner map block, but not as the final statement in that
> block. That should remain the td call.
>
> --
>         Bart.

pff that makes an easy readible language like perl very hard to understand.
i prefer to use as little as modules as possible for learning purposes.
have to get it to work raw first.

thanks for the help all.



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

Date: 21 Dec 2000 08:35:11 +0000
From: nobull@mail.com
Subject: Re: Perl newbie question
Message-Id: <u97l4uyrry.fsf@wcl-l.bham.ac.uk>

Patrick Fong <lielar@my-deja.com> writes:

> Subject: Perl newbie question

The all-time classic useless subject line.

"Perl" is implicit because this is a Perl newsgroup.  Save valuable
space in subject lines by omiting the word "Perl".  As it happens, in
this case, it is also wrong [see below].

"Newbie" in subject lines is usually read as "I'm too lazy to read
manuals".  This may or may not be true but either way it's probably
not a message you urgently want to convey.  Save valuable space in
subject lines by omiting the word "newbie".

"Question" would be implicit if you actaully put any real information
in the subject line.  Save valuable space in subject lines by omiting
the word "question".

Use the valuable space you have seved in the subject line to actually
tell us what you are posting about.  For example:

Subject: CGI script source downloads, not executes

For futher advice see:

    http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post

> I have a slight problem. When I submit a form to my server, I call it
> http://www.experimedia.vic.gov.au/~pfong/cgi-bin/pattemp.cgi it returns
> me the download of the file on the web browser. It should print out my
> favourite color after processing the form.
> 
> Am I missing some setting on perl, cgi-bin directory, public_html
> directory that causes this?

This question is totally unrelated to Perl.  Something you could have
worked out if you'd either asked yourself the simple question "would
by situation be likely to be different if I'd written my CGI script in
Python?".  If you think about what is going wrong it is clearly going
wrong at an earlier stage in the HTTP/CGI process than the point at
which the Perl interpreter gets involved.

You must configure your web server software to know either that files
in your cgi-bin directory or files with a .cgi suffix are executable
as CGI scripts.  For details of how to do this check the documentation
for your web server software.  Or ask you web administrator.  Or post
to a newsgroup where webserver configuration is discussed.

> Sent via Deja.com

Deja.com has a Usenet search engine.  Since this question is asked
here at least once a week how come you didn't find it?

Perhaps is could be because most of the people who post this question
are too selfish to bother giving the thread a descriptive subject
line.  Don't you just hate people like that?

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Thu, 21 Dec 2000 14:23:16 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Range operator with incremental (step size)
Message-Id: <91s7oo$qlj@netnews.hinet.net>

Dear all,

Range operator, by nature, has a step size.  This is true
in many programming languages.  Perl's primitive range operator
has only fixed step size = 1.  IMHO, this could be extended.

    print 'A'..'Z' :2;
    ACEGIKMOQSUWY

Step down

    print for 1000000..1 :-1;

is better than

    print for reverse 1..1000000;  # because it creates a large list

Other examples are

    @slice = @array[1..100:5];

    perl -ne 'print if 20..30:5'

as short hand for

    perl -ne 'print if $range = 20..30 and ($range-1) % 5 == 0'

as well as

    perl -ne 'print if /START/..eof :2'  # every other line

Although they are all achievable by map and for(;;),
I think step size is more natural and less twisted.
It also makes this language more complete.

What do you think about it?

John Lin





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

Date: Thu, 21 Dec 2000 13:14:58 GMT
From: trwww <trwww@my-deja.com>
Subject: Re: switch/case in Perl?
Message-Id: <91svoh$1pe$1@nnrp1.deja.com>

In article <91r20b$hoc$1@nnrp1.deja.com>,
  Adam Levenstein <cleon42@my-deja.com> wrote:
> In article <3a410424@cs.colorado.edu>,
>   tchrist@perl.com (Tom Christiansen) wrote:
> >
> > --tom, who's convinced he should globally killfile my-deja for
> >        fricking ever.
>
> But gee, then we'd miss your oh-so-polite, well-mannered responses. In
> fact, putting in a killfilter would undoubtedly take less time than
> making such a polite response every time someone asks a fairly simple
> question.
>

Do you know who Tom Christiansen is? He is one of the gentlemen that
take the time out of their busy day and write the documentation for
perl. He does it for absolutely nothing in return.

Lets say you wrote documentation. Lets even say you were getting paid
for it. How would you feel if you spent months, or even years, writing
documentation and then the day after you give it to your customer they
call you and say, "How do I turn this thing on?" Then tomorrow, they
call you back and ask the exact same thing? How would you feel?

You are even using deja... right below the post button is a button to
search every posting for the last 5 years. Do you not think ayone else
has asked this question?

--
trwww


Sent via Deja.com
http://www.deja.com/


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

Date: Thu, 21 Dec 2000 14:39:11 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: switch/case in Perl?
Message-Id: <Pine.LNX.4.30.0012211437580.9156-100000@lxplus003.cern.ch>

On Wed, 20 Dec 2000, Adam Levenstein wrote:

(to tchrist@perl.com , of all people...)

> But gee, then we'd miss your oh-so-polite, well-mannered responses. In
> fact, putting in a killfilter would undoubtedly take less time than
> making such a polite response every time someone asks a fairly simple
> question.

Your application for entry to the killfile has been enthusiastically
approved.



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

Date: Thu, 21 Dec 2000 13:49:39 GMT
From: Adam Levenstein <cleon42@my-deja.com>
Subject: Re: switch/case in Perl?
Message-Id: <91t1ph$3aq$1@nnrp1.deja.com>

In article <91svoh$1pe$1@nnrp1.deja.com>,
  trwww <trwww@my-deja.com> wrote:

> Lets say you wrote documentation. Lets even say you were getting paid
> for it. How would you feel if you spent months, or even years, writing
> documentation and then the day after you give it to your customer they
> call you and say, "How do I turn this thing on?" Then tomorrow, they
> call you back and ask the exact same thing? How would you feel?

Difference: I didn't call him. I didn't email him. My posting wasn't
directed at him. I didn't bother him personally at all. I posted a
general, public message, which was answered by a number of people who
*didn't* see the need to be rude.

> You are even using deja... right below the post button is a button to
> search every posting for the last 5 years. Do you not think ayone else
> has asked this question?

You're absolutely right, and I apologize for not doing so. It seems that
someone asked this question back in June, and he went without
Christiansen throwing a hissy fit.

Now, with that over with, I'm going to spend my time doing more
intellectually profitable things than talking about politeness on a ng -
such as putting my hand in a meat grinder.

--
-------------------------------------------------
Adam Levenstein
cleon42@my-deja.com

"Extraordinary claims require extraordinary evidence."
				-- Carl Sagan


Sent via Deja.com
http://www.deja.com/


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

Date: Thu, 21 Dec 2000 13:52:07 GMT
From: Adam Levenstein <cleon42@my-deja.com>
Subject: Re: switch/case in Perl?
Message-Id: <91t1u6$3d7$1@nnrp1.deja.com>



Ah, ok, thanks...No, I wasn't aware of it. I was hunting through the web
version. This will make my life a lot easier.

Adam

In article <91rl88$4a8$1@hermes.nz.eds.com>,
  "Peter Sundstrom" <peter.sundstrom@eds.com> wrote:
>
>
> You haven't found 'perldoc -q' ?
>
> perldoc -q switch
> perldoc -q case
>
> both find the relevant part from the FAQ
>
>

--
-------------------------------------------------
Adam Levenstein
cleon42@my-deja.com

"Extraordinary claims require extraordinary evidence."
				-- Carl Sagan


Sent via Deja.com
http://www.deja.com/


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

Date: Thu, 21 Dec 2000 11:14:38 GMT
From: trwww <trwww@my-deja.com>
Subject: Re: trying to count words - not working
Message-Id: <91somr$std$1@nnrp1.deja.com>

In article <91sc32$ja3$1@nnrp1.deja.com>,
  fhinchey@my-deja.com wrote:
>
>     $leftcnt = 0;
>
>     for ($body =~ m/<left>/g) {
>       $leftcnt++;
>     }
>

Hello Frank,

the camel book says:

while (m/ (\d+) /g) {
  print("Found Number: $1");
}

notice the while....

in list context, /g pulls out all the matches...

@matches = m/ (\d+) /g;

i do belive that after you do work inside parenthesis on an iterator
the return value is evaluated in list context, so it leads me to belive
that your code does work as expected??!!??

$body = 'you go <left> and you go ';
$body .= '<left> but you go <left> and you go <left>';

for ($body =~ m/<left>/g) {
       $leftcnt++;
}

print($leftcnt);

works dandy for me......
I would probably do it like this though:

$leftcnt = ($body =~ s/<left>/<left>/g);

in scalar context, s/ returns how many times the replacement was made.

This is a frequently asked question. have you tried using
www.deja.com/usenet/ and searching c.l.p.m.? I typed: count words into
its earch engine and got 19 matches from just this week. Its alot
faster than waiting for an answer.

trwww


Sent via Deja.com
http://www.deja.com/


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

Date: Thu, 21 Dec 2000 12:16:39 +0100
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: Understanding interpolation
Message-Id: <ifn34tks6p2suu3dk1fvbnh2p2rcatsf6l@4ax.com>

On 21 Dec 2000 04:52:00 GMT, The WebDragon <nospam@nospam.com> wrote:

 ...
> How would one re-write this to alternate every n lines.. so that instead 
> of every other line being different, it could be 2 and 2 or 3 and 3 and 
> 3 etc. ?
> 
> it's a nice trick, but what if you want more? :) embed the bgcolor in a 
> subroutine?

	my @colors = qw( orange red white blue );

	printf "Alternate every %u lines\n", scalar @colors;
	for my $cnt ( 0 .. (@colors * 2) - 1 ) {
		print "line $cnt -> $colors[ $cnt % @colors ]\n";
	}

	# or did you want:
	
	printf "\nHighlight every %u-th line\n", scalar @colors;
	for my $cnt ( 0 .. (@colors * 2) - 1 ) {
		print "line $cnt -> $colors[ $cnt % @colors?1:0 ]\n"
	}

-- 
Good luck,
Abe
perl -wle '$_=q@Just\@another\@Perl\@hacker@;print qq@\@{[split/\@/]}@'


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

Date: Thu, 21 Dec 2000 12:00:13 GMT
From: trwww <trwww@my-deja.com>
Subject: Re: Understanding interpolation
Message-Id: <91srcc$ukp$1@nnrp1.deja.com>

In article <3A41BDD0.4FE85440@qimr.edu.au>,
  Damian James <damian@qimr.edu.au> wrote:

> print $cgi->header,
>       $cgi->start_html("Test for alternating colours"),
>       &alternating_colours($n, \@rows),
>       $cgi->end_html;
>
> exit();
>
> sub alternating_colours {
>
>    ### need longer list of colours for n>6
>     my $colours = [ qw(red green yellow purple orange blue) ];
>
>     my $n = shift;
>     my $rows = shift;
>     my $count = 0;
>     my $table = "<table>";
>
>     foreach (@{$rows}) {
>         $table .= qq!<tr><td
> bgcolor="$colours->[($count++)%$n]">$_</td></tr>!;
>     }
>
>     $table .= "</table>";
>     return $table;
> }

That works if you are printing with a list, but what if you are in a
here document?

I found this thread facinating and did some more research:

perldoc perlref

Here's a trick for interpolating a subroutine call into a string:

  print "My sub returned @{[mysub(1,2,3)]} that time.\n";

The way it works is that when the @{...} is seen in the double-quoted
string, it's evaluated as a block. The block creates a reference to
an anonymous array containing the results of the call to mysub(1,2,3).
So the whole block returns a reference to an array, which is then
dereferenced by @{...} and stuck into the double-quoted string. This
chicanery is also useful for arbitrary expressions:

  print "That yields @{[$n + 5]} widgets\n";

Brilliant... this stuff gets more exciting every day

trwww


Sent via Deja.com
http://www.deja.com/


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

Date: Thu, 21 Dec 2000 12:25:26 GMT
From: patrick_k6801@my-deja.com
Subject: very strange thing with closures
Message-Id: <91ssrk$vo8$1@nnrp1.deja.com>

Hello out there.

I am desperately thrying to find, why this two subs behave in different
ways. Both are creating two closures that print out a variable (value 1
or 2). But only the second one is behaving correct and the closures are
printing 1 and 2. The first sub's closures are both printing 2. Has
anybody an idea about this ?

regards,
  Patrick

#!/usr/bin/perl

sub this_is_not_fucking
  {
    my $fucking_variable = 1;
    my $fucking_sub = sub { print $fucking_variable; };
    $fucking_variable = 2;
    my $another_fucking_sub = sub { print $fucking_variable; };
    &$fucking_sub();
    print "\n";
    &$another_fucking_sub();
    print "\n";
  }

sub this_is_fucking
  {
    my $fucking_list = ();
    for my $fucking_variable (1..2) {
      push @fucking_list , sub { print $fucking_variable; };
    }

    $fucking_list[0]();
    print "\n";
    $fucking_list[1]();
    print "\n";
  }

this_is_not_fucking();
this_is_fucking();


Sent via Deja.com
http://www.deja.com/


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

Date: Fri, 22 Dec 2000 00:02:31 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: very strange thing with closures
Message-Id: <slrn943vr7.8i7.mgjv@martien.heliotrope.home>

On Thu, 21 Dec 2000 12:25:26 GMT,
	patrick_k6801@my-deja.com <patrick_k6801@my-deja.com> wrote:
> Hello out there.
> 
> I am desperately thrying to find, why this two subs behave in different

*sigh* I just don't know why I thought it would be a good idea to clean
up my score file, and let my-deja through again. 3/4 of the irritating
posts today came from there. Time to fix that again, and to all my-deja
users who are not idiots: get a decent newsreader and news provider.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | 
Commercial Dynamics Pty. Ltd.   | Curiouser and curiouser, said Alice.
NSW, Australia                  | 


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 5170
**************************************


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