[19795] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1990 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 23 11:06:17 2001

Date: Tue, 23 Oct 2001 08:05:11 -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: <1003849511-v10-i1990@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 23 Oct 2001     Volume: 10 Number: 1990

Today's topics:
        'REMOTE_HOST' (=?ISO-8859-1?Q?St=E9phane?=)
    Re: 'REMOTE_HOST' <diehard@nospam.userve.co.uk>
    Re: 'REMOTE_HOST' <jeff@vpservices.com>
    Re: alarm and termination before timeout (Mark Jason Dominus)
        Can anyone sugest a way to reduce the CPU usage of this (Stan Brown)
    Re: Can anyone sugest a way to reduce the CPU usage of  <please@no.spam>
    Re: create hashrefs / speed <please@no.spam>
    Re: Form Validation, detecting a comma <goldbb2@earthlink.net>
    Re: Form Validation, detecting a comma <SPG@NoMrtbbrtbrbref.com>
    Re: Form Validation, detecting a comma <bart.lateur@skynet.be>
    Re: Form Validation, detecting a comma <bernard.el-hagin@lido-tech.net>
    Re: Form Validation, detecting a comma <tintin@snowy.calculus>
    Re: Good Literature (Dave Cross)
        Hash to Array? <diehard@nospam.userve.co.uk>
    Re: Hash to Array? (Rafael Garcia-Suarez)
    Re: Hash to Array? <Thomas@Baetzler.de>
    Re: Hash to Array? <bart.lateur@skynet.be>
    Re: Hash to Array? <diehard@nospam.userve.co.uk>
    Re: Hash to Array? <tsee@gmx.net>
    Re: Hash to Array? <please@no.spam>
    Re: Hash to Array? <jurgenex@hotmail.com>
    Re: Hash to Array? <bart.lateur@skynet.be>
        How can i define a global variable ? <sasha_lui@yahoo.com>
    Re: How can i define a global variable ? (Mark Jason Dominus)
        multiple versions of the same module (D.J. Miller II)
    Re: Perl Vs. Java (Rafael Garcia-Suarez)
    Re: Perl Vs. Java (M.A. Oxby)
    Re: Premature end of script header <tony_curtis32@yahoo.com>
    Re: Webpage Passwords <news@scottbell.org>
    Re: Webpage Passwords <bart.lateur@skynet.be>
    Re: Webpage Passwords (John J. Trammell)
    Re: Webpage Passwords <jurgenex@hotmail.com>
        What the **** is WRONG with this!? <me@REMOVETHIStoao.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 23 Oct 2001 06:34:41 -0700
From: ange324@free.fr (=?ISO-8859-1?Q?St=E9phane?=)
Subject: 'REMOTE_HOST'
Message-Id: <6b593558.0110230534.e558402@posting.google.com>

Hi,

I have a problem with : 
print ("Host: "$ENV{'REMOTE_HOST'}"<br>\n");

When i do this command, i have the ip adress, why ?
What do i have to do to have the host name ?

Thanks.
Stéphane


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

Date: Tue, 23 Oct 2001 14:39:42 +0100
From: "Diehard Duck" <diehard@nospam.userve.co.uk>
Subject: Re: 'REMOTE_HOST'
Message-Id: <1003844387.17153.0.nnrp-08.9e98e2c7@news.demon.co.uk>

> I have a problem with :
> print ("Host: "$ENV{'REMOTE_HOST'}"<br>\n");
>
> When i do this command, i have the ip adress, why ?
> What do i have to do to have the host name ?

The hostname will only be shown if it has a name mapped to it (Reverse DNS
lookup).

If it doesn't then the IP address will be shown.

Try pinging an IP address and you may see what I mean.

DD




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

Date: Tue, 23 Oct 2001 06:45:54 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: 'REMOTE_HOST'
Message-Id: <3BD57492.D8570C3B@vpservices.com>

Diehard Duck wrote:
> 
> > I have a problem with :
> > print ("Host: "$ENV{'REMOTE_HOST'}"<br>\n");
> >
> > When i do this command, i have the ip adress, why ?
> > What do i have to do to have the host name ?
> 
> The hostname will only be shown if it has a name mapped to it (Reverse DNS
> lookup).
> 
> If it doesn't then the IP address will be shown.
> 
> Try pinging an IP address and you may see what I mean.

And there may be other reasons that you can't get the host name, none of
which has to do with perl.  Rather than getting half answers in this
newsgroup, you're better off asking your question in a group related to
CGI and and/or to web server issues where the answers are likely to be
more complete and more relevant to the group's readers.

-- 
Jeff



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

Date: Tue, 23 Oct 2001 13:34:22 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: alarm and termination before timeout
Message-Id: <3bd571dd.54e1$1a3@news.op.net>

In article <9r18jp$b03$1@wanadoo.fr>,
Gildas PERROT <perrot@NOSPAM.fluxus.net> wrote:
>eval {
>        alarm($timeout);
>        while (<CMD>) {
>                print $_;
>                if (/icmp_seq=2/) {
>                        print "PATTERN FOUND\n";
>                        last;
>                }
>        }
>        alarm(0);
>};
>close(CMD);
>
>if ($@) {
>        if ($@ =~ /TIMEOUT/) {
>                print "TIMEOUT\n";
>        }
>        else {
>                print "NORMAL END\n";
>        }
>}
>
>With that example,  "FOUND" is printed but not "NORMAL END" nor "TIMEOUT".

I tried your example.  When the command times out, it did print TIMEOUT.

You are exiting the while loop correctly, but NORMAL END is in the
wrong place.  That branch will only be reached if the 'eval' block
encounters a fatal error, such as a division by zero.  You did not
copy the example from the Cookbook.  In their example, they have a
second 'die' there, to abort the program if there is an unexpected
error.

I suggest that you replace the last 'if' block with:

        if ($@) {
                if ($@ =~ /TIMEOUT/) {
                        print "TIMEOUT\n";
                }
                else {
                        die;
                }
        } else {
                print "NORMAL END\n";
        }



-- 
@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: 23 Oct 2001 08:18:52 -0400
From: stanb@panix.com (Stan Brown)
Subject: Can anyone sugest a way to reduce the CPU usage of this script?
Message-Id: <9r3n7c$6nj$1@panix2.panix.com>

I'v got an old slow 486 acting as a network gateway. It spensd most of it's
time in itrupt handling under heavy network loading. It's runing an older
(3.x) version of FreebSD. routed is dying during these  high load periods.

I wrote the script below to restart it when it died. It works, but it uses
25 -> 40 of the CPU time itslef.

Anyone got any sugestiosn on how to do this with less load on the CPU?


#!/usr/bin/perl

#################################################################
#
#   routedwatcher.pl
#
#   @(#)routedwatcher.pl 
#
#       %W% %E% %U%	SCCS what string
#
#  10/22/2001 SDB Westvaco
#
# Perl  script to restart routed, if it dies.
# I'm having a problem with it dying under heavy network loading
# on a slow amchine, with an older version of FreeBSD
#
# NOTES:
#  1. process(es) to watch should be read from a config file
#  2. sleep time should be set from a config file
#  3. Might be a more eficent eeay of doing this, than walking
#     the whole process tree every time (perhaps keeping up with
#     the pid of the daemon we are watching?
#
################################################################

use strict;
use Proc::ProcessTable;
use Proc::PID_File;
use Proc::Daemon;
use Sys::Syslog;

my $found;
my $true = 1;
my $program = "routedwatcher";
my $Pid_File = Proc::PID_File->new(path=>"/var/run/$program.pid");
my $t = new Proc::ProcessTable;


# Check to make ceratin I'm not already runing
if (!$Pid_File->init)  { die "Can't open/create pid file: $!" }
if ($Pid_File->active) { die "routedwatcher is already running" }

# Become a daemon
Proc::Daemon::Init;

# Log our startup
openlog($program, 'cons,pid', 'user');
syslog('daemon|info', '$s started', $program);
closelog();

while ($true)
{
    $found = 0;
    # walk the process trree, looking for routed
    foreach my $p (@{$t->table}) {
      my $name = $p->fname;
      if ($name eq "routed")
      {
          # Good it's still runing
          $found = 1;
      }
    }
    # If we finished walking the whole process tree and never found a
	# process by that name
    # then we need to restart it
    if ($found != 1)
    {
       system "/sbin/routed";
       # Log the event, suing syslog
       openlog($program, 'cons,pid', 'user');
       syslog('daemon|warning', 'Had to restart routed: %d', time);
       closelog();
    }
    sleep 2;
}

-- 
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
						-- Benjamin Franklin


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

Date: Tue, 23 Oct 2001 14:51:08 GMT
From: Andrew Cady <please@no.spam>
Subject: Re: Can anyone sugest a way to reduce the CPU usage of this script?
Message-Id: <871yju5s51.fsf@homer.cghm>


Apparently, the routed process itself is dying (as opposed to locking
up), which means your approach here is all wrong.  You should
fork/exec and wait() for SIGCHLD (and loop when you get it).  But
then, not "you" personally (or your code).  Have init do this.  It
will likely do it better.  man 8 init; man 5 inittab.

stanb@panix.com (Stan Brown) writes:

> I'v got an old slow 486 acting as a network gateway. It spensd most
> of it's time in itrupt handling under heavy network loading. It's
> runing an older (3.x) version of FreebSD. routed is dying during
> these high load periods.
> 
> I wrote the script below to restart it when it died. It works, but
> it uses 25 -> 40 of the CPU time itslef.
> 
> Anyone got any sugestiosn on how to do this with less load on the CPU?

[...]

> my $true = 1;

Yuck.  Use while (1) or for (;;) for an infinite loop.  $true is
acceptable as a constant, but not as a variable.  This is very
dangerous.  (Reminds me of the jargon file entry for C+-).

[...]

OK, looking at it, I don't see where it would be taking up so much
CPU.  Your overall approach could be made much better, though.  As I
said, you should just wait().  However, even if we pretend there is no
SIGCHLD, a still better approach is to record routed's IP once when
you launch it, and then just use kill to check whether it's still
there every couple seconds.  Thus, your program stucture would be:

while (1) {
  my $pid;

  #start routed, set $pid to its pid

  while (kill 0, $pid) {
    sleep 2;
  }
}

This inner loop would take up hardly any CPU.  There is the
theoretical possibility that within those 2 seconds routed would die
and $pid would be assigned to another process.  In reality pid's are
not recycled that fast, but if you were paranoid you could check
$pid's (and just $pid's) process table entry.

Anyway, use init to do this for you, or SIGCHLD if you insist on
writing your own.

HTH.


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

Date: Tue, 23 Oct 2001 13:44:17 GMT
From: Andrew Cady <please@no.spam>
Subject: Re: create hashrefs / speed
Message-Id: <87bsiy5v8g.fsf@homer.cghm>

Jens Luedicke <jens@irs-net.com> writes:

> which code is faster? A benchmark showed no real differences, with a
> much larger code snippet. Comments?

No real difference.


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

Date: Tue, 23 Oct 2001 06:10:20 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Form Validation, detecting a comma
Message-Id: <3BD5420C.60ECAC6A@earthlink.net>

Bart Lateur wrote:
> 
> Benjamin Goldberg wrote:
> 
> >Perhaps someone will write a module which uses Parse::RecDescent to
> >determine if something is a valid email address?
> 
> It's been done (by Abigail): RFC::RFC822::Address

That's 822, not 2822.

-- 
Klein bottle for rent - inquire within.


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

Date: Tue, 23 Oct 2001 11:26:59 +0100
From: "Stephen Graham" <SPG@NoMrtbbrtbrbref.com>
Subject: Re: Form Validation, detecting a comma
Message-Id: <9BbB7.63674$sF.5884143@news2-win.server.ntlworld.com>

> But remember that, as Benjamin G. stated, you're not really
> checking for valid e-mail addresses with your regex. Maybe for your
> purposes the above is enough, but then again, maybe not.

Sure but getting into things like DNS lookups (if that's what RFC2822 does)
and so on is way over my head for Perl.

The script I've got seems to work fine for my purposes.

Thanks again.

SG





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

Date: Tue, 23 Oct 2001 10:57:52 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Form Validation, detecting a comma
Message-Id: <n5jatt8th2eq4lsftt0cj39oehv347n5lu@4ax.com>

Benjamin Goldberg wrote:

>> >Perhaps someone will write a module which uses Parse::RecDescent to
>> >determine if something is a valid email address?
>> 
>> It's been done (by Abigail): RFC::RFC822::Address
>
>That's 822, not 2822.

	Request for Comments: 2822
	Obsoletes: 822

   Earlier versions of this standard allowed for different (usually more
   liberal) syntax than is allowed in this version.
   Though some of these syntactic forms MUST NOT be generated according
   to the grammar in section 3, they MUST be accepted and parsed by a
   conformant receiver.

-- 
	Bart.


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

Date: 23 Oct 2001 10:59:51 GMT
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: Form Validation, detecting a comma
Message-Id: <slrn9taj1d.3nk.bernard.el-hagin@gdndev25.lido-tech>

On Tue, 23 Oct 2001 11:26:59 +0100, Stephen Graham <SPG@NoMrtbbrtbrbref.com>
wrote:
>> But remember that, as Benjamin G. stated, you're not really
>> checking for valid e-mail addresses with your regex. Maybe for your
>> purposes the above is enough, but then again, maybe not.
> 
> Sure but getting into things like DNS lookups (if that's what RFC2822 does)
> and so on is way over my head for Perl.


RFC2822 doesn't actually *do* anything. And I'm not talking about
DNS lookups. I'm talking about verifying if an e-mail address
is valid as specified by RFC2822 (which doesn't mean the address
actually has to exist). Your regex will miss many valid e-mail
addresses and thus is not compliant with RFC2822.


> The script I've got seems to work fine for my purposes.


If that's the case then the point above is moot.


> Thanks again.


You betcha.


Cheers,
Bernard	


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

Date: Tue, 23 Oct 2001 21:53:40 +1000
From: "Tintin" <tintin@snowy.calculus>
Subject: Re: Form Validation, detecting a comma
Message-Id: <iUcB7.23$aB7.322619@news.interact.net.au>


"Stephen Graham" <SPG@NoMrtbbrtbrbref.com> wrote in message
news:Lv9B7.62981$sF.5765693@news2-win.server.ntlworld.com...
> Hi All,
>
> I have a Perl script that checks the validity of an email address. However
> it doesn't seem to invalidate a 'comma', causing an incorrectly entered
> email to parse as two emails.

This question has been done to death.  A search on Google groups will reveal
many, many, many threads on validating email addresses.

Also you should read the FAQ

perldoc -q "valid mail"

and also check out some of the modules on CPAN for validating email
addresses.




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

Date: 23 Oct 2001 03:41:12 -0700
From: dave@dave.org.uk (Dave Cross)
Subject: Re: Good Literature
Message-Id: <9d3debce.0110230241.43952707@posting.google.com>

"Rob - Rock13.com" <rob_13@excite.com> wrote in message news:<Xns91431CCEE793Brock13com@64.8.1.226>...
> Dave Cross <news:3BD47402.3B1BDFDB@dave.org.uk>:

[snip]

> > [...] Liz Castro's "Perl and CGI for the WWW" is a
> > lot better than it was, but it's still not a great book. All of
> > the other "Learn Perl and CGI" books are rubbish.
> 
> I have one (c)1999 that I don't think mentions the CGI module or 
> the like. Personally I think it'd be easier to point at the CGI 
> module as a black box and show how to use it than to fiddle with 
> the raw CGI exchange.

And that's pretty much what Castro does in the second edition of her
book which was published earlier this year.

> > The three good Perl/CGI books that we have (the mouse book, the
> > spiky ball book and Lincoln's guide to CGI.pm) fail to appeal
> > to beginners. In fact, tey all assume a certain level of Perl
> > knowledge. 
> 
> Well, I can identify 2 out of 3 but what is the 'spiky ball book'? 
> As a beginner I must admit those were not my first considerations.

Oh, it's "Writing CGI Applications with Perl" by Kevin Meltzer and
Brent Michalski. Published by Addison-Wesley Pub, ISBN: 0201710145.

> > The only solution that I can see is that _someone_ is going to
> > have to write a respectable Perl/CGI for beginners book. 
> > 
> > Any volunteers?
> 
> I'd do it but don't know near enough Perl, probably not enough CGI 
> either. {crawling back under my rock now...}

I've also been told that Clint Pierce's "Teach Yourself Perl in 24
Hours" is a pretty good beginners book and the final third is
dedicated to CGI programming. So there might not be any need to write
a new one. Perhaps we just need to push Clint's book a bit more.

Dave...


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

Date: Tue, 23 Oct 2001 12:48:10 +0100
From: "Diehard Duck" <diehard@nospam.userve.co.uk>
Subject: Hash to Array?
Message-Id: <1003837694.14328.0.nnrp-08.9e98e2c7@news.demon.co.uk>

How can I safely convert

a) a %Hash into an @Array
b) an @Array into a %Hash

Thanks,
Russ




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

Date: 23 Oct 2001 12:07:03 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Hash to Array?
Message-Id: <slrn9tanbi.b3g.rgarciasuarez@rafael.kazibao.net>

Diehard Duck wrote in comp.lang.perl.misc:
> How can I safely convert
> 
> a) a %Hash into an @Array

    @array = %hash

> b) an @Array into a %Hash

    %hash = @array

but you may loose keys :
    $ perl -wle '@x=(1..4,1,6);%y=@x;print %y'
    1634

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


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

Date: Tue, 23 Oct 2001 14:22:47 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: Hash to Array?
Message-Id: <47oatt08brqo6is6bjo8mga5ukrvof95nq@4ax.com>

On Tue, 23 Oct 2001, "Diehard Duck" <diehard@nospam.userve.co.uk> wrote:

>How can I safely convert
>
>a) a %Hash into an @Array
>b) an @Array into a %Hash

By using the "=" operator:

#!perl -w

use strict;

my @array = (1, 'foo', 2, 'bar', 3, 'baz' );

my %hash = @array;

print "Hash:\n";

foreach ( keys %hash ){ print "$_ => $hash{$_}\n"; }

print "Array:\n";

@array = %hash;

print join(', ', @array), "\n";

__END__

HTH,
-- 
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl


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

Date: Tue, 23 Oct 2001 12:39:33 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Hash to Array?
Message-Id: <t7patts9cmle2s2dbgsauubn0mmpccmqai@4ax.com>

Diehard Duck wrote:

>How can I safely convert
>
>a) a %Hash into an @Array
>b) an @Array into a %Hash

Many ways. What are you trying to achieve?

-- 
	Bart.


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

Date: Tue, 23 Oct 2001 14:17:04 +0100
From: "Diehard Duck" <diehard@nospam.userve.co.uk>
Subject: Re: Hash to Array?
Message-Id: <1003843030.16599.0.nnrp-08.9e98e2c7@news.demon.co.uk>

"Bart Lateur" <bart.lateur@skynet.be> wrote in message
news:t7patts9cmle2s2dbgsauubn0mmpccmqai@4ax.com...
> Diehard Duck wrote:
>
> >How can I safely convert
> >
> >a) a %Hash into an @Array
> >b) an @Array into a %Hash
>
> Many ways. What are you trying to achieve?
>

glad you asked.

Basically, I have a script (which I didn't write...I'm hacking it for my own
needs).  It creates a hash of search results, pipe-delimited.  I need to put
these into an array to sort them.

I do

@srsearch_results = %search_results;

Which works, and then I sort the array into @srsorted_results

However, if I do

%search_sorted = @srsorted_results

There is data in the hash, but it's all mixed up again, defeating the object
of the entire exercise!

The other issue I have is that once the results are sorted there is a weird
string of numbers:

1021112230241223312613253228142733315293451643571763691881920

Before the actual ordered results.

Any light people can shed on this is much appreciated.

DD




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

Date: Tue, 23 Oct 2001 16:10:15 +0200
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: Hash to Array?
Message-Id: <9r3tl4$4cn$00$1@news.t-online.com>

"Diehard Duck" <diehard@nospam.userve.co.uk> schrieb im Newsbeitrag
news:1003843030.16599.0.nnrp-08.9e98e2c7@news.demon.co.uk...
| "Bart Lateur" <bart.lateur@skynet.be> wrote in message
| news:t7patts9cmle2s2dbgsauubn0mmpccmqai@4ax.com...
| > Diehard Duck wrote:
| >
| > >How can I safely convert
| > >
| > >a) a %Hash into an @Array
| > >b) an @Array into a %Hash
| >
| > Many ways. What are you trying to achieve?
| >
|
| glad you asked.
|
| Basically, I have a script (which I didn't write...I'm hacking it for my
own
| needs).  It creates a hash of search results, pipe-delimited.  I need to
put
| these into an array to sort them.
|
| I do
|
| @srsearch_results = %search_results;
|
| Which works, and then I sort the array into @srsorted_results
|
| However, if I do
|
| %search_sorted = @srsorted_results
|
| There is data in the hash, but it's all mixed up again, defeating the
object
| of the entire exercise!
|
| The other issue I have is that once the results are sorted there is a
weird
| string of numbers:
|
| 1021112230241223312613253228142733315293451643571763691881920
|
| Before the actual ordered results.

Cannot tell you anything about the last issue without looking at the code.

But I do know that normal hashes are by definition unordered. You'll have to
keep an ordered array of keys and access the hash using the ordered keys.

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: Tue, 23 Oct 2001 14:15:59 GMT
From: Andrew Cady <please@no.spam>
Subject: Re: Hash to Array?
Message-Id: <8766965trn.fsf@homer.cghm>

"Diehard Duck" <diehard@nospam.userve.co.uk> writes:

> glad you asked.
> 
> Basically, I have a script (which I didn't write...I'm hacking it
> for my own needs).  It creates a hash of search results,
> pipe-delimited.  I need to put these into an array to sort them.

Eh?  It's a hash of pipe-delimited results keyed against...  search
strings?  Something else?  Or are the results the keys?

> I do
> 
> @srsearch_results = %search_results;
> 
> Which works, and then I sort the array into @srsorted_results

Sorting an array assigned from a hash doesn't make sense.  Assigning a
hash to an array assigns key,value,key,value alternating between the
two.  Your sort will sort the keys and values together as if they were
the same thing.

> However, if I do
> 
> %search_sorted = @srsorted_results

Assigning an array to a hash makes every other element in the array
become a key/value.  That's not what you're trying to do here.  Also,
there's no such thing as a sorted hash.  It doesn't make sense.  A
hash is an associative array, it doesn't have an order (you need to
provide a key to access any data), and thus it can't be in
alphabetical order, or numerical order, etc.  If you want to access
its elements in order, you'll have to put them into an array and sort
it (and leave them there).  "each", "keys", and "values" make no
guarantee about the order in which they return elements from a hash.

> There is data in the hash, but it's all mixed up again, defeating
> the object of the entire exercise!

Why don't you just use the sorted array?

> The other issue I have is that once the results are sorted there is
> a weird string of numbers:
> 
> 1021112230241223312613253228142733315293451643571763691881920
> 
> Before the actual ordered results.
> 
> Any light people can shed on this is much appreciated.

Those sound like the values of the hash.  You probably wanted:

@srsearch_results = sort keys %search_results;

Which takes just the keys, not alternating key,value,key,value...


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

Date: Tue, 23 Oct 2001 07:43:18 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Hash to Array?
Message-Id: <3bd5820b@news.microsoft.com>

"Diehard Duck" <diehard@nospam.userve.co.uk> wrote in message
news:1003843030.16599.0.nnrp-08.9e98e2c7@news.demon.co.uk...
> "Bart Lateur" <bart.lateur@skynet.be> wrote in message
> news:t7patts9cmle2s2dbgsauubn0mmpccmqai@4ax.com...
> Basically, I have a script (which I didn't write...I'm hacking it for my
own
> needs).  It creates a hash of search results, pipe-delimited.  I need to
put
> these into an array to sort them.
>
> I do
> @srsearch_results = %search_results;
> Which works, and then I sort the array into @srsorted_results
> However, if I do
> %search_sorted = @srsorted_results
> There is data in the hash, but it's all mixed up again, defeating the
object
> of the entire exercise!

You are asking for a Union Jack (I noticed that you have a UK email address)
in green and yellow.
You cannot sort hashes because there is no sequence in hashes. Hashes don't
have a first, a last, or a next element. The very sentence "sorting a hash"
is meaningless.

Having said that I suggest you read the PerlFAQ4:
     How do I sort a hash (optionally by value instead of key)?
which tells you how to sort the keys or the values of the hash.

BTW: When you assing a hash to a an array the array will contain the keys
*and* the values of the hash as alternating pairs. An vice versa when
assigning an array to a hash the array will be split in pairs of elements
and the first element of each pair will be used as key, the second as value.
Now, if you sort the array and then assign it back to a hash you obviously
get a totally different hash with has little to do with the original one.

jue






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

Date: Tue, 23 Oct 2001 14:46:02 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Hash to Array?
Message-Id: <ec0btt8ui04dj6jh30epdk7d4baj0h9bd7@4ax.com>

Diehard Duck wrote:

>Basically, I have a script (which I didn't write...I'm hacking it for my own
>needs).  It creates a hash of search results, pipe-delimited.  I need to put
>these into an array to sort them.

Hmm... have you seen the entries on sorting in the FAQ? 

	How do I sort a hash (optionally by value instead of key)?

For more complex sorting requirement,s, for example if you want to split
your data into columns and sort on a combination of them, check out
stuff like the Schwartzian Transform, also in the (same) FAQ.

	How do I sort an array by (anything)?

Both are in perlfaq4, part of the standard documentation (i.e. "perldoc
perlfaq4" on the command prompt should work), but are also on the web,
for example, here: <http://www.perldoc.com/perl5.6.1/pod/perlfaq4.html>.

-- 
	Bart.


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

Date: Tue, 23 Oct 2001 14:41:22 +0200
From: "sasha" <sasha_lui@yahoo.com>
Subject: How can i define a global variable ?
Message-Id: <9r3nap$nj$1@newstoo.ericsson.se>

 Hi
 How can i define a global variable ?

 I have a small program which uses three modules, how can I call or change a
variable ( a variable which is defined in a main program  )  from a module ?

Thanks    Sasha









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

Date: Tue, 23 Oct 2001 13:25:57 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: How can i define a global variable ?
Message-Id: <3bd56fe4.54be$2e1@news.op.net>

In article <9r3nap$nj$1@newstoo.ericsson.se>,
sasha <sasha_lui@yahoo.com> wrote:
> Hi
> How can i define a global variable ?
>
> I have a small program which uses three modules, how can I call or change a
>variable ( a variable which is defined in a main program  )  from a module ?

        $main::var = 13;

-- 
@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: 23 Oct 2001 09:51:59 -0500
From: jamesm@sullivan.realtime.net (D.J. Miller II)
Subject: multiple versions of the same module
Message-Id: <kig08az9ww.fsf@sullivan.realtime.net>

Hello,

(Reposting message posted on comp.lang.perl.modules.)

Have searched the FAQs and newsgroup archives for an answer to this
question to no avail, so am posting it here:

Is there a way to run multiple versions of a Perl module on the same
Perl installation?

The problem is a bit hairier in that the module in question uses C (.xs)
extensions to an underlying DLL.

In particular, I'm trying to run XML::Parser 2.29 installed in a 'local'
library/module directory against an Active State installation of Perl
5.6.0, which includes XML::Parser 2.27 (installed in its "site"
subdirectory).  The script which needs version 2.29 starts out with

  use lib <path-to-local-perl-library>;

to ensure that it will get that newer version.  This falls down when
XML::Parser::Expat attempts to use DynaLoader (from the 5.6.0
installation) to load the underlying DLL.  DynaLoader's bootstrap method
is somehow getting hold of the XML::Parser::Expat version number in its
own tree (2.27) and dying when this doesn't match the version number it
was given by XML::Parser::Expat (2.29).

Building and installing 2.29 into the Active State Perl 5.6.0 tree
clears up the problem, but this isn't an acceptable general solution in
our shop; all existing Perl installations must keep their old
XML::Parser 2.27 modules.  Hence my search for a way to run two versions
'simultaneously.'

Can anyone suggest how this might be done?


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

Date: 23 Oct 2001 06:30:08 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Perl Vs. Java
Message-Id: <slrn9ta3jq.4ia.rgarciasuarez@rafael.kazibao.net>

Krishna Kumar wrote in comp.lang.perl.misc:
> Folks at my work are talking about using Java as a standard instead of Perl.
> 
> I have no knowledge of Java to agree or disagree with this.
> 
> They are trying to convince me that Java can do everything that Perl can.

Well, those languages are both Turing-complete.
The question is : what language is good for which use ?
Perl is much better at text processing (Java has no support for regexps
and very poor string handling primitives) and system-programming.
In fact it's very difficult to handle system calls within Java, because
Java aims to be portable and hence does not provide basic system calls
such as fork, chown or stat, to name a few.

-- 
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
perl -sleprint -- -_='Just another Perl hacker,'


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

Date: Tue, 23 Oct 2001 13:39:13 GMT
From: JHM1MAO@leeds.ac.uk (M.A. Oxby)
Subject: Re: Perl Vs. Java
Message-Id: <GLnv4I.Fxp@leeds.ac.uk>

In article <slrn9ta3jq.4ia.rgarciasuarez@rafael.kazibao.net>, rgarciasuarez@free.fr (Rafael Garcia-Suarez) wrote:
>Krishna Kumar wrote in comp.lang.perl.misc:
>> Folks at my work are talking about using Java as a standard instead of Perl.
>> 
>> I have no knowledge of Java to agree or disagree with this.
>> 
>> They are trying to convince me that Java can do everything that Perl can.
>

==> Your folks are lying to you ;-) You could always use both to gain the 
advantages of each language :-)

>Well, those languages are both Turing-complete.
>The question is : what language is good for which use ?
>Perl is much better at text processing (Java has no support for regexps
>and very poor string handling primitives) and system-programming.
>In fact it's very difficult to handle system calls within Java, because
>Java aims to be portable and hence does not provide basic system calls
>such as fork, chown or stat, to name a few.
>

- Martin Oxby
Founder and Administrator
[http://www.resource-centre.net]
Web Resources, Free Email, Messaging and Programming Tutorials all under one roof!


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

Date: Tue, 23 Oct 2001 08:37:04 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Premature end of script header
Message-Id: <87zo6i1nr3.fsf@limey.hpcc.uh.edu>

>> On Tue, 23 Oct 2001 09:22:54 +0100,
>> "Diehard Duck" <diehard@nospam.userve.co.uk> said:

>> #!c:\perl_prog\bin\perl

> print "Content-type: text/html\n\n";

> Will let the browser know what sort of content you are
> trying to send.  Without it the browser doesn't know
> what to do.  Put it straight under the #!C:\... line.

Straight after the #! should be -w and "use strict".

This isn't the problem.  The OP is using cgi-lib.pl and
this provides a subr to output the content-type, and the
OP used it, viz.

> print &PrintHeader;

Of course, as others pointed out, cgi-lib.pl is
practically antediluvian, and the OP should investigate
CGI.pm (and friends) instead.

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


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

Date: Tue, 23 Oct 2001 14:28:21 +0100
From: "Scott Bell" <news@scottbell.org>
Subject: Re: Webpage Passwords
Message-Id: <9eeB7.65077$sF.6028240@news2-win.server.ntlworld.com>

I didn't want to write a script that manages a .htaccess file nor was I
asking how to make a .htaccess file. I already know how to write .htaccess
files. What I wanted to do was write a .cgi script that would output a
header which would cause the browser to ask for a password. I don't
understand why people are saying this has nothing to do with perl, the
webpage is a CGI script written in the perl language.


--
Scott Bell
Email: scott@scottbell.org

The content of this message has been certified 100% correct.

Scott Bell <news@scottbell.org> wrote in message
news:FmSA7.54149$sF.4733750@news2-win.server.ntlworld.com...
> I wish to create a CGI script that allows users to create accounts. Is
there
> a way of getting the popup box in internet browsers that asks for the
login
> name and password via a CGI script?
>
>
>
> --
> Scott Bell
> Email: scott@scottbell.org
>
>
>




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

Date: Tue, 23 Oct 2001 14:39:48 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Webpage Passwords
Message-Id: <g20bttorlqsqaoncmgrktpg0dt4es7c5qm@4ax.com>

Scott Bell wrote:

>What I wanted to do was write a .cgi script that would output a
>header which would cause the browser to ask for a password. I don't
>understand why people are saying this has nothing to do with perl, the
>webpage is a CGI script written in the perl language.

!!!

Anyway: output a status header that indicates that autorization is
required. I think the status code must be 401 or something like it.

    <http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html>


And next time, ask things like this in the CGI newsgroup. Did you see
anything related to Perl in my answer? There, then.

-- 
	Bart.


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

Date: Tue, 23 Oct 2001 09:50:37 -0500
From: trammell@haqq.hypersloth.invalid (John J. Trammell)
Subject: Re: Webpage Passwords
Message-Id: <slrn9tb0tt.nfq.trammell@haqq.hypersloth.net>

On Tue, 23 Oct 2001 14:28:21 +0100, Scott Bell <news@scottbell.org> wrote:
> I didn't want to write a script that manages a .htaccess file nor was I
> asking how to make a .htaccess file. I already know how to write .htaccess
> files. What I wanted to do was write a .cgi script that would output a
> header which would cause the browser to ask for a password. I don't
> understand why people are saying this has nothing to do with perl, the
> webpage is a CGI script written in the perl language.
> 
If your question is "How do I write custom HTML headers in Perl?", my
answer is, "consult the CGI documentation via 'perldoc CGI'."

If your question is "What headers do I need to include to do this?",
my answer is "This newsgroup is about Perl, not HTML; you may as well
be asking 'How do I make my text look bold?'.  Just because your CGI
script is written in Perl does not mean all questions regarding it
are Perl-related."

-- 
When a true genius appears in the world, you may know him by this sign, that
the dunces are all in confederacy against him.             -- Jonathan Swift


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

Date: Tue, 23 Oct 2001 07:52:43 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Webpage Passwords
Message-Id: <3bd5843f@news.microsoft.com>

[Please don't post jeopardy style]

"Scott Bell" <news@scottbell.org> wrote in message
news:9eeB7.65077$sF.6028240@news2-win.server.ntlworld.com...
> I didn't want to write a script that manages a .htaccess file nor was I
> asking how to make a .htaccess file. I already know how to write .htaccess
> files. What I wanted to do was write a .cgi script that would output a
> header which would cause the browser to ask for a password. I don't
> understand why people are saying this has nothing to do with perl, the
> webpage is a CGI script written in the perl language.

You are absolutely right. Your question is related to Perl and the Perl part
of the answer is:

    You use "print" to print the proper header. For further details please
consult ""perldoc -f print".

Now, as for what the content of the print statement is supposed to be, that
part has nothing to do with Perl any more because that content
    - is HTML/HTTP (please ask in a NG that deals with HTML/HTTP)
    - would be exactly the same regardless of if the script was written in
Perl, Fortran, Haskell, Lisp, bash or any other programming language. Or in
other words: IT HAS NOTHING TO DO WITH PERL.

jue




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

Date: Tue, 23 Oct 2001 14:59:00 GMT
From: "Graham W. Boyes" <me@REMOVETHIStoao.net>
Subject: What the **** is WRONG with this!?
Message-Id: <Xns9143515AAEAFA15497002270367234@24.2.10.79>

I swear I did this and it worked yesterday.  I'm using a CGI script to make 
a new directory inside the directory that's inside the directory the script 
is in.

system("mkd /home/XXXX/data/forum/data/test");

/home/XXXX/data/forum is where the script is.  /home/XXXX/data/forum/data is 
chmoded to 777.

I am new to Linux (as you will probably guess before you fall out of your 
chair laughing) so please tell me where I have gone wrong.
Thanks

Graham
-- 
Health warning: diet soft drinks, Equal sweetener and NutraSweet contain the 
artificial sweetener Aspartame WHICH CAN CAUSE CANCER, DIABETES, OBESITY, 
EYE DISEASE, PARKINSON'S AND MORE.  Read more here: http://www.dorway.com/




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

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


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