[19105] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1300 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 13 14:10:41 2001

Date: Fri, 13 Jul 2001 11:10:17 -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: <995047817-v10-i1300@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 13 Jul 2001     Volume: 10 Number: 1300

Today's topics:
        Help <dstevens@polaris.umuc.edu>
        is Perl adequate as a job control langage <tmSpamMeNot@jcfgroup.com>
    Re: is Perl adequate as a job control langage (Eric Bohlman)
    Re: List files in a directory <andrew@mvt.ie>
    Re: List files in a directory (Eric Bohlman)
    Re: newbie question regarding tables in perl <laszlo.gerencser@portologic.com>
    Re: newbie question regarding tables in perl <tom.melly@ccl.com>
        Newbie: Need template script for merging text info from <dejus@aps.anl.gov>
        Passing sed Expression on Command Line (Buck Turgidson)
    Re: Q about fork and kill nobull@mail.com
    Re: rand confusion (Anno Siegel)
        Random Numbers... <ted_godwin@mindspring.com>
    Re: Random Numbers... <person@company.com>
        redirect in Perl (sergey)
    Re: script already running <ubl@schaffhausen.de>
    Re: script already running (Ronald Blaschke)
    Re: script already running <newspost@coppit.org>
        search and replace $ <mdudley@execonn.com>
    Re: Signal SEGV - What is it? <dan@tuatha.sidhe.org>
        Some more online mailreader questions (=?ISO-8859-1?Q?Morten_Tanger=E5s?=)
    Re: sortlen -- filter to sort text by line length (Greg Bacon)
        Specifying username and password to networked machine f <bholness@nortelnetworks.com>
    Re: Specifying username and password to networked machi nobull@mail.com
    Re: turn off redirect in LWP? (Rafael Garcia-Suarez)
    Re: Using a variable in a regular expression (Jay Tilton)
    Re: Using a variable in a regular expression <uri@sysarch.com>
    Re: Using long integer in PERL <ubl@schaffhausen.de>
    Re: Using long integer in PERL nobull@mail.com
    Re: vvp:Changing Unix Environments with Perl? <vprasad@americasm01.nt.com>
    Re: vvp:Changing Unix Environments with Perl? (Eric Bohlman)
    Re: vvp:Changing Unix Environments with Perl? (Tad McClellan)
    Re: Wildcards in hash (associative) arrays? <bholness@nortelnetworks.com>
    Re: Wildcards in hash (associative) arrays? <bholness@nortelnetworks.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 13 Jul 2001 12:07:39 -0400
From: "David Stevens" <dstevens@polaris.umuc.edu>
Subject: Help
Message-Id: <tku7crndonq6a7@corp.supernews.com>

I'm in an internet PERL class and missing out on to write simple PERL
programs.

Anyone willing to give me some help via email?

Address is blaster1072@yahoo.com

Thanks




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

Date: Fri, 13 Jul 2001 15:50:50 +0200
From: "TM" <tmSpamMeNot@jcfgroup.com>
Subject: is Perl adequate as a job control langage
Message-Id: <9imu19$bl$1@reader1.imaginet.fr>

Hello,
I'm currently using a special program as a quite sophisticate launcher for
other programs on Window NT or 2000. The problem is that the sources were
lost and we can't add features. It has its own syntax with variable aliasing
but also reads and analyzes the content of special configuration files etc.

I'm thinking of replacing it by an equivalent in Perl but I need some clues
about the adequation. The questions are:

* Is there another way than the system() or exec() instructions to execute a
Win32 program. Same question about a DLL entry point. Anyway how do these
istructions interact with the system resources.
* Is launching a win32 program from a Perl script a good idea or does Perl
itself uses a significant part of the system resources, especially CPU and
RAM, that would slow down the execution of the launched programs.

Thanks

TM






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

Date: 13 Jul 2001 15:47:05 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: is Perl adequate as a job control langage
Message-Id: <9in55p$c0c$8@bob.news.rcn.net>

TM <tmSpamMeNot@jcfgroup.com> wrote:
> I'm currently using a special program as a quite sophisticate launcher for
> other programs on Window NT or 2000. The problem is that the sources were
> lost and we can't add features. It has its own syntax with variable aliasing
> but also reads and analyzes the content of special configuration files etc.

> I'm thinking of replacing it by an equivalent in Perl but I need some clues
> about the adequation. The questions are:

> * Is there another way than the system() or exec() instructions to execute a
> Win32 program.

Win32::Process

> Same question about a DLL entry point.

Win32::API

> Anyway how do these
> istructions interact with the system resources.

Not quite sure what you mean.

> * Is launching a win32 program from a Perl script a good idea or does Perl
> itself uses a significant part of the system resources, especially CPU and
> RAM, that would slow down the execution of the launched programs.

It uses a fair amount of RAM; it shouldn't use up much CPU time while just 
waiting for other processes to finish.  For an application like this that 
doesn't involve processing huge chunks of data, the majority of the RAM 
usage is going to be just from the interpreter itself, so you should be 
able to easily test by creating a really simple program that just loads up 
the necessary Win32::* modules and runs one application.



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

Date: Fri, 13 Jul 2001 14:30:42 +0100
From: "Andrew" <andrew@mvt.ie>
Subject: Re: List files in a directory
Message-Id: <9imt6a$nas$1@kermit.esat.net>


"Logan Shaw" <logan@cs.utexas.edu> wrote in message
news:9ime18$km8$1@charity.cs.utexas.edu...
> In article <9imd8n$fav$1@kermit.esat.net>, Andrew <andrew@mvt.ie> wrote:
> >for (0..$#files)
> >{
> >    printf "$files[$_]\n";
> >}
>
> That's not really very much in the Perl idiom.  It's much more natural
> to just do this:
>
> foreach (@files)
> {
> print "$_\n";
> }
>
I'll doing things that way from now on - so much less typing involved.
One thing I love about this group is that even answering questions can be a
great way to learn :-)

Going back to the part of the answers relevant to the OP, are there any big
differences between

  @my_array = glob "*.sql";

and

  while(<*.sql>)
  {
      push @files,$_;
  }

From reading the documentation for glob, it seems like they both do the
exact same thing, and I then discovered that I could do this;

@files = <*.sql>;

Which is neater & shorter than my while loop (slightly faster too, according
to my benchmark (below).  One question - why is the output given in the
order shown, which is different than the order in the script.  (I don't mean
to imply that execution time would be a big reason to pick one way over
another for something like this..

Andrew

---------------------------------------------------------------
#!/usr/bin/perl
# Run on my perl scripts directory, containing 138 *.pl files
use strict;
use Benchmark;

my @array;
timethese(2000, {
 'One' => '@array = glob "*.pl";',
 'Two' => '@array = <*.pl>',
 'Three' => 'while (<*.pl>){ push @array,$_;}',
});


Benchmark: timing 2000 iterations of One, Three, Two...
       One: 75 wallclock secs (19.91 usr + 53.58 sys = 73.48 CPU) @ 27.22/s
(n=2000)
     Three: 78 wallclock secs (25.86 usr + 52.29 sys = 78.14 CPU) @ 25.59/s
(n=2000)
       Two: 74 wallclock secs (20.92 usr + 52.63 sys = 73.55 CPU) @ 27.19/s
(n=2000)






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

Date: 13 Jul 2001 15:33:30 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: List files in a directory
Message-Id: <9in4ca$c0c$6@bob.news.rcn.net>

Andrew <andrew@mvt.ie> wrote:
> Which is neater & shorter than my while loop (slightly faster too, according
> to my benchmark (below).  One question - why is the output given in the
> order shown, which is different than the order in the script.  (I don't mean
> to imply that execution time would be a big reason to pick one way over
> another for something like this..

> timethese(2000, {

The curly brace here creates a reference to an anonymous ____.  The items 
in a ____ are unordered.  Fill in the blanks :)


>  'One' => '@array = glob "*.pl";',
>  'Two' => '@array = <*.pl>',
>  'Three' => 'while (<*.pl>){ push @array,$_;}',
> });


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

Date: Fri, 13 Jul 2001 13:38:45 GMT
From: Laszlo Gerencser <laszlo.gerencser@portologic.com>
Subject: Re: newbie question regarding tables in perl
Message-Id: <3B4EFA1F.7E6DAF8D@portologic.com>

Well, it seems that I completely misunderstood the original post.
I really can't figure out how and why.
Sorry for that.
It's not my day.

Friday 13th.

--
Laszlo Gerencser
PortoLogic Ltd.


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

Date: Fri, 13 Jul 2001 16:12:00 +0100
From: "Tom Melly" <tom.melly@ccl.com>
Subject: Re: newbie question regarding tables in perl
Message-Id: <3b4f0fc1$0$3762$ed9e5944@reading.news.pipex.net>

"gnari" <gnarinn@hotmail.com> wrote in message
news:995022358.389404777437449.gnarinn@hotmail.com...

<snip>

 ... alternatively, if you want to avoid referencing, you could use a series of
hashes (one for product desc., one for price, etc.). The product ID would be a
suitable key.

e.g.
open(IN, "list.txt");
chomp(@recs = <IN>);

foreach(@recs){
  @prod_array = split /#/, $_ if ($_);
  $descript{$prod_array[0]} = $prod_array[1];
  $price{$prod_array[0]} = $prod_array[2];
}

foreach $key(keys %descript){
  $total = @ARGV[0] * $price{$key};
  print "$key - $descript{$key} - £$price{$key} * @ARGV[0] = £$total\n";
}

where list.txt is something like:
134vf3#a sky-hook#12.34
344432d3#a grommet extractor#5.45




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

Date: Fri, 13 Jul 2001 12:33:26 -0500
From: Roger Dejus <dejus@aps.anl.gov>
Subject: Newbie: Need template script for merging text info from files
Message-Id: <3B4F30E6.84FEFC50@aps.anl.gov>

Hi everyone, hope someone will be able to guide me ... I'm convinced
that this is an easy task for experienced Perl programmers.

I need to take selected text information from several input files and
make a combined output file (with the text reformatted). The input files
typically contain measured data mixed with descriptive texts and the
purpose is to retrieve some of the data and make a summary file (output
file).

Here is my first take on this in plain English (remember, I haven't
coded a piece yet of Perl even though I just got some books and did
reading on the web):

Use an input file (configuration file) to denote the files to be used.
(We will do this for many different configuration files that correspond
to different sets of data to be merged.)

--- file u1.config ---
line1
line2
line3
/home/oxygen/DEJUS/test/perl/u1.out     # output file
/home/oxygen/DEJUS/test/perl/u1.in1     # input file 1
/home/oxygen/DEJUS/test/perl/u1.in2     # inpuf file 2
---

Note: the first three lines are user's text that will identity the run

Here is the pseudo code (in English) what I want to do:
--- file test ---
#!/usr/bin/perl -w

{
read u1.config file to get general info and to get full filenames of
output and
input files

open all files

for each input file
  read whole text file into memory
endfor
close input files

generate new selected output and write to output file
  retrieve info from input files (using line numbers)
    for selected lines, split lines using white space and make formatted
printouts

close output file
done
}
---

Thanks for any comments/help. It will be greatly appreciated.

Cheers, Roger Dejus (dejus@aps.anl.gov).






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

Date: 13 Jul 2001 10:25:21 -0700
From: JC_VA@HOTMAIL.COM (Buck Turgidson)
Subject: Passing sed Expression on Command Line
Message-Id: <265a3988.0107130925.6c148635@posting.google.com>

This should be an easy one.  I have written a simple Perl to use as a
sed for Windows.  However, it does not recognize the expression that I
pass on the command line.
 
Can someone spot my error?




<code>
#!/usr/bin/perl -w

my $sedexpression = $ARGV[0];
my $openfile = $ARGV[1];

open(INFILE,$openfile) or die "Can't open $openfile\n";;
while ($line = <INFILE>) {
    $line =~ $sedexpression;
    # $line =~ s/XX/YY/;  This works fine.
    print $line;
}
close(INFILE);
</code>




<xx.txt>
THIS IS XX
</xx.txt>






<command line>
d:\>perl sedfile.pl s/XX/YY/  xx.txt
THIS IS XX

</command line>


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

Date: 13 Jul 2001 18:12:20 +0100
From: nobull@mail.com
Subject: Re: Q about fork and kill
Message-Id: <u9elrk7nyj.fsf@wcl-l.bham.ac.uk>

Sorry about drifting off-topic here...

logan@cs.utexas.edu (Logan Shaw) writes:

> In article <9a95c0dd.0107121634.1e2b376b@posting.google.com>,
> gene <usenet@smalltime.com> wrote:
> >
> >   8: 		while (kill 0 => $pid) {
> >
> >This works on one machine (Mac OS X), but on another machine (SunOS)
> >the kill statement on line 8 never registers that the child is dead.
> 
> I believe this example is using the old "kill with signal
> zero to test if it exists" trick.  This has never been a
> standard feature on all versions of Unix

Really?  It's in "The Single UNIX Specification, Version 2
- Copyright 1997 The Open Group".

I'd been under the impression that the intension of that document was
to define a minimum set of requirements for an OS to be allowed to use
the trademark "UNIX".  Am I wrong?

Personally I suspect the OP may be suffering from zombies - SUS2 does
not appear to unambiguously define the semantics of doing a kill-zero
on a zombie.

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


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

Date: 13 Jul 2001 14:39:19 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: rand confusion
Message-Id: <9in16n$aur$2@mamenchi.zrz.TU-Berlin.DE>

According to Philip Lees <pjlees@ics.forthcomingevents.gr>:

[ambiguity of "rand < 0.5"]

> But ... the stream of bytes would only make sense as a filehandle read
> if the < was followed by a > later in the line: otherwise it can only

Not necessarily in that line.  <> could contain a complex filehandle-
valued expression that extends far below.

> be a simple condition. Given Perl's amazing string parsing
> capabilities I would have expected the compiler to be able to
> discriminate between the two cases, rather than just throwing up an
> error.

Perl attains its apparent smartness with very little actual knowledge.
AFAIK the parser does a one-token lookahead to resolve such ambiguities.
Sometimes this isn't enough.

>         Something similar could be said about < versus <<.
> Playing around, I was quite surprised to find that this works:
> 
> print rand <<"HERE";
> 4
> HERE

That's because "<<" is a single unambiguous token.
 
Anno



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

Date: Fri, 13 Jul 2001 13:18:13 -0400
From: "TedWeb" <ted_godwin@mindspring.com>
Subject: Random Numbers...
Message-Id: <9inam1$34q$1@slb4.atl.mindspring.net>

Does perl have a random number generator? If so, how do I use it?

Many thanks,
TedWeb




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

Date: Fri, 13 Jul 2001 11:01:13 -0700
From: The Small Kahuna <person@company.com>
Subject: Re: Random Numbers...
Message-Id: <3B4F3769.8BF80578@company.com>

TedWeb wrote:
> 
> Does perl have a random number generator? If so, how do I use it?
> 
> Many thanks,
> TedWeb

You could start by reading perlfunc.


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

Date: 13 Jul 2001 07:49:53 -0700
From: spanchenko@iqsale.com (sergey)
Subject: redirect in Perl
Message-Id: <113301c6.0107130649.29913644@posting.google.com>

I redesign VBScript ASP site to PerlScript ASP site. All worked as for
today under Windows and under Linux.
But now I have module from Cybercash which work on Perl instead of
Perlscript.
My question is : could I have in Perl something like
$Response->Redirect in
PerlScript (realy in ASP) - unconditional redirect to another URL
without pushing any button ?
script could be:
 if ($POP{'pop.status'} =~ /^success/) {
    $Response->Redirect 'new URL'; # and I am on another page.
    };

Perl - ?
In sample I have HTML:
<FORM ACTION='new URL' METHOD='POST'>
but I don't like to have any button.
Thanks,
sergey


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

Date: Fri, 13 Jul 2001 15:10:21 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: script already running
Message-Id: <3B4F014D.876268D@schaffhausen.de>

Hans Scholte schrieb:
> 
> Hi all,
> 
> Does anybody know if there is a way in Perl to check this

Yes, a good cross platform solution is to have a process check
whether some file exists, if not create it, else exit, and after
finishing computations, delete the file. If I remember right
there was some discussion about this method some time ago, so 
go check the google groups (deja) to find it.

Bye,
->malte


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

Date: 13 Jul 2001 13:49:21 GMT
From: TGVCDPVNTLMI@spammotel.com (Ronald Blaschke)
Subject: Re: script already running
Message-Id: <9imu91$k9o14$1@ID-57488.news.dfncis.de>

One easy way is to use a lockfile.  You might write something like
this:

#! c:\perl\bin\perl.exe -w

my $LOCKFILE = 'C:\TEMP\mylock';

die "Already running!" if -f $LOCKFILE;

open LCK, ">$LOCKFILE" or die "Unable to open lockfile $LOCKFILE: $!";
print LCK "## autogenerated lockfile ##";
close LCK or die "Unable to close lockfile $LOCKFILE: $!";

## do something useful here
sleep 10;
## instead

## don't forget to unlink at the end of the program!
unlink $LOCKFILE or die "Unable to unlink $LOCKFILE: $!";


You also might want to check out the LockFile::Simple module.

Ron


On Fri, 13 Jul 2001 08:47:27 +0200, Hans Scholte <hans@salience.nl> wrote:
> Hi all,
> 
> I have a script and i want to know when starting it if it is already running
> and then subsequently die.
> Does anybody know if there is a way in Perl to check this (on a windows
> platform)?
> 
> Thanks,
> 
> Hans
-- 


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

Date: Fri, 13 Jul 2001 10:12:16 -0500
From: David Coppit <newspost@coppit.org>
Subject: Re: script already running
Message-Id: <3B4F0FD0.7040404@coppit.org>

Ronald Blaschke wrote:

> One easy way is to use a lockfile.  You might write something like
> this:
> 
> #! c:\perl\bin\perl.exe -w
> 
> my $LOCKFILE = 'C:\TEMP\mylock';
> 
> die "Already running!" if -f $LOCKFILE;
> 
> open LCK, ">$LOCKFILE" or die "Unable to open lockfile $LOCKFILE: $!";
> print LCK "## autogenerated lockfile ##";
> close LCK or die "Unable to close lockfile $LOCKFILE: $!";
> 
> ## do something useful here
> sleep 10;
> ## instead
> 
> ## don't forget to unlink at the end of the program!
> unlink $LOCKFILE or die "Unable to unlink $LOCKFILE: $!";


Even better:

   END
   {
     unlink $LOCKFILE or die "Unable to unlink $LOCKFILE: $!";
   }

Sometimes something nasty will happen so that your program never reaches 
that line. (Say a module die's unexpectedly.) This ensures that you 
always wipe the lockfile.

> You also might want to check out the LockFile::Simple module.


I wholeheartedly agree. *Don't* reinvent the wheel. Among other things, 
it can detect stale locks.


David



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

Date: Fri, 13 Jul 2001 13:29:12 -0400
From: Marshall Dudley <mdudley@execonn.com>
Subject: search and replace $
Message-Id: <3B4F2FE8.DCEAB8C4@execonn.com>

I don't know if this is a bug, or what, but I am finding it impossible
to search for a dollar sign and replace it with something else.

I am running perl verison 5.005_03

For instance, with the following code:

$text = "this product cost $5 to purchase\n";
$text =~ s/\$/ dollars /;
print "$text\n";


I get the following:

this product cost  to purchase

If I search for any other character than the "$" it works fine, it just
messes up with the dollar sign.

What I am wanting to do in the end is to replace all "$" with "\$" in a
string so I can use it for a regular expression.

Anyone know a workaround for this?

Thanks,

Marshall




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

Date: Fri, 13 Jul 2001 14:51:07 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: Signal SEGV - What is it?
Message-Id: <vVD37.158720$v5.12197549@news1.rdc1.ct.home.com>

Stuart Moore <stumo@bigfoot.com> wrote:

> Just for the record:

> The error was solved when commenting out a particular line of a hash definition
> (as in %hash = (a=>b, ...)
> The value of this key was from a variable, I changed the lines where this
> variable value was obtained, so that exactly the same value was obtained in a
> slightly different manner (it had to de reference the output of a function
> pointing to an array and take the first subscript) and it worked. There's more
> than one way to do it, but one of them causes a signal fault ;-)

That's really, really bad, and it means something's wrong internally. If you
can ship the entire program causing the problem off to activestate that
woul dbe a good thing, since there's a bug in perl somewhere. (If you can
duplicate the death on another OS that'd be even better)

Did you fork() along the way by any chance?

					Dan


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

Date: Fri, 13 Jul 2001 16:33:11 +0200
From: morten@tangeraas.com (=?ISO-8859-1?Q?Morten_Tanger=E5s?=)
Subject: Some more online mailreader questions
Message-Id: <1ewhrfa.12ndbnywodv28N%morten@tangeraas.com>

Hi!

I also have another question. Are there anyone that knows about good
modules that has head and body as input, parses the head and body, and
has from, to, subject, content, attachment etc. as output?



Jitendra Agrawal <jeet@dexponet.com> wrote:

[-- About seing if a message is read or not read--]
> 
> UIDL is the best method, what you might do is whenever a message is
> "retr"ieved you will mark the UIDL as read (in a local index/db).

That might work if the user only uses my mail reader to read online
mail. But it wouldn't work as well it the user also uses other mail
readers, would it?
Anyway, this should at least be better than nothing, so I go for it
until some even better solution shows up :)

[-- Timeout and summary --]

> Are you planning to keep this POP connection open all the time for a
> session till the user logs out.
> 
> I guess better way will be to relogin every time.

Yepp, that's how it works today. But password and server address is
being written to a temporary file which is invisible / unaccessable on
the web (it in a parent directory "above" the web directory on the
server), and this file has a timeout. The timeout time updates when a
user does something (reloads, does a move etc.), and is being deleted
when the user logs out. It will also be deleted if the user tries to do
something when the file has logged out, and you have to log in again.

> You might like to give a "welcome" page which tells just about any
> unread mails.
> using "List" and "UIDL"

Good idea! I also plan to make it possible to set your own settings, so
the user can choose which page he or she wants to see first when the
user logs in!

> and use "TOP 0" to retrieve header. It should left to the user as how
> many mail summaries he/she wants to see, normally webmail service
> providers keep these limits as "10-200".

I think I'll do it that way too, like make "steps" in a select box where
you i.e. can choose 10 - 25 - 50 - 75 - 100 - 150 - 200 or something
like that!

Regards,
Morten


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

Date: Fri, 13 Jul 2001 16:12:47 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: sortlen -- filter to sort text by line length
Message-Id: <tku7fvmi7mmjda@corp.supernews.com>

In article <74f348f7.0107120317.54c631c7@posting.google.com>,
    Yves Orton <demerphq@hotmail.com> wrote:

: Benjamin Goldberg <goldbb2@earthlink.net> wrote in message
: news:<3B49CB78.BD415164@earthlink.net>...
: 
: > Or combine things even further:
: >     print sort { length($a) <=> length($b) } <>;
: > or, with GRT:
: >     print map { substr $_, 4 } sort map { pack 'Na*', length, $_ } <>;
: 
: Curious about something, surely the following is more efficient
: (focusing only on the sort part, input/output concerns aside....)
: 
: #Shwarzian Transform
: my @sorted=map {
:                  $_->[1]
:                } sort { 
:                        $a->[0] <=> $b->[0]
:                       } map {
:                              [length($_),$_]
:                             } @string_list;
: 
: From what Ive read/experienced this type of transform is MUCH more
: efficient than repeatedly calling function on each element in the
: compare part of the sort, especially on large arrays. (Although
: length() may be a special case.  I believe Perl stores the string
: length as part of the SV so it does not need to be mapped out
: first...)

A scalar already knows its length, so all the time and space used
in constructing, accessing, and stripping the augmented list is
wasted.

Greg
-- 
It has been discovered that C++ provides a remarkable facility for concealing
the trival details of a program--such as where its bugs are. 
    -- David Keppel


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

Date: Fri, 13 Jul 2001 13:54:56 +0100
From: "Ben Holness" <bholness@nortelnetworks.com>
Subject: Specifying username and password to networked machine from Perl script on webserver (!)
Message-Id: <9imr8d$61c$1@qnsgh006.europe.nortel.com>

Hi all,

First off, apologies for the cross-post - I have no idea where the solution
to this problem lies!

I have a websever (MS IIS 4) running on Windows NT 4 machine.
Drive U: on this machine is mapped to a Samba server that provides access to
our unix subsystem.

I have a perl script that runs on this webserver and accesses some files
through the Samba server (by looking at the U: drive).

After 30 minutes of inactivity, the samba server gets disconnected from the
webserver (I am not allowed to change this).

If you are sitting locally on the machine, you can reconnect to the samba
server simply by accessing the U: drive, or the machine itself (by finding
the samba server, \\samba, in network neighbourhood and opening it). No
username and password are required in this case - the Windows NT username
and password are used.

Once this connection has been established, the perl script runs fine from
anybody's browser. For the purposes of this post, all that the perl script
does is open a file on the U: drive and print the contents to the users
browser.

If, however, there is more than 30 minutes worth of activity, the samba
server gets disconnected. When someone tries to run the script from the
browser, they get the following message: "The specified network password is
not correct."
When this happens, I go back to the webserver and open the U: drive to
re-establish the connection. The users can now run the script with no
issues, until another 30 minutes worth of activity crops up.

Is there anyway to have this connection re-established with the correct
password, from within the perl script?
If not, can I specify a username and password to connect with?

Hope you can help me with this IIS/Networking/Perl/Samba issue :)

Cheers,

Ben




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

Date: 13 Jul 2001 17:42:32 +0100
From: nobull@mail.com
Subject: Re: Specifying username and password to networked machine from Perl script on webserver (!)
Message-Id: <u9n1687pc7.fsf@wcl-l.bham.ac.uk>

"Ben Holness" <bholness@nortelnetworks.com> writes:
> 
> If you are sitting locally on the machine, you can reconnect to the samba
> server simply by accessing the U: drive, or the machine itself (by finding
> the samba server, \\samba, in network neighbourhood and opening it). No
> username and password are required in this case - the Windows NT username
> and password are used.
> 
> Once this connection has been established, the perl script runs fine from
> anybody's browser. For the purposes of this post, all that the perl script
> does is open a file on the U: drive and print the contents to the users
> browser.
> 
> If, however, there is more than 30 minutes worth of activity, the samba
> server gets disconnected. When someone tries to run the script from the
> browser, they get the following message: "The specified network password is
> not correct."

I suspect this means that you have an old version of Samba.  This
sounds like a description of a security bug I reported and which was
fixed over a year ago.  With the current version of Samba unauthorized
processes on NT servers are not able to obtain illicit access like
this by using a connection set up by another user.

(In other words it's not a bug that it stops working after 30 minutes,
it is a bug that it works at all).

Would it be appropriate to set up the share as public but restricted
by IP address?

> Is there anyway to have this connection re-established with the correct
> password, from within the perl script?

No, like I said you are exploiting a bug.

> If not, can I specify a username and password to connect with?

I've never tried it but in principle I guess you could try:

system("net use \\\\samba\\share $password /USER:$user");

You could also use Win32::NetResource::AddConnection() but it's rather
more complex.

Note you should use UNC names rather than U: throughout your script as
it's rather rude for background jobs to piss about with drive
mappings.

> Hope you can help me with this IIS/Networking/Perl/Samba issue :)

Of course the _real_ solution is to get IIS to run your scripts under
a domain UID rather than a local UID and make Samba use domain
authentication.

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


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

Date: 13 Jul 2001 13:07:15 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: turn off redirect in LWP?
Message-Id: <slrn9ktsks.i7a.rgarciasuarez@rafael.kazibao.net>

Oliver Sass wrote in comp.lang.perl.misc:
> Nevertheless, I will sniff around in the http-headers for a while.

Perhaps a tool that I have written can be helpful to you : an HTTP proxy
that can handle this kind of thing. See
<http://rgarciasuarez.free.fr/perl/biscuit.php3>

-- 
Rafael Garcia-Suarez
use lib sub{$_=$_[1];y;_.mp; ,\n;d;print;
open+0;*0};use Just_another_Perl_hacker;1


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

Date: Fri, 13 Jul 2001 15:43:04 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Using a variable in a regular expression
Message-Id: <3b4f159e.9532486@news.erols.com>

On Fri, 13 Jul 2001 12:42:53 GMT, Peter@angeltec.fsnetNOTTHIS.co.uk (Pete)
wrote:

>>qr// is what you want.
>This system is perl 4 and says something about qr being a future
>reserved word

Yikes!  Is there a reason for not upgrading it to 5?  Don't expect too much
sympathy when code presented here does not work as expected.

>>  if($psk =~ $pskformat) { #do something }
>Why is the 'm' not required somewhere in the string?  Or is that the
>default?

Yup.


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

Date: Fri, 13 Jul 2001 16:32:22 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Using a variable in a regular expression
Message-Id: <x7zoa8x016.fsf@home.sysarch.com>

>>>>> "P" == Pete  <Peter@angeltec.fsnetNOTTHIS.co.uk> writes:

  P> I've been thrown into this and don't understand the difference between
  P> single and double quotes yet - or lots of other things come to that!

that is a fundamental thing you should learn immediately.

  P> This system is perl 4 and says something about qr being a future
  P> reserved word

that is soemthing you must upgrade immediately. no one supports perl4
anymore and too many correct answers you will get rely on perl5. you are
just shooting yourself in the foot using perl4 now.

  >> $pskformat = qr"(\d\d[A-Z][A-Z]\d\d\d\d)";
  >> if($psk =~ $pskformat) { #do something }
  P> Why is the 'm' not required somewhere in the string?  Or is that the
  P> default?  e.g. 
  P> if($psk =~ m"$pskformat) { #do something }

you don't seem to understand the difference between the regular
expression part and the match operator and its delimiters. m// IS NOT a
regex. it CONTAINS a regex. so the m// is not part of the regex and so
it shouldn't be in the variable. and the m is not needed if the match
delimiters are just the normal // (they are also NOT PART OF THE
REGEX). m is required if you choose different delimiters which is nice
when you actually have / in the regex or replacement string. perl hates
requiring using \ any more than you have to so all stringish things
(quoted strings, regex ops, translate, etc.) can have alternate
delimiters.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info:     http://www.sysarch.com/perl/OOP_class.html


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

Date: Fri, 13 Jul 2001 16:55:07 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: Using long integer in PERL
Message-Id: <3B4F19DB.F4A7A378@schaffhausen.de>

Beng schrieb:
> 
> Just a short question :
> 
> I have an array with big numbers, and I am supposed to write a script to
> crunch these numbers and do arithmetric sums on them. The main problem is
> that those numbers are something like 677621651341564.2345, and they exist
> as strings in the array.
> 
> I am trying to convert these strings into some kind of long integer that
> allows me to perform arithmetric functions. The int command won't work for
> my case. Anyone got any suggestions on how I could tackle this problem???

Take a look at the Math modules (standard distribution). They will do
what you want.

->malte


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

Date: 13 Jul 2001 17:46:21 +0100
From: nobull@mail.com
Subject: Re: Using long integer in PERL
Message-Id: <u9itgw7p5u.fsf@wcl-l.bham.ac.uk>

"Beng" <benghua@NOSPAMMING.cyberworks.net.sg> writes:

> I have an array with big numbers, and I am supposed to write a script to
> crunch these numbers and do arithmetric sums on them. The main problem is
> that those numbers are something like 677621651341564.2345, and they exist
> as strings in the array.
> 
> I am trying to convert these strings into some kind of long integer that
> allows me to perform arithmetric functions. The int command won't work for
> my case. Anyone got any suggestions on how I could tackle this problem???

Look on CPAN for a module that handles long integer arithmetic.

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


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

Date: Fri, 13 Jul 2001 10:35:10 -0400
From: "Prasad, Victor [FITZ:K500:EXCH]" <vprasad@americasm01.nt.com>
To: nobull@mail.com
Subject: Re: vvp:Changing Unix Environments with Perl?
Message-Id: <3B4F071E.DD990A4@americasm01.nt.com>

Where do I find the FAQ?

Thanks,

V

nobull@mail.com wrote:
> 
> "Prasad, Victor [FITZ:K500:EXCH]" <vprasad@americasm01.nt.com> writes:
> 
> > I have a script that is trying to change a Unix environment variable:
> 
> Plese see FAQ.
> 
> --
>      \\   ( )
>   .  _\\__[oo
>  .__/  \\ /\@
>  .  l___\\
>   # ll  l\\
>  ###LL  LL\\


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

Date: 13 Jul 2001 15:41:09 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: vvp:Changing Unix Environments with Perl?
Message-Id: <9in4ql$c0c$7@bob.news.rcn.net>

Prasad, Victor [FITZ:K500:EXCH] <vprasad@americasm01.nt.com> wrote:
> Where do I find the FAQ?

In whatever directory the documentation for your Perl installation is 
stored.  There will be 9 documents, perlfaq1.pod..perlfaq9.pod and, 
depending on the nature of your installation, there may be Unix man pages 
or HTML documents generated from them.



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

Date: Fri, 13 Jul 2001 10:51:22 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: vvp:Changing Unix Environments with Perl?
Message-Id: <slrn9ku2na.naj.tadmc@tadmc26.august.net>

Prasad, Victor [FITZ:K500:EXCH] <vprasad@americasm01.nt.com> wrote:

>Where do I find the FAQ?

Didn't the welcome message that you got the first time you
posted tell you that?


You find the Perl FAQ on your very own hard drive:

   perldoc perlfaq


Or, you go to www.google.com and type "Perl FAQ" into the little
search box.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Fri, 13 Jul 2001 11:53:54 +0100
From: "Ben Holness" <bholness@nortelnetworks.com>
Subject: Re: Wildcards in hash (associative) arrays?
Message-Id: <9imk5f$30a$1@qnsgh006.europe.nortel.com>

> >    > Is there any way to wildcard a key, or to pattern
> >    > match a key (something like $dogs{/Spot<:::>Charles/}) in perl?
> >
> >         @matches = @dogs{grep /Spot<:::>Charles/, keys %dogs}
> >
> > Damian
>
> Pretty good! Is there any way to get the full key as well as the value? I
> need to know what the sort key is too...
>

OK figured it out : just use @matches = grep /Spot<:::>Charles/, keys %dogs.

Cheers,

Ben




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

Date: Fri, 13 Jul 2001 10:32:23 +0100
From: "Ben Holness" <bholness@nortelnetworks.com>
Subject: Re: Wildcards in hash (associative) arrays?
Message-Id: <9imfcj$q7$1@qnsgh006.europe.nortel.com>


"Damian Conway" <damian@cs.monash.edu.au> wrote in message
news:9ikjrk$5a8$1@towncrier.cc.monash.edu.au...
> "Ben Holness" <bholness@nortelnetworks.com> writes:
>
>    > Is there any way to wildcard a key, or to pattern
>    > match a key (something like $dogs{/Spot<:::>Charles/}) in perl?
>
>         @matches = @dogs{grep /Spot<:::>Charles/, keys %dogs}
>
> Damian

Pretty good! Is there any way to get the full key as well as the value? I
need to know what the sort key is too...

Cheers




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

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


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