[24430] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6616 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 27 14:05:57 2004

Date: Thu, 27 May 2004 11:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 27 May 2004     Volume: 10 Number: 6616

Today's topics:
        (repost) Math problem - converting between arbitrary ba <ToGroun@NotTo.me>
    Re: accessing Windows 64bit registry <ToGroun@NotTo.me>
        Changing priority and overcoming kill <ToGroun@NotTo.me>
    Re: Changing priority and overcoming kill <jgibson@mail.arc.nasa.gov>
    Re: Error in ldap->add <ittyspam@yahoo.com>
    Re: Error in ldap->add <kkeller-usenet@wombat.san-francisco.ca.us>
        Is there a good process control module on CPAN? <jtc@shell.dimensional.com>
    Re: Listing files sorted by creation time <jgibson@mail.arc.nasa.gov>
        Login to MS Exchange to send e-mail <ywwong_hk@hotmail.com>
    Re: Login to MS Exchange to send e-mail <Petri_member@newsguy.com>
        Making sure that we're dealing with an array (reference <tore@aursand.no>
    Re: Making sure that we're dealing with an array (refer <nobull@mail.com>
    Re: Moving Perl+modules from one directory to another <ToGroun@NotTo.me>
        perl hash speed and memory efficiency (odigity)
    Re: Perl work? <jtc@shell.dimensional.com>
    Re: Perl work? <ThomasKratz@REMOVEwebCAPS.de>
    Re: Perl work? <jtc@shell.dimensional.com>
        Perl: exec function with rename and Java <akarseraszerospam@yahoo.com>
        Preserve aliasing with Map ctcgag@hotmail.com
    Re: Preserve aliasing with Map <nobull@mail.com>
    Re: Remove first letter of each string in array <jtc@shell.dimensional.com>
    Re: Remove first letter of each string in array <ToGroun@NotTo.me>
    Re: Remove first letter of each string in array <tore@aursand.no>
    Re: Remove first letter of each string in array <nobull@mail.com>
    Re: Running remote commands on Windows <ToGroun@NotTo.me>
    Re: Stat() function fails? <http://joecosby.com/code/mail.pl>
    Re: Using Cookies With Perl (GreenLight)
    Re: Using Cookies With Perl <dwall@fastmail.fm>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 27 May 2004 16:00:15 GMT
From: " ! aaa" <ToGroun@NotTo.me>
Subject: (repost) Math problem - converting between arbitrary bases in perl - help!
Message-Id: <7cbc129479039b8818a1e1f5e4a61c35@news.teranews.com>

I Posted earlier to Newsgroups: comp.lang.perl,alt.perl,alt.math,
but this looks like the more appropriate place in hindsight...


Hi all - I've been trying to write a small sub to convert form an input base
(eg: 16) to an output base (eg:64) and back.

The reason is that I need to communicate tristate (base 3) data efficiently
via DNS (base 37 a-z0-9 and '-').

I *could* do it by converting into a "bigmath binary" structure I guess, but
I thought there might be a more elegant way...

but such a solution eludes me.

Can anyone think how to approach the problem?

Below is my NON-working attempt.  I thought of creating a "buffer" (I called
it $remainder) through which I can
convert incoming stuff to the outgoing stuff, but (A) I'm not sure if this
is even possible, and (B) if so, I'm lost
near the end, where I'm "nibbling off" parts of the $remainder variable as I
output results.  In short. I'm wrong
there someplace :-)

# Sorry I forgot to comment it :-))




#!perl

use strict;

# my($from_base)=10; my($to_base)=94; my($data)='92356234';
# my($from_base)=10; my($to_base)=16; my($data)='283036414'; # 283036414
should be 10DECAFE in hex
my($from_base)=16; my($to_base)=10; my($data)='C0DECAFE'; # 283036414 should
be 10DECAFE in hex

my $b2 = &baseconv($from_base,$to_base,$data);
print "Base$from_base($data)=Base$to_base($b2)\n";

sub baseconv {
  my($from_base,$to_base,$data)=@_;
  my
$collseq='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!"#$
%&\'()*+,-./:;<=>?@[\]^_`{|}~'; # 94 "digits"
  my $remainder=0; my $pow=0; my $ret=''; my $tmp; my $mop=0;
  while(($data ne '')||($remainder)) {
    $remainder+=index($collseq,chop $data)*($from_base**($pow++))
while(($data ne '')&&($remainder<(($to_base*$from_base)**2)));
print "remainder=$remainder\n";

    my($tgt)=($to_base*$from_base)**2; $mop=0;
    while((($tgt % $from_base)==0)||(($data eq '')&&($remainder>0))) {
      $pow--; $tgt=$tgt/$from_base;
      $tmp=$remainder % $to_base;
      $ret.=substr($collseq,$tmp,1); $remainder=($remainder-$tmp)/$to_base;
print "ret=$ret data=$data remainder=$remainder tgt=$tgt\n";
exit(0) if($pow<-10);
    }

    # while(($remainder>=$to_base)||($data eq '')) { $tmp=$remainder %
$to_base; $ret.=substr($collseq,$tmp,1); $remainder=($remaind
er-$tmp)/$to_base; }


print "ret=$ret\n";
  }
  return reverse($ret);
}





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

Date: Thu, 27 May 2004 16:19:26 GMT
From: " ! aaa" <ToGroun@NotTo.me>
Subject: Re: accessing Windows 64bit registry
Message-Id: <dfcda46320f85a1df0735d21884fb89f@news.teranews.com>

do this:-

  `regedit.exe -he outfile`;

 ... and read in the resultant file (you gotta wait for the regedit to end
tho, since it's asyncronous)


"Erwin Jussli" <erwin.jussli@t-online.de> wrote in message
news:c8148r$gkm$1@online.de...
> Hi NG,
>
> I am using TieRegistry to access the registries of WinNT,
> Win2000, WinXP and Win2003 to find out the installed
> patches and hotfixes.
>
> What is working well with 32 bit is not working with 64 bit,
> i.e. I am having problems to access the registry of an IA64
> system with Win2003.
>
> Does anyone have any hint for me ?
>
> Thanks and best regards,
> Erwin
>
>




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

Date: Thu, 27 May 2004 16:31:12 GMT
From: " ! aaa" <ToGroun@NotTo.me>
Subject: Changing priority and overcoming kill
Message-Id: <55b25bd74d0c23f8aca08bfe985ffdda@news.teranews.com>

1. Is there a way to relinquish "root" privs in a script, or, some way to
let a "nobody" script listen on ports <1024 easily ?

2. I've got some code which runs in the background (uses fork() inside to do
this automatically) and the background code kicks off another process (a
compiled application in C) - and I'm having some problems with this:-

  If I "kill" the C application, the perl code also gets a kill signal from
somewhere (and so does the code which originally started the perl code too,
if it wasn't run manually!)

What is the correct way to "orphan" a chunk of code so that none of its
parents can suffer related signals later ?
Is there a way to run some other process without being the parent of that
process?

I'm using RedHat BTW.






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

Date: Thu, 27 May 2004 10:37:04 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Changing priority and overcoming kill
Message-Id: <270520041037047592%jgibson@mail.arc.nasa.gov>

In article <55b25bd74d0c23f8aca08bfe985ffdda@news.teranews.com>, ! aaa
<ToGroun@NotTo.me> wrote:

[other problem descriptions snipped]

> 
> What is the correct way to "orphan" a chunk of code so that none of its
> parents can suffer related signals later ?
> Is there a way to run some other process without being the parent of that
> process?
> 

Look at 'perldoc perlipc' and search for 'Complete Dissociation of
Child from Parent' or find a Unix reference and look for 'daemon'.


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

Date: Thu, 27 May 2004 11:31:35 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Error in ldap->add
Message-Id: <20040527112946.D3804@dishwasher.cs.rpi.edu>

On Thu, 27 May 2004 neelesh@netyantra.com wrote:

> Hi....
> I am using perl with open LDAP over linux and i am getting error of
> invalid dn when i use following statement.....
>
> $result = $ldap->add(dn =>'$dn', attr => [$attr]);

The dn is invalid because you are giving a value of the literal string
'$dn'.  That is, the string of a dollar sign, the letter 'd', and the
letter 'n'.

Change it to
dn => "$dn"
or even better
dn => $dn

The problem is that single quoted strings do not undergo variable
interpolation - that is, variable names within ' ' do not expand to their
contents.

Paul Lalli


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

Date: Thu, 27 May 2004 08:31:44 -0700
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: Error in ldap->add
Message-Id: <0l159c.fpo.ln@goaway.wombat.san-francisco.ca.us>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

On 2004-05-27, neelesh@netyantra.com <neelesh@netyantra.com> wrote:
> Hi....
> I am using perl with open LDAP over linux and i am getting error of
> invalid dn when i use following statement.....
>  
> $result = $ldap->add(dn =>'$dn', attr => [$attr]);

Is the string $dn a valid DN for your LDAP server?  Because that's
what your single quotes are doing.  Try

$result = $ldap->add(dn =>"$dn", attr => [$attr]);

or even

$result = $ldap->add(dn => $dn , attr => [$attr]);

- --keith

- -- 
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom

-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQFAtgnehVcNCxZ5ID8RAsvGAJ9cf3IwEFGCOoqvNaOf07NOHE9VRgCeMGaJ
14Tkbo/09+1FpoBs6Nw6hAw=
=ocim
-----END PGP SIGNATURE-----


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

Date: 27 May 2004 10:46:53 -0600
From: Jim Cochrane <jtc@shell.dimensional.com>
Subject: Is there a good process control module on CPAN?
Message-Id: <slrncbc6s3.o13.jtc@shell.dimensional.com>

I'm looking for a good, stable module for controlling processes - execing,
waiting, etc.  It also needs to be portable - that is, work well on at
least UNIX/Linux and Windows.  It looks like:

Proc::Background

is a candidate, but it has no rating on CPAN.  Does anyone know if this is
a reasonably reliable module?  Are there other modules that I should look
at for this?

Sidetrack - Does anyone else find the search.cpan.org search facility
inadequate?  One major complaint I have is that it appears to do
an OR search by default if multiple words are entered in the search
string, although using AND in the string appears to force an and search.
There also appears to be no way to search for a literal word - for example,
I searched for

unix AND windows

and got hits for modules for which 'window' appeared, but not 'windows'.
Could I be missing something or using it wrong?

Thanks!

-- 
Jim Cochrane; jtc@dimensional.com
[When responding by email, include the term non-spam in the subject line to
get through my spam filter.]


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

Date: Thu, 27 May 2004 09:27:38 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Listing files sorted by creation time
Message-Id: <270520040927389574%jgibson@mail.arc.nasa.gov>

In article <5a373b1d.0405270647.239815a0@posting.google.com>, Yash
<yashgt@yahoo.com> wrote:

> Hi,
> 
> I would like to do something with every text file from a directory,
> with the latest created file taken first.
> What is the best way to do this. I am looking for something like:
> 
> for my $file ( <something> glob("/mydir/*.txt") )
> {
>  #my code
> }
> 
> The glob will create an array of filenames. How do I make sure the
> list comes in time order , latest fist?
> 
> Thanks

On unix, you can do:

   my @files = `cd /mydir;ls -t *.txt`;
   for my $file ( @files ) {
      # your code
   }


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

Date: Fri, 28 May 2004 00:36:19 +0800
From: "Y W Wong" <ywwong_hk@hotmail.com>
Subject: Login to MS Exchange to send e-mail
Message-Id: <c956nn$23eb$1@news.hgc.com.hk>

Dear all,

Anyone know that how can I login to a MS Exchange server using my corporate
e-mail account to send a e-mail.
I use to do some automatic job and send the result to my colleagues in my
corporation.
I am using a RH9 Linux box and prefer to use Perl or shell script to do
that.

Many thanks,

YW




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

Date: 27 May 2004 10:14:55 -0700
From: Petri <Petri_member@newsguy.com>
Subject: Re: Login to MS Exchange to send e-mail
Message-Id: <c957mf01dkd@drn.newsguy.com>

In article <c956nn$23eb$1@news.hgc.com.hk>, Y W Wong says...
> Anyone know that how can I login to a MS Exchange server using
> my corporate e-mail account to send a e-mail.
> I use to do some automatic job and send the result to my
> colleagues in my corporation.
> I am using a RH9 Linux box and prefer to use Perl or shell
> script to do that.

Ask your exchange admin to start the SMTP-, and IMAP- or POP3-connectors on the
Exchange Server.
Then use the usual mail-modules available from CPAN.

If the connectors aren't already active, that is.
Have you checked if they are?


Petri



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

Date: Thu, 27 May 2004 18:24:13 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Making sure that we're dealing with an array (reference)
Message-Id: <pan.2004.05.27.16.24.01.678130@aursand.no>

Hi!

One thing that happens quite often when I program in Perl, is that I need
to initialise a variable to be an array reference.

Let me explain what I'm talking about:

  sub init {
      my %ARGS = @_;

      my $paths = $ARGS{'paths'} || [];
  }

In the code above, I want $self->{'_paths'} to always be an array
reference, even if $ARGS{'paths'} is just a plain string.  How can I do
this the best way?

Currently, I'm stuck with code like this:

  my $paths = $ARGS{'paths'} || [];
     $paths = ( ref($paths) eq 'ARRAY' ) ? $paths : [ $paths ];

It seems to work, though, but I feel that there's something wrong with
this approach...?

Even though I have a lot og scripts and modules which uses this code, I
have luckily gathered the code above in my Misc module (50K and still
growing).  The function is called 'as_arrayref' and is quite nice;

  my $ref = as_arrayref( $something );

Tata! :)


-- 
Tore Aursand <tore@aursand.no>
"When you love someone, all your saved-up wishes start coming out."
 (Elizabeth Bowen)


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

Date: 27 May 2004 18:05:33 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Making sure that we're dealing with an array (reference)
Message-Id: <u9r7t5reaq.fsf@wcl-l.bham.ac.uk>

Tore Aursand <tore@aursand.no> writes:

> One thing that happens quite often when I program in Perl, is that I need
> to initialise a variable to be an array reference.

>      $paths = ( ref($paths) eq 'ARRAY' ) ? $paths : [ $paths ];
> 
> It seems to work, though, but I feel that there's something wrong with
> this approach...?

I can't fault it except...

If you know $paths can never be an reference to anything but an array
(and often you do know this) it simplifies to:

   $paths = ref($paths) ? $paths : [ $paths ];

Conversly if $paths is a reference to an object that can function as
an array (either because it really is a blessed array or because it
overloads @{}) then (ref($paths) eq 'ARRAY') will be false even though
it perhaps you would not want to wrap the array.

I can't really see any way round this as it is impossible to tell if
the array-ness of a blessed array is part of the public interface.

It's also seems OTT to test overload::Method($path,'@{}').

> Even though I have a lot og scripts and modules which uses this code, I
> have luckily gathered the code above in my Misc module (50K and still
> growing).  The function is called 'as_arrayref' and is quite nice;
> 
>   my $ref = as_arrayref( $something );

Seems a resonable thing to do.

That said having a huge 'Misc' module may not be as good as several
smaller ones.

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


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

Date: Thu, 27 May 2004 16:11:53 GMT
From: " ! aaa" <ToGroun@NotTo.me>
Subject: Re: Moving Perl+modules from one directory to another
Message-Id: <0e87c6c4daf683931d348d7467ec5de9@news.teranews.com>

Build a test platform and copy it over, instead of doing everything on the
same box?




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

Date: 27 May 2004 10:50:18 -0700
From: ofer@netapt.com (odigity)
Subject: perl hash speed and memory efficiency
Message-Id: <de652f7.0405270950.1d0078b8@posting.google.com>

I'm running some tests to try to gauge the speed of perl's hashing
abilities, as well as the memory footprint.  I wrote this function:

sub buildhash
{
  my %hash;
  foreach my $foo (1..100_000) {
    foreach my $bar ('a'..'z') {
      $hash{"$foo.$bar"} = 1;
    }
  }
  undef %hash;
}

Then I threw in the Benchmark module, like this:

timethis( 1, "buildhash()" );

It seems to use about 200MB of memory for 2.6 million small key/value
pairs, which is pretty efficient (~80bytes/pair).  However, it doesn't
release the memory after the undef (I checked by stopping execution at
that point with a sleep statement and studying memory usage with
`ps`).

It either takes 11 seconds or 75 seconds depending on how I execute
it.  Let me explain.

I first tried running it once, and it took 11 seconds.  I tried twice,
and it took 86.  This didn't make any sense to me.  Here's the command
I used:

timethis( 2, "buildhash()" );

Then I tried unrolling it like this:

timethis( 1, "buildhash()" );
timethis( 1, "buildhash()" );

And that took 22 seconds (11/each), as I expected the first time.

So the question that is most driving me crazy is: For the sake of
Pete, why the difference!?

-ofer


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

Date: 27 May 2004 09:31:14 -0600
From: Jim Cochrane <jtc@shell.dimensional.com>
Subject: Re: Perl work?
Message-Id: <slrncbc2e8.ier.jtc@shell.dimensional.com>

In article <40b5f16f.0@juno.wiesbaden.netsurf.de>, Thomas Kratz wrote:
> John Bokma wrote:
> 
>> AFAIK camels are used in India :-D. And you can eat rice where camels 
>> live :-D
> 
> You can eat rice where camels live, but you most probably can't grow it 
> there. Camels (independent from humpcount) live in hot and dry climates. 
> So the (twohumped) camel that originates from the Gobi desert (and lives 
> domesticated in other dry parts of Asia) comes from China, where they eat 
> rice; but the rice is grown in other parts of China where you have enough 
> rain to do so.
> 
> Thomas
> 

And I suppose the reason that this thread is still relevant to Perl is that
one of the most-recommended Perl books has a picture of a camel on it, eh?

-- 
Jim Cochrane; jtc@dimensional.com
[When responding by email, include the term non-spam in the subject line to
get through my spam filter.]


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

Date: Thu, 27 May 2004 17:41:05 +0200
From: Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de>
Subject: Re: Perl work?
Message-Id: <40b60d96.0@juno.wiesbaden.netsurf.de>

Jim Cochrane wrote:

> In article <40b5f16f.0@juno.wiesbaden.netsurf.de>, Thomas Kratz wrote:
> 
>>John Bokma wrote:
>>
>>
>>>AFAIK camels are used in India :-D. And you can eat rice where camels 
>>>live :-D
>>
>>You can eat rice where camels live, but you most probably can't grow it 
>>there. Camels (independent from humpcount) live in hot and dry climates. 
>>So the (twohumped) camel that originates from the Gobi desert (and lives 
>>domesticated in other dry parts of Asia) comes from China, where they eat 
>>rice; but the rice is grown in other parts of China where you have enough 
>>rain to do so.
>>
>>Thomas
>>
> 
> 
> And I suppose the reason that this thread is still relevant to Perl is that
> one of the most-recommended Perl books has a picture of a camel on it, eh?
> 

No a dromedary ;-)
You're right. This thread went off topic after the second post.

Thomas

-- 
open STDIN,"<&DATA";$=+=14;$%=50;while($_=(seek( #J~.> a>n~>>e~.......>r.
STDIN,$:*$=+$,+$%,0),getc)){/\./&&last;/\w| /&&( #.u.t.^..oP..r.>h>a~.e..
print,$_=$~);/~/&&++$:;/\^/&&--$:;/>/&&++$,;/</  #.>s^~h<t< ..~. ...c.^..
&&--$,;$:%=4;$,%=23;$~=$_;++$i==1?++$,:_;}__END__#....>>e>r^..>l^...>k^..


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

Date: 27 May 2004 09:50:24 -0600
From: Jim Cochrane <jtc@shell.dimensional.com>
Subject: Re: Perl work?
Message-Id: <slrncbc3i6.ier.jtc@shell.dimensional.com>

In article <40b60d96.0@juno.wiesbaden.netsurf.de>, Thomas Kratz wrote:
> Jim Cochrane wrote:
> 
>> In article <40b5f16f.0@juno.wiesbaden.netsurf.de>, Thomas Kratz wrote:
>> 
>>>John Bokma wrote:
>>>
>>>
>>>>AFAIK camels are used in India :-D. And you can eat rice where camels 
>>>>live :-D
>>>
>>>You can eat rice where camels live, but you most probably can't grow it 
>>>...
>> 
>> And I suppose the reason that this thread is still relevant to Perl is that
>> one of the most-recommended Perl books has a picture of a camel on it, eh?
>> 
> 
> No a dromedary ;-)
> You're right. This thread went off topic after the second post.

Yes - it was somewhat interesting at first, but now it's just become
distracting.

:-)

-- 
Jim Cochrane; jtc@dimensional.com
[When responding by email, include the term non-spam in the subject line to
get through my spam filter.]


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

Date: Thu, 27 May 2004 12:16:41 -0400
From: "Andy K" <akarseraszerospam@yahoo.com>
Subject: Perl: exec function with rename and Java
Message-Id: <c9544v$g4i$1@zcars0v6.ca.nortel.com>

Hi

I am trying to use the Perl 'exec' function to execute a Java application
using a different process name, similar to...
    exec {'/bin/sleep'} 'minute', 60;
When I grep for the process, I get 'minute 60' as expected.

However, when calling a Java application, the following call does not to
work:-
    exec {'/opt/java/bin/../bin/PA_RISC2.0/native_threads/java'} 'newname',
myApp;
and I get a coredump.

although I am able to successfully use 'exec' without renaming the process
e.g.
    exec('/opt/java/bin/../bin/PA_RISC2.0/native_threads/java myApp');

For clarification, am avoiding the call to the .java_wrapper in
java/bin...hence the call to the Java binary.
Am using Perl v5.6.1 on an HP-UX 11.11 box

Any ideas how I can call my Java app with 'exec' and successfully rename the
process ?

Thanks.

Andy

P.S.
Wasn't sure whether to post to a Perl of Java ng so thought I'd try here
first





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

Date: 27 May 2004 15:25:26 GMT
From: ctcgag@hotmail.com
Subject: Preserve aliasing with Map
Message-Id: <20040527112526.326$l9@newsreader.com>

I had a script whose inner workings (greatly simplified) worked like this:

foreach my $r (@record) {
  my @codes=something($r);
  foreach my $entry ( grep foo($_), @entry_hash{@codes} ) {
    next unless defined $entry;
    ## do some stuff here
    undef $entry;
  };
}

Since a hash slice gives L-values, and since both grep and foreach do
aliasing, the last line of the inner loop actually changed each value (in
%entry_hash) on which it did work, so that later I could figure out if any
thing in %entry_hash were "orphans" that didn't get operated on.

Later, I needed to change it so that each slot in %entry_hash held a list
of entries, rather than one entry.  But this code:

foreach my $r (@record) {
  my @codes=something($r);
  foreach my $entry ( grep foo($_), map {$_?@$_:()} @entry_hash{@codes} ) {
    next unless defined $entry;
    ## do some stuff here
    undef $entry;
  };
}

Did not work, because the map broke the aliasing chain and so the change to
$entry would not be reflected in the original data structure.  I ended up
adding an extra foreach loop between the inner and outer ones, but I wonder
of there was a more elegant way to preserve the aliasing chain.

Thanks,

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: 27 May 2004 18:09:09 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Preserve aliasing with Map
Message-Id: <u9n03tre4q.fsf@wcl-l.bham.ac.uk>

ctcgag@hotmail.com writes:

> I had a script whose inner workings (greatly simplified) worked like this:

>   foreach my $entry ( grep foo($_), @entry_hash{@codes} ) {

> Later, I needed to change it so that each slot in %entry_hash held a list
> of entries, rather than one entry.  But this code:

>   foreach my $entry ( grep foo($_), map {$_?@$_:()} @entry_hash{@codes} ) {

> Did not work, because the map broke the aliasing chain and so the change to
> $entry would not be reflected in the original data structure.

This is a problem I've encountered a number of times.

> I ended up adding an extra foreach loop

That's what I usually do.

> but I wonder of there was a more elegant way to preserve the
> aliasing chain.

You could switch to using references.
 
  foreach my $entry ( grep foo($$_), map {$_ ? \(@$_) : () } @entry_hash{@codes} ) {

Now a change to $$entry will be reflected in the original data structure.

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


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

Date: 27 May 2004 09:42:33 -0600
From: Jim Cochrane <jtc@shell.dimensional.com>
Subject: Re: Remove first letter of each string in array
Message-Id: <slrncbc33f.ier.jtc@shell.dimensional.com>

In article <7Cmtc.25879$FV7.6195@doctor.cableinet.net>, Julia deSilva wrote:
> Hi there all.
> 
> my @array = qw(1this 2is 3a 4new 5message);
> 
> for (my $x=0;$x<@array;$x++){
>   $array[$x] = substr($array[$x],1,length($array[$x]))
> }
> 
> foreach (@array){print"$_\n";};
> 
> This does indeed remove the first letter of each string in this array, but
> is there a better way ! ?
> 
> Thanks for your help in advance


I'm sure the other replies give you some good solutions, but I needed some
Perl practice, so here's one of the many other ways to do it:

#!/usr/bin/perl

use strict;
use warnings;

my @array = qw(1this 2is 3a 4new 5message);

@array = map {
	/^.(.*)/;
} @array;

foreach (@array){print"$_\n";};

-- 
Jim Cochrane; jtc@dimensional.com
[When responding by email, include the term non-spam in the subject line to
get through my spam filter.]


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

Date: Thu, 27 May 2004 16:07:00 GMT
From: " ! aaa" <ToGroun@NotTo.me>
Subject: Re: Remove first letter of each string in array
Message-Id: <fb1f2371aa91d0585d04aa1c1fbc97ee@news.teranews.com>

reverse() and then chop() might be more efficient ?

otherwise, the whole thing need to get shifted around in memory all the
time.





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

Date: Thu, 27 May 2004 18:51:51 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: Remove first letter of each string in array
Message-Id: <pan.2004.05.27.16.26.41.643930@aursand.no>

On Thu, 27 May 2004 16:07:00 +0000,  ! aaa wrote:
> reverse() and then chop() might be more efficient ?

That _might_ be more effective than using a regular expression, but in
this case 'substr' is far superior.

And - why use 'reverse' and 'chop'?  Do you have a working example?


-- 
Tore Aursand <tore@aursand.no>
"I know not with what weapons World War 3 will be fought, but World War
 4 will be fought with sticks and stones." (Albert Einstein)


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

Date: 27 May 2004 17:50:29 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Remove first letter of each string in array
Message-Id: <u9y8ndrezu.fsf@wcl-l.bham.ac.uk>

Kien Ha <kha@rogers.com> writes:

> Julia deSilva wrote:

> > my @array = qw(1this 2is 3a 4new 5message);
> > for (my $x=0;$x<@array;$x++){
> >   $array[$x] = substr($array[$x],1,length($array[$x]))
> > }
> 
> Shorter and more Perlish:
>    $_ = substr $_, 1 for @array;
> or
>    @array = map { substr $_, 1 } @array;

Note: those do different things.  The first alters the existing
elements of @array the second replaces them with new elements.  This
difference may be significant if there are other references floating
about to the elements of @array.  The second is also a lot slower.

Arguably it's even more ideomatic to say.

  substr $_, 0, 1, '' for @array;

or 

  substr($_, 0, 1) = '' for @array;


However, it's not so fast...

use Benchmark;
my @data = ( 'aaa' ... 'zzz' );
timethese 100 => {
    substr1 => sub {
	my @array = @data;
	$_ = substr $_, 1 for @array;
    },
    substr2 => sub {
	my @array = @data;
	substr $_, 0, 1, '' for @array;
    },
    substr3 => sub {
	my @array = @data;
	substr($_, 0, 1) = '' for @array;
    },
    map => sub {
	my @array = @data;
	@array = map { substr $_, 1 } @array;
    },
};

__END__
Benchmark: timing 100 iterations of map, substr1, substr2, substr3...
       map:  7 wallclock secs ( 7.59 usr +  0.00 sys =  7.59 CPU) @ 13.18/s (n=100)
   substr1:  4 wallclock secs ( 3.89 usr +  0.00 sys =  3.89 CPU) @ 25.71/s (n=100)
   substr2:  4 wallclock secs ( 4.15 usr +  0.00 sys =  4.15 CPU) @ 24.10/s (n=100)
   substr3:  5 wallclock secs ( 5.14 usr +  0.00 sys =  5.14 CPU) @ 19.46/s (n=100)

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


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

Date: Thu, 27 May 2004 16:16:39 GMT
From: " ! aaa" <ToGroun@NotTo.me>
Subject: Re: Running remote commands on Windows
Message-Id: <b83d3174deb87861f5608a01f61c53b8@news.teranews.com>

Win32::OLE and Win32::API are nice.

perl can launch commands natively - system() - so you don't need anything
else really.

Here's how API does it tho:-

  $Shellex = new Win32::API("shell32", "ShellExecute",
['N','P','P','P','P','N'], 'I');
  my $result = $Shellex->Call( $handle, $operation, $file, $params, $dir,
$show);
  return $result > 32;

See MSDN for the SHellExecute FN doco.

"Filipe Bonjour" <fb@i.am.nowhere.net> wrote in message
news:pan.2004.05.21.17.53.16.90199@i.am.nowhere.net...
> Hi,
>
> I'm writing a series of scripts to be run on a Windows 2000 server to
> control applications on a series of other Windows servers.
>
> Most commands to control the application are network-transparent. But we
> still need to launch from the controlling server some commands on the
> running servers. For instance we need to run tlist.exe to gather
> information on processes running remotely.
>
> I tried to find both generic modules for launching commands remotely (e.g.
> Net::Rsh) or more specific modules (e.g. Win32::Process) but I haven't
> found anything 100% satisfactory. I also thought of building a small
> daemon running on the remote servers that would accepts requests, run
> tlist.exe and return the reply. (I was thinking Net::Daemon, because I
> don't know enough about Windows to write a server in C).
>
> Any thoughts would be appreciated!
>
> TIA,
>
> Filipe




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

Date: Thu, 27 May 2004 08:26:29 -0700
From: Joe Cosby <http://joecosby.com/code/mail.pl>
Subject: Re: Stat() function fails?
Message-Id: <rv0cb09lrta6n35im0q49k9fpogmt9caqi@4ax.com>

On Thu, 27 May 2004 07:21:26 -0500, Tad McClellan
<tadmc@augustmail.com> wrote:

>Perhaps you should think a bit more carefully about identifying the root
>cause of the "jumping". It is very very seldom because you asked
>a question, even an obvious one. It is nearly always because
>of some (real or perceived) breach of netiquette.

I apologize if I took something as being insulting when it wasn't
intended to be.

I have gotten a lot of very good help from people on usenet and I have
spent time providing help for other people over the years.  It is a
great source of knowledge.  I do think though that the person asking a
question often gets jumped on.

I wasn't really referring to the replies in general but to the
particular one I followed up to.  It's just the kind of thing I have
seen a lot of times over the years and usually I just ignore it but
yesterday I was finding the docs very frustrating and was under time
pressure and I just wasn't up for it.

As you say, I have undoubtedly paid a price for it.

-- 
Joe Cosby
http://joecosby.com/ 
And this...
   (((
:>(
   (((
 ...might mean you're unhappy because you have gills.

iggy topo
 


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

Date: 27 May 2004 09:58:30 -0700
From: google@milbaugh.com (GreenLight)
Subject: Re: Using Cookies With Perl
Message-Id: <c4b60ce1.0405270858.7526aa2@posting.google.com>

merlyn@stonehenge.com (Randal L. Schwartz) wrote in message news:<6f04cfb363d9fa14a3f928e795072204@news.teranews.com>...
> Many people refer to my
> <http://www.stonehenge.com/merlyn/WebTechniques/col61.html> for "basic
> Cookie Management".

That is an interesting article.

I have found, however, that the File::Cache module is not available on
Win32 with ActiveState Perl 5.6x.

Has anyone recoded Randall's cookie management technique to account
for this shortcoming in AS Perl / Win32?


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

Date: Thu, 27 May 2004 17:08:05 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: Using Cookies With Perl
Message-Id: <Xns94F6859D48FF8dkwwashere@216.168.3.30>

GreenLight <google@milbaugh.com> wrote:

> merlyn@stonehenge.com (Randal L. Schwartz) wrote in message
> news:<6f04cfb363d9fa14a3f928e795072204@news.teranews.com>... 
>> Many people refer to my
>> <http://www.stonehenge.com/merlyn/WebTechniques/col61.html> for
>> "basic Cookie Management".
> 
> That is an interesting article.
> 
> I have found, however, that the File::Cache module is not
> available on Win32 with ActiveState Perl 5.6x.
> 
> Has anyone recoded Randall's cookie management technique to
> account for this shortcoming in AS Perl / Win32?

So just install File::Cache from CPAN, or better yet, install 
Cache::Cache and modify the code appropriately.



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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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