[18401] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 569 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 26 14:07:40 2001

Date: Mon, 26 Mar 2001 11:05:14 -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: <985633513-v10-i569@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 26 Mar 2001     Volume: 10 Number: 569

Today's topics:
        '@' in POSTed HTML form appears as '%40' (was: Email do nobull@mail.com
    Re: Basic socket logic (server) discussion... <mischief@velma.motion.net>
    Re: Error DBI (Mark Jason Dominus)
    Re: Error DBI nobull@mail.com
    Re: fetch back STDERR outputs nobull@mail.com
    Re: Followup - evaluating functions in a FILE nobull@mail.com
    Re: forking a process that stays around <tps12@columbia.edu>
        Help with reading between two points in a file. <joeybach@hotmail.com>
    Re: How adding Hours & Days to current date? (Arek P)
    Re: How to post to a newsgroup from a script? <waverley2000@hotmail.com>
    Re: How to post to a newsgroup from a script? <revjack@revjack.net>
    Re: keeping variations on a script up to date nobull@mail.com
    Re: Newbie (Mark Jason Dominus)
    Re: Newbie <clinton.munden@alcatel.com>
    Re: Print "tar" Success or Failure <mischief@velma.motion.net>
    Re: Print To Same Line - No Carriage Return - Thanks! (Steve Reiss)
    Re: Sort messes up? (Mark Jason Dominus)
    Re: Sort messes up? <joe+usenet@sunstarsys.com>
    Re: Sort messes up? nobull@mail.com
    Re: Sort messes up? (Jay Tilton)
    Re: Statistics (Greg Bacon)
    Re: Sub String <carllindsay1978@nospam.hotmail.com>
    Re: Sub string nobull@mail.com
    Re: system() return value (BUCK NAKED1)
    Re: Writing a script to install Perl modules automatica <comdog@panix.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 26 Mar 2001 19:03:48 +0100
From: nobull@mail.com
Subject: '@' in POSTed HTML form appears as '%40' (was: Email do not show up in MYSLQ)
Message-Id: <u9n1a8flvf.fsf@wcl-l.bham.ac.uk>

Victor Prasad <vivekvp@spliced.com> writes:

> Subject: Email do not show up in MYSQL

Question has nothing to do with Email or MYSQL.  You should have been
able to work this out.  Furthermore it is not the case that something
"does not show up" but rather that one thing shows up as something
different.

Working out a relevant subject line for your post not only improves
the quality of discorse on the newsgroup but also is a valuable first
step in analysing the problem and solving it yourself.

Another step that comes before posting to Usenet is to look in the
FAQ.  Having worked out what was the question you were really asking
you'd have stood a good chance of recognising that it was in fact
closely related to the FAQ "How do I decode a CGI form?".
 
> I am trying to use an HTML form to a perl script to pass an email
> address in the form:
> 
> test@test.com
>
> It shows up in the database and perl script as:  test%40test.com

So you are say it's wrong in the perl script _before_ you wrote it to
the database.  The fact that you are writing it to a database is
therefore clearly irrelevant and certainly doesn't warrant mention in
the scarce space of a subject line.

Also you've not apparently done anything that uses this as an email
address so the fact that it happens to be an email address can't be
relevant.  All that is likely to be relevant is the fact that it is a
string that contains the '@' character.

> I am using the POST method - how do I get it to enter it correctly?

Of course the fact that this is a HTML form/CGI question _is_ relevant
and you should have mentioned this in your subject line.  As far as
you could have known the use of POST might have been relevant - but,
in fact, it probably isn't.

You are probably trying (and failing) to write your own low-level
CGI/HTML form processing logic rather than using the standard modules.
If you want to do this please read details of HTML form encoding (not
Perl related).  If you want clues at how to implement this stuff in
Perl then please study the sources of the standard modules.

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


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

Date: Mon, 26 Mar 2001 18:36:33 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Basic socket logic (server) discussion...
Message-Id: <tbv31hl9ugod9e@corp.supernews.com>

Uri Guttman <uri@sysarch.com> wrote:
>>>>>> "w" == wdstaff  <lafondd@sympatico.ca> writes:

>   w> hey peeps,

> i am not a peep.

Damn, there goes my mental image of Uri as a giant marshmallow
bunny rabbit.  Now I guess I'll have to picture him as a teddy bear
or something. ;-)

[snip  a bunch of stuff about wanting to write a chat server
 and Uri's comical responses (remember, the funniest things 
 in life are funny because they are true) ]

W, why can't you send data to a socket while it's taking input?
(Now I feel like I'm addressing PotUS).

If you really mean that you merely don't want a user to see output
from other messages until they complete their own input, then what
you want is a flag saying a user is sending a message and a buffer
that holds messages that have yet to be sent. If you have the memory,
you can keep a buffer for each user, but that's wasteful. I'd keep
a buffer of messages each with a way to identify which message is
which, and I'd keep an array or list of messages that each user has
not seen. This is really very similar to how things are done in a
Citadel-derived BBS for express messages.

Chris

-- 
Christopher E. Stith
Parking for people we like only. All other vehicles will be vandalized.



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

Date: Mon, 26 Mar 2001 16:45:51 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Error DBI
Message-Id: <3abf724f.4758$2a2@news.op.net>
Keywords: excretory, hoop, spoof, stater


In article <3ABF3300.48937B72@americasm01.nt.com>,
Bertrand, Jean-Starff [BAN:X740:EXCH] <bertj00@americasm01.nt.com> wrote:
>How can i fix that error

Is the DBD::Oracle module installed?
Does d:/ActivePerl/site/lib/auto/DBD/Oracle/Oracle.dll exist?
Do the permissions on that file allow you to read and execute it?

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: 26 Mar 2001 18:54:16 +0100
From: nobull@mail.com
Subject: Re: Error DBI
Message-Id: <u9vgowfmbb.fsf@wcl-l.bham.ac.uk>

"Bertrand, Jean-Starff [BAN:X740:EXCH]" <bertj00@americasm01.nt.com> writes:

> How can i fix that error

> 'd:/ActivePerl/site/lib/auto/DBD/Oracle/Oracle.dll'
 ...
> Access is denied

Have you eliminated the blindingly obvious?  I.E. that the permissions
on'd:/ActivePerl/site/lib/auto/DBD/Oracle/Oracle.dll' deny you access?

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


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

Date: 26 Mar 2001 18:54:58 +0100
From: nobull@mail.com
Subject: Re: fetch back STDERR outputs
Message-Id: <u9u24gfma5.fsf@wcl-l.bham.ac.uk>

"John Lin" <johnlin@chttl.com.tw> writes:

> nobull writes
> > "John Lin" writes:
> > > > Get rid of the local().
> > > Hmm... I thought it was a good habbit
> > No using local() is not a good habit.
> 
> open TOUCH,"+>zero-length.file" or die $!;
> # ... and implicitly close

Implicitly close?  Do you mean implicitly close when the script
terminates?  The above file would not be closed before that.

> Name "main::TOUCH" used only once: possible typo at line 1.
> 
> I remember I tried many ways to shut it up and finally found
> local *TOUCH;

If all you want is to suppress the "used once" I think I'd prefer:

use vars qw ( *TOUCH );

Of course what local() actually does is put an implicit close of the
filehandle at the end of execution of the current block.  This is no
bad thing most of the time but in the original post in this thread
this is exactly what you wanted to avoid since you wanted the file to
remain open so that it could be used in the END block.

> That's how I mis-got this habit of putting
> local *FILEHANDLE;
> before first using FILEHANDLE, just like the habbit of my();

Of course you best thing to do would probably be to ditch the old
filehandle syntax and use only the modern filehandle reference syntax
so that you can use my() and don't have to worry about local().  You
may even want to switch to the OO syntax (the IO::* modules) so that
files look just like any other object in Perl.

If you'd used a filehandle reference and my() in the original post
you'd have been OK because the closure action of END block would have
kept the file open even after the completion os the execution of the
block where the file was opened.

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


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

Date: 26 Mar 2001 19:01:20 +0100
From: nobull@mail.com
Subject: Re: Followup - evaluating functions in a FILE
Message-Id: <u9r8zkflzj.fsf@wcl-l.bham.ac.uk>

Michael Carman <mjcarman@home.com> writes:

> Gregory Toomey wrote:
> > 
> > [A]ssume we have a file test.htm that contains the following 3 lines:
> > Element is $mylist[1+2]
> > Server is $ENV{"SERVER_NAME"}
> > Func is @{[myfunc()]}
> > 
> > It's trivial to read the file into a list or variable.
> > But can the file be processed to correctly evaluate each line?
> 
> You want a template. There are lots of modules for doing this:
> HTML::Template
> Text::Template
> Text::MetaText
> Template Toolkit
> ...

Or for a quick one-liner solution:

chop ( my $substituted = eval "<<__EOF__\n$template\n__EOF__\n" );

Note: Yes, that is chop() and not chomp().  Of course I'm assuming
here that $template does not contain the sequence "\n__EOF__\n". You
may want to choose a more obscure string.

Very important caveat: This allows the template to contain arbitrary
Perl code.  This can be exteemly useful also but means you must only
use this solution if the template can only be edited by people who
would be trusted with edit access to the Perl script itself.  If you
do not have such complete trust you may want to look into the Safe
module (although the latter has never been proved to be 100% secure).

This really should be in the FAQ.  AFAIK the FAQ maintainer refuses to
let it in because he is affraid that people will write scripts using
this mechanism and then pass these scripts on to other people without
impressing on the latter the importance of then above caveat.  

This argument is, IMNSHO, greatly outweighed by two factors:

 1) This mechanism if used correctly is very useful.

 2) Eventually most Perl programmers will discover this mechanism
    independantly.  Not all of them immediately realise the dangers.
    Describing this technique in the FAQ and explaining the hazards
    would significantly _reduce_ the scope for secuity holes being
    introduced by the misuse of this mechanism.

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


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

Date: Mon, 26 Mar 2001 12:07:32 -0500
From: tps12 <tps12@columbia.edu>
Subject: Re: forking a process that stays around
Message-Id: <Pine.GSO.4.10.10103261206430.7080-100000@sawasdee.cc.columbia.edu>

Thank you. I added a "close STDOUT", and it seemed to work. I will take a
look at perlipc, though. Thanks.


On Sun, 25 Mar 2001, David Efflandt wrote:

> On Sun, 25 Mar 2001 13:00:14 -0500, tps12 <tps12@columbia.edu> wrote:
> >1. page loads and finishes loading
> >and
> >2. child runs regardless of when/whether parent exits
> >Is this possible?
> 
> perldoc perlipc
> 
> Look for daemonize.  You have to alienate the child from the parent by
> closing all the doors between them.
> 
> 

                                                         | tps
                                               --------- |   2we1ve
                                                         | r&r



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

Date: Mon, 26 Mar 2001 16:56:37 GMT
From: "Unknown" <joeybach@hotmail.com>
Subject: Help with reading between two points in a file.
Message-Id: <9xKv6.13974$y63.3661433@typhoon.tampabay.rr.com>

I new to Perl so forgive my inorance,
I need to create a script that can read through a file and print all
entries between two date stamps. The date/time stamps reads as like this 
Feb 7 02:02:02 [stuff].
the file lists in desending order (newer items towards the bottom).
With Perl how can I list all lines between two time stamps?


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

Date: Mon, 26 Mar 2001 13:40:41 EST
From: Arek@nospam.tv (Arek P)
Subject: Re: How adding Hours & Days to current date?
Message-Id: <99o2f9$2e9i$1@earth.superlink.net>

On Sat, 24 Mar 2001 02:07:16 GMT, macv@multiweb.nl (MAC) wrote:

> Cano someone help me with this :
> 
>I need a sub routine that adds xx number of days or xx number of hour to a
>already existing valid date like the current time and date.
> 
>This sub routine has to add these days or hours and checks if it is a  
>valid
>date, and returns the new found date.
> 
>Please can someone help, cause now when i add the dates, i do not know how
>to check for a valid date or time. I come to problems when i add say: 8
>hours to a time when the time is already 23:59 or... adding 14 days, while
>tracking the number of days in a month.


Try this;

$hr=60*60; 	#60 second * 60 minutes in an hour
$day=$hr*24;	#see the logic?

so to add 2 days and 5 hours to right now would be ;

my $future=time() + 2*$day + 5* $hr ;

U may want to read about time and localtime....

				ArekP






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

Date: Mon, 26 Mar 2001 18:32:35 +0100
From: "Chris Thompson" <waverley2000@hotmail.com>
Subject: Re: How to post to a newsgroup from a script?
Message-Id: <985627951.7553.0.nnrp-08.c1ed3545@news.demon.co.uk>

>  Chris> My own (novice's) interpretation of this is that somehow the
>  Chris> $nntp variable isn't getting initialised properly in the "my
>  Chris> $nntp = new Net::NNTP('news.demon.co.uk');" line of the
>  Chris> script, though I am not sure how to get this working. The news
>  Chris> server specified is not the one where the script is hosted,
>  Chris> does this matter?
>
> Yes.
>
> I won't be any more explicit than that, or point out any of the other
> bugs in your script, because automated posting of job ads is an abuse
> of Usenet. In some newsgroups it's got so bad that no-one reads them
> anymore except spam-cancelling bots.
>
> The only advice I'll give you is to go and read this:
> <http://www.eyrie.org/~eagle/writing/rant.html>
>
> --
> Andrew.


Whilst I applaud your community spirit, suffice it to say that the
application I am writing is intended to post details of a very limited
numbers of vacancies to relevant jobs newsgroups where the content would be
of direct interest to readers.  I hardly think this is comparable to dumping
thousands of (often spurious) jobs to inappropriate groups.  If you wish to
discuss this matter further, I suggest you email me, so that this thread can
be kept on-topic.

Needless to say, I'd still be grateful if anyone can help me with getting my
script to work (included below).

Kind regards,
Chris


#!/usr/local/bin/perl -w

use CGI;
use CGI::Carp qw{fatalsToBrowser};
use strict;
use Net::NNTP;

my $co = new CGI;
my $nntp = new Net::NNTP('news.demon.co.uk');

print $co->header;

my @newsgroups_to_send_to = split(" ", $co->param('newsgroups'));  # gets
the newsgroups to send to

# construct content of posting
my @posting = qq`
Position: Web Developer
Web developer required to join prestigious Internet consultancy.
----------
`;

# loop through all of the newsgroups to send to and send details to each one
using the net::nntp module
my $newsgroup_to_send_to;
foreach $newsgroup_to_send_to (@newsgroups_to_send_to) {

    # select newsgroup
    $nntp->group($newsgroup_to_send_to);

    # post message
    $nntp->post(@posting);
};

# display success message
print qq`
<HTML>
<HEAD>
<TITLE>Post Vacancy Details to Newsgroups</TITLE>
</HEAD>
<BODY>

<H1>Post Vacancy Details to Newsgroups</H1>

The vacancy has been succesfully posted to the selected newsgroups.<P>

</BODY>
</HTML>
`;





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

Date: 26 Mar 2001 18:25:56 GMT
From: revjack <revjack@revjack.net>
Subject: Re: How to post to a newsgroup from a script?
Message-Id: <99o1jk$igo$1@news1.Radix.Net>
Keywords: Hexapodia as the key insight

Chris Thompson <waverley2000@hotmail.com> wrote:

: # loop through all of the newsgroups to send to and send details to each one
: using the net::nntp module
: my $newsgroup_to_send_to;
: foreach $newsgroup_to_send_to (@newsgroups_to_send_to) {
:     # select newsgroup
:     $nntp->group($newsgroup_to_send_to);
:     # post message
:     $nntp->post(@posting);
: };

Wow. Really, really don't do this to usenet.

-- 
___________________
revjack@revjack.net


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

Date: 26 Mar 2001 18:29:55 +0100
From: nobull@mail.com
Subject: Re: keeping variations on a script up to date
Message-Id: <u9y9tsfnfw.fsf@wcl-l.bham.ac.uk>

Bart Lateur <bart.lateur@skynet.be> writes:

> Say I have a script, that is in pretty developed state. I want to make
> copies of that script on other sites, with some minor changes: a
> different data directory, a different lib directroy, a few minor changes
> in the data, such as server name or email address.
> 
> Next step: using diff, I get a list of all the changes.
> 
> But now, when I make modifications to the original script, additions or
> bug fixes, I'd like to be able to simply patch this modified script with
> the diff file, and generate an updated version of the variant script.
> 
> What's the easiest way to achieve this?

The conventional tool for this sort of thing is diff3 untility.

Alternatively you may get away with just using the "fuzz" parameter
when you patch.

> p.s. Stuffing all the modifiable data in a config file doesn't really
> help, as I'd still need to modify the path to the config file.

Consider using a config file that's itself as Perl module so is
located by searching @INC and/or consider using FindBin to locate the
config file.

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


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

Date: Mon, 26 Mar 2001 16:44:38 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Newbie
Message-Id: <3abf7207.4751$12b@news.op.net>

In article <3abf56c6@bluesky.reedtech.com>, Y <nospam@email.com> wrote:
>I am trying to delete a line from an array and it isn't working:
>
>open (FILE, "$file") || die $!;
> %data = <FILE>;
> delete %data {"$address1 $address2"};
>
>What am I doing wrong?

Everything.   First, %data is not an array.  It is a hash.

You'd better show a small smaple of the data in the file, and show a
specific example of what you are trying to do.  What you've shown so
far is so peculiar and wrong that I can't figure out what you really
want.  

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Mon, 26 Mar 2001 11:46:50 -0500
From: Clinton Munden <clinton.munden@alcatel.com>
Subject: Re: Newbie
Message-Id: <3ABF727A.32BEA7AF@alcatel.com>

I agree with what Mark said.  You must give more specs on what exactly you are
dealing with and what it is you want to do.

Clinton Munden
IPSec ToolKit Group
Alcatel Corp.

Mark Jason Dominus wrote:

> In article <3abf56c6@bluesky.reedtech.com>, Y <nospam@email.com> wrote:
> >I am trying to delete a line from an array and it isn't working:
> >
> >open (FILE, "$file") || die $!;
> > %data = <FILE>;
> > delete %data {"$address1 $address2"};
> >
> >What am I doing wrong?
>
> Everything.   First, %data is not an array.  It is a hash.
>
> You'd better show a small smaple of the data in the file, and show a
> specific example of what you are trying to do.  What you've shown so
> far is so peculiar and wrong that I can't figure out what you really
> want.
>
> --
> @P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
> @p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
> ($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
> close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print



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

Date: Mon, 26 Mar 2001 18:22:09 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Print "tar" Success or Failure
Message-Id: <tbv26hnlabr50b@corp.supernews.com>

What A Man ! <whataman@home.com> wrote:
> Tad McClellan wrote:
>> 
>> BUCK NAKED1 <dennis100@webtv.net> wrote:
>> >
>> >> peter.sundstrom-eds@eds.com
>> >> *All* Unix commands return a status
>> >> code. They do *not* return nothing for
>> >> success, they generally return 0.
>> >

[snip]

>> Yet another good reason to ask questions in the right newsgroup :-)

[snip]

> weren't about how to use tar. They were about getting the correct Perl
> coding to implement it's correct exit status, and how to get perl to
> print success or failure. So, with all due respect, I think this was the
> proper newsgroup.

How so? It fits in a Perl newsgroup to ask what the status code
standard for Unix is? What if tar on some other platform needs
to be checked? What if you need to check the return status of
a program from another language? What is the constant here? What
is the variable? Nothing changes about this situation when changing
languages. What changes the outcome of this situation is when you
change platforms. Therefore, it is a platform question.

Chris

-- 
Christopher E. Stith
For the pleasure of others, please adhere to the following
rules when visiting your park:
    No swimming.  No fishing.  No flying kites.  No frisbees.
    No audio equipment. Stay off grass.  No pets. No running.



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

Date: Mon, 26 Mar 2001 17:54:30 GMT
From: NoSPAM@netmind.com (Steve Reiss)
Subject: Re: Print To Same Line - No Carriage Return - Thanks!
Message-Id: <3abb9cc8.9660671@news.got.net>

All,

Thank you for all of the help!  I'm glad it was a simple solution of
using the \r instead of \n.

This solution works fine on Win32, but on Solaris the output line
would remain at the prompt for the next command.  I fixed this by
adding a newline at the end of the loop :

for($i = 0; $i < 1000; $i++) {

 print "Loop = $i\r";

}
print "\n";



On Tue, 20 Mar 2001 22:58:27 GMT, trammell@bayazid.hypersloth.invalid
(John Joseph Trammell) wrote:

>On Tue, 20 Mar 2001 20:46:10 GMT, Steve Reiss <NoSPAM@netmind.com> wrote:
>> All,
>> 
>> I need to print out the progress of an operation as it iterates
>> through its loop.  I want to print this out on the same line so there
>> is no advancement of the row & column.
>> 
>> In other words, how do I print to the same row & column without a
>> carriage return?
>
>No, you want a carriage return, but no *newline*.  Try this:
>
>  #!/usr/bin/perl -w
>  use strict;
>  print "++++++++++ foo\r";
>  print "abcdefghij\n";
>

-----------------------------------------------------
Anti-Spam Device in Place:

To Reply : Replace NoSPAM with stever

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



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

Date: Mon, 26 Mar 2001 16:41:58 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Sort messes up?
Message-Id: <3abf7155.4744$3e@news.op.net>


In article <99nnfs$j49$1@newsy.ifm.liu.se>,
Jonas Nilsson <jonni@ifm.liu.se> wrote:
>print get_keys(\%a,\%b);
>print "\n";
>print sort get_keys(\%a,\%b);

sort gets an optional argument, interpreted as a function name, which
says how the items should be ordered; the default is alphabetical
order.    The typical use is:

        sort numerically (...);
        sub numerically { ... }

Or 

        sort descending_by_bank_balance (...);
        sub descending_by_bank_balance { ... }

>print sort get_keys(\%a,\%b);

Here Perl thinks you want to use get_keys as the comparison function.

use 

        { my @keys = get_keys(\%a, \%b);
          print sort @keys;
        }

instead.

>I can see that sort might use get_keys as a sub to sort the hashrefs, but
>why? Doesn't the syntax func($var) bind func rather tightly to ($var) ?

Not in this case.  It *could* work the way you want it to, but then

        sort descending (...);

would not work the way everyone else wants.

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: 26 Mar 2001 12:46:55 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Sort messes up?
Message-Id: <m37l1cbey8.fsf@mumonkan.sunstarsys.com>

mjd@plover.com (Mark Jason Dominus) writes:

> >I can see that sort might use get_keys as a sub to sort the hashrefs, but
> >why? Doesn't the syntax func($var) bind func rather tightly to ($var) ?
> 
> Not in this case.  It *could* work the way you want it to, but then
> 
>         sort descending (...);
> 
> would not work the way everyone else wants.

Why can't it work both ways? print() sometimes sees the difference
between foo() and foo (): 


  % perl -wle 'print foo ("bar"); sub foo {"hello ", shift }'
  Unquoted string "foo" may clash with future reserved word at -e line 1.
  Filehandle main::foo never opened at -e line 1.

  % perl -wle 'print foo("bar"); sub foo {"hello ", shift}'
  hello bar


It seems that it could (in principle) be done, but perhaps it's Not a 
Very Good Idea.

OTOH, all OP needs to do is break sort()'s strong prototyping behavior 
with "+":


  % perl -wle 'print sort +foo("bar"); sub foo {"hello ", shift}'
  barhello


But while I'm on the subject of prototypes, is there any rationale 
behind why "printf" and "print sprintf" behave so differently?


  % perl -wle 'print sprintf foo("bar"); sub foo {"hello %s", shift}'
  bar

  % perl -wle 'printf foo("bar"); sub foo {"hello %s", shift}'
  hello bar


Personally I like the latter behavior ("printf") better.  Can anyone
think of a situation where the scalar context enforced by sprintf on 
it's first argument could somehow be useful?

-- 
Joe Schaefer      "Peace cannot be kept by force. It can only be achieved by
                                       understanding."
                                               --Albert Einstein


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

Date: 26 Mar 2001 18:59:43 +0100
From: nobull@mail.com
Subject: Re: Sort messes up?
Message-Id: <u9snk0fm28.fsf@wcl-l.bham.ac.uk>

"Jonas Nilsson" <jonni@ifm.liu.se> writes:

> print sort get_keys(\%a,\%b);

> I can see that sort might use get_keys as a sub to sort the hashrefs, but
> why? Doesn't the syntax func($var) bind func rather tightly to ($var) ?

Yes rather tightly, but unfortunately not quite tight enough in this situation.

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


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

Date: Mon, 26 Mar 2001 18:25:03 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Sort messes up?
Message-Id: <3abf830e.120139710@news.erols.com>

On Mon, 26 Mar 2001 17:35:15 +0200, "Jonas Nilsson" <jonni@ifm.liu.se>
wrote:

>print sort get_keys(\%a,\%b);
>I can see that sort might use get_keys as a sub to sort the hashrefs,

You nailed it.

>but why?

Because that's how sort's syntax is defined.

>Doesn't the syntax func($var) bind func rather tightly to ($var) ?

That doesn't stop sort from trying to use it as the comparison
function, even though it will have an empty list to sort when it does.
Without being explicit, it can't know that you really want to sort the
list returned by get_keys.

This works as desired.
  print sort {$a cmp $b} get_keys(\%a, \%b);
Although having hashes named %a and %b there might confuse an unwary
reader.


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

Date: Mon, 26 Mar 2001 18:49:49 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: Statistics
Message-Id: <tbv3qddmaeoff0@corp.supernews.com>

In article <slrn9bntr8.p30.abigail@tsathoggua.rlyeh.net>,
    Abigail <abigail@foad.org> wrote:

: Martien Verbruggen (mgjv@tradingpost.com.au) wrote on MMDCCLXII September
: MCMXCIII in <URL:news:slrn9bnqct.ugg.mgjv@martien.heliotrope.home>:
:
: \\ Find all articles of Greg Bacon, with the subject 'Statistics for
: \\ comp.lang.perl.misc'. [...]
: 
: I once wrote a program that goes out to deja, grabs all the those
: articles, and graphs the usage, caching the results in a dbm file.
: 
: Deja is no more, but it shouldn't be too hard to adapt it for google.

I have an archive of the stats posts plus a bunch of other data for this
group going all the way back to 1997-12-19.  I'll be happy to make it
available to interested parties.

Greg
-- 
Anger is a gift.
    -- rage against the machine


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

Date: Mon, 26 Mar 2001 17:09:59 +0100
From: Carl Lindsay <carllindsay1978@nospam.hotmail.com>
Subject: Re: Sub String
Message-Id: <3ABF69D7.30194274@nospam.hotmail.com>


Thanks for that it works a treat.  And for the explanation I am used to java so
perl notation is a little strange for me, this helped a lot.

Thanks again.

Mark Jason Dominus wrote:

> In article <3ABF43F3.A615BFD4@nospam.hotmail.com>,
> Carl Lindsay  <carllindsay1978@nospam.hotmail.com> wrote:
> >i.e. checkbox2(-flags)
> >
> >I need to be able to have access to the -flags so the string in the
> >brackets I have tried:
>
>         ($part_in_parentheses) =
>             ($string =~ /\( (.*) \)/x );
>
>         # Now $part_in_parentheses has the value '-flags'
>
> Do not tamper with any of the parentheses here.  They are all important.
>
> In the pattern, \( means to look for a '(' character.
> Then (.*) means to look for something matching .* and then to 'capture' it.
> The \( means to look for a ')' character.
>
> The 'captured' data is assigned to the variable on the left, which is
> $part_in_parentheses.
>
> > $name[$i]=~ s/(\w+)/<$1>/;
> > $name[$i]=~ s/\(/ /;
> > $name[$i]=~ s/\)/ /;
> >
> >which works
>
> I don't see how it could.  The '-' in 'flags' will not match the \w+.
>
> --
> @P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
> @p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
> ($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
> close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print



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

Date: 26 Mar 2001 18:53:42 +0100
From: nobull@mail.com
Subject: Re: Sub string
Message-Id: <u9wv9cfmc9.fsf@wcl-l.bham.ac.uk>

Carl Lindsay <carllindsay1978@nospam.hotmail.com> writes:

> I was hopping that someone could help me I want to extract a string from
> another string is there a way to do this in perl

<VOICE TONE=SARCASTIC> No, abosolutely not.  Perl has no string
manipulation functions and certainly is not widely known for it's
powerful extended regular expressions.  Furthermore these regular
expressions are not documented in the in the standard documentation
that comes with Perl nor are they explained in any of the books or
tutorials you may have seen on Perl.</VOICE>

> i.e. checkbox2(-flags)
> 
> I need to be able to have access to the -flags so the string in the
> brackets

Do you mean you want to extract the bit starting following the first opening
parenthesis and ending before the subsequent closing parenthesis?

my ($bit_in_parenthises) = $string =~ /\((.*?)\)/;

> I have tried:
 
  [something complex using three s/// operators ]

Why?

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


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

Date: Mon, 26 Mar 2001 11:37:44 -0600 (CST)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: system() return value
Message-Id: <5175-3ABF7E68-15@storefull-246.iap.bryant.webtv.net>

Look at the "tar" threads where "system" return values are discussed. I
kinda wore people out on it, so I doubt if you'll find many who are
still willing to discuss this again so soon. :)

--Dennis



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

Date: Mon, 26 Mar 2001 10:52:31 -0600
From: brian d foy <comdog@panix.com>
Subject: Re: Writing a script to install Perl modules automatically
Message-Id: <comdog-58801D.10523126032001@news.panix.com>

In article <3ABEB938.5149FC7D@acedsl.com>, "Matthew O. Persico" 
<persicom@acedsl.com> wrote:

> Makhno wrote:

> > MyModule
> > MyModule/Somefink/Else
> > MyModule/YetMore

> > with the Makefile.PL at the end of this chain. Is there a 'nice' way of
> > installing the modules separately with a script without

what do you mean "at the end of the chain"?  do you have a Makefile.PL
in MyModule/ ?  are each of these subpackages distinct so that you have
to install them separately?

> > a) Combining all the modules into one big module (not an option)

> > b) Making my bash script search around the hierarchy for the Makefile.PL



> What's the big deal about (b)?  (UNTESTED CODE, but should work, modulo
> any typos)

> #!/bin/bash
> ## install_all_mods
> ## install all modules, unconditionally:
> cd /where_ever_it_is/MyModule
> make realclean
> perl Makefile.PL
> make test install

the part that this misses is dependencies.  i like to create a CPAN
bundle and let CPAN.pm take care of the hard work. :)

-- 
brian d foy <comdog@panix.com>



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

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 V10 Issue 569
**************************************


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