[16836] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4248 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 7 11:10:30 2000

Date: Thu, 7 Sep 2000 08:10:14 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <968339413-v9-i4248@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 7 Sep 2000     Volume: 9 Number: 4248

Today's topics:
    Re: Perl and Cobalt Qube2 mj.stevenson@auckland.ac.nz
    Re: Perl and Cobalt Qube2 <info@ezboo.com.xx>
    Re: Perl and Cobalt Qube2 mj.stevenson@auckland.ac.nz
        Perl hases and memory <martin.djernaes@kecam-han.de>
    Re: Secure IMAP Connection <mjy@geizhals.at>
    Re: Sending mail with body from external file included <care227@attglobal.net>
        Small golf problem (Rafael Garcia-Suarez)
    Re: Small golf problem <rick.delaney@home.com>
    Re: Small golf problem <yanick@babyl.sympatico.ca>
    Re: Small golf problem <aqumsieh@hyperchip.com>
    Re: Stable sorting <bart.lateur@skynet.be>
        Trouble using CGI.pm on VMS Perl  <mflaherty2@earthlink.net>
    Re: use strict: why? <wyzelli@yahoo.com>
    Re: why does foreach iterate on an undef variable? <bart.lateur@skynet.be>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 07 Sep 2000 11:06:10 GMT
From: mj.stevenson@auckland.ac.nz
Subject: Re: Perl and Cobalt Qube2
Message-Id: <39b77723.592194831@news.chello.nl>

On Thu, 7 Sep 2000 10:34:08 +0200, "Thierry" <info@ezboo.com.xx>
wrote:

>sorry for last post (mistake, was not finished)
>
>Perl5 is installed on my Cobalt Qube2, but how to execute a simple Perl
>script ?
>like:
>###################################
>#!/usr/bin/perl
> print "Content-type: text/html\n\n";
> print "toto\n";
>###################################
>
>If I save this file as toto.pl and I chmod 755 I get an error message at
>execution.
>
>Thanks a lot for your help
>
>Thierry
>
>

First try 

/usr/bin/perl -V

then your file should read (no comment line across top)

#!/usr/bin/perl -w
print "Content-type: text/html\n\n";
print "toto\n";

Should work form the command line.

Matthew




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

Date: Thu, 7 Sep 2000 13:59:52 +0200
From: "Thierry" <info@ezboo.com.xx>
Subject: Re: Perl and Cobalt Qube2
Message-Id: <8p80hp$dtb$1@reader1.fr.uu.net>

It does not work.
But if I write

#!/usr/bin/perl -v
print "Content-type: text/html\n\n";
print "toto\n";

Then I have:
###
This is perl, version 5.004_04 built for mips-linux
Copyright 1987-1997, Larry Wall
Perl may be copied only under the terms of either the Artistic License or
the
GNU General Public License, which may be found in the Perl 5.0 source kit.
###

What's wrong ?
Thanks for your help.

Thierry

<mj.stevenson@auckland.ac.nz> a écrit dans le message :
39b77723.592194831@news.chello.nl...
> On Thu, 7 Sep 2000 10:34:08 +0200, "Thierry" <info@ezboo.com.xx>
> wrote:
>
> >sorry for last post (mistake, was not finished)
> >
> >Perl5 is installed on my Cobalt Qube2, but how to execute a simple Perl
> >script ?
> >like:
> >###################################
> >#!/usr/bin/perl
> > print "Content-type: text/html\n\n";
> > print "toto\n";
> >###################################
> >
> >If I save this file as toto.pl and I chmod 755 I get an error message at
> >execution.
> >
> >Thanks a lot for your help
> >
> >Thierry
> >
> >
>
> First try
>
> /usr/bin/perl -V
>
> then your file should read (no comment line across top)
>
> #!/usr/bin/perl -w
> print "Content-type: text/html\n\n";
> print "toto\n";
>
> Should work form the command line.
>
> Matthew
>
>




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

Date: Thu, 07 Sep 2000 12:04:52 GMT
From: mj.stevenson@auckland.ac.nz
Subject: Re: Perl and Cobalt Qube2
Message-Id: <39b78246.595045560@news.chello.nl>

On Thu, 7 Sep 2000 13:59:52 +0200, "Thierry" <info@ezboo.com.xx>
wrote:

>It does not work.
>But if I write
>
>#!/usr/bin/perl -v
>print "Content-type: text/html\n\n";
>print "toto\n";

Ok, here is a better explanation.

To check you have perl installed run ...

/usr/bin/perl -V

Now write a file with following lines ...

#!/usr/bin/perl -w
use CGI qw/:standard/;

print header;
print start_html;
print "This perl script is working\n";
print end_html;


Now change premissions

chmod 755 filename

Run the file

 ./filename
or
/usr/bin/perl filename

if this works perl is not the problem.

Now it looks like you want to have this run as a cgi-bin. Make sure
you have the correct ScriptAlias set up in Apache.

ScriptAlias /cgi-bin/ /your/cgi/bin/dir/

Go to www.apache.org they have a good FAQ on setting up Apache to run
cgi-bin.

Matthew







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

Date: Thu, 07 Sep 2000 16:17:31 +0200
From: Martin =?iso-8859-1?Q?Djern=E6s?= <martin.djernaes@kecam-han.de>
Subject: Perl hases and memory
Message-Id: <39B7A37B.C195C849@kecam-han.de>

Hi,

Before I start - please be kind to me I'm a C programmer just started to
get my first non-hello-world cgi script up and running.

My platform is P90 WinNT 4 w. 64MB+128MB swap+Apache 1.3+Perl 5!

I have created a script which read a file (about 512K) into an array,
for accessing the data a bit later.

Then I iterate through the list for finding some lines with special
values. These values I mark with a hash ($idx{$txt} = $line_no) so I
easy can find entries in the file later (the hash get about 1800
entries).

For getting a dataset from the list I have a function which receive the
ID (the ones I marked ealier in the hash) and return a new hash with the
information found (about 10 entries with small texts and numbers).

See now I can do several things, but I have experienced problems with
the following:

Worst: I have to get a data entry, print it, find links to several new
entries, loop through these entries and perform the same on these (I
have a infinite-loop control and max depth is about 15). I should never
have to have more than 30 entry hashes at the "stack" at the time.
See this did not work at my platform, but did atctually work on a Linux
PII450 128MB + Apache 1.3 + Perl 5.

Bad: I have a list of entries (lets say 80) which should be found and
printed. I get the entry from the hash, print it and get the next. I
should never have to have more than one hash on the "stack" at the time. 
This does only work for up to about 10 entries (at my platform), but on
the other Linux machine it works.

OK I have to admit that I have made it a bit simpler - there is a bit
more to it than just getting an entry and print it (some prints contain
several entries in one print), so I'm actually using more memory than
indicated.

See for getting this to work at my "lousy" machine, I started finding
out of what I could do to decrease the load on the machine, and thought
that I should create "local" variables (with my) for getting a dataset.
(my %hash;) and call my function with a reference (func(\%hash);). The
function processing (filling, printing or whatever) uses the hash via
the reference (my $local_hash = $_[0];).

In this way I experienced that calling a function which again were
calling a function which uses the hash were killing my
script/apache/machine.

Is references the way to go? should I use global variables (I hate them
as a C programmer)? should I change to the "local"  decleration? etc.

What do you think - I'm I expecting the impossible, or do I just not
know how to code in perl yet?

Please help me!

Martin


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

Date: Thu, 7 Sep 2000 11:44:48 +0200
From: "Marinos J. Yannikos" <mjy@geizhals.at>
Subject: Re: Secure IMAP Connection
Message-Id: <7ro7p8.tu71.ln@192.168.1.43>

"Matthew Ramadanovic" <matthew.ramadanovic@yale.edu> wrote in message
news:8p7cas$5oi$1@news.ycc.yale.edu...
> I need to authenticate by connecting to an IMAP server (a different server
> than the web
> server).[...]
> The server supports SSH client connections.

The simplest way is probably to establish an ssh tunnel
(ssh -L12345:localhost:143 remote.host.com) and use that ...

-mjy
--
Dipl.-Ing Marinos J. Yannikos                    E-Mail: mjy@geizhals.at
Preisvergleich Internet Services AG     Tel.: (+431) 5811609-50
Linke Wienzeile 4/2/5, A-1060 Wien, Austria/EU     Fax: (+431) 5811609-55





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

Date: 07 Sep 2000 14:59:08 GMT
From: Drew Simonis <care227@attglobal.net>
Subject: Re: Sending mail with body from external file included
Message-Id: <39B7AABC.C086C446@attglobal.net>

Marcel van de Burgwal wrote:
> 
> Somebody asked me to write a perl program which can do the following:
> -Results of HTML form used for start .cgi file
> -URL contains:
>  x Email address to send mail to
>  x number of file containing message body (files called mail1.txt, mail2.txt
> .. mail14.txt)
>  x few numbers which have to be substituded in the mail_.txt file
> 
> I'm quite new to perl so I'm not sure what I'm doing right or wrong.
> Because the program is little too big, I included an attackment with it.

You've made a few oversights that I spotted right off.  You start 
your program like so:

:#!/usr/bin/perl
:
:use CGI;
:
:$cgiobject= new CGI;

What you should be using is:

#!/usr/bin/perl -Tw
use strict;
use CGI;


> If somebody could help me.. I would be very pleased if anybody knew what the
> errors are

Adding warnings (-w) and taint checking (-T) will help you alot.  
The strict module (use strict;) will also be of great benefit in 
figuring out your errors.


Also, I noted odd things like:

sub subst_procent {
  local i=0;
  for (i=0; i<$lines; i++) {
    $lines[i]=~ s/\"(procent_1)\"/$percent1/g;      #replace procent_1
with $percent1
    $lines[i]=~ s/\"(procent_2)\"/$percent2/g;      #replace procent_2
with $percent2
  }
}

You are using i?  not $i?  That is bad, and using warnings and strict 
would have alerted you to these mistakes.  Also, you use $lines as a 
counter, but that variable (as far as I can see) is undefined before 
its use.  This is an example of the sort of thing warnings and strict
help you catch.  

HTH


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

Date: Thu, 07 Sep 2000 12:19:23 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Small golf problem
Message-Id: <slrn8rf29t.3rf.rgarciasuarez@rafael.kazibao.net>

Here's the problem :
I've an hash %foo, assocating keys to values that are either 0 or 1.
I want to construct a string 'key1,key2;key3,key4' from this hash,
where key1 and key2 are the keys associated to 1, and key3 and key4
the keys associated to 0.

I came up with this code :
  %foo = (key1 => 1, key2 => 1, key3 => 0, key4 => 0);
  print ((join ',' => grep {   $foo{$_} } keys %foo) . ';' .
         (join ',' => grep { ! $foo{$_} } keys %foo));
but I wonder if there is are shorter / smarter way to do it.
(besides the obvious removal of whitespaces...)

-- 
Rafael Garcia-Suarez | http://rgarciasuarez.free.fr/


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

Date: Thu, 07 Sep 2000 13:22:29 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Small golf problem
Message-Id: <39B79913.A43A8661@home.com>


Rafael Garcia-Suarez wrote:
> 
> I want to construct a string 'key1,key2;key3,key4' from this hash,
> where key1 and key2 are the keys associated to 1, and key3 and key4
> the keys associated to 0.
> 
> I came up with this code :
>   %foo = (key1 => 1, key2 => 1, key3 => 0, key4 => 0);
>   print ((join ',' => grep {   $foo{$_} } keys %foo) . ';' .
>          (join ',' => grep { ! $foo{$_} } keys %foo));
> but I wonder if there is are shorter / smarter way to do it.
> (besides the obvious removal of whitespaces...)

This only scans through the keys once.  I'm only using symrefs because
you said, "golf".

    @1,@0;push @{$foo{$_}},$_ for keys%foo;$"=",";print "@1;@0";

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Thu, 07 Sep 2000 13:27:02 GMT
From: Yanick Champoux <yanick@babyl.sympatico.ca>
Subject: Re: Small golf problem
Message-Id: <GIMt5.242428$1h3.4514070@news20.bellglobal.com>

Rafael Garcia-Suarez <rgarciasuarez@free.fr> wrote:
: Here's the problem :
: I've an hash %foo, assocating keys to values that are either 0 or 1.
: I want to construct a string 'key1,key2;key3,key4' from this hash,
: where key1 and key2 are the keys associated to 1, and key3 and key4
: the keys associated to 0.

: I came up with this code :
:   %foo = (key1 => 1, key2 => 1, key3 => 0, key4 => 0);
:   print ((join ',' => grep {   $foo{$_} } keys %foo) . ';' .
:          (join ',' => grep { ! $foo{$_} } keys %foo));
: but I wonder if there is are shorter / smarter way to do it.
: (besides the obvious removal of whitespaces...)

That one is a wee bit shorter. But I can't vouch
for the 'smarter' part. :)

my %foo = ( key1 => 1, key2 => 1, key3 => 0, key4 => 0 );

my $s = ';';
$s = $foo{$_}?"$_,$s":"$s,$_" for keys %foo;
$s =~ s/,?;,?/;/;

print $s;

Joy,
Yanick

-- 
$_="+21P-A6-d-.+i-51-12+V-#+22-;-L+6-2-H+6-21+R+3-5-13+T-12";
s/[#.A-Wild;]/ord$&/eg;while( /[-+]\d+/g ){   @a or @a=($&) and next; 
unshift @a, map {($_+$&)/2 => ($_-$&)/2} pop @a; } print map chr, @a;


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

Date: Thu, 07 Sep 2000 13:32:38 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: Small golf problem
Message-Id: <7aya145nuw.fsf@merlin.hyperchip.com>


rgarciasuarez@free.fr (Rafael Garcia-Suarez) writes:

> Here's the problem :
> I've an hash %foo, assocating keys to values that are either 0 or 1.
> I want to construct a string 'key1,key2;key3,key4' from this hash,
> where key1 and key2 are the keys associated to 1, and key3 and key4
> the keys associated to 0.
> 
> I came up with this code :
>   %foo = (key1 => 1, key2 => 1, key3 => 0, key4 => 0);
>   print ((join ',' => grep {   $foo{$_} } keys %foo) . ';' .
>          (join ',' => grep { ! $foo{$_} } keys %foo));
> but I wonder if there is are shorter / smarter way to do it.
> (besides the obvious removal of whitespaces...)

My first thought would be to invert the hash first:

	{
		my %inverted;
		local $" = ',';

		push @{$inverted{$foo{$_}}} => $_ for keys %foo;
		print "@{$inverted{1}};@{$inverted{0}}";
	}

But, if a better golf score is what you're after, then maybe something
like this:

	my $x = ';';
	substr $x, $foo{$_} ? 0 : length $x, 0, "$_," for keys %foo;
	print $x;

But this gives you a couple of extra commas. How about:

	my $x = ';';
	map { $x = $foo{$_} ? $x =~ /^;/ ? "$_$x" : "$_,$x" : 
                              $x =~ /;$/ ? "$x$_" : "$x,$_"
	    } keys %foo;
	print $x;

But this seems more like Bowling that Golf to me ..

--Ala


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

Date: Thu, 07 Sep 2000 13:52:28 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Stable sorting
Message-Id: <1c7frssd63dg2qs3vpk0ft8nqflh7d4vgp@4ax.com>

Abigail wrote:

>Then why do you want the ability to turn off stability?

I think he wants an option for a faster algorithm, that isn't
necessarily stable.

Or is merge sort the fastest sort around?

-- 
	Bart.


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

Date: Thu, 07 Sep 2000 13:09:34 GMT
From: "Mike Flaherty" <mflaherty2@earthlink.net>
Subject: Trouble using CGI.pm on VMS Perl 
Message-Id: <isMt5.25656$K4.1147823@newsread1.prod.itd.earthlink.net>

#!/usr/local/bin/perl

use CGI;
$query = new CGI;

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

When I run the above script on a Solaris box, I get...

sparky# ./billperl.pl
(offline mode: enter name=value pairs on standard input)
^Csparky#

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

this is expected.  However, when I run the same script (minus the path to
perl) on VMS, I get

DILBRT> perl billperl.pl

Unrecognized character \x13 at /perl_root/lib/shellwords.pl line 49.
Compilation failed in require at (eval 2) line 7.
%SYSTEM-F-NOLOGNAM, no logical name match
DILBRT>

Any Ideas.




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

Date: Thu, 7 Sep 2000 20:12:59 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: use strict: why?
Message-Id: <SiKt5.6$mX.1160@vic.nntp.telstra.net>


"Jonathan Stowe" <gellyfish@gellyfish.com> wrote in message
news:8p4nb8$qs4$1@orpheus.gellyfish.com...
>
> Anyhow using 'strict' gives you something to type in those awkward first
> moments of starting to write the program.
>

That is probably one of the best things about it! :)

More seriously though, it does force you to pause and consider the wider
ramifications of what you are about to do, which helps the initial process.

Wyzelli




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

Date: Thu, 07 Sep 2000 14:06:24 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: why does foreach iterate on an undef variable?
Message-Id: <e58frs0l29jfmjt2pfu5d2snrto2496vm9@4ax.com>

Paul Johnston wrote:

>I'm confused as to the logic of why a foreach loop block *is* entered when
>the LIST is undef (NOT expected), but *is not* when the LIST is an empty
>array (expected behavior):

An array cannot be undef(). If you do:

	@ary = "item";

then the array will ocntain one scalar item: "item".

undef() too is just a scalar. So

	@ary = undef;

is an array containing one undefined scalar.

-- 
	Bart.


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

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


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