[19837] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2032 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 29 18:06:17 2001

Date: Mon, 29 Oct 2001 15:05:10 -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: <1004396709-v10-i2032@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 29 Oct 2001     Volume: 10 Number: 2032

Today's topics:
    Re: Can perl fill-in a web form without submitting it? (Qunfeng Dong)
    Re: DBI MySQL problems (Andrew Hutchinson)
    Re: digital signature <spam@thecouch.homeip.net>
    Re: double and single spacing <tintin@snowy.calculus>
    Re: double and single spacing <stuart@otenet.gr>
    Re: files in the process of being written <tintin@snowy.calculus>
        How can I make a \t be a tab? <mdudley@execonn.com>
    Re: How can I make a \t be a tab? (Clinton A. Pierce)
    Re: How can I make a \t be a tab? (Chas Friedman)
    Re: https and writing files <tintin@snowy.calculus>
    Re: keyname glob? (aaron smith)
    Re: keyname glob? <tony_curtis32@yahoo.com>
    Re: keyname glob? <uri@stemsystems.com>
    Re: keyname glob? (aaron smith)
    Re: Logic Question <tsee@gmx.net>
    Re: Performance gap in Benchmark.pm with/without Tk int <hen20040@bestweb.net>
    Re: Performance gap in Benchmark.pm with/without Tk int <hen20040@bestweb.net>
        perl build on different linux system. (yan lin)
        Perl from NT OS to Linux/Unix (Straatvark)
        question of Perl style using map <chris.wallace@lshtm.ac.uk>
    Re: question of Perl style using map <uri@stemsystems.com>
    Re: question of Perl style using map <usenet@diefenba.ch>
    Re: question of Perl style using map <mjcarman@home.com>
    Re: regexp and printing \0,\1 etc... <bart.lateur@skynet.be>
    Re: Regexp for email address <tintin@snowy.calculus>
    Re: Regular expression stumps me ... <bart.lateur@skynet.be>
    Re: Screen handling question <gellyfish@gellyfish.com>
    Re: Troubleshootng Bundle::libnet installation (Yury V Bukhman)
    Re: XML parsing <gellyfish@gellyfish.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 29 Oct 2001 22:37:31 GMT
From: qfdong@iastate.edu (Qunfeng Dong)
Subject: Re: Can perl fill-in a web form without submitting it?
Message-Id: <9rklnb$o5l$1@news.iastate.edu>

Hi Guys, 

Thanks so much for answering my web form question. I guess I didn't make 
my question clear. I will try it just one more time. 

I want to write a CGI script to create a web form (I know how to do 
this), collect some text info input from users. Then use the collected 
info to partially fill out another static web form at another website 
(How do I do that?). This lets users look at the partially filled-out 
(by my script) form and fill out the rest of the static web form. 

Thanks again!

Qunfeng 
-- 
Qunfeng Dong
qfdong@iastate.edu


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

Date: Mon, 29 Oct 2001 20:46:17 GMT
From: andrew.hutchinson@mcmail.vanderbilt.edu (Andrew Hutchinson)
Subject: Re: DBI MySQL problems
Message-Id: <3bddbf84.528897078@news.vanderbilt.edu>

I can only count to 29 without line numbers, so I'll only answer the
first part of your question.

At line 29, you say 

print header;

which would be valid of header were a filehandle.  However, I think
that what you mean is:

print $q->header();

You failed to reference the CGI object that you created, which makes
Perl think that you're referring to an unopened handle.

Hope this helps,

Andrew

On 29 Oct 2001 10:22:12 -0800, martinblack26@yahoo.com (martinblack)
wrote:

>Hi, I've been having trouble with this script from day one. I'm not
>sure what the problem is, but I'm trying to query the database with
>the form parameters ie: $product_id = $q->param('product_id');. If the
>item in question is already in the database, the script should UPDATE.
>If not, the script should INSERT. Instead, I get a 500 error. If I
>turn the warn flag on, I get:
>"Filehandle main::header never opened at add.cgi line 29". and
>"Use of uninitialized value at add.cgi line 107". I have totaly
>revamped this script about four times, nothing seems to work. Any help
>on this would be greatly apprecieated. Thanks in advance.
>Cheers. Martinblack. 
>
>Below is a copy of the script:
>
>#!/usr/bin/perl
>
>BEGIN {
>open (STDERR, ">html/error.txt");
>}
>
>### add.cgi
>
>	use DBI;
>	use CGI::Carp qw(fatalsToBrowser carpout);
>	use CGI;
>	$q=new CGI;
>
>
>	# input..................................
>
>	$io{'company_id'} = $company_id = $q->param('company_id');
>	$io{'product_id'} = $product_id = $q->param('product_id');
>	$io{'title'} = $title = $q->param('title');
>	$io{'description'} = $description  = $q->param('description');
>	$io{'spex'} = $spex  = $q->param('spex');
>	$io{'price'} = $price  = $q->param('price');
>	$io{'sex'} = $sex  = $q->param('sex');
>	
>
>	# mainline...............................
>
>
>	print header;
>
>	$DBname= "dbi:mysql:minmin";
>        $DBhost = "localhost";
>        $DBusername = "minmin";
>        $DBpassword = "fFUZsFtD";
>
>	$dbh = DBI->connect("$DBname:$DBhost", $DBusername, $DBpassword ||   
>  die "connection problem: ", $DBI::errstr;
>	$dbh->{'RaiseError'} = 1;
>
>	&kaboom;
>
>	&print_output || die "we've got a problem: ";
>
>  # Disconnect from the database
>	$dbh->disconnect || die "disconnection problem: ", $DBI::errstr;
>	exit;
>
>
> 
>	# the subs...............................
>
>
>sub print_output{
>   print<<HTML;
>    <HTML><BODY>   
>    <CENTER><FONT SIZE=5>
>     Record added to database
>      <P>
>     he he he ha ha
>      </P>
>    </FONT></CENTER>
>   </BODY></HTML>
>HTML
>
>} 
>
>sub kaboom() { 
>
>
>	$sth = $dbh->prepare( q[
>		SELECT company_id, product_id
>		FROM product
>		WHERE company_id = ? and 
>		product_id= ?
>	] ) || die "prep problem: ", $DBI::errstr;
>	$sth->execute( $company_id, $product_id ) || die "execution problem:
>", $DBI::errstr;
>
>	&fetch_results;
>	
>		
>	if ($newid) {
>
>	$dbh->do(do { local $" = ", "; qq[
>		UPDATE product
>		SET @{[map "$_ = ?", keys %io]}
>		WHERE company_id = ? AND product_id = ?
>	] }, undef,
>	values %io,
>	@io{qw(company_id product_id)} );
>
>	} else {
>
>	$dbh->do(do { local $" = ", "; qq[
>		INSERT INTO product (@{[ keys %io ]})
>		VALUES (@{[ ('?') x values %io ]})
>	] }, undef, values %io );
>		   
>	}
>}
>
>
>sub fetch_results {
>  
>    while ($x = $sth->fetchrow_hashref) {
>     $com = $x->{'company_id'};
>     $pro = $x->{'product_id'};
>   }
>	$newid = $com ."-".$pro;   
>}



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

Date: Mon, 29 Oct 2001 17:26:00 -0500
From: "Mina Naguib" <spam@thecouch.homeip.net>
Subject: Re: digital signature
Message-Id: <SHkD7.4677$NY2.262670@wagner.videotron.net>


"TD" <tushar08@yahoo.com> wrote in message
news:584a8362.0110290708.7abc27ca@posting.google.com...
> Hello All,
>
> Is there any way we can create digital signature using Perl
> I am fairly new in this....
>
> Here is what I need....
>
> 1) my current XML="<xml data....>"
> 2) signature = sign XML with private key using MD5 or SHA1
> 3) encodedsignature = base64.encode(signature)
> 4) publiccertificate= base64.encode(public cert)
> 5) now I can post data as
>
requestxml=XML&digitalsignature=encodedsignature&certificate=publiccertifica
te

I read an article a few weeks ago which might answer your question:

http://www.perl.com/pub/a/2001/09/26/crypto1.html

>
>
> Please help..if there is a better/best way than this....let me know.
>
> T.




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

Date: Tue, 30 Oct 2001 08:25:06 +1100
From: "Tintin" <tintin@snowy.calculus>
Subject: Re: double and single spacing
Message-Id: <iNjD7.6$O16.164908@news.interact.net.au>


"Jason Kohles" <usenet@jasonkohles.com> wrote in message
news:slrn9tpopq.rmv.usenet@poseidon.mediabang.com...
> On Mon, 29 Oct 2001 13:00:04 +0800, hugo wrote:
> >I have a problem I can't seem to solve although initially it seem
> >straightforward.
> >
> >I thought it would be easy enough to do this:
> >
> >open(INFILE, "$datafile");
> >       open(OUTFILE, ">$fileconvert");
> >       while (INFILE) {
> >        print OUTFILE "$_\n";  #here I add the extra newline
> >       }
> >       close (INFILE);
> >       close(OUTFILE);
> >
> >But nothing is written to the outfile, even if I change open(INFILE,
> >"$datafile"); to open(INFILE, "<$datafile");
> >
> Your problem has nothing to do with the open, it has to do with the fact
> that while(INFILE) doesn't mean anything, you seem to have meant
> while(<INFILE>).

The OP does have a problem with open (no error checking).  Not much point in
trying to read a file that isn't there or you don't have permission to read.




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

Date: Mon, 29 Oct 2001 23:35:22 +0200
From: "Stuart Gall" <stuart@otenet.gr>
Subject: Re: double and single spacing
Message-Id: <9rkj7h$oaj$2@usenet.otenet.gr>

"hugo" <hugo@fractalgraphics.com.au> wrote in message
news:3BDCE7DD.21F8052B@fractalgraphics.com.au...
> OOPs.. sorry about that first mistake - rather stupid really.
>
> Any ideas on the way to keep lines together? - I mean if I do the first
> operation (double spacing) I suppose I would have to re-open the output
> file once more to do the second operation, isn't it?  Or can they both
> operations be done together somehow?
>
open(INFILE, "<$datafile") or die;
open(OUTFILE, ">$fileconvert") or die;
      while (<INFILE>) {
        $q= 3 if /subsequently/;
      print OUTFILE;
    print OUTFILE "\n" unless $q
    $q-- if $q
}
close (INFILE);
close(OUTFILE);




--

Stuart Gall
------------------------------------------------
This message is not provable.



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

Date: Tue, 30 Oct 2001 08:13:42 +1100
From: "Tintin" <tintin@snowy.calculus>
Subject: Re: files in the process of being written
Message-Id: <vEjD7.4$7U5.146542@news.interact.net.au>


"Just in" <justin.devanandan.allegakoen@intel.com> wrote in message
news:9riiqi$8cl@news.or.intel.com...
> All,
>
> Theres a problem I have come across, and to date
> I haven't found a solution for.
>
> The problem itself is not related to Perl, and I wouldn't
> be surprised if I get a few catty replies, but its worth a
> post because you guys are omniscient, and I am but a
> mere mortal . . .
>
> Here's the beef:-
>
> I have a Perl program working as a scheduled task on
> a Windoze 2000 server.
>
> This utilises the Net::FTP module to connect to a
> Unix workstation to do some FTP'ng.
>
> The files on the Unix platform are created and written
> to at any random moment in time. As far as I can figure out
> the program running as a scheduled task has a nasty
> habit of FTP'ng files from the Unix workstation over to
> the 2000 server that haven't been finished being written to
> (on the Unix workstation).
>
> What I'm looking for is a way to tell


The usual ways include:

Using temporary filenames, temporary directories and permissions, or a
combination of all these.




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

Date: Mon, 29 Oct 2001 16:55:51 -0500
From: Marshall Dudley <mdudley@execonn.com>
Subject: How can I make a \t be a tab?
Message-Id: <3BDDD067.3E7F50D0@execonn.com>

I have a form where the user enters a delimiter they want a flat file to
use that they are about to download.  They have a box where they enter
the delimiter they want, ie. \t for a tab.

When I try to do a substitution with the "\t" that comes from the form,
it does not substitute a tab, but puts in a \t instead.  Even if I set a
variable to the input variable with "" which should convert it (like
$delimiter = "$in{'delimiter'}"), it still puts in "\t" instead of
[tab].

I.E.

$text = "This|is|a|test";
$delimiter = "$in{'delimiter'}";
$text =~ s/\|/$delimiter/g;
print $text;


result: This\tis\ta\ttest

Is there any way to get the reg to use a \t for a tab?

Thanks,

Marshall




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

Date: Mon, 29 Oct 2001 22:46:22 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: How can I make a \t be a tab?
Message-Id: <2%kD7.208887$K6.102634419@news2>

[Posted and mailed]

In article <3BDDD067.3E7F50D0@execonn.com>,
	Marshall Dudley <mdudley@execonn.com> writes:
> I have a form where the user enters a delimiter they want a flat file to
> use that they are about to download.  They have a box where they enter
> the delimiter they want, ie. \t for a tab.
> 
> When I try to do a substitution with the "\t" that comes from the form,
> it does not substitute a tab, but puts in a \t instead.  Even if I set a
> variable to the input variable with "" which should convert it (like
> $delimiter = "$in{'delimiter'}"), it still puts in "\t" instead of
> [tab].

If you don't mind danger:

	$delim=eval qq{"$in{delimiter}"};

-- 
    Clinton A. Pierce            Teach Yourself Perl in 24 Hours  *and*
  clintp@geeksalad.org                Perl Developer's Dictionary
"If you rush a Miracle Man,     for details, see http://geeksalad.org     
	you get rotten Miracles." --Miracle Max, The Princess Bride


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

Date: Mon, 29 Oct 2001 22:54:16 GMT
From: friedman@math.utexas.edu (Chas Friedman)
Subject: Re: How can I make a \t be a tab?
Message-Id: <3bddddfd.14765043@news.itouch.net>

On Mon, 29 Oct 2001 16:55:51 -0500, Marshall Dudley
<mdudley@execonn.com> wrote:

>I have a form where the user enters a delimiter they want a flat file to
>use that they are about to download.  They have a box where they enter
>the delimiter they want, ie. \t for a tab.
>
>When I try to do a substitution with the "\t" that comes from the form,
>it does not substitute a tab, but puts in a \t instead.  Even if I set a
>variable to the input variable with "" which should convert it (like
>$delimiter = "$in{'delimiter'}"), it still puts in "\t" instead of
>[tab].
>
>I.E.
>
>$text = "This|is|a|test";
>$delimiter = "$in{'delimiter'}";
>$text =~ s/\|/$delimiter/g;
>print $text;

>result: This\tis\ta\ttest
>
>Is there any way to get the reg to use a \t for a tab?
>
>Thanks,
>
>Marshall
 
If you have:

$_ = "This|is|a|test\n";
$x='\t';
s/\|/$x/g;
print;
$_ = "This|is|a|test\n";
$x="\t";
s/\|/$x/g;
print;

the output is:

This\tis\ta\ttest
This    is      a       test

Remark: In the following:
>$delimiter = "$in{'delimiter'}"; 
(The double quotes seem unnecessary.)
>$text =~ s/\|/$delimiter/g;
It is unclear how %delimiter defined. Have you set
$in{'delimiter'} to be '\t' perhaps?
              chas


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

Date: Tue, 30 Oct 2001 08:33:37 +1100
From: "Tintin" <tintin@snowy.calculus>
Subject: Re: https and writing files
Message-Id: <hVjD7.7$cR5.20501@news.interact.net.au>


"Ted Apke" <tedapke@apkesoftware.com> wrote in message
news:BMeD7.30096$IR4.18011349@news1.denver1.co.home.com...
> Indeed, it was that simple.  I thought I had the directory permissions
setup
> properly but, I didn't.  The error reported "Permission denied", or
> something equivalent.  I changed the directory where the file was to be
> created to 777 and gave the file write permisson to all and was in
business.

All of which demonstrates the importance of being able to separate Perl
problems from OS/CGI/Web server problems.




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

Date: 29 Oct 2001 11:19:19 -0800
From: asmith6@nc.rr.com (aaron smith)
Subject: Re: keyname glob?
Message-Id: <a52be220.0110291119.4845e210@posting.google.com>

> What is a "keyname glob"?  Don't expect people to understand technical
> terms you just made up for the nonce.

keyname = name of a key of a hash
glob = splat (*)

can i use a keyname glob in perl?

$hash{ke*}++ = $hash{key}++, $hash{keyname}++, $hash{keystone}++,
$hash{kermit}++, etc.


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

Date: Mon, 29 Oct 2001 13:27:57 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: keyname glob?
Message-Id: <877kteb60y.fsf@limey.hpcc.uh.edu>

>> On 29 Oct 2001 11:19:19 -0800,
>> asmith6@nc.rr.com (aaron smith) said:

>> What is a "keyname glob"?  Don't expect people to
>> understand technical terms you just made up for the
>> nonce.

> keyname = name of a key of a hash
> glob = splat (*)

That's not what glob() means.  "Wildcard" would be closer
to the mark, as you actually mean "regular expression".

> can i use a keyname glob in perl?

> $hash{ke*}++ = $hash{key}++, $hash{keyname}++,
> $hash{keystone}++, $hash{kermit}++, etc.

No, at least not directly.

You could iterate over a grep() of the keys() of the hash,
which is arguably as easy.

hth
t
-- 
Oh!  I've said too much.  Smithers, use the amnesia ray.


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

Date: Mon, 29 Oct 2001 19:33:06 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: keyname glob?
Message-Id: <x7lmhuxmu5.fsf@home.sysarch.com>

>>>>> "as" == aaron smith <asmith6@nc.rr.com> writes:

  >> What is a "keyname glob"?  Don't expect people to understand technical
  >> terms you just made up for the nonce.

  as> keyname = name of a key of a hash
  as> glob = splat (*)

lousy name you created out of thin air. globbing is actually a shell
expansion thing that perl borrowed. it is still only used for file name
expansion and never inside perl for any data filtering. that is done with
grep and regexes.

  as> can i use a keyname glob in perl?

no.


  as> $hash{ke*}++ = $hash{key}++, $hash{keyname}++, $hash{keystone}++,
  as> $hash{kermit}++, etc.

<untested>

$hash{ $_ }++ for grep /^ke/, keys %hash ;

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs  --------------------------  http://jobs.perl.org


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

Date: 29 Oct 2001 15:01:57 -0800
From: asmith6@nc.rr.com (aaron smith)
Subject: Re: keyname glob?
Message-Id: <a52be220.0110291501.1bf5f687@posting.google.com>

thanks all! Very helpful!


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

Date: Mon, 29 Oct 2001 21:45:02 +0100
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: Logic Question
Message-Id: <9rkf1v$sjm$03$1@news.t-online.com>

"Drew Myers" <bh_ent@hotmail.com> schrieb im Newsbeitrag
news:d1b6a249.0110290621.2256bb5@posting.google.com...
| Hi,
|
| I'm in the process of planning a perl script.  I'm having trouble with
| some of the logic, and I'm hoping someone here will help.
|
| I have a list of items which may vary from 15-80 items.  The number of
| items in the list will not vary while the perl script is executing.  I
| store the items in @totest.
|
| The difficulty I'm having, is I want to do something to all the items,
| but in groups of 20.  For instance, if there are 15 items in the list,
| this is easy:
|
| while (@totest) {
|   ...something...
| }
|
| My problem is I don't know how to write the logic if there are more
| than 20 items in the list.
|
| A rough sketch of what I want to do would be:
|
| while (@totest) {
|   if (scalar(@totest) <= 20) {
|     ..do something good..
|   }
|   else {
|     ..do something bad..
|   }
| }
|
| However, this doesn't "do something good" on each of the items in
| groups of 20.
|
| Any ideas?

Hi,

Your code is wrong. Note that the problem with your code is that you're
always testing against the total number of elements in the array.

Not saying it's good code (splice is better as suggested by others), but
modifying your code like this should make it work:

foreach my $i ( 0 .. int(totest / 20) + 1 ) {
  my @slice = @totest[$i .. $i + 20]
}

Alright. It's got nothing to do with the original any more. ;)

Steffen
--
$_=q;33352987319029872958319011313364356732192639127636833335345138283712
3712336415083973397340602842912;;s;\n;;;print"\n";$o=$_;push@o,substr($o,
$_*4,4)for(0..24);pop@o;for(@o){$i++;print' 'x(26-$i).(chr$_/29-$i)."\n"}





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

Date: Mon, 29 Oct 2001 17:16:27 -0500
From: "Hans N." <hen20040@bestweb.net>
Subject: Re: Performance gap in Benchmark.pm with/without Tk interface
Message-Id: <ttrkp87a8t7bf@corp.supernews.com>



"Benjamin Goldberg" <goldbb2@earthlink.net> wrote in message
news:<3BDD5F3A.D7C64B7D@earthlink.net>...
> [snip]
> >     sub Code1 {
> >       eval($code1); # Block to benchmark
> >     }
>
> I assume at this point, $code1 contains a string like '$x = 3' ?

Correct, but '$x = 3' is only for testing, most likely it will be any other
piece of code besides a simple variable assignment.

> [snip]
> > eval($x = 3); # Simulate optional block from Tk version
>
> First this does $x=3, then passes the result of that expression (3) to
> eval... so it's rather like doing eval('3')
>
> Which do you think should be faster, eval('$x = 3') or eval('3') ?

Obviously eval('3') would be faster. I was leaning more towards help with
the performance ramifications of using eval(). I found a huge make up in my
initial performance loss when I assigned the user code to an array, as
opposed to a scalar variable. But, I'm going to play off the post from Anno
Siegel and find a way to avoid recompiling the eval() statement for each
loop. I appreciate your effort, even though it was a tad bit off mark from
what I was hoping.

Hans N.




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

Date: Mon, 29 Oct 2001 17:17:52 -0500
From: "Hans N." <hen20040@bestweb.net>
Subject: Re: Performance gap in Benchmark.pm with/without Tk interface
Message-Id: <ttrkri2ne787d8@corp.supernews.com>

Thank you very much Anno, I know have a path to follow for a solution :^)

Hans N.

"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:9rjk9f$jr4$1@mamenchi.zrz.TU-Berlin.DE...

> Well, yes.  Code1 is a closure that will eval whatever $code1 contains
> each time it is called.  Since the code is compiled each time, the
> execution time has little to do with what you actually want to measure.
>
> Give only the code string to Benchmark::timethis, it knows what to
> do with it.
>
> Anno




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

Date: 29 Oct 2001 12:11:59 -0800
From: ylin@reshape.com (yan lin)
Subject: perl build on different linux system.
Message-Id: <e03ac419.0110291211.6165b23d@posting.google.com>

Hi everyone,
  I have a server linux 6.2, and my desktop is linux 7.1. I try to
build a perl and some packages on 7.1 and make it run both 7.1 and
6.2. It seems to me that I need to downward config my system to match
6.2. But config.sh is way complicated for me to tackle. Does anyone
has some success experience on it? Please help.


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

Date: 29 Oct 2001 13:15:29 -0800
From: gert@up-front.co.za (Straatvark)
Subject: Perl from NT OS to Linux/Unix
Message-Id: <2856a052.0110291315.4a5c076c@posting.google.com>

I have a piece of perl code i want to run on a Unix box.

I do remove the control-M's with a perl script on my windos OS
I do upload in ASCII mode with CuteFTP 4.2.2
I did try in with '#!/.../perl --' instead of '#!/.../perl' 

I even FTP downloaded a perl script that do run on the Unix box and
then upload it again with and without running the remove control-M's
perl script on it before uploading but always get the error included
in the bottom of this message.

Is it maybe that i miss something so basic that I'm supposed to run
the remove control-M's script on the Unix server?


thanx, gert

"Error Message: Permission denied 
Error Number: 13 
This message usually indicates there is a problem with the script
itself. Often this indicates either that the #! line of the script is
incorrect, or the script was uploaded in binary mode instead of ascii
mode. Check to make sure that the script does not have control-M's at
the end of every line. That will prevent it from executing. An easy
fix that takes care of this most of the time is to put '#!/.../perl
--' instead of '#!/.../perl' on the first line of the script. "


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

Date: 29 Oct 2001 20:14:10 +0000
From: chris <chris.wallace@lshtm.ac.uk>
Subject: question of Perl style using map
Message-Id: <m3snc2uru5.fsf@localhost.localdomain>

I am relatively new to Perl and trying to produce code that looks like Perl
(rather than C).  This post is a result of me trying to learn a Perl style.

I'm looking at the output of a simulation program, which simulates 1000 events
at a time.  I need at least $required of each possible event, and so loop over
the simulation, storing the cumulative number of each event till I have the
required number.

The question is how (Perlishly) to check all elements of this array are >=
$required?

My first effort is below (using a much smaller @array and $required for the
example):

#!/usr/bin/perl -w

use strict;

my $required=3;
my @array=(0,1,2);

while(1) {
  @array = map { ++$_ } @array;
  print "@array\n";

  # exit loop only if *all* elements of @array >= $required;
  my $continue=0;
  map { $continue=1 if $_ < $required } @array;  ###
  last unless $continue;
}

This is obviously fairly inefficient when @array is large and, say, $array[0]
< $required, since it cycles through the rest of the array unnecesssary after
testing $array[0].

So I replaced the line marked ### with

  for (@array) {
    if($_ < $required) {
      $continue=1;
      last;
    }
  }

which works, but looks clunky (to me).  Question: is there a way to do this
with map, similar to above or another (better) approach?  Note that @array and
$required may both be quite large.

Many thanks, Chris.


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

Date: Mon, 29 Oct 2001 20:12:07 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: question of Perl style using map
Message-Id: <x7g082xl15.fsf@home.sysarch.com>

>>>>> "c" == chris  <chris.wallace@lshtm.ac.uk> writes:

  c>   for (@array) {
  c>     if($_ < $required) {
  c>       $continue=1;
  c>       last;
  c>     }
  c>   }

	for ( @array ) {

		last if $_ < $required ;

		blah ;
	}

the statement modifiers and flow control ops work very well
together. you can eliminate many levels of braces and indents by
judicious use of them. one improvement i see all the time is an if/then
clause with a next and also an else clause. the next usually obviates
the need for the else{} and the code in there could be indented left. it
makes for much less cluttered code.

and the number of bugs is really tied to lines of code on average so
this will lower you bug counts over time as well. it is not compressing
code to an extreme but more of a concise and clearer way of expressing
flow controllogic.

  c> which works, but looks clunky (to me).  Question: is there a way to
  c> do this with map, similar to above or another (better) approach?
  c> Note that @array and $required may both be quite large.

the size of array doesn't matter there. 

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs  --------------------------  http://jobs.perl.org


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

Date: 30 Oct 2001 01:14:04 +0100
From: Kai Diefenbach <usenet@diefenba.ch>
Subject: Re: question of Perl style using map
Message-Id: <d9snc2ass3.fsf@diefenba.ch>

Hi, 
>>>>> "c" == chris  <chris.wallace@lshtm.ac.uk> writes:

 c>   @array = map { ++$_ } @array;
	
	$_++ for @array;

 c>   for (@array) {
 c>     if($_ < $required) {
 c>       $continue=1;
 c>       last;
 c>     }
 c>   } 
 c> which works, but looks clunky (to me).  Question: is there a way to do this
 c> with map, similar to above or another (better) approach?  
	
	I wouldn't use map here, because you don't need the return list, but 
	this is often discussed. see perldoc -q map
	
	for (@ary) { $continue=1, last if $_ < $required };		
	

Regards Kai

-- 
Linux - The choice of the GNU generation
12. Platz beim Linux-Slogan Wettbewerb (http://www.linux.de)


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

Date: Mon, 29 Oct 2001 14:56:38 -0600
From: Michael Carman <mjcarman@home.com>
Subject: Re: question of Perl style using map
Message-Id: <3BDDC286.99C35DE6@home.com>

chris wrote:
> 
> The question is how (Perlishly) to check all elements of this
> array are >= $required?

Probably the most idiomatic way would be to use grep:

   if (grep {$_ < $required} @array) {
      # At least one element < # required
   }

though it may not be the most efficient, because grep() is a list
operator.

>   for (@array) {
>     if($_ < $required) {
>       $continue=1;
>       last;
>     }
>   }
> 
> which works, but looks clunky (to me). 

You could compact it a little:

   for (@array) {
      next if $_ >= $required;
      $continue = 1;
      last;
   }

but it still does the same thing. Clunky or not, this is probably the
faster approach for very large arrays, because builtins (like grep)
won't short-circuit.

There may be a better overall algorithm for your particular problem, but
we would need more information.

-mjc


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

Date: Mon, 29 Oct 2001 19:32:01 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: regexp and printing \0,\1 etc...
Message-Id: <fkbrtt4ik4pu8b0j3eev2ltaa7eh5c79if@4ax.com>

M G wrote:

>If I was able to generate the source, believe me, I would simply refuse the
>creation of these things first

But where do you create those things? "\v" won't have any effect but in
in source code.

-- 
	Bart.


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

Date: Tue, 30 Oct 2001 08:23:34 +1100
From: "Tintin" <tintin@snowy.calculus>
Subject: Re: Regexp for email address
Message-Id: <SLjD7.5$SS5.108651@news.interact.net.au>


"Jürgen Exner" <jurgenex@hotmail.com> wrote in message
news:3bdcd35d@news.microsoft.com...
>
> "Glenn White" <spam.killer@home.com_nospam> wrote in message
> news:Xns9148C455FE541ccruizermydejacom@24.0.0.25...
> > I am writing a NT Perl program to take a text file, then mail the
contents
> > out using the TO and CC info from the file. The problem I'm running into
> > has to do with how the address can be listed. Since it is on a intranet,
> > the address can be either just the person's identifier or the whole
> > address. EX: WRFL or WRFL@TESTER.COM. I'm trying to use Sendmail by
> Milivoj
> > Ivkovic and have ran into a problem. It gives an error if I only use the
> > identifier.
> >
> > I've solved the problem for the FROM field with the following:
> [...]
> > Question? Am I way off on my attempt? Even if I do find a failure, then
I
>
> Are you dealing with internal addresses *only* or may those be regular
> Internet Email-Addresses, too? If you need regular addresses, too, then I
> suggest to read
>     Found in C:\Perl\lib\pod\perlfaq9.pod
>       How do I check a valid mail address?
>
> It's quite enlightening

And probably in need of updating to mention the various CPAN modules for
validating email addresses.




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

Date: Mon, 29 Oct 2001 19:28:24 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Regular expression stumps me ...
Message-Id: <u8brttsj4ipp04hl4m1fl0tu1n789vb6a9@4ax.com>

Philip S Tellis wrote:

>> > >  s|.*/$source_root/||o;
>> > >
>> > >that I'm not seeing?
>> > 
>> > Prevention of useless backtracking in case of a failure to match. In
>[snip]
>> 
>> Unless of course perl optomizes .* at the beginning into ^.*
>
>.* is not at the beginning.  It's at the beginning of the regex only. 
>The regex can still match anywhere within the string, and there's no
>reason for perl to optimise away from that.  Such optimisations would
>only break very valid regexes at other places.  Remember, . doesn't
>match a newline unless /s is specified.

Where else would you expect it to match, but at the beginning of a
string, or just after a newline?

So I do think you can safely optimize .* into (?m:^.*) (.* anchored at
beginning of line).

-- 
	Bart.


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

Date: 29 Oct 2001 22:10:55 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Screen handling question
Message-Id: <9rkk5f$389$5@neptunium.btinternet.com>

Colin Coe <coec@iinet.net.au> wrote:
> "Jonathan Stowe" <gellyfish@gellyfish.com> wrote in message
> news:9rgqmt$96q$3@neptunium.btinternet.com...
>> Colin Coe <coec@iinet.net.au> wrote:
>> > Hi all, I'm planying with a couple of screen handling modules (Curses and
>> > Term::Screen) but its not making much sense.  I have looked at the demo's
>> > included with Curses, looked through perldoc and checked out www.perl.com
>> > but still no joy.
>> >
>> > Can anyone point me at 'real live' examples using either (or both) of these
>> > screen handling modules.
>> >
>>
>>
>> This is far from a real life example but it shows most of the things that
>> Term::Screen can do:
>>
>> #!/usr/bin/perl
>>
>> require Screen;
>>
>> my $terminal = new Term::Screen;
>>
>>
>> $terminal->clrscr();
>>
>> $terminal->at(12,36)->reverse()->puts("Whatever")->normal();
>> $terminal->getch();
>> $terminal->clrscr();
>>
>>
>> It will print "Whatever" in the middle of the screen and wait for a keypress
>> before terminating.
>>
>> There appears to a problem with the current version of Term::Screen on CPAN
>> at the moment inasmuch as it installs itself as Screen and not Term::Screen
>> hence the 'require Screen' in the code above.  I will mail the fix to the
>> author :)
>>
> 
> What I want to do is have 3 windows with borders.  The first 2 take up the
> top 22 lines and 40 chars each, while the last is a sort of status area.
> How do I put borders around these and how can I use scroll bars?
> 

You really do need to use curses for this :)  I would suggest that you look
at the manpages for the curses functions on your system - check it out with
man -k curses ;-}


/J\
-- 
Jonathan Stowe                      |
<http://www.gellyfish.com>          |      This space for rent
                                    |


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

Date: 29 Oct 2001 12:41:17 -0800
From: ybukhman@hotmail.com (Yury V Bukhman)
Subject: Re: Troubleshootng Bundle::libnet installation
Message-Id: <3ee67e28.0110291241.6e23941@posting.google.com>

Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de> wrote in message news:<3BCE5F98.4010804@post.rwth-aachen.de>...
> bill wrote:
> 
> > I tried to install Bundle::libnet (following CPAN.pm's
> > recommendation), but the installation fails for reasons I don't
> > understand.  I include CPAN.pm's entire output below, but the crucial
> > portion, as far as I can tell, is this:
> > 
> >     Running make test
> >     PERL_DL_NONLAZY=1 /usr/local/bin/perl -Iblib/arch -Iblib/lib -I/usr/local/lib/perl5/5.6.1/i586-linux -I/usr/local/lib/perl5/5.6.1 -e 'use Test::Harness qw(&runtests $verbose); $verbose=0; runtests @ARGV;' t/*.t
> >     t/ftp...............skipped test on this platform
> >     t/hostname..........Use of uninitialized value in pattern match (m//) at blib/lib/Net/Domain.pm line 226.
> >     Use of uninitialized value in split at blib/lib/Net/Domain.pm line 233.
> >     ok
> >     t/nntp..............skipped test on this platform
> >     t/require...........FAILED tests 8-9
> > 	    Failed 2/11 tests, 81.82% okay
> 
> 
> That's an already known shortcoming of the test-suite that comes with 
> libnet. require.t eval()s several require()-statements, amongst those 
> testing for Net::SNPP and Net::PH which are not part of libnet. Just 
> edit t/require.t and remove the two lines that test for those modules or 
> install them before you 'make test' libnet.
> 
> [...]
> 
> Tassilo

I had the same problem as Bill.  Tassilo's advice worked for me, but
another problem popped up.  While most of libnet seems to install,
Net::Telnet still fails:

cpan> install Bundle::libnet  
[...]
t/select............FAILED test 3
        Failed 1/3 tests, 66.67% okay
Failed Test Status Wstat Total Fail  Failed  List of Failed
--------------------------------------------------------------------------------
t/select.t                     3    1  33.33%  3
Failed 1/1 test scripts, 0.00% okay. 1/3 subtests failed, 66.67% okay.
make: *** [test_dynamic] Error 29
  /usr/bin/make test -- NOT OK
Running make install
  make test had returned bad status, won't install without force
Net::Cmd is up to date.
Bundle summary: The following items in bundle Bundle::libnet had
installation problems:
  Net::Telnet

Anyone knows what to do about this one?

Yury


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

Date: 29 Oct 2001 22:02:10 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: XML parsing
Message-Id: <9rkjl2$389$4@neptunium.btinternet.com>

Spike <just.ice@mailcity.com> wrote:
> Hi. I am new to XML parsing and have enherited some code which uses
> XMl::Simple.
> This reads in the entire XML file and parses it into a data structure.
> However, when a large file is encountered the machine runs out of
> memory.
> 
> Is there some other way to deal with these XML files rather than the
> way outlined above? Perhaps a module which deals with the file in a
> step-wise fashion?
> 

Examine XML::Parser - this is what XML::Simple uses ...

/J\
-- 
Jonathan Stowe                      |
<http://www.gellyfish.com>          |      This space for rent
                                    |


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

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.  

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


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