[19937] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2132 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 14 14:11:13 2001

Date: Wed, 14 Nov 2001 11:10:13 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1005765013-v10-i2132@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 14 Nov 2001     Volume: 10 Number: 2132

Today's topics:
    Re: ranged arrays (Anno Siegel)
    Re: ranged arrays <djberge@qwest.com>
    Re: ranged arrays (Logan Shaw)
    Re: ranged arrays <tsee@gmx.net>
    Re: ranged arrays <tsee@gmx.net>
    Re: ranged arrays <tsee@gmx.net>
    Re: Re: Using TCP "keep alives" with IO::Socket <4875.3bf2a342.1804289383@temp>
    Re: RegEx problem -- trying to match To: or From: at be <Tassilo.Parseval@post.rwth-aachen.de>
    Re: Returning peer information with IO:Sockets ? (Garry Williams)
    Re: socket buffering even with $| set <uri@stemsystems.com>
        Tie and anonymous hashes <mark.riehl@agilecommunications.com>
    Re: Tie and anonymous hashes <Tassilo.Parseval@post.rwth-aachen.de>
    Re: Tie and anonymous hashes <mark.riehl@agilecommunications.com>
    Re: Tie and anonymous hashes <Tassilo.Parseval@post.rwth-aachen.de>
    Re: Tie and anonymous hashes <mbudash@sonic.net>
    Re: web page editing with browser (Ifan Payne)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 14 Nov 2001 16:23:42 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: ranged arrays
Message-Id: <9su5qe$4pd$1@mamenchi.zrz.TU-Berlin.DE>

According to Steffen Müller <tsee@gmx.net>:
> Hi,
>     I know fixed range arrays (eg. arrays that are only valid between -5 and
> 50) don't exist in Perl. That's why I tried to cook up some hack using tie.
> In TIEARRAY, I used the following little hack to create an array that can
> hold $upper_limit-$lower_limit scalars.
> 
> $#{$self->{ARRAY}} = $self->{UPPER} - $self->{LOWER};
> 
>     This and most of the rest work fine, but there's something that makes
> the whole attempt futile: Instead of passing negative index values to the
> appropriate methods, perl translates them to non-negatives the way we're
> used to with arrays starting at 0 by using FETCHSIZE.
>     If perl passed the negative index values to the custom methods, I could
> map them to the upper range of the array myself so that I could test for
> indices to be within $lower_limit < $index < $upper_limit instead of
> $lower_limit < $index < $#{$self->{ARRAY}}!
> Does anybody have a workaround for this?
> 
> (Almost) any input approciated.

Rearrange storage accordingly.  In your -5 .. 50 example, store elements
0 .. 50 under indices 0 .. 50, then -5 .. -1 under 51 .. 55.  Well,
actually this will happen all by itself when you initialize the actual
array to [ ( undef ) x ( $upper - $lower)].  The drawback is that you
cannot tell the user in an error message whether they have violated the
upper or the lower limit, you'll only know they're out of range.

Anno


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

Date: Wed, 14 Nov 2001 11:54:55 -0600
From: "Mr. Sunblade" <djberge@qwest.com>
Subject: Re: ranged arrays
Message-Id: <%9yI7.35$J13.77754@news.uswest.net>


"Steffen Müller" <tsee@gmx.net> wrote in message
news:9su1ms$c5u$00$1@news.t-online.com...
> Hi,
>     I know fixed range arrays (eg. arrays that are only valid between -5
and
> 50) don't exist in Perl. That's why I tried to cook up some hack using
tie.
> In TIEARRAY, I used the following little hack to create an array that can
> hold $upper_limit-$lower_limit scalars.
>
> $#{$self->{ARRAY}} = $self->{UPPER} - $self->{LOWER};
>
>     This and most of the rest work fine, but there's something that makes
> the whole attempt futile: Instead of passing negative index values to the
> appropriate methods, perl translates them to non-negatives the way we're
> used to with arrays starting at 0 by using FETCHSIZE.
>     If perl passed the negative index values to the custom methods, I
could
> map them to the upper range of the array myself so that I could test for
> indices to be within $lower_limit < $index < $upper_limit instead of
> $lower_limit < $index < $#{$self->{ARRAY}}!
> Does anybody have a workaround for this?
>
> (Almost) any input approciated.

Take a look at Set::IntRange by Steffen Beyer (on CPAN) if you're willing to
install a module.  I suspect it does what you want.  If not, perhaps you can
cajole Robert Rothenberg to create a Tie::RangeArray module (he already has
a Tie::RangeHash module out there).

Regards,

Mr. Sunblade




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

Date: 14 Nov 2001 12:10:24 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: ranged arrays
Message-Id: <9suc2g$cqv$1@charity.cs.utexas.edu>

In article <9su1ms$c5u$00$1@news.t-online.com>,
Steffen Müller <tsee@gmx.net> wrote:
>    I know fixed range arrays (eg. arrays that are only valid between -5 and
>50) don't exist in Perl. That's why I tried to cook up some hack using tie.
  :
  :
>    This and most of the rest work fine, but there's something that makes
>the whole attempt futile: Instead of passing negative index values to the
>appropriate methods, perl translates them to non-negatives the way we're
>used to with arrays starting at 0 by using FETCHSIZE.

If you can live with having a different syntax, you can could simply
define a class that does bounded arrays.  The fact that recent versions
of Perl have lvalue subroutines make that syntax a lot less ugly.

You should be able to code it so that usign it looks something like
this:

	use BoundedArray;

	$ba = BoundedArray->new(-5, 50);

	$ba->at(-3) = 17;
	print $ba->at(-3), "\n";

Handling slices of the bounded array will be a little bit trickier, but
I think even that can be done if you define a function that returns an
lvalue array, and if that lvalue array is not the internal storage
itself but an array that happens to be tied back to your object.

Then you can do something like this:

	$ba->slice(-1, 2) = qw{ a b c d };

When you do this, slice() would create a new tied array that's bound to
the values at -1, 0, 1, and 2 and would return that tied array as an
lvalue.  Then when you assign qw{ a b c d } to it, the tied array would
call back into the BoundedArray object to set the elements to the
appropriate values.  Or rather, it would call back into the
BoundedArray object to retrieve the necessary lvalues to assign the
values to.  :-)

I'd also make slice() with no arguments create an lvalue tie binding to
the whole array, so you can do this:

	foreach my $x ($ba->slice())
	{
	    $x =~ s/foo/bar/;
	}

I know there's a little more to do (like splice()) to make that do
everything real arrays do, but it's pretty close.

Of course, I realize this is twisted, but it could be fun!

Another approach, which is a gross hack, is to create contexts on the
fly in which to set $[ and create your arrays.  Since this is so
thoroughly evil, I will speak about it no more.  (I'm not sure it's
even really possible.  "perldoc perlvar" says it's a compiler directive
now, and it "cannot influence the behavior of any other file", which
means little to me since in my mind files don't "behave".)

  - Logan
-- 
"In order to be prepared to hope in what does not deceive,
 we must first lose hope in everything that deceives."

                                          Georges Bernanos


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

Date: Wed, 14 Nov 2001 19:26:39 +0100
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: ranged arrays
Message-Id: <9sue20$30a$06$1@news.t-online.com>

"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> schrieb im Newsbeitrag
news:9su5qe$4pd$1@mamenchi.zrz.TU-Berlin.DE...
| According to Steffen Müller <tsee@gmx.net>:

[...]

| >     If perl passed the negative index values to the custom methods, I
could
| > map them to the upper range of the array myself so that I could test for
| > indices to be within $lower_limit < $index < $upper_limit instead of
| > $lower_limit < $index < $#{$self->{ARRAY}}!
| > Does anybody have a workaround for this?
|
| Rearrange storage accordingly.  In your -5 .. 50 example, store elements
| 0 .. 50 under indices 0 .. 50, then -5 .. -1 under 51 .. 55.  Well,
| actually this will happen all by itself when you initialize the actual
| array to [ ( undef ) x ( $upper - $lower)].  The drawback is that you
| cannot tell the user in an error message whether they have violated the
| upper or the lower limit, you'll only know they're out of range.

I did that initialization for just that reason. I can't even warn the users
that they've violated any limit in *all* cases. The problem is that my
FETCH/STORE methods never see the original negative value. In my example,
Perl automatically maps -5..-1 to 51..55, so I must not warn if the users
access 51..55 because I don't want to warn if they access -5..-1 (because
for my method, it looks exactly the same).

Seems kind of hopeless to get it working *this* way. *sigh*

Steffen
--
$_=q;0cb212c210b0bb010c0113bb0c410c0b516c0bb3d212c2b0b0b016b6cb2b2c21010c0
b41110b3bba0e0c0d2c4b2b6bc013d2c0d0b01012b0b0;;s/\n//g;s/(\d)/$1<2?$1:'0'x
$1/ge;s/([a-f])/'1'x(ord($1)-97)/ge;print"\n";$o=$_;push@o,substr($o,$_*8,
8)for(0..24);for(@o){print"\0"x(26-$i).chr(oct('0b'.($_)))."\n";$i++}#st_m





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

Date: Wed, 14 Nov 2001 19:44:13 +0100
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: ranged arrays
Message-Id: <9sue21$30a$06$3@news.t-online.com>

"Logan Shaw" <logan@cs.utexas.edu> schrieb im Newsbeitrag
news:9suc2g$cqv$1@charity.cs.utexas.edu...
| In article <9su1ms$c5u$00$1@news.t-online.com>,
| Steffen Müller <tsee@gmx.net> wrote:
| >    I know fixed range arrays (eg. arrays that are only valid between -5
and
| >50) don't exist in Perl. That's why I tried to cook up some hack using
tie.
|   :
|   :
| >    This and most of the rest work fine, but there's something that makes
| >the whole attempt futile: Instead of passing negative index values to the
| >appropriate methods, perl translates them to non-negatives the way we're
| >used to with arrays starting at 0 by using FETCHSIZE.
|
| If you can live with having a different syntax, you can could simply
| define a class that does bounded arrays.  The fact that recent versions
| of Perl have lvalue subroutines make that syntax a lot less ugly.

I thought about using lvalue subs, but so far, I preferred trying to do it
the 'tie'-way. That would just have the most intuitive syntax.

| You should be able to code it so that usign it looks something like
| this:
|
| use BoundedArray;
|
| $ba = BoundedArray->new(-5, 50);
|
| $ba->at(-3) = 17;
| print $ba->at(-3), "\n";

Well, that would certainly work, but I wonder whether that's intuitive
syntax?
Besides, what really scares me away from lvalue subs is perlsub:

"WARNING: Lvalue subroutines are still experimental and the implementation
may change in future versions of Perl."

| Handling slices of the bounded array will be a little bit trickier, but
| I think even that can be done if you define a function that returns an
| lvalue array, and if that lvalue array is not the internal storage
| itself but an array that happens to be tied back to your object.
|
| Then you can do something like this:
|
| $ba->slice(-1, 2) = qw{ a b c d };
|
| When you do this, slice() would create a new tied array that's bound to
| the values at -1, 0, 1, and 2 and would return that tied array as an
| lvalue.  Then when you assign qw{ a b c d } to it, the tied array would
| call back into the BoundedArray object to set the elements to the
| appropriate values.  Or rather, it would call back into the
| BoundedArray object to retrieve the necessary lvalues to assign the
| values to.  :-)
|
| I'd also make slice() with no arguments create an lvalue tie binding to
| the whole array, so you can do this:
|
| foreach my $x ($ba->slice())
| {
|     $x =~ s/foo/bar/;
| }
|
| I know there's a little more to do (like splice()) to make that do
| everything real arrays do, but it's pretty close.
|
| Of course, I realize this is twisted, but it could be fun!

Which is why I'm planning to do it.

| Another approach, which is a gross hack, is to create contexts on the
| fly in which to set $[ and create your arrays.  Since this is so
| thoroughly evil, I will speak about it no more.  (I'm not sure it's
| even really possible.  "perldoc perlvar" says it's a compiler directive
| now, and it "cannot influence the behavior of any other file", which
| means little to me since in my mind files don't "behave".)

That is so evil I haven't wasted more than... umm... one thought on it.
Really, no more.

Thanks for your input. It's the only solution so far.

Steffen
--
$_=q;0cb212c210b0bb010c0113bb0c410c0b516c0bb3d212c2b0b0b016b6cb2b2c21010c0
b41110b3bba0e0c0d2c4b2b6bc013d2c0d0b01012b0b0;;s/\n//g;s/(\d)/$1<2?$1:'0'x
$1/ge;s/([a-f])/'1'x(ord($1)-97)/ge;print"\n";$o=$_;push@o,substr($o,$_*8,
8)for(0..24);for(@o){print"\0"x(26-$i).chr(oct('0b'.($_)))."\n";$i++}#st_m




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

Date: Wed, 14 Nov 2001 19:37:58 +0100
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: ranged arrays
Message-Id: <9sue21$30a$06$2@news.t-online.com>


"Mr. Sunblade" <djberge@qwest.com> schrieb im Newsbeitrag
news:%9yI7.35$J13.77754@news.uswest.net...
|
| Take a look at Set::IntRange by Steffen Beyer (on CPAN) if you're willing
to
| install a module.  I suspect it does what you want.  If not, perhaps you
can
| cajole Robert Rothenberg to create a Tie::RangeArray module (he already
has
| a Tie::RangeHash module out there).

Sure I'm willing to install modules. I had a look at the two and eventhough
they're interesting (will keep them in mind for some experiments later on),
they have little to do with my problem - save the name.
About the Tie::RangeArray module: Guess what I was trying to do? :)

Steffen
--
$_=q;0cb212c210b0bb010c0113bb0c410c0b516c0bb3d212c2b0b0b016b6cb2b2c21010c0
b41110b3bba0e0c0d2c4b2b6bc013d2c0d0b01012b0b0;;s/\n//g;s/(\d)/$1<2?$1:'0'x
$1/ge;s/([a-f])/'1'x(ord($1)-97)/ge;print"\n";$o=$_;push@o,substr($o,$_*8,
8)for(0..24);for(@o){print"\0"x(26-$i).chr(oct('0b'.($_)))."\n";$i++}#st_m





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

Date: Wed, 14 Nov 2001 17:06:10 GMT
From: "4875.3bf2a342.1804289383" <4875.3bf2a342.1804289383@temp>
Subject: Re: Re: Using TCP "keep alives" with IO::Socket
Message-Id: <3bf2a482.494e.1804289383@opus.randori.com>

> nokesja@netscape.net wrote:
> > I've been scouring the internet, news, all the
> PerlFAQ's,
> > PerlMonks, and every O'reilly book I have ... and I
> cannot
> > find any article that discusses how to utilize the perl
> > IO::Socket module and TCP 'keep-alives'.
>
> > Can anyone help me shed some light on this?
>
> perldoc IO::Socket::INET says refer to IO::Socket for
> options, which
> says it unifies getsockopt(2) and setsockopt(2) as
> sockopt(). Trying man
> 2 setsockopt says refer to socket(7) for details, which
> finally shows
> that SO_KEEPALIVE is indeed a valid option.
>
> So, without trying it, and assuming your IP stack supports
> it, I would
> imagine that calling sockopt(SO_KEEPALIVE,1) would solve
> your problem.
>
> Have you tried this and does it work?
> Chris

Thanks for the help Chris.  I have tried coding this in, now
I just need a way to test it.  I guess I need a sniffer of
some sort to look at the TCP activity on my Solaris box to
make sure the "keep alive" packets are actually being sent. 
If you have any suggestions for a good packet sniffer, let
me know.  I'll post a follow-up if I get this thing working.

Thanks again,
 - Jeff


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

Date: Wed, 14 Nov 2001 17:48:16 +0100
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: RegEx problem -- trying to match To: or From: at beginning of line
Message-Id: <9su78g$6jt$04$2@news.t-online.com>

On Wed, 14 Nov 2001 15:52:10 GMT, Mark wrote:
> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
> news:9sthio$9jq$1@mamenchi.zrz.TU-Berlin.DE...
> 
>> According to Mark <admin@asarian-host.net>:
> 
>> > /^(To|From):/i
>>
>> You have said this twice, explaining correctly why the caret must be
>> where it is. However, you haven't explained why you propose the /i
>> modifier. It shouldn't be there, IMHO.
> 
> 
> According to RFC822 (STANDARD FOR THE FORMAT OF ARPA INTERNET TEXT
> MESSAGES), "A field-name consists of one or more printable characters
> (excluding colon, space, and control-characters). A field-name MUST be
> contained on one line. Upper and lower case are not distinguished when
> comparing field-names." I further quote, "When matching any other syntactic
> unit, case is to be ignored. For example, the field-names 'From', 'FROM',
> 'from', and even 'FroM' are semantically equal and should all be treated
> identically."

I think 822 is sort of contradicting itself. Quote from
part 4 "MESSAGE SPECIFICATIONS" reads as follows:

     authentic   =   "From"       ":"   mailbox  ; Single author
                 / ( "Sender"     ":"   mailbox  ; Actual submittor
                     "From"       ":" 1#mailbox) ; Multiple authors
                                                 ;  or not sender

These actually look like literals to me so one might thought that case
does matter.

Of course, your quote still stands and technically case does indeed not matter.
In practice however I'd leave the /i out. I grepped all of my mailboxes.
There is not one single mail among a few thousand that has a field-name
that does not at least start with a capital letter and then following
small ones. One exception: the field-name contains a hyphen, so I can
find "Message-Id", "Message-ID", "Message-id", "Reply-To", "Reply-to"
etc in my mails. So in favour of speed I'd write 

/^Message-[Ii][Dd]: /

if I wanted to match this line.
/

Tassilo
-- 
She liked him; he was a man of many qualities, even if most of them were bad.


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

Date: Wed, 14 Nov 2001 16:32:34 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Returning peer information with IO:Sockets ?
Message-Id: <slrn9v5755.3jm.garry@zfw.zvolve.net>

On Wed, 14 Nov 2001 15:38:28 -0000, Scott <thechile@ntlworld.com>
wrote:

> Does anyone know if its possible to return peer info using
> IO:sockets. I know that if you just use UNIX sockets you can call
> getpeername and sockaddre_in etc.. to get the client ip and port
> number but i can't find any info on this with the perl module??

The answer is plainly available in the manual pages for IO::Socket and
IO::Socket::INET.  

-- 
Garry Williams


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

Date: Wed, 14 Nov 2001 18:54:34 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: socket buffering even with $| set
Message-Id: <x7k7wtgp1c.fsf@home.sysarch.com>

>>>>> "MC" == Maurizio Codogno <mau@beatles.cselt.it> writes:

  MC> =-=-=-=-=
  MC> #!/bin/perl

  MC> use IO::Socket;

  MC> my $server_port = 31416;

  MC> $server = IO::Socket::INET->new(LocalPort => $server_port,
  MC>                                 Type      => SOCK_STREAM,
  MC>                                 Reuse     => 1,
  MC>                                 Listen    => 10 )   # or SOMAXCONN
  MC>     or die "Couldn't be a tcp server on port $server_port : $@\n";

  MC> # output is sent right away!
  MC> select ((select($server), $|=1)[0]);

that has no effect on accepted sockets. a server/listener socket never
does any i/o, it is only used for accepting connections.


  MC> while ($client = $server->accept()) {

IO::Socket now makes sockets unbuffered by default. check your version
of perl and this module and upgrade if necessary.

also you can call 

	$client->autoflush() ;

which is much nicer then the single arg select call hack you use above.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
-- Stem is an Open Source Network Development Toolkit and Application Suite -
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Wed, 14 Nov 2001 17:00:11 GMT
From: "Mark Riehl" <mark.riehl@agilecommunications.com>
Subject: Tie and anonymous hashes
Message-Id: <vqxI7.16$377.8324@typhoon1.gnilink.net>

All - I'm trying to build an array of hashes.  I'm doing the following:

push @AoH, {husband=>"fred", wife=>"wilma", daughter=>"pebbles"};

Problem is that when I try to access the elements in the hash (i.e., each
row of the array), the keys returned from the hash aren't in insertion
order.  Is there a way to use Tie on an anonymous hash like this?

I'm doing the following:

#!perl -w

use strict;
use diagnostics;

my (@AoH, $index, $key, $val);
push @AoH, {husband=>"fred", wife=>"wilma", daughter=>"pebbles"};


for $index ( 0 .. $#AoH) {
  print "\$index = $index\n";

  for $key ( keys % {$AoH[$index] } ) {
    $val = $AoH[$index]{$key};
    print "\$key = $key, \$val = $val\n";
  }
}


If not, any way to keep the hash elements in insertion order?

Thanks,
Mark






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

Date: Wed, 14 Nov 2001 18:18:18 +0100
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Tie and anonymous hashes
Message-Id: <9su90q$9he$04$1@news.t-online.com>

On Wed, 14 Nov 2001 17:00:11 GMT, Mark Riehl wrote:
> All - I'm trying to build an array of hashes.  I'm doing the following:
> 
> push @AoH, {husband=>"fred", wife=>"wilma", daughter=>"pebbles"};
> 
> Problem is that when I try to access the elements in the hash (i.e., each
> row of the array), the keys returned from the hash aren't in insertion
> order.  Is there a way to use Tie on an anonymous hash like this?

A hash is due to its nature of 'hashing' keys unordered. 
You mentioned tie and indeed there is a way of tying your hash to the 
Tie::IxHash class which adds order to your hash-keys.

use Tie::IxHash;

my %array;
tie %array, Tie::IxHash;

# now use it as an ordinary hash

Tassilo
-- 
Life is what happens to you while you're busy making other plans.
		-- John Lennon, "Beautiful Boy"


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

Date: Wed, 14 Nov 2001 17:48:13 GMT
From: "Mark Riehl" <mark.riehl@agilecommunications.com>
Subject: Re: Tie and anonymous hashes
Message-Id: <x7yI7.25$377.10851@typhoon1.gnilink.net>

Tassilo - I understand that I can use Tie to retrieve in insertion order.
The question is - can you use Tie on an anonymous hash?  If so, how do you
do it?

In the example that I posted, there aren't any hashes declared, so I can't
use Tie as it is normally used.

Mark

"Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de> wrote in
message news:9su90q$9he$04$1@news.t-online.com...
> On Wed, 14 Nov 2001 17:00:11 GMT, Mark Riehl wrote:
> > All - I'm trying to build an array of hashes.  I'm doing the following:
> >
> > push @AoH, {husband=>"fred", wife=>"wilma", daughter=>"pebbles"};
> >
> > Problem is that when I try to access the elements in the hash (i.e.,
each
> > row of the array), the keys returned from the hash aren't in insertion
> > order.  Is there a way to use Tie on an anonymous hash like this?
>
> A hash is due to its nature of 'hashing' keys unordered.
> You mentioned tie and indeed there is a way of tying your hash to the
> Tie::IxHash class which adds order to your hash-keys.
>
> use Tie::IxHash;
>
> my %array;
> tie %array, Tie::IxHash;
>
> # now use it as an ordinary hash
>
> Tassilo
> --
> Life is what happens to you while you're busy making other plans.
> -- John Lennon, "Beautiful Boy"




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

Date: Wed, 14 Nov 2001 19:02:36 +0100
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Tie and anonymous hashes
Message-Id: <9subjs$b9i$05$1@news.t-online.com>

[ 
    Please put your comments below the part you are quoting,
    not on top. Trim it suitably. Don't quote signatures. Be a 
    good boy. ;-)
]

On Wed, 14 Nov 2001 17:48:13 GMT, Mark Riehl wrote:
> Tassilo - I understand that I can use Tie to retrieve in insertion order.
> The question is - can you use Tie on an anonymous hash?  If so, how do you
> do it?
> 
> In the example that I posted, there aren't any hashes declared, so I can't
> use Tie as it is normally used.

Ah, now I understand your question.
No, I don't think you can. That will certainly make it unpleasant to add
many tied hashes into an array.
If order _really_ matters for you, then you would need a temporary hash:

while (<HANDLE>) {
    # do some splitting etc
    # now tie a hash
    my %hash; 
    tie %hash, Tie::IxHash;
    
    # fill it
    $hash{key} = "value"...;
    push @array, \%hash;
}

This will put references to tied hashes into the array.
I am not sure, but you could try to tie a global hash and create copies
in the while loop to not always have to tie one:

tie %global_hash, Tie::IxHash;
while (...) {
    my %tmp = %global_hash;
    # fill %tmp
    push @array, \%tmp;
}

But then again I am not sure whether a copy of a tied hash wont loose
it's tiedness. Well, objects don't so hashes probably either.

Tassilo
-- 
Drop that pickle!


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

Date: Wed, 14 Nov 2001 18:05:41 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Tie and anonymous hashes
Message-Id: <mbudash-435683.10054414112001@news.sonic.net>

[please don't top-post. thread rearranged...]

In article <x7yI7.25$377.10851@typhoon1.gnilink.net>, "Mark Riehl" 
<mark.riehl@agilecommunications.com> wrote:

> "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de> wrote in
> message news:9su90q$9he$04$1@news.t-online.com...
>
> > On Wed, 14 Nov 2001 17:00:11 GMT, Mark Riehl wrote:
> > > All - I'm trying to build an array of hashes.  I'm doing the 
> > > following:
> > >
> > > push @AoH, {husband=>"fred", wife=>"wilma", daughter=>"pebbles"};
> > >
> > > Problem is that when I try to access the elements in the hash (i.e.,
> each
> > > row of the array), the keys returned from the hash aren't in 
> > > insertion
> > > order.  Is there a way to use Tie on an anonymous hash like this?
> >
> > A hash is due to its nature of 'hashing' keys unordered.
> > You mentioned tie and indeed there is a way of tying your hash to the
> > Tie::IxHash class which adds order to your hash-keys.
> >
> > use Tie::IxHash;
> >
> > my %array;
> > tie %array, Tie::IxHash;
> >
> > # now use it as an ordinary hash
> >

> Tassilo - I understand that I can use Tie to retrieve in insertion order.
> The question is - can you use Tie on an anonymous hash?  If so, how do 
> you
> do it?
> 
> In the example that I posted, there aren't any hashes declared, so I 
> can't use Tie as it is normally used.

here's  ahack of your original code, now using Tie::IxHash. ugly, but 
perhaps you get the idea:

use Tie::IxHash;
push @AoH, Tie::IxHash->new(husband=>"fred", wife=>"wilma", 
daughter=>"pebbles");

for $index ( 0 .. $#AoH) {
  print "\$index = $index\n";

  for $key ( $AoH[$index]->Keys ) {
    $val = $AoH[$index]->Values($AoH[$index]->Indices($key));
    print "\$key = $key, \$val = $val\n";
  }
}

hope this helps -
-- 
Michael Budash ~~~~~~~~~~ mbudash@sonic.net


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

Date: 14 Nov 2001 08:24:47 -0800
From: ip@dot-solutions.net (Ifan Payne)
Subject: Re: web page editing with browser
Message-Id: <49a7136c.0111140824.78b8fc33@posting.google.com>

Thank you for the lead. Is there anything online that you know of

Ifan




friedman@math.utexas.edu (Chas Friedman) wrote in message news:<3bf12c74.55845908@news.itouch.net>...
> On 12 Nov 2001 20:34:53 -0800, ip@dot-solutions.net (Ifan Payne)
> wrote:
> 
> >Could anyone suggest a free PERL script that enables editing of web
> >pages via a browser? I am looking for a way for users to edit/add
> >information to their web pages with thier browsers.
> There is an example of such a script in the book "Instant Perl
> Modules", Sparling and Wiles, Osborne. 
> (Online HTML Editor, Ch 13.)
>                         chas friedman


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

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


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