[12513] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6113 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 24 00:07:28 1999

Date: Wed, 23 Jun 99 21:00:21 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 23 Jun 1999     Volume: 8 Number: 6113

Today's topics:
    Re: 'warn' question ? (Charles DeRykus)
    Re: A foreach question <charliem@phegos.com>
    Re: adding whitespaces <troyknight@troyknight.eurobell.co.uk>
    Re: adding whitespaces <cassell@mail.cor.epa.gov>
    Re: ANNOUNCE: PUBcrawl newsletter <cassell@mail.cor.epa.gov>
    Re: aut et vel (Damian Conway)
    Re: Continuing fun with Hash or Lists... <rick.delaney@home.com>
        core file <cglcomputer@earthlink.net>
    Re: core file (Martien Verbruggen)
    Re: deleting whitespace ()
        Directory structures... (Mitch)
    Re: Directory structures... <rereidy@uswest.net>
    Re: global vars <troyknight@troyknight.eurobell.co.uk>
    Re: global vars <troyknight@troyknight.eurobell.co.uk>
    Re: Help with PPM <cassell@mail.cor.epa.gov>
        HELP: Can't delete ONE stinking file with Unlink! roberthp@my-deja.com
    Re: HELP: Can't delete ONE stinking file with Unlink! (Martien Verbruggen)
        insert some data to a file's beginning <maistro@swi.hu>
    Re: insert some data to a file's beginning <rick.delaney@home.com>
    Re: linux passwords <assakhof@mimos.my>
    Re: Looking for 3D Array sort... <assakhof@mimos.my>
        Losing Date/Time Information from Oracle Database (Lee Borkman)
    Re: NT - Server Up time (brian d foy)
        Perl<-->Mail Server on NT asssi@my-deja.com
        Sorting Hash Keys <troyknight@troyknight.eurobell.co.uk>
    Re: Sorting Hash Keys <walton@frontiernet.net>
    Re: Sorting Hash Keys (Martien Verbruggen)
    Re: suid problem with perl <rootbeer@redcat.com>
    Re: system exec <cassell@mail.cor.epa.gov>
    Re: What in my concatenated string? <rick.delaney@home.com>
        WWW-Authentication using CGi <techam@tm.net.my>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Thu, 24 Jun 1999 02:01:56 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: 'warn' question ?
Message-Id: <FDt6z8.8M8@news.boeing.com>

In article <7kr3b8$hce$1@panther.cs.ucla.edu>,
Hong Yuan <hongy@panther.cs.ucla.edu> wrote:
>Hi,
>
>I've modified File::Find so that I can specify a maxlevel N to do 
>breadth-first recursion in the dir hierarchy. It works now, ignoring
>files/dirs deeper than N levels from the topdir. 
>
>There're warn lines in the module that looks like this:
>
>  dosomething || (warn("warning: ...\n"), return);
>
>I can't get the warning to print to STDERR.  But if I change the line
>to this:
>
>  dosomething || (warn("warning: ...\n") and next);
>
>then, the warning message will be printed to STDERR. 
>


Actually, the File::Find line looks like:

   opendir(DIR,'.') || (warn "Can't open $dir: $!\n", return); 

What you've mistakenly reproduced: 

   dosomething || (warn("warning: ...\n"), return);

would have corrected the problem. 
 
So either the parens or an C<and> would help the parser 
do the right thing. I think...

   opendir(DIR,'.') || (warn("Can't open $dir: $!\n"), return); 
   opendir(DIR,'.') || (warn "Can't open $dir: $!\n" and return); 



hth,
--
Charles DeRykus


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

Date: Wed, 23 Jun 1999 13:56:23 -0800
From: CharlieMa <charliem@phegos.com>
Subject: Re: A foreach question
Message-Id: <930174985.23799@www.remarq.com>

OK a note of clarification for photoguy, who having only
been exposed to the madness of perl for 3 weeks may find
Larry Rossler's reply unintelligible.  When I was learning
perl I found newsgroup replies rather confusing, especially
the use of 'and' and 'or' for abbreviating code.  See
comments below.  Ignore me if I'm just being unnecessarily
nosy.

-charlie

Mr. Rossler's program looks for 'foo' in each line of
input, if 'foo' found then it tries to look in the
following line for 'baz', printing message if match found.

#!/usr/local/bin/perl -w use strict;

while () {
  #or while(<FILEHANDLE>) {
  #if you already have FILEHANDLE associated
  #with a file as in your original example.

next unless /foo/;

defined($_ = ) or die "Unexpected end-of-file\n";
  #this evaluates the first half of the 'or' statement
  #and will execute the 2nd half only if the first half
  #is false.

/baz/ and print "Matched baz in $_"; }
  #this tries to match /baz/ and will only execute
  #the 2nd half of the 'and' statement if the first half
  #evaluates to true.

  #the following would be the data in your input file
zilch
foobar
bashbazbam
zorp
barfoo
bashBAZbam
quux
foofuraw
second baz match
foo
  #END OF YOUR INPUT FILE


#the following would be output to console
Matched baz in bashbazbam Matched baz in second baz match
Unexpected end-of-file



**** Posted from RemarQ - http://www.remarq.com - Discussions Start Here (tm) ****


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

Date: Thu, 24 Jun 1999 02:58:34 +0100
From: "Troy Knight" <troyknight@troyknight.eurobell.co.uk>
Subject: Re: adding whitespaces
Message-Id: <7ks361$39s$1@aub.eurobell.net>

you are forgetting the ^ sign. This tells perl to only match the beginning
of the string, or if used with the m option, each line!!!

Matt Melton <arm@home.net> wrote in message
news:37717CCA.B54E1565@home.net...
> The books on Perl and I have 5 of them refer to deleting
> whitespaces from the beginning of a line s/^ *//; or from
> the end of the line but if I have a line that reads,
> how are you today, after it goes through a perl search
> routine, that line comes back  howareyoutoday. With the
> exception of adding dashes  ~s/\s+\-/g; how can I add a whitespace
> to get the output to read    how are you today.
> Matt




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

Date: Wed, 23 Jun 1999 20:44:02 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: adding whitespaces
Message-Id: <3771A982.DFB34742@mail.cor.epa.gov>

Matt Melton wrote:
> 
> The books on Perl and I have 5 of them refer to deleting

I hope they're the good ones, instead of the ones with
misleading statements and serious errors.

> whitespaces from the beginning of a line s/^ *//; or from
> the end of the line but if I have a line that reads,
> how are you today, after it goes through a perl search
> routine, that line comes back  howareyoutoday. With the

Then you ran it through s/// without that little '^' in front
of the regex to anchor the regex to the beginning of the text.

> exception of adding dashes  ~s/\s+\-/g; how can I add a whitespace
> to get the output to read    how are you today.

If you want to *add* whitespace at the beginning, just match
the start of the line and add in some spaces:

$line =~ s/^/  /;   # add two blanks to the front of the line

If you feel that you're struggling with regexen, then you
might want to look at the Perl tutorial:
http://www.netcat.co.uk/rob/perl/win32perltut.html
and read the section on regexes.

HTH,
David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Wed, 23 Jun 1999 20:28:22 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: ANNOUNCE: PUBcrawl newsletter
Message-Id: <3771A5D6.182483BC@mail.cor.epa.gov>

Andrew Johnson wrote:
> Announcing PUBcrawl Issue 01:
> [snip]
>     For LP and noweb info see:
>         http://shelob.ce.ttu.edu/daves/faq.html

I read this...

>         http://www.cs.virginia.edu/~nr/noweb/

But I was rudely told I didn't have permission to peek at this
one.  And I pulled up a 403 error to add insult to injury.
I even tried using one of the 'popular' browsers, to no avail.
 
Just thought you'd want to know...
David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: 24 Jun 1999 01:29:59 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: aut et vel
Message-Id: <7ks1mn$ud0$1@towncrier.cc.monash.edu.au>

nospam.newton@gmx.net (Philip 'Yes, that's my address' Newton) writes:

> On 22 Jun 1999 17:30:06 -0700, Tom Christiansen <tchrist@mox.perl.com>
> wrote:
> 
> >They have both an inclusive and an exclusive "or" in their language,
> >after all. :-)
> 
> Forgive my sorely lacking classical upbringing, but:
> 
> Which of "aut" and "vel" is which of "inclusive or" and "exclusive
> or"?

Here's a mnemonic:

	^ is the top half of 'A', so "Aut" is exclusive or
	| is ve(rtica)l, sp "Vel" is inclusive or

Here's another:

	Lexicographically, "aut" comes before "vel",
	just as "exclusive" comes before "inclusive"

Damian


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

Date: Thu, 24 Jun 1999 03:03:00 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Continuing fun with Hash or Lists...
Message-Id: <37719FA6.AB030F55@home.com>

[posted & mailed]

Mitch wrote:
> 
> If I have a hash of lists that contains something like:
> 
> coke sucks rules bites, where coke is the hash, and the rest is the
> list.  How can I remove "rules" from the list?

If you know the position of 'rules' in the array, you can splice it
out.  If not, create a new, filtered list with grep.

perldoc -f splice
perldoc -f grep

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Wed, 23 Jun 1999 21:33:29 -0400
From: Chris Lambrou <cglcomputer@earthlink.net>
Subject: core file
Message-Id: <37718AE9.2869810C@earthlink.net>

When/Why does PERL dump the core?  And how can I know which script 
dumped the core?  

I've opened a core file on my server.  Towards the top of the file
there's a script file name.  Is it safe to assume that this is the
script that dumped the core?

Thanks.



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

Date: Thu, 24 Jun 1999 03:48:11 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: core file
Message-Id: <%Thc3.943$Fw1.9451@nsw.nnrp.telstra.net>

In article <37718AE9.2869810C@earthlink.net>,
	Chris Lambrou <cglcomputer@earthlink.net> writes:
> When/Why does PERL dump the core?  And how can I know which script 
> dumped the core?  

# man core

core files have nothing to do with perl. They are a unix thingie. The
man page on your system will tell you how to investigate.

That said: If your perl dumps core, it probably isn't
installed/compiled correctly. Recompile and reinstall.

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | Useful Statistic: 75% of the people
Commercial Dynamics Pty. Ltd.       | make up 3/4 of the population.
NSW, Australia                      | 


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

Date: 24 Jun 1999 01:46:49 GMT
From: mr@kells.kells ()
Subject: Re: deleting whitespace
Message-Id: <slrn7n33r4.avf.mr@kells.kells>

$line =~ tr/ \t//d;

On Wed, 23 Jun 1999 18:34:42 GMT, <dragnet@internalysis.com> wrote:
>In article <P9Ub3.3018$I72.384814@nnrp1.ptd.net>, tfiedler@ptd.net says...
>>
>>how do i delete whitespace or for what its worth any junk on a line?
>>
>
>$line =~ s/ //;
>
>
>-- 
>----------------------------
>Marc Bissonnette
>InternAlysis
>Corporate Internet Research and Results!
>http://www.internalysis.com
>


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

Date: Thu, 24 Jun 1999 03:11:06 GMT
From: portboy@home.com (Mitch)
Subject: Directory structures...
Message-Id: <37713198.437203695@24.0.3.71>

if I have a directory structure like:

/foo/bar/foothis/you/foofile

How can I slurp that entire structure into a string?

So, if I did a print on $slurp I'd get

print "$slurp\n"; 

/foo/bar/foothis/you/foofile

Any suggestions?

 ./mitch


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

Date: Wed, 23 Jun 1999 21:33:36 -0600
From: Ron Reidy <rereidy@uswest.net>
Subject: Re: Directory structures...
Message-Id: <3771A710.6FA38D72@uswest.net>

Mitch wrote:

> if I have a directory structure like:
>
> /foo/bar/foothis/you/foofile
>
> How can I slurp that entire structure into a string?
>
> So, if I did a print on $slurp I'd get
>
> print "$slurp\n";
>
> /foo/bar/foothis/you/foofile
>
> Any suggestions?
>
> ./mitch

What do you mean by "slurp"?  Do you mean the contents of the
directory?  If so, "perldoc opendir".  If not, then I'm confused.


--
Ron Reidy
Oracle DBA
Reidy Consulting, L.L.C.




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

Date: Thu, 24 Jun 1999 02:11:54 +0100
From: "Troy Knight" <troyknight@troyknight.eurobell.co.uk>
Subject: Re: global vars
Message-Id: <7ks0ei$38m$1@aub.eurobell.net>

Yep, simple ain't it!

Ariel <fake@nospam.edu> wrote in message
news:7krlso$73q@news.or.intel.com...
> let's say i have a variable $a in FILE1.pl. what if i want to access and
> change that variable in another file, FILE2.pl. Also, in FILE2 i want to
use
> subroutines defined in FILE1. how do i do this. do I just say "require
> FILE1.pl" in the beginning of FILE2?
>
> thanks.
>
>
>
>




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

Date: Thu, 24 Jun 1999 02:45:56 +0100
From: "Troy Knight" <troyknight@troyknight.eurobell.co.uk>
Subject: Re: global vars
Message-Id: <7ks2ec$39k$1@aub.eurobell.net>

using do will start that script separately from the script you are on.
using require will just treat that script as part of the script you are
using!


David Cassell <cassell@mail.cor.epa.gov> wrote in message
news:377175A3.FE467A23@mail.cor.epa.gov...
> Ariel wrote:
> >
> > let's say i have a variable $a in FILE1.pl. what if i want to access and
> > change that variable in another file, FILE2.pl. Also, in FILE2 i want to
use
> > subroutines defined in FILE1. how do i do this. do I just say "require
> > FILE1.pl" in the beginning of FILE2?
>
> It sounds to me like you want to read up on the do() function.
> This:
>
> do 'FILE1.pl';
>
> will execute the contents of the file as a Perl program.  It
> does other nice things which are covered in perlfunc.
>
> HTH,
> David
> --
> David Cassell, OAO                     cassell@mail.cor.epa.gov
> Senior computing specialist
> mathematical statistician




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

Date: Wed, 23 Jun 1999 20:55:26 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
To: pjd <duraip@extendsys.com>
Subject: Re: Help with PPM
Message-Id: <3771AC2E.287E3988@mail.cor.epa.gov>

[courtesy cc sent to poster]

pjd wrote:
> 
> Whats the matter with this PPM ?
> I just cant seem to get this right.
> I have the latest version of perl from ActiveState installed.
> Here is a sample session.
>
> [SNIP]
> no element found at line 1, column 0, byte -1 at
> C:/Perl/site/lib/XML/Parser.pm
> line 153

Hmm, it looks like you've munged XML::Parser.  Did you
try to install it using ppm?  That's bad, because ppm
uses XML::Parser to do the installs.  I believe there's
a fix for this on the ActiveState site, although you'd 
think that they would just put a line in ppm to keep it 
from trying to install XML::Parser incorrectly...

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Thu, 24 Jun 1999 02:32:29 GMT
From: roberthp@my-deja.com
Subject: HELP: Can't delete ONE stinking file with Unlink!
Message-Id: <7ks5bt$p8s$1@nnrp1.deja.com>

Hello:

I'm trying to modify a machine's registry with Perl (works
beautifully), and then open a directory, delete one file, and then
close the directory.  (script below)

The file in question exists because I can see it in the output list
being generated by the script.  I've tried 10 different variations of
the filename, including wildcards, to delete it, and it just says "file
or directory does not exist....

Can anyone tell me what I'm doing wrong???

Also, how can I check for this directory and, if it doesn't exist, go
to another directory for the process?

Thanks
Robert H. Patterson

---------SCRIPT---------------
use Win32::Registry;
use POSIX;
$main::HKEY_LOCAL_MACHINE->Open("Software\\Microsoft\\Active Setup",
$Microsoft) ||  	die "Open: $!";
$Microsoft->Open("Installed Components", $installed); $installed-
>GetKeys(\@kids);
foreach $k (@kids) 	{
	$installed->DeleteKey($k);
}
opendir(Desktop,"C:/WINNT/Profiles/All Users/Desktop") ||
	die "Opendir: $!";
while ($name = readdir(Desktop)) {
	print "$name\n";
}
unlink("Acrobat Reader 4.0.lnk") ||   (<-Dies here without unlink)
	die "Unlink: $!";
closedir(Desktop);

---------OUTPUT------------
Unlink: No such file or directory at script line 20.
 .
 ..
Acrobat Reader 4.0.lnk  (<-Won't delete this file, but it's there!)
Emergency Undelete.lnk
PrimalSCRIPT.lnk


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Thu, 24 Jun 1999 03:50:52 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: HELP: Can't delete ONE stinking file with Unlink!
Message-Id: <wWhc3.955$Fw1.9451@nsw.nnrp.telstra.net>

In article <7ks5bt$p8s$1@nnrp1.deja.com>,
	roberthp@my-deja.com writes:

> opendir(Desktop,"C:/WINNT/Profiles/All Users/Desktop") ||
> 	die "Opendir: $!";
> while ($name = readdir(Desktop)) {
> 	print "$name\n";
> }
> unlink("Acrobat Reader 4.0.lnk") ||   (<-Dies here without unlink)
> 	die "Unlink: $!";

Are you in the right directory?

# perldoc -f opendir
# perldoc -f readdir
[snip]
If you're planning to filetest the return values out of a
C<readdir()>, you'd better prepend the directory in question.
Otherwise, because we didn't C<chdir()> there, it would have been
testing the wrong file.
[snip]

I am sure that you of course read the documentation, but simply missed
that point.

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | The world is complex; sendmail.cf
Commercial Dynamics Pty. Ltd.       | reflects this.
NSW, Australia                      | 


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

Date: Wed, 23 Jun 1999 19:53:45 +0200
From: "Oreg Dixie" <maistro@swi.hu>
Subject: insert some data to a file's beginning
Message-Id: <7krg43$2a5$1@pollux.matav.net>

Hi!

What is the "best" way to insert some data into a file's beginning?

Best Regards,
Flatline




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

Date: Thu, 24 Jun 1999 02:54:50 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: insert some data to a file's beginning
Message-Id: <37719DBC.EE07A8B1@home.com>

[posted & mailed]

Oreg Dixie wrote:
> 
> What is the "best" way to insert some data into a file's beginning?

The best way should be the method described in the second question of
perlfaq5.  If you come up with a better one, please submit it to
perlbug.

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Thu, 24 Jun 1999 09:18:34 +0800
From: assakhof <assakhof@mimos.my>
Subject: Re: linux passwords
Message-Id: <3771876A.8ECA6A7A@mimos.my>



David Stringer wrote:
> 
> Hi,
> 
>   I would like to change Linux user passwords in a Perl script, what
> would be the easiest way of doing this?
> 

My friend found a code (below) at http://www.boutell.com/calendars/ to
change apache authentication password mentioned by .htaccess .

sub pwd
{
 my($arg) = @_;
 return crypt($arg,pack("CC",ord('a')+rand(26),ord('a')+rand(26)));
}

It will return encrypted string. 

I don't know whether this encrypted string is same as in /etc/password .
Does anyone know ?

Regards, 

--assakhof


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

Date: Thu, 24 Jun 1999 09:39:52 +0800
From: assakhof <assakhof@mimos.my>
Subject: Re: Looking for 3D Array sort...
Message-Id: <37718C68.5377AF49@mimos.my>



James Park wrote:
> 
> Hi everyone.
> 
> I'm looking for a 3d array (list of lists) sorting module.  If you
> know the location of one, I would appreciate it.  I've noticed that
> standard module only has the 2d array sort.  I really don't want to
> program one myself, so any help would be great.
>


Hi, please have a look in a book by Josephn N Hall "Effective perl
Proggram" it's available on line. Point your browser here
http://www.effectiveperl.com/EP.03.pdf
(chapter Idiomatic Perl).

It may not a good refference to you, but may help newbie who want to
write a program himself rather than 'I don't want to program myself'.

regards,

-assakhof


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

Date: Thu, 24 Jun 1999 02:22:38 GMT
From: borkman@usa.net (Lee Borkman)
Subject: Losing Date/Time Information from Oracle Database
Message-Id: <37719398.4380649@news>

Hi,

I am using DBI and DBD::Oracle to build a web page live from an
Oracle7.3 database.

Everything is fine except for the date fields.

When I use SQL-NET to examine the data 'directly', a field (called
TIME_OF_REPORT) will have a value like this:
1999-06-01 12:05:01

Okay, now I fetch the data with Perl, like this:
 	$sth = $dbh->prepare("SELECT * FROM Incidents_Local" );

	$sth->execute;

	$hashref = $sth->fetchrow_hashref();
	%rowval = %{$hashref};
	print "TIME: $rowval{'TIME_OF_REPORT'}\n";


And I get this:
11-JUN-1999


SO, where is the translation occurring, and can I get at the entire
date/time?  It doesn't matter what the format is, as long as nothing's
missing.

TIA,
Lee Borkman



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

Date: Wed, 23 Jun 1999 23:25:54 -0400
From: brian@pm.org (brian d foy)
Subject: Re: NT - Server Up time
Message-Id: <brian-2306992325550001@126.pittsburgh-03-04rs.pa.dial-access.att.net>

In article <3770f096@newsread3.dircon.co.uk>, Jonathan Stowe
<gellyfish@gellyfish.com> wrote:

> mirak63@yahoo.com wrote:
> > Hello,
> > 
> > Is there a way in Perl to be able to determine the time
> > and date that an NT server came up?
> > 
> 
> print "Uptime: 10 mins\n";

i think you have to use Time::HiRes for that.

-- 
brian d foy                    
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
Perl Monger Hats! <URL:http://www.pm.org/clothing.shtml>


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

Date: Thu, 24 Jun 1999 00:46:52 GMT
From: asssi@my-deja.com
Subject: Perl<-->Mail Server on NT
Message-Id: <7krv5p$n9r$1@nnrp1.deja.com>

Hi guys!

  I have two questions for you..

1. I've studied perl and built some CGI, now I would like to add an
ability to send email through them, on an NT platform, which software
would you recommand to make a good Mail server that would be compatible
with perl?

2. I'd like to connect perl with a databse, no I'm not asking how to,
just where I can learn more about it online, again, the platform is
Windows NT with probably Access database installed (for starters)

I would appriciate any help, please email me a copy as well to
asio@netscape.net

Thanks in advance!

Asi.


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Thu, 24 Jun 1999 02:03:40 +0100
From: "Troy Knight" <troyknight@troyknight.eurobell.co.uk>
Subject: Sorting Hash Keys
Message-Id: <7krvv4$37m$1@aub.eurobell.net>

Here's a couple of questions for all you programming purists.

1) Usually when calling the sort function, if you supply a value which isn't
an array or hash it after it, it will look for that subroutine to supply the
sort order. When you sort a hash keys (eg. sort keys(%hash)), how come it
knows that it is to use the hash keys and sort normally, rather than sorting
the values in the hash and using the 'keys' subroutine to get the sort
order?

2) When using the elements of a hash, it will use the fastest order in which
to give them. Is there any way of giving the elements in the order they were
created?

Thanks, TK




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

Date: Wed, 23 Jun 1999 23:40:57 -0400
From: Bob Walton <walton@frontiernet.net>
To: Troy Knight <troyknight@troyknight.eurobell.co.uk>
Subject: Re: Sorting Hash Keys
Message-Id: <3771A8C9.9B54938F@frontiernet.net>



Troy Knight wrote:

> Here's a couple of questions for all you programming purists.
>
> 1) Usually when calling the sort function, if you supply a value which isn't
> an array or hash it after it, it will look for that subroutine to supply the
> sort order. When you sort a hash keys (eg. sort keys(%hash)), how come it
> knows that it is to use the hash keys and sort normally, rather than sorting
> the values in the hash and using the 'keys' subroutine to get the sort
> order?

Hmm...interesting.

sort keys(%hash)

is straightforward:  The function keys is applied to its argument %hash, and the
resulting array is sorted.  However:

sort keys %hash

does the same thing.  It must be automagical, as

sort foo %hash

applies sub "foo" as a sort subroutine to the array made from the keys and
values of %hash munged into an array.

>
>
> 2) When using the elements of a hash, it will use the fastest order in which
> to give them. Is there any way of giving the elements in the order they were
> created?

Yes.  In fact, "there is more than one way to do it":

use DB_File; and tie the hash using the DB_BTREE option and your favorite sort
sub converted to a regular sub (with the arguments in @_).  Put your data into
the hash, and it will be retrieved in sorted order by "each", "keys", or
"values".  See recipe 14.6 in "Perl Cookbook".  If you aren't storing your
DB_BTREE data permanently, give "undef" as the filename.

use Tie::IxHash; if your data is coming in sorted -- Tie::IxHash will preserve
the insertion order, whatever it was.  See recipe 5.6.

>
>
> Thanks, TK

You're welcome.



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

Date: Thu, 24 Jun 1999 03:55:10 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Sorting Hash Keys
Message-Id: <y_hc3.974$Fw1.9451@nsw.nnrp.telstra.net>

In article <7krvv4$37m$1@aub.eurobell.net>,
	"Troy Knight" <troyknight@troyknight.eurobell.co.uk> writes:
> Here's a couple of questions for all you programming purists.

Huh? How does any of the following have anything to do with purism?

> 1) [...] how come [sort] knows that it is to use the hash keys and
> sort normally, rather than sorting the values in the hash and using
> the 'keys' subroutine to get the sort order?

Because of the brackets. Because perl is smart. Because keys is not a sub.

> 2) When using the elements of a hash, it will use the fastest order in which
> to give them. Is there any way of giving the elements in the order they were
> created?

No. It's explained in the FAQ, There's another thread going on as well
about this (which started before you posted), and it's documented. You
have to keep the order yourself. A hash is by nature unordered.

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | Useful Statistic: 75% of the people
Commercial Dynamics Pty. Ltd.       | make up 3/4 of the population.
NSW, Australia                      | 


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

Date: Wed, 23 Jun 1999 18:21:28 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: suid problem with perl
Message-Id: <Pine.GSO.4.02A.9906231816480.1698-100000@user2.teleport.com>

On Wed, 23 Jun 1999, Mike wrote:

> Newsgroups: comp.lang.perl.misc, comp.lang.perl

If your news administrator still carries comp.lang.perl, please let him
or her know that that newsgroup has not existed since 1995. If you
have such an outdated newsgroup listing, you are probably missing out
on many other valid newsgroups as well. You'll be doing yourself and
many others a favor to use only comp.lang.perl.misc (and other valid
Perl newsgroups) instead.

> I am trying to make a simple SUID script and I get some irrationnal
> results.  For example if I try running the following program:
> 
> opendir (CURRENT, "$cur");

You should check the return value from opendir. And why are you quoting
$cur? That's misleading, at best.

> while ($file = (readdir CURRENT))
> {
>         print "$file\n" if (-d $file);
> }

Of course, $file is the name of something in the directory $cur. But -d is
looking in the current directory. How could perl know that you mean for it
to look somewhere else? If you mean for -d to look in $cur, include the
path as part of the filename arg. Or, to keep things simple, first chdir
to $cur, then opendir on '.'.

> By the way I cannot use "chdir" because of the "tainted" property of
> perl and the fact that I am doing a SUID script.

Set-id perl programs (or others with taint checking enabled) can chdir.
But perhaps you need to read the perlsec manpage more closely to find out
how to extract untainted data from a tainted source.

Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 23 Jun 1999 20:34:35 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
To: jmtth@my-deja.com
Subject: Re: system exec
Message-Id: <3771A74B.EB7B7B69@mail.cor.epa.gov>

[courtesy cc to poster]

jmtth@my-deja.com wrote: 
> From my perl script I want to execute a batch file (mybat.bat) which set
> environnement's variables.
> At the end of batch's execution ; perl script must know those variables.
> The System statement make a fork(), so I can't use it ;

More importantly, system executes commands in a child process,
so the variables would only be defined in the child and not in 
the parent (as you want).

>                                                         the Exec
> statement finish the perl script, as a result what is after the exec
> isn't compute.

Right.

> How can I execute my batch in the script's process and in order to don't
> shortcut the end of the script ?

It seems to me that you want to read about the function do() ,
which will let you execute another file as a Perl script.  You
could write your variables in the form of Perl statements and
then:

do 'otherfile.with.variables';

Then it wouldn't have to be a batch file either.

If you insist on placing non-Perl lines in that 'batch' file,
then you could read it in and parse it in Perl, assigning
variables as you go.  This has been discussed ad nauseam in
this newsgroup over the last few days.  Just look in the archives
for the posts answering the various questions from Mitch, alias
portboy.

HTH,
David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Thu, 24 Jun 1999 03:11:55 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: What in my concatenated string?
Message-Id: <3771A1BE.FE51BB4A@home.com>

[posted & mailed]

AEF wrote:
> 
> @topics = split (/,/,$Cookies{'topics'} );
> 

[snip]

> for(@topics) {
> print "topic: $_ \n";
> }
> 
> #prints
> topic:
>  topic:
>  topic:
> topic: 30
> topic: 31
> topic: 32
> 
> #Fixing  that isn't a problem.

That's good.

> #But, for my own information, I couldn't figure out what the value was
> #of the empty places.  It didn't seem to be "" or " ", and couldn't be
> #substituted in a regex.

It's "".  You showed us all the stuff that you did to get around it but
none of the stuff that caused your confusion.  Substituted in a regex?

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Thu, 24 Jun 1999 09:54:02 +0800
From: "Mohd Idaham" <techam@tm.net.my>
Subject: WWW-Authentication using CGi
Message-Id: <7ks2dm$c2f$1@news5.jaring.my>

Hi,
I'm trying to create a script where users can relogin with their other
account. But unfortunately the script doesn't work. Below is the code and
please tell me how to improve this.  My web server = Apache 1.3.6.

Thanks...
----------------------------------------------
#!/usr/bin/perl

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
        ($name, $value) = split(/=/, $pair);
        $value =~ tr/+/ /;
        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
        if ($INPUT{$name}) { $INPUT{$name} = $INPUT{$name}.",".$value; }
        else { $INPUT{$name} = $value; }
}

open (SA, "<switch.num");
my $Last = <SA>;
close SA;
chomp($Last);

my $switchindex = $INPUT{'switchIndex'};
&blank_response($Last) unless $switchindex;
if ($Last == $switchindex)
  {
   $Last++;
   open (SA, ">switch.num");
   print SA "$Last\n";
   close SA;

   print "Status: 401 Unauthorized\n";
   print "WWW-Authenticate: Basic realm=Traffic_Analysis_Report\n\n";
exit;
  }
else
  {
   close SA;
  }


EOM
;


sub blank_response
{
 local($numvalue) = @_;

print <<EOM
Pragma: no-cache
Expires: Wednesday, 1 Jan 97
Cache-control: no-store
Content-type:text/html\n\n
<html><body bgcolor=#FFFFFF>
<head>
<title> Traffic Analysis Report </title>
</head>
<table>
<tr><td align=left width=400 bgcolor=#C0C0C0>
<font face=Arial color=#FFFFFF>
<h1>Switch Account</h1>
</font>
</td></tr>
</table>
<font face=Arial size=2>

<p><p>
<b>If you have more than one account (more than one leased-line), this
utility will allow you to switch between accounts, using your other name and
password.</b><p>
To continue press the button below, expect a dialogue box asking for a Name
and Password.
</font>
<form action="http://myserver.com.my/authtest.cgi" method="POST">
<input type="hidden" value="$numvalue" name="switchIndex">
<input type="submit" value="Switch Account" name="switchAccount">
</form>
</body></html>
EOM
;

exit;
}





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

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 6113
**************************************

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