[19490] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1685 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 3 18:06:01 2001

Date: Mon, 3 Sep 2001 15:05:08 -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: <999554708-v10-i1685@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 3 Sep 2001     Volume: 10 Number: 1685

Today's topics:
    Re: accessing hash of hashes in package <goldbb2@earthlink.net>
    Re: array questions (E.Chang)
    Re: array questions <jasper@guideguide.com>
    Re: array questions <dtweed@acm.org>
    Re: array questions (Randal L. Schwartz)
    Re: array questions <tinamue@zedat.fu-berlin.de>
    Re: Bug or silly mistake? (D. Stevenson)
    Re: Can i do the divx stuff with perl? <bcaligari@fireforged.com>
        ending http session <news@althepal#nospam#.com>
    Re: ending http session (David Efflandt)
        ENV{'REMOTE_HOST'}; .... does not work ?! <of@abakus-musik.de>
        Help needed with x,y output <sexyroo@hotmail.com>
    Re: Help needed with x,y output <info@fruiture.de>
    Re: Help needed with x,y output <bwalton@rochester.rr.com>
    Re: Help needed with x,y output (Tad McClellan)
    Re: Help needed with x,y output (Randal L. Schwartz)
    Re: Open 2 exes from Perl <bart.lateur@skynet.be>
    Re: Open 2 exes from Perl <nospam-abuse@ilyaz.org>
    Re: Perl handcoded? <dtweed@acm.org>
    Re: Perl mailing lists - alternative interface? <peb@bms.umist.ac.uk>
    Re: Perl mailing lists - alternative interface? <comdog@panix.com>
    Re: POD2Doc? <rob_13@excite.com>
    Re: Q: File globbing and scalar vars <newspost@coppit.org>
    Re: Recommendations for a PERL editor (Abigail)
    Re: references, slices, voodoo <bart.lateur@skynet.be>
    Re: RegEx? <garry_short@hotmail.com>
        weird kind of eof <bart@nijlen.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 03 Sep 2001 17:59:09 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: accessing hash of hashes in package
Message-Id: <3B93FD2D.2CD099F6@earthlink.net>

Laith Suheimat wrote:
> 
> "Homer J Simpson" <homer@simpsons.com> wrote:
> 
> > Hmm I not sure if I'm write about this by why not have your
> > pkg::create_hoh routine return a reference to the hash you are
> > trying to access. Such as...
> 
> you're right. i've tried it and it works as suggested. here's the
> snippet from the calling script:
> 
> use pkg;
> $hoh_ref = pkg::create_hoh();
> %hoh = %{$hoh_ref};

This doesn't just dereference it, it copies it.

> foreach $outer_key (keys %hoh) {
>    print "\n$outer_key";
>    foreach $inner_key (keys %{$hoh{$outer_key}}) {
>       print "\n$inner_key : $hoh{$outer_key}{$inner_key}";
>    }
> }
> 
> i'm just wondering which is more efficient: accessing the hash in the
> package's namespace, or copying the hash into the caller's namespace?
> is the latter solution equivalent to switching namespaces, viz:

Any copying is generally innefficient.
What would be best would be returning a reference to the hash, and using
that reference as is [not copying it].

> use pkg;
> pkg::create_hoh();
> 
> package pkg;
> 
> foreach $outer_key (keys %hoh) {
>    print "\n$outer_key";
>    foreach $inner_key (keys %{$hoh{$outer_key}}) {
>       print "\n$inner_key : $hoh{$outer_key}{$inner_key}";
>    }
> }

my $hoh_ref = pkg::create_hoh();
while( my ( $outer_key, $outer_val ) = each %$hoh_ref ) {
	print "\n$outer_key";
	while( my ( $inner_key, $inner_val ) = each %$outer_val ) {
		print "\n$inner_key : $inner_key";
	}
}

This code doesn't copy any hashes, nor unnecessarily create lists of
keys, nor do unnecessarily lookups.  It's probably more efficient than
any other version posted so far.

-- 
"I think not," said Descartes, and promptly disappeared.


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

Date: Mon, 03 Sep 2001 16:56:48 GMT
From: echang@netstorm.net (E.Chang)
Subject: Re: array questions
Message-Id: <Xns9111847A611C1echangnetstormnet@207.106.93.86>

Jasper McCrea <jasper@guideguide.com> wrote in
<3B937B6D.1E3CB973@guideguide.com>: 

>"E.Chang" wrote:
>> 
>> "Billy Ng" <kwokng@earthlink.net> wrote in
>> <Ydjk7.702$IP6.68371@newsread2.prod.itd.earthlink.net>:
>> 
>>> I have 2 questions regarding the array.
>>> 
>>> 1) how can I put an array into an array?  If I do push(@parent,
>>> @child), it will add the @child's elements into @parent.  But I
>>> each element in the array is a individual array.  Do I need the
>>> use hash instead? 
>> 
>> The elements of an array are always scalars.  To create an "array
>> of arrays" you will need to use references to arrays as the
>> elements rather than the arrays themselves.  Read the core
>> documentation sections perlreftut, perlref, and perllol.  The
>> documentation in available with your Perl installation and also
>> online at perldoc.com. 
>
>or you could do this:
>
>@array1 = (@array1, @array2);

That produces a single flattened list, the same as using push. That is, 
I believe, not what the OP wants; he wants an array of arrays ("But I 
need ...").

>(straight from 'Learning Perl' IIRC)

Yes, and LP explains that it creates a single list of the elements 
from each.

-- 
EBC


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

Date: Mon, 03 Sep 2001 18:16:13 +0100
From: Jasper McCrea <jasper@guideguide.com>
Subject: Re: array questions
Message-Id: <3B93BADD.4177B527@guideguide.com>

"E.Chang" wrote:
> 
> Jasper McCrea <jasper@guideguide.com> wrote in
> <3B937B6D.1E3CB973@guideguide.com>:

> >or you could do this:
> >
> >@array1 = (@array1, @array2);
> 
> That produces a single flattened list, the same as using push. That is,
> I believe, not what the OP wants; he wants an array of arrays ("But I
> need ...").
> 
> >(straight from 'Learning Perl' IIRC)
> 
> Yes, and LP explains that it creates a single list of the elements
> from each.
> 
> --
> EBC

erk. I feel pretty stoopid, now. Even more so than usual, as if that
were possible.

And my dad always told me to 'read the question'. Still, who ever
listens to their old man.

Jasper
-- 
      split//,'019617511192'.
      '17011111610114101114'.
      '21011141011840799901'.
            '17101174';
            foreach(0..         # my
            $#_){$_[$_          # signature is too
            ++]^=$_[$_          # bignature
            --]^=$_[$_
]^=$_[++    $_]if!($_%
2)}$g.=$_  ,chr($g)=~
 /(\w)/&&($o.=$1and
   $g='')foreach@_;
      print"$o\n"


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

Date: Mon, 03 Sep 2001 17:55:08 GMT
From: Dave Tweed <dtweed@acm.org>
Subject: Re: array questions
Message-Id: <3B93C2E7.C6935F9D@acm.org>

Billy Ng wrote:
> 1) how can I put an array into an array?  If I do push(@parent, @child), it
> will add the @child's elements into @parent.  But I each element in the
> array is a individual array.  Do I need the use hash instead?
> 
> 2) how I pass the mixed type argurments in a subroutine? for example, I want
> to call:
> 
>     foo(@a, $i);

The answer to both questions is: references

For the array of arrays, there are two ways to go about it:

   push @parent, \@child;

will put a reference to the original @child array into @parent. This is
a "shallow" copy -- if you subsequently modify @child in any way, the
effects will be seen via @parent as well.

   push @parent, [@child];

This makes a "deep" copy, which means that fresh copies of all of the
elements in @child are placed in a new anonymous array, a reference to
which is then pushed onto @parent.

Similarly, to pass an array as anything but the last argument to a
subroutine, you can make a reference to the original array, which
means that changes made to the array in the subroutine will be visible
after it returns:

   foo (\@a, $i);

or you can make a new anonymous copy of the array to pass in, which
will be discarded when the subroutine exits:

   foo ([@a], $i);

In either case, inside the subroutine, you need to dereference the
parameter when referring to the array:

   sub foo {
      my ($ra, $i) = @_;
      my $x;

      $x = $ra->[$i];   # not $ra[$i]
      for (@$ra) {      # not @ra
         # ...
      }
   }

If you're not sure which way the subroutine will be called, you can
make another deep copy inside the subroutine and use that:

   sub foo {
      my ($ra, $i) = @_;
      my @a = @$ra;
      my $x;

      $x = $a[$i];
      for (@a) {
         # ...
      }
   }

-- Dave Tweed


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

Date: 03 Sep 2001 11:17:42 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: array questions
Message-Id: <m1g0a4cf5l.fsf@halfdome.holdit.com>

>>>>> "Dave" == Dave Tweed <dtweed@acm.org> writes:

Dave> For the array of arrays, there are two ways to go about it:

Dave>    push @parent, \@child;

Dave> will put a reference to the original @child array into @parent. This is
Dave> a "shallow" copy -- if you subsequently modify @child in any way, the
Dave> effects will be seen via @parent as well.

Dave>    push @parent, [@child];

Dave> This makes a "deep" copy, which means that fresh copies of all of the
Dave> elements in @child are placed in a new anonymous array, a reference to
Dave> which is then pushed onto @parent.

Well, "deeper" copy, but not technically a "deep" copy.  For the difference,
see my article on deep copies at:

        <http://www.stonehenge.com/merlyn/UnixReview/col30.html>

print "Just another Perl hacker,"

(Hmm.  Is there *anything* I haven't written a magazine article
on yet? :)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: 3 Sep 2001 20:18:20 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: array questions
Message-Id: <9n0oic$4n0q0$1@fu-berlin.de>

Dave Tweed <dtweed@acm.org> wrote:
> Billy Ng wrote:
>> 1) how can I put an array into an array?  If I do push(@parent, @child), it
>> will add the @child's elements into @parent.  But I each element in the
>> array is a individual array.  Do I need the use hash instead?
>> 
>> 2) how I pass the mixed type argurments in a subroutine? for example, I want
>> to call:
>> 
>>     foo(@a, $i);

> The answer to both questions is: references

> For the array of arrays, there are two ways to go about it:

>    push @parent, \@child;

> will put a reference to the original @child array into @parent. This is
> a "shallow" copy -- if you subsequently modify @child in any way, the
> effects will be seen via @parent as well.

>    push @parent, [@child];

> This makes a "deep" copy, which means that fresh copies of all of the
> elements in @child are placed in a new anonymous array, a reference to
> which is then pushed onto @parent.

but be aware, if @child contains references, then the "deep"
copy here doesn't mean they are resolved. it just creates fresh
references, but if you modify them, they still will
modify the referenced variable.

regards,
tina

-- 
http://www.tinita.de \  enter__| |__the___ _ _ ___
tina's moviedatabase  \     / _` / _ \/ _ \ '_(_-< of
search & add comments  \    \ _,_\ __/\ __/_| /__/ perception


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

Date: 3 Sep 2001 13:45:06 -0700
From: stevenson.20@nd.edu (D. Stevenson)
Subject: Re: Bug or silly mistake?
Message-Id: <878e2749.0109031245.65fb0bac@posting.google.com>

Thank you all so much.  I just couldn't see it no matter how long I
looked at it.  Thanks for the programming tips that will help me next
time I have a problem.  That the code actually worked for so much of
my data besides "Inf" threw me completely.  Thanks!


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

Date: Mon, 3 Sep 2001 18:07:34 -0000
From: "Brendon Caligari" <bcaligari@fireforged.com>
Subject: Re: Can i do the divx stuff with perl?
Message-Id: <9n0gg50102v@enews2.newsguy.com>


"Dav Lam" <crud@hongkong.com> wrote in message
news:fc25f4f2.0109030001.3d255c60@posting.google.com...
> I'm wondering is it possible to do conversion between common video
> formats(avi, mpeg, etc...) and divx...
>
> Is there a module can handle this kind of job?
>
> Or have anybody ever heard some similar command line program that i
> can integrated them into perl script?

not yet it seems....but check out:

http://www.divx.com
http://www.projectmayo.com
http://www.sourceforge.com (and search for divx)






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

Date: Mon, 03 Sep 2001 16:42:46 GMT
From: Alex Hart <news@althepal#nospam#.com>
Subject: ending http session
Message-Id: <aqOk7.6759$Op6.1210848@typhoon1.gnilink.net>

I'm not sure if this is a protocol question or a programming question,
so excuse me if I'm in the wrong place for this.

If I'm communicating with a web server, assuming the web server does not
send the content length of the document, how do I know when the
transaction is complete? Do I need to monitor the connection somehow, or
will the server send out an identifying EOF? I know the POP server will
send a period (.) alone on a line to signify end of document. Is there
something similar with the server, or is another technique used?

Thanks.

- Alex



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

Date: Mon, 3 Sep 2001 18:25:32 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: ending http session
Message-Id: <slrn9p7ior.62o.efflandt@typhoon.xnet.com>

On Mon, 03 Sep 2001 16:42:46 GMT, Alex Hart <news@althepal#nospam#.com> wrote:
> I'm not sure if this is a protocol question or a programming question,
> so excuse me if I'm in the wrong place for this.
> 
> If I'm communicating with a web server, assuming the web server does not
> send the content length of the document, how do I know when the
> transaction is complete? Do I need to monitor the connection somehow, or
> will the server send out an identifying EOF? I know the POP server will
> send a period (.) alone on a line to signify end of document. Is there
> something similar with the server, or is another technique used?

I posted a more detailed answer with example where you separately posted
this on the *.www.server.unix newsgroup I think.  Basically if there is no
CONTENT_LENGTH header, the response ends when the socket no longer exists,
so when reading the socket you just need to check if it is defined:

while (defined($line = <SOCKET>)) { push @reply,$line; }

-- 
David Efflandt - All spam is ignored - http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: Mon, 3 Sep 2001 23:01:09 +0200
From: "Oliver Fietz" <of@abakus-musik.de>
Subject: ENV{'REMOTE_HOST'}; .... does not work ?!
Message-Id: <9n0r2n$rb4$01$1@news.t-online.com>

Hi

i have a problem to getting my little shopping cart to work on a unix
server.
it did work fine on  a winnt machine.
It look like it has a problem with ip lookup
iam pasting some code at the bottom. iam not very familiar with perl ...
It should produce a file in a temp dir thats filename has the stucture:
"storename"-"customer IP"
The Problem: customer ip is always missing ! This way the shopping cart is
always the same for every user .......


sub get_host {
$host = $ENV{'REMOTE_HOST'};
$reffile = "$tmpdir$delim$storename-$host";
}

Are some server maybe blocking the lookup command ?

any idea ??

thx ... OF





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

Date: Tue, 4 Sep 2001 03:28:46 +1000
From: "sexyroo" <sexyroo@hotmail.com>
Subject: Help needed with x,y output
Message-Id: <3b93bbb7$0$20921$7f31c96c@news01.syd.optusnet.com.au>

Im new to perl and really need assistance with writing a Perl script that
will print the output of specified X and Y factor from a text file...

ie: below is an example of what the text file will contain,

        1,                2,                3,            4,
5,
a,    bob,            mary,            sue,        peter,        sam,
b,    xxx,            xxx,              xxx,        xxx,           xxx,
c,    xxx,            xxx,              xxx,        xxx,           xxx,
d,    xxx,            xxx,              xxx,        xxx,           xxx,
e,    xxx,            xxx,              xxx,        xxx,           xxx,

user will input of row and then input of line and the crossed reference
selected will $print
ie: row = 3 and line = a  ...the output to print will be "sue"

Would anyone be able to send me with an example script that will help
explain how this can be achieved....

Any assistance will be much appreciated
Sexyroo




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

Date: Mon, 3 Sep 2001 20:04:15 +0200
From: "fruiture" <info@fruiture.de>
Subject: Re: Help needed with x,y output
Message-Id: <9n0h5q$ncf$07$1@news.t-online.com>

"sexyroo" <sexyroo@hotmail.com> wrote:
> Im new to perl and really need assistance with writing a Perl script
that
> will print the output of specified X and Y factor from a text file...
>
> ie: below is an example of what the text file will contain,
>
>         1,                2,                3,            4,
> 5,
> a,    bob,            mary,            sue,        peter,        sam,
> b,    xxx,            xxx,              xxx,        xxx,           xxx,
> c,    xxx,            xxx,              xxx,        xxx,           xxx,
> d,    xxx,            xxx,              xxx,        xxx,           xxx,
> e,    xxx,            xxx,              xxx,        xxx,           xxx,
>
> user will input of row and then input of line and the crossed reference
> selected will $print
> ie: row = 3 and line = a  ...the output to print will be "sue"

i do not really knwo what you mean. but try this:

sub make_matrix ($) {
    my $file = shift;
    my $matrix = [];
    open MFILE,"<$file" or return;
    push @$matrix,[ split /,/ ] foreach map chomp($_),<MFILE>;
    close MFILE;
    return $matrix;
}
sub write_matrix ($;$) {
    my $file = shift;
    my $matrix = shift || $_;
    open MFILE,">$file" or return;
    print MFILE (join ',',@$_),$/ foreach @$matrix;
    close MFILE or return;
    return 1;
}

my $matrix = make_matrix('myfile.mtx') or die "Error $!";
while(chomp($_ = <STDIN>) and $_ ne 'end'){
    print 'row> ';chomp(my $row = <STDIN>);
    print 'col> ';chomp(my $col = <STDIN>);
    print $matrix->[$row][$col].$/;
}
HTH

--
require Time::HiRes;my @m=split(/8/,55.52.56.49.49.55.56.49.49.53);push
@m,map{($_%2)?$_-1:$_+1} map ord($_),split//,'u!`onuids!Qdsm!i`bjds';
unshift @m,43 for(0..@m);for(0..@m){print map chr($_),@m[0..(@m/2-1)];
push @m,shift @m;print "\b"x(@m/2);Time::HiRes::usleep(0246*0xA**3);}



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

Date: Mon, 03 Sep 2001 19:19:15 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Help needed with x,y output
Message-Id: <3B93D7A0.55AF1779@rochester.rr.com>

sexyroo wrote:
> 
> Im new to perl and really need assistance with writing a Perl script that
> will print the output of specified X and Y factor from a text file...
> 
> ie: below is an example of what the text file will contain,
> 
>         1,                2,                3,            4,
> 5,
> a,    bob,            mary,            sue,        peter,        sam,
> b,    xxx,            xxx,              xxx,        xxx,           xxx,
> c,    xxx,            xxx,              xxx,        xxx,           xxx,
> d,    xxx,            xxx,              xxx,        xxx,           xxx,
> e,    xxx,            xxx,              xxx,        xxx,           xxx,
> 
> user will input of row and then input of line and the crossed reference
> selected will $print
> ie: row = 3 and line = a  ...the output to print will be "sue"
> 
> Would anyone be able to send me with an example script that will help
> explain how this can be achieved....
 ...
> Sexyroo

Here is one way:

@header=split /[\s,]+/,<DATA>;chomp @header;shift @header;
while(<DATA>){
	chomp;
	@line=split /,\s*/,$_;
	@head=@header;
	$line=shift @line;
	while(@line){
		$data{$line}{shift @head}=shift @line;
	}
}
while(1){
	print "Enter line, column: ";$line=<STDIN>;chomp $line;
	exit unless $line;
	($line,$col)=$line=~/([^,\s]+),\s*(.*)/;
	print "Data is: $data{$line}{$col}\n";
}
__END__
        1,                2,                3,            4, 5,
a,    bob,            mary,            sue,        peter,        sam,
b,    xxx,            xxx,              xxx,        xxx,           xxx,
c,    xxx,            xxx,              xxx,        xxx,           xxx,
d,    xxx,            xxx,              xxx,        xxx,           xxx,
e,    xxx,            xxx,              xxx,        xxx,           xxx,
-- 
Bob Walton


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

Date: Mon, 3 Sep 2001 14:52:01 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Help needed with x,y output
Message-Id: <slrn9p7kah.n24.tadmc@tadmc26.august.net>

sexyroo <sexyroo@hotmail.com> wrote:
>Im new to perl and really need assistance with writing a Perl script that
>will print the output of specified X and Y factor from a text file...
>
>ie: below is an example of what the text file will contain,
>
>        1,                2,                3,            4,
>5,
>a,    bob,            mary,            sue,        peter,        sam,
>b,    xxx,            xxx,              xxx,        xxx,           xxx,
>c,    xxx,            xxx,              xxx,        xxx,           xxx,
>d,    xxx,            xxx,              xxx,        xxx,           xxx,
>e,    xxx,            xxx,              xxx,        xxx,           xxx,
>
>user will input of row and then input of line 


Huh? A "row" _is_ a "line". Did you mean "column" instead of "row" there?


>and the crossed reference
>selected will $print
>ie: row = 3 and line = a  ...the output to print will be "sue"
>
>Would anyone be able to send me with an example script that will help
>explain how this can be achieved....


You can make use of a multiline data structure:

   perldoc perlreftut
   perldoc perlref
   perldoc perllol
   perldoc perldsc


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

my %HoL = (
   a => [ qw/bob mary sue peter sam/ ],
   b => [ qw/xxx xxx xxx xxx xxx/ ],
   c => [ qw/xxx xxx xxx xxx xxx/ ],
);

my $row = 'a';
my $col = 3;

print "$row/$col: '$HoL{$row}[$col-1]'\n";
-------------------------


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


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

Date: 03 Sep 2001 13:07:28 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Help needed with x,y output
Message-Id: <m1u1ykavi7.fsf@halfdome.holdit.com>

>>>>> "sexyroo" == sexyroo  <sexyroo@hotmail.com> writes:

sexyroo>         1,                2,                3,            4,
sexyroo> 5,
sexyroo> a,    bob,            mary,            sue,        peter,        sam,
sexyroo> b,    xxx,            xxx,              xxx,        xxx,           xxx,
sexyroo> c,    xxx,            xxx,              xxx,        xxx,           xxx,
sexyroo> d,    xxx,            xxx,              xxx,        xxx,           xxx,
sexyroo> e,    xxx,            xxx,              xxx,        xxx,           xxx,

sexyroo> user will input of row and then input of line and the crossed reference
sexyroo> selected will $print
sexyroo> ie: row = 3 and line = a  ...the output to print will be "sue"

[as already answered in alt.perl, but MULTIPLY POSTED instead of CROSS
POSTED...]

Well, presuming the data is well-formed (no need for embedded commas),
we merely need to create a "two-dimensional" data structure, such
that $data{"a"}{3} = "sue".

That's a simple matter of iterating over the data:

my @columns = split /,\s*/, <STDIN>; # get 1..5
my %data;
while (<STDIN>) {
  my @row = split /,\s*/;
  my $row_label = shift @row;
  @{$data{$row_label}}{@columns} = @rows;
}

And that's it.  For a detailed explanation, turn to "perldoc perlref"
and "perldoc perlreftut" if you've got it.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Mon, 03 Sep 2001 15:36:10 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Open 2 exes from Perl
Message-Id: <mn87ptctb9o1ggvmncbdbpaqdnriaid2u3@4ax.com>

Ilya Zakharevich wrote:

>With the exception of legacy systems, you can put 1 as the first
>argument to system() to start a program asyncroneously (retval is the PID).

Hold it.

I just tried this on Win32 (Indigoperl 5.6.1 on Win98), and it works:

	system(1, 'notepad');

but htis does not:

	system('1 notepad');

I can't find any mention in the docs (perldoc -f system). Is this one of
those undocumented features, one that may disappear some time in the
near future?

-- 
	Bart.


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

Date: Mon, 3 Sep 2001 16:56:56 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Open 2 exes from Perl
Message-Id: <9n0coo$le$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Bart Lateur 
<bart.lateur@skynet.be>], who wrote in article <mn87ptctb9o1ggvmncbdbpaqdnriaid2u3@4ax.com>:
> Ilya Zakharevich wrote:
> 
> >With the exception of legacy systems, you can put 1 as the first
> >argument to system() to start a program asyncroneously (retval is the PID).
> 
> Hold it.
> 
> I just tried this on Win32 (Indigoperl 5.6.1 on Win98), and it works:
> 
> 	system(1, 'notepad');
> 
> but htis does not:
> 
> 	system('1 notepad');

As far as I can see, here the first argument to system is not 1 (and
by the way, it cannot be '1' either ;-).

> I can't find any mention in the docs (perldoc -f system).

I have no idea about win32 docs, for OS/2 (where it originated - with
a bunch of other possible values, as for spawnve() arguments) it is
documented where OS/2-extensions are documented (perlos2.pod=README.os2).

Ilya


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

Date: Mon, 03 Sep 2001 15:35:03 GMT
From: Dave Tweed <dtweed@acm.org>
Subject: Re: Perl handcoded?
Message-Id: <3B93A1E2.54535617@acm.org>

Dan Sugalski wrote:
> Dave Tweed <dtweed@acm.org> wrote:
> > Lijiv Khil wrote:
> >> I was going through the sources of perl v 1.0. Is Perl written without
> >> using any compiler construction tools like Lex and Yacc? I found that
> >> all the transition tables etc were hand-coded in the sources.
> 
> > Even perl-1.000 (found at http://www.etla.org/retroperl/perl1/) has a
> > perl.y file, so the answer is no. You might be looking at a distribution
> > for a platform that didn't (yet) have a yacc or bison (DOS?), and so it
> > included the pre-processed grammar.
> 
> All versions of perl, AFAIK, come with a preprocessed grammar. We don't
> require a working yacc to build perl.

Who is "we"?

The early kits at the above site don't include the preprocessed grammar
(perl.c), but a distribution of perl-3.018 for MSDOS that I have from
elsewhere does, and it does *not* include perl.y.

I assumed Lijiv asked the question because the distribution that he's
looking at also does not include perl.y.

-- Dave Tweed


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

Date: Mon, 03 Sep 2001 16:22:01 +0100
From: Paul Boardman <peb@bms.umist.ac.uk>
Subject: Re: Perl mailing lists - alternative interface?
Message-Id: <3B93A019.9A0D9F2F@bms.umist.ac.uk>

"Randal L. Schwartz" wrote:
> 
> >>>>> "Rafael" == Rafael Garcia-Suarez <rgarciasuarez@free.fr> writes:
> 
> Rafael> nntp.perl.org carries a lot of mailing lists. It's read-only (I think).
> 
> No, I post all the time through it.  I'm now on all 50-ish mailing lists
> without a single subscription.  Wheee!

how do you ever find the time to do anything but read mail & newsgroup
articles Randal?

Paul


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

Date: Mon, 03 Sep 2001 13:45:19 -0400
From: brian d foy <comdog@panix.com>
Subject: Re: Perl mailing lists - alternative interface?
Message-Id: <comdog-F10D13.13451903092001@news.panix.com>

In article <3B93A019.9A0D9F2F@bms.umist.ac.uk>, Paul Boardman 
<peb@bms.umist.ac.uk> wrote:

> "Randal L. Schwartz" wrote:

> > >>>>> "Rafael" == Rafael Garcia-Suarez <rgarciasuarez@free.fr> writes:

> > Rafael> nntp.perl.org carries a lot of mailing lists. It's read-only (I think).

> > No, I post all the time through it.  I'm now on all 50-ish mailing lists
> > without a single subscription.  Wheee!

> how do you ever find the time to do anything but read mail & newsgroup
> articles Randal?

what makes you think he does anything but read mail & newsgroup articles ;)

-- 
brian d foy <comdog@panix.com> - Perl services for hire
CGI Meta FAQ - http://www.perl.org/CGI_MetaFAQ.html
Troubleshooting CGI scripts - http://www.perl.org/troubleshooting_CGI.html



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

Date: Mon, 03 Sep 2001 19:10:10 GMT
From: "Rob - Rock13.com" <rob_13@excite.com>
Subject: Re: POD2Doc?
Message-Id: <Xns91119A4A4C0D3rock13com@64.8.1.226>

Benjamin Wilson
<news:E5Mk7.59113$hT4.14742628@news1.rdc1.md.home.com>: 

> However, since there is some desire with the customer (i.e., US
> Government) to have things in a 'universal' standard (i.e., MS
> Word--talk about ironic). 

Maybe you should remind them about accessibility. If its on the web 
it is more accessible as HTML than a Word DOC I would presume. :-)

-- 
Rob - http://rock13.com/
Web Stuff: http://rock13.com/webhelp/


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

Date: Mon, 03 Sep 2001 12:17:35 -0400
From: David Coppit <newspost@coppit.org>
Subject: Re: Q: File globbing and scalar vars
Message-Id: <3B93AD1F.6080402@coppit.org>

Eric Bohlman wrote:

> David Coppit <newspost@coppit.org> wrote:
> 
>>>>perl -e '$a = "*";print <$a>'
>>>>
>>>>fails
>>>>
> 
> What's inside the angle brackets is a simple scalar variable, so perl 
> DWIMs the angle-bracket operator to an indirect filehandle read.


Ah... A case of DWIM being DWIDM. :) The idea is to assume that it's a 
reference to a filehandle instead of a string. Got it.

Thanks,
David



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

Date: 3 Sep 2001 17:59:00 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Recommendations for a PERL editor
Message-Id: <slrn9p7h70.dfa.abigail@alexandra.xs4all.nl>

RoJo (rojo@mindspring.com) wrote on MMCMXXIV September MCMXCIII in
<URL:news:3b926160.358347636@news.mindspring.com>:
@@ 
@@ I'm new to PERL.

We could see that from the subject of your post. You fail to spell the
name of the language correctly. It's called Perl, or perl for the binary.

@@                   I keep getting "The page cannot be displayed" when I
@@ use Windows 2000's Notepad to edit my scripts.  An ISP support person
@@ tells me it has syntax errors that are introduced by the editor.

Really? Could the ISP support person also say what the introduced syntax
errors were, or was (s)he just bullshitting?

@@ Can someone recommend to me a reliable Windows-based editor that WON'T
@@ create these problems for me ???

Did you check the FAQ?

@@ My email address is rojo@mindspring.com

Why repeat what's obvious from the headers?



Abigail
-- 
BEGIN{$^H=2097152}$_="(?\173\160\162\151\156\164'\112\165\163\164\040\141\156".
"\157\164\150\145\162\40\120\145\162\154\40H\141\143\153\145\162\012'\175)";/$_/


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

Date: Mon, 03 Sep 2001 15:12:58 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: references, slices, voodoo
Message-Id: <qo67ptkej2sqqfkm9imteu4hohmrca3gfk@4ax.com>

Walter Hafner wrote:

># fisher_yates_shuffle( \@array ) :
># generate a random permutation of @array in place
>sub fisher_yates_shuffle {
>  my $array = shift;
>  for (my $i = @$array; --$i; ) {
>    my $j = int rand ($i+1);
>    @$array[$i,$j] = @$array[$j,$i] unless  $i == $j; # ???
>  }
>}

>Well, it works - but that's not surprising, being in the FAQs.
>Since i don't like to use code I don't understand, i really need to know 
>WHY this code works.

Ok... the basic idea is: for your first element, you pick any element
from the array. For your second element, you pick any item from the
remainder. Etc... For simplicity of coding, replace "first" with "last",
i.e. you start from the back...

So how does it work? Say you start with 5 elements, "zero", "one",
"two", "three" and "four". You pick a random integer less than 5, i.e.
any integer between 0 (incl.) and 4 (incl.). Say you get 2. You get that
element there, "two", and swap it with the element at position 4:
"four". So the sequence is now "zero", "one", "four", three", "two". For
the next step, the last element (the "two") is ignored, so you have 4.
You pick a random item from these 4... continue until there's only one
left. Your array is shuffled.

As for the array slice:

	@ary[2, 4] = @ary[4, 2];

is functionally equivalent to

	($ary[2], $ary[4]) = ($ary[4], $ary[2]);

so you simply switch the contents of those two scalars.

Remains: the $i!=$j test. You could have troubles if you were to try

	@ary[4, 4] = @ary[4, 4];

because you'd be assinging to the same scalar twice. This is now
supposed to be a null operation, so the simplest is just to skip it. 
(In fact, uner 5.6.1 this doesn't give an error.)

-- 
	Bart.


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

Date: Mon, 3 Sep 2001 22:49:46 +0100
From: "Garry Short" <garry_short@hotmail.com>
Subject: Re: RegEx?
Message-Id: <999554113.24059.0.nnrp-07.d4e59550@news.demon.co.uk>

Just out of interest, why a regex? How about using split instead?

my ($firstname, $lastname, $email) = split /\s+/, $row->[1];
# the above splits on varying amounts of whitespace

# If you wanted, you could then do ...
my $from = join(" ", $firstname, $lastname);

would give you what you wanted, and more besides. Additionally, I seem to
recall that this would work quicker than a regex, so could be useful for big
files.

Regards,

Garry


"Jason Baker" <baker@Akira.cyborgworkshop.com> wrote in message
news:tokodmm7552r95@news.supernews.com...
> I hope this is a simple problem that I have just been staring at for too
long.  I have, in a database, a field that looks like this
>
> firstname lastname <email@wherever.com>
>
> All I want to do is capture the name, not email address, into a variable.
I have tried this
>
> my ($from) = $row->[1] =~ /^  .. \</;
>
> and several other variations of that with no luck.  Anyone care to help a
guy out?
>
> --
>               Jason
>        www.cyborgworkshop.com
> ...and the geek shall inherit the earth...




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

Date: Mon, 03 Sep 2001 21:08:47 GMT
From: "Bart Van der Donck" <bart@nijlen.com>
Subject: weird kind of eof
Message-Id: <zjSk7.34414$6x5.7423595@afrodite.telenet-ops.be>

Hello,

My string contains an eof that I cannot detect.
The purpose is to delete the eof from my string.

I tried about all to delete it:
chop $a;
chomp $a;
$a=~s/\n\gi;
$a=~s/\\n\gi;
$a=~s/\^M//gi;
and some others that I found in the docs.

In notepad the string appears as a little square. On a unix prompt it has
the same effect as pressing the "Return"-key.

The question is:
Is there a line that erases all kinds of eofs (DOS, Unix) from my string ?

Many thanks
Bart




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

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


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