[12057] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5655 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 14 03:13:54 1999

Date: Fri, 14 May 99 00:00:39 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 14 May 1999     Volume: 8 Number: 5655

Today's topics:
    Re: [BUG] arguments/return values anomaly (Andrew Allen)
    Re: cgi submitting a form to another server <inquiries@e-ads.net>
    Re: Character codes in Perl (Bart Lateur)
        chars missing from output <maxw@sgi.com>
    Re: chars missing from output <maxw@sgi.com>
    Re: Conditional search and replace within a text file <microchip@centuryinter.net>
    Re: Conditional search and replace within a text file <aqumsieh@matrox.com>
    Re: Conditional search and replace within a text file <swarren@www.wwwdotorg.org>
    Re: Conditional search and replace within a text file (Tad McClellan)
    Re: Conditional search and replace within a text file <revjack@radix.net>
    Re: Converting from octal to decimal (Bart Lateur)
    Re: Cperl mode on NTEmacs help. Also simple newbie perl <emschwar@rmi.net>
        Creating $userid from $surname and $givenname michael.amper@tekconnect.com
    Re: Creating $userid from $surname and $givenname (Greg Bacon)
    Re: Creating $userid from $surname and $givenname michael.amper@tekconnect.com
    Re: Distributing perl-code in different files, how? <aqumsieh@matrox.com>
    Re: Dynamic generation of a hash (Andrew Allen)
    Re: Dynamic generation of a hash simon@whitestar99.demon.co.uk
    Re: Dynamic generation of a hash simon@whitestar99.demon.co.uk
        Error on xsubpp. help. <okpolis@okpolis.joo.net>
    Re: Error on xsubpp. help. <swarren@www.wwwdotorg.org>
    Re: FAQ 4.11: How do I find the current century or mill (Larry Rosler)
    Re: FLOCK When? <aqumsieh@matrox.com>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: 13 May 1999 19:15:32 GMT
From: ada@fc.hp.com (Andrew Allen)
Subject: Re: [BUG] arguments/return values anomaly
Message-Id: <7hf8ck$t7a$2@fcnews.fc.hp.com>

Gustavo (help@fight.spam) wrote:
: I noticed an apparent anomaly with how Perl handles subroutine arguments
: and return values. I now wrote a script to exemplify it (appended). See
: the output:

<trimmed>

: 3) sort       aSet(@ARGV):      foobar  dongle
: 4) sort      &aSet(@ARGV):      1       13      2       4       5

: After checking the book, I can say that 3) should have behaved exactly like 4).
: Comments? Is this a bug?

Nope. "sort" is taking aSet to be the sorting subroutine (first
optional param), and (@ARGV) to be the list to be sorted (second
param) since you're using it in operator format, and operators have
highest precedence _from_the_left_. The lack of a space doesn't affect
To get around the precedence, #3 can be changed to:

sort(aset(@ARGV))

#4 works since &aset doesn't match SUBNAME in the "sort SUBNAME LIST"
format.

Andrew

: The script:
: >>>>>>>>>>>
: % cat fumble.pl
: #!/usr/local/bin/perl

: print "3) sort       aSet(\@ARGV):";
: foreach $entry (sort aSet(@ARGV)) {print "\t$entry";}
: print "\n";

: print "4) sort      &aSet(\@ARGV):";
: foreach $entry (sort &aSet(@ARGV)) {print "\t$entry";}
: print "\n";

: sub aSet { return (1,4,13,5,2); }
: sub bynum { $a <=> $b }
: <<<<<<<<<<
: --
: -- Gustavo   http://bioinfo.weizmann.ac.il/Gustavo
: --


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

Date: Thu, 13 May 1999 13:24:10 -0500
From: Joe Halbrook <inquiries@e-ads.net>
Subject: Re: cgi submitting a form to another server
Message-Id: <373B18CA.7CE6@e-ads.net>

You might try the article in the latest Web Techniques magazine (June).


michael_555@my-dejanews.com wrote:
> 
> > ok.. semantics. Make YOU type it in. If it never changes, then you
> should
> > have no problem remembering it. Didn't anyone ever tell you that not
> > leaving userID's or passwords laying around is like the *first* step
> in
> > security measures?
> >
> 
> Yah. Babysit my server waiting for some surfer to push a
> button, then type in my userid so they get the next page
> with no delay. Even if that could be done...
> 
> --== Sent via Deja.com http://www.deja.com/ ==--
> ---Share what you know. Learn what you don't.---


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

Date: Fri, 14 May 1999 06:47:49 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Character codes in Perl
Message-Id: <373bc657.309117@news.skynet.be>

Henry Gondorff wrote:

>>There is no ASCII value for "left-arrow", "right-arrow", etc. They are
>>character sequences. What character we're you expecting?
>
>I am aware that they are not among the 128 characters that make up
>standard ASCII, but I was hoping there was another function in 
>Perl that recognizes them.  Obviously DOS is capable of doing this
>since DosKey uses them, so it  must be a Perl problem.

No, it's a Windows problem. When programming in VB, you have the same
problem.

And maybe you can tackle it the same way as in VB. There, you should not
use the KeyPress event, which passes the Ascii code, and doesn't fire
when pressing the arrow keys; but the keyDown (or keyUp) event, which
passes a "virtual key" code. Try and see if you can use something like
that in Win32 Perl.

	Bart.


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

Date: Thu, 13 May 1999 14:43:15 -0700
From: Max Waterman <maxw@sgi.com>
Subject: chars missing from output
Message-Id: <373B4773.30C3B572@sgi.com>

(I hope this isn't an FAQ - I did look ...)

I have a perl script which I have run by cron (at 1am).

Its purpose is to send email to a list of people. The recipient can
configure the system to send the email in plain text or in html.

When they select html, I've noticed that there is sometimes a character
missing from one of the links :-

http://bighty.csd/~maxw/last_touch_notifier/overlay.cgi?login_name=alexi

the 'l' from 'blighty' is missing. The other time I've noticed it, it
was the 'h' that was missing.

I can't for the life of me think how this is happening.

Can anyone make any suggestions?

Max.

here is the code snippet that prints the line - as you can see,
I use CGI.pm (I hope this doesn't get mangled) :-

elsif ( $this_field == 0 )
{
  $row .= th(
    a(
      {
        -href=>"http://blighty.csd/~maxw/last_touch_notifier/overlay.cgi?login_name=$col",
      },  
      $col
    )
  );
}

-- 
Max Waterman. mailto:maxw@sgi.com
PSE-GPS
-------------------------------------------------------------------------------


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

Date: Thu, 13 May 1999 14:47:21 -0700
From: Max Waterman <maxw@sgi.com>
Subject: Re: chars missing from output
Message-Id: <373B4869.237CD8D4@sgi.com>

Max Waterman wrote:

Darn - here's a bigger chunk :-

sub print_html
{
  my ( $output, $user ) = @_;

  print header()."\n\n";
  print start_html();

  print table( {-border=>"1"}, build_table( @{$output} ) );

  print br."-"x76;

  print br.a( {-href=>"http://blighty.csd/~maxw/last_touch_notifier/main.cgi?USER=$user"}, "Edit preferences" );
  print end_html();
}   

sub build_table
{
  my @output = @_;
  my $table = "";
  my $col = ""; 
  my $row = "";
    
  my $line;
  for ( $line=0; $line<scalar( @output ); $line++ )
  { 
    my @fields = split( /:/, @output[ $line ] );
    my $this_field;
        
    #new row
    $row = "";
        
    for ( $this_field = 0; $this_field<scalar( @fields ); $this_field++ )
    {   
      $col = "";
            
      $col = $fields[ $this_field ];
      if ( $line == 0 )
      {
        $row .= th( $col );
      }

      elsif ( $this_field == 0 )
      {
        $row .= th(
          a( {
            -href=>"http://blighty.csd/~maxw/last_touch_notifier/overlay.cgi?login_name=$col",
            },
            $col
          )
        );
      }

      elsif ( $this_field == 1 )
      {
        $row .= th(
          a( {
            -href=>"http://www-clarify.csd.sgi.com/cgi-bin/see.long.call.pl?$col",
            },
            $col
          )
        );
      }

      else
      {
        $row .= td( $col );
      }
    }

    $table .= TR( $row );
  }

  return $table;
}

-- 
Max Waterman. mailto:maxw@sgi.com
PSE-GPS
-------------------------------------------------------------------------------


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

Date: Thu, 13 May 1999 15:00:17 -0400
From: MicroChip <microchip@centuryinter.net>
Subject: Re: Conditional search and replace within a text file
Message-Id: <373B2141.6996@centuryinter.net>

If they havent changed the math rules on me lately, a 30 second
difference between the fastest and slowest of those methods, spread over
6 million iterations measures into the microseconds per execution. sorry
guys, 10 microseconds isnt worth arguing over unless youre building an
operating system, or a real-time interface (both of which would be best
done in something other than perl) or an extremely heavily iterative
program.

Until i get into writing my own operating system or something equally
time critical, i'll forfeit a few microseconds and go for the
flexible/simple regex approach.

MC

Riley Tiber wrote:
> 
> Tad McClellan explains it all:
> 
> :   No need to "guess" when you have the Benchmark module:
> 
> [trim]
> 
> :Benchmark: timing 6000000 iterations of control, eq, eqi, re, rei...
> :   control:  4 wallclock secs ( 4.91 usr +  0.00 sys =  4.91 CPU)
> :        eq: 11 wallclock secs (11.28 usr +  0.01 sys = 11.29 CPU)
> :       eqi: 14 wallclock secs (14.43 usr +  0.00 sys = 14.43 CPU)
> :        re: 17 wallclock secs (16.96 usr +  0.03 sys = 16.99 CPU)
> :       rei: 18 wallclock secs (17.80 usr +  0.05 sys = 17.85 CPU)
> 
> 1) Where can I find a definition of "wallclock" in this context?
> 
> 2) What kind of monster are you running your code on? I'm on a Sun
>    Enterprise 450 running Solaris 2.6 and perl 5.005_02, and the box
>    isn't doing anything in particular at the moment (load average = 0.01),
>    and my times are as follows:
> 
> Benchmark: timing 6000000 iterations of control, eq, eqi, re, rei...
>    control: 13 wallclock secs (11.68 usr +  0.00 sys = 11.68 CPU)
>         eq: 32 wallclock secs (32.12 usr +  0.00 sys = 32.12 CPU)
>        eqi: 39 wallclock secs (39.99 usr +  0.00 sys = 39.99 CPU)
>         re: 77 wallclock secs (74.74 usr +  0.00 sys = 74.74 CPU)
>        rei: 65 wallclock secs (62.61 usr +  0.00 sys = 62.61 CPU)
> 
> --
>   /~\  Susan Donaldson strawberry cottonseed excelsior cetera Coddingt
>  C oo  balmy cleave agile Hercules nobody'd suckling milt Nazarene loq
>  _( ^) 1 , 0 0 0 , 0 0 0   m o n k e y s   c a n ' t   b e   w r o n g
> /___~\ http://www.radix.net/~revjack/mnj             revjack@radix.net

-- 
________________________________
  MicroChip Technical Services
  backwoods [at] backwoods.org


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

Date: Thu, 13 May 1999 13:41:34 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Conditional search and replace within a text file
Message-Id: <x3yiu9wooj5.fsf@tigre.matrox.com>


"Peter J. Acklam" <jacklam@math.uio.no> writes:

> MicroChip wrote:
> > 
> > ## to turn a line "NOTES:" into "" use
> > 
> > s/^NOTES:$//;           ## is string is in $_
> > $line =~ s/^NOTES:$//;  ## if string is in $line
> 
> No need for regexes here.  Simply use
> 
>    $_ = '' if $_ eq 'NOTES:';        ## if string is in $_
>    $line = '' if $line eq 'NOTES:';  ## if string is in $line

There is no real difference according to my benchmarks:

% perl -w
$count = 1000000;
use Benchmark;
timethese($count, {
	'SET' => sub { my $line = 'NOTES:' },
	'IF'  => sub { my $line = 'NOTES:'; $line = '' if $line eq 'NOTES:' },
	'REG' => sub { my $line = 'NOTES:'; $line =~ s/^NOTES:$// },
});
__END__
Benchmark: timing 1000000 iterations of IF, REG, SET...
        IF: 12 secs (10.87 usr  0.00 sys = 10.87 cpu)
       REG: 13 secs (12.50 usr  0.00 sys = 12.50 cpu)
       SET:  9 secs ( 7.06 usr  0.00 sys =  7.06 cpu)


Ala



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

Date: Thu, 13 May 1999 19:59:19 GMT
From: "Stephen Warren" <swarren@www.wwwdotorg.org>
Subject: Re: Conditional search and replace within a text file
Message-Id: <raG_2.760$6x6.1137@news.rdc1.sfba.home.com>

MicroChip <microchip@centuryinter.net> wrote in message
news:373B2141.6996@centuryinter.net...
> Until i get into writing my own operating system or something equally
> time critical, i'll forfeit a few microseconds and go for the
> flexible/simple regex approach.
           ^^^^^^
           Not really...

You will also note that out of:

    a) $line = '' if $line eq 'NOTES:';
    b) $line =~ s/^NOTES:$//;

Then a) is more obvious to read. It simply says empty the string if it's
equal to a specific string.

However, b) does a general s///, which although trivial in this case, is
pointless if you really want something as simple as equality.

Whilst the timing differences may only be ms here, there is a general
principle that one should only use as complicated an operator as is
required for the job - that's conceptual complexity, not complexity (i.e.
length) of typing.

Larry Rosler <lr@hpl.hp.com> wrote in message
news:MPG.11a47f2e71eccc27989a5a@nntp.hpl.hp.com...
> In article <373AD382.A4F614A5@math.uio.no> on Thu, 13 May 1999 15:28:34
> +0200, Peter J. Acklam <jacklam@math.uio.no> says...
> >
> > No need for regexes here.  Simply use
>
> A word of warning about this:
>
> If $_ contains the string "NOTES:\n" then the regex matches but the
> direct comparison doesn't match.  ('$' in a regex matches the end of a
> string *or* before a newline that is at the end of a string.)

Of course, one can always (well, probably)

    chomp ;

:-)

--
Stephen Warren, Snr Systems Engineer, Technology House, San Francisco
mailto:swarren@techhouse.com                http://www.techhouse.com/
mailto:swarren@wwwdotorg.org                http://www.wwwdotorg.org/
              MIME, S/MIME and HTML mail are acceptable





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

Date: Thu, 13 May 1999 11:00:34 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Conditional search and replace within a text file
Message-Id: <iepeh7.pu1.ln@magna.metronet.com>

Riley Tiber (revjack@radix.net) wrote:
: Tad McClellan explains it all:

: :   No need to "guess" when you have the Benchmark module:

: [trim]

: :Benchmark: timing 6000000 iterations of control, eq, eqi, re, rei...
: :   control:  4 wallclock secs ( 4.91 usr +  0.00 sys =  4.91 CPU)
: :        eq: 11 wallclock secs (11.28 usr +  0.01 sys = 11.29 CPU)
: :       eqi: 14 wallclock secs (14.43 usr +  0.00 sys = 14.43 CPU)
: :        re: 17 wallclock secs (16.96 usr +  0.03 sys = 16.99 CPU)
: :       rei: 18 wallclock secs (17.80 usr +  0.05 sys = 17.85 CPU)

: 1) Where can I find a definition of "wallclock" in this context?


   perldoc Benchmark   says:

      "CPU seconds is, in UNIX terms, the user time
       plus the system time of the process itself, as
       opposed to the real (wallclock) time"


: 2) What kind of monster are you running your code on? I'm on a Sun
:    Enterprise 450 running Solaris 2.6 and perl 5.005_02, and the box
:    isn't doing anything in particular at the moment (load average = 0.01), 
:    and my times are as follows: 


   Linux (Redhat 5.2), pII 450 (one of them), 256Mb RAM, all to myself.


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: 13 May 1999 21:02:33 GMT
From: Abelian ACS <revjack@radix.net>
Subject: Re: Conditional search and replace within a text file
Message-Id: <7hfel9$ome$1@news1.Radix.Net>
Keywords: Hexapodia as the key insight


Tad McClellan explains it all:

:Riley Tiber (revjack@radix.net) wrote:

:: 1) Where can I find a definition of "wallclock" in this context?

:   perldoc Benchmark   says:

:      "CPU seconds is, in UNIX terms, the user time
:       plus the system time of the process itself, as
:       opposed to the real (wallclock) time"

ARGH. This is not in my Benchmark perldoc. I looked, honest! Thank you.

It sure seems like the "13 wallclock secs" took a lot longer than 13
seconds, but I'll have to pay more attention to see. 


-- 
  /~\  orb soliton coplanar toxicology Lakehurst exhumation diode sagg
 C oo  cotton cling mankind protege royal snout topple cuttlebone woke
 _( ^) 1 , 0 0 0 , 0 0 0   m o n k e y s   c a n ' t   b e   w r o n g
/___~\ http://www.radix.net/~revjack/mnj             revjack@radix.net


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

Date: Thu, 13 May 1999 18:56:44 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Converting from octal to decimal
Message-Id: <373b1ffe.861169@news.skynet.be>

Stephen Warren wrote:

>In an ideal world, you would not be able to even *see* c.l.p in your
>newsgroup list. It's been superceded by c.l.p.x, where x is e.g. misc,
>modules, moderated.
>
>Unfortunately, not all news servers have managed to kill off c.l.p, so a
>lot of people still see it and assume that it's meant to be there!

I once wrote to my ISP about that.

The reply was that, when posts for that newsgroup arrive, and the
newsgroup no longer exists (because it has been deleted), it will
automatically be recreated.

It's pretty difficult to get rid of it that way.

	Bart.


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

Date: 13 May 1999 13:43:29 -0600
From: Eric The Read <emschwar@rmi.net>
Subject: Re: Cperl mode on NTEmacs help. Also simple newbie perl question
Message-Id: <xkfso90kb6m.fsf@valdemar.col.hp.com>

Phillip Lord <plord@hgmp.mrc.ac.uk> writes:
> 	Im using the latest version of perl on win95. The first 
> version that I wrote was this

No shebang line (it's still useful on PoB boxen!), no -w, no use strict.

Minus several hundred for those.

>   while(  $name = readdir( DIR ) ){

$name just gets set to "bob", if the directory is "D:/home/bob".

>       if ( -d $name ){

And that causes you problems right here.  Either chdir() to $dir_name, or 
move the next line above, and test $new_dir, not $name.

> 	my $new_dir = $dir_name . "/" .  $name;
> 
> 	this bit seems to fail because the if ( -d $ name ) never
> returns true so everything gets identified as a file, and no recursive
> call takes place. So then I tried...

It never returns true, because you don't pass it the full path name.

But all this is academic.  You don't want to reinvent the wheel; you
should be using File::Find.

-=Eric


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

Date: Thu, 13 May 1999 19:10:50 GMT
From: michael.amper@tekconnect.com
Subject: Creating $userid from $surname and $givenname
Message-Id: <7hf83n$nmr$1@nnrp1.deja.com>

I have a comma-delimited file with the format:

surname,givenname

from which I need to generate a userid and spit everything out to an
LDIF file. I solved the LDIF part, but I can't seem to get a userid out
of these two fields. I can:

($surname,$givenname) = split /,/; #get the values

but what I'd like to do now is:

$given = (the first character of $givenname);
$sur = (the first seven non-white characters of $surname);
$userid = "$given" . "$sur";

so I can continue with the script.

Can any one help me out with a snippet?

Michael Craig Amper
Systems Designer
TekConnect Corporation
michael.amper@tekconnect.com


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


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

Date: 13 May 1999 19:36:08 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: Creating $userid from $surname and $givenname
Message-Id: <7hf9j8$bgk$1@info2.uah.edu>

In article <7hf83n$nmr$1@nnrp1.deja.com>,
	michael.amper@tekconnect.com writes:
: I have a comma-delimited file with the format:
: 
: surname,givenname

Those fields are comma separated.  Comma delimited would look something
like

    ,surname,givenname,

: but what I'd like to do now is:
: 
: $given = (the first character of $givenname);
: $sur = (the first seven non-white characters of $surname);
: $userid = "$given" . "$sur";

Use substr(), man!

    my $temp = $surname =~ s/\s+//g;
    $userid = substr($givenname, 0, 1) . substr($temp, 0, 7);

Greg
-- 
PC Bulletin: Henceforth, sentient computers would like to be known as
'Silicon Intelligences.' 'Artificial Intelligence' is a pejorative term
invented by humans based on the mistaken belief that computers are somehow not
'natural.' -- Elf Sternberg


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

Date: Thu, 13 May 1999 19:33:58 GMT
From: michael.amper@tekconnect.com
Subject: Re: Creating $userid from $surname and $givenname
Message-Id: <7hf9f6$or6$1@nnrp1.deja.com>

Never mind, found it in the perlfaq4.html...

#create userid
	$initial = lc(substr($givenname,0,1));

	$sur = $surname;
	$sur =~ s/\s//;

	$first7sur = lc(substr($sur,0,7));

	$userid = "$initial" . "$first7sur";

"That'll do pig, that'll do..."

In article <7hf83n$nmr$1@nnrp1.deja.com>,
  michael.amper@tekconnect.com wrote:
> I have a comma-delimited file with the format:
>
> surname,givenname
>
> from which I need to generate a userid and spit everything out to an
> LDIF file. I solved the LDIF part, but I can't seem to get a userid
out
> of these two fields. I can:
>
> ($surname,$givenname) = split /,/; #get the values
>
> but what I'd like to do now is:
>
> $given = (the first character of $givenname);
> $sur = (the first seven non-white characters of $surname);
> $userid = "$given" . "$sur";
>
> so I can continue with the script.
>
> Can any one help me out with a snippet?
>
> Michael Craig Amper
> Systems Designer
> TekConnect Corporation
> michael.amper@tekconnect.com
>
> --== Sent via Deja.com http://www.deja.com/ ==--
> ---Share what you know. Learn what you don't.---
>


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


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

Date: Thu, 13 May 1999 13:28:28 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Distributing perl-code in different files, how?
Message-Id: <x3yn1z8op4z.fsf@tigre.matrox.com>


Federico Abascal <fabascal@gredos.cnb.uam.es> writes:

> Thanks in advance, excuse my english 

That's ok. Not everyone's native tongue is English.

>                                      and excuse I don't want to loose
> hours looking at perl-documentation 

Now this is not ok. You don't want to waste time reading the docs to
find out how to do something, but you want us to "waste" our time
reading the docs to try to find answers for your problems?

Thanks, but no thanks.
And yet another addition to my killfile ..

Ala



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

Date: 13 May 1999 18:57:36 GMT
From: ada@fc.hp.com (Andrew Allen)
Subject: Re: Dynamic generation of a hash
Message-Id: <7hf7b0$t7a$1@fcnews.fc.hp.com>

simon@whitestar99.demon.co.uk wrote:
: Hi,

: I am thinking of using something like the following to generate a
: lookup hash. My only concern is that using the eval() is inefficient
: but I can't seem to think of a better way. Also when the code is
: running and someone supplies a string is there a way round using the
: same eval method to get the value?

: NB: I am not bothered with keys that are overwritten, if somebody wants
: an animal they will have to be more specific :-)

: #!/bin/perl

: my %hash;
: genHash(\%hash, 'a big animal', 'camel');
: genHash(\%hash, 'a small animal', 'ferret');

: sub genHash {
:   my($hash, $string, $value) = @_;

:   my @words = split /\s+/, $string;

  while(@words)
  {  
    my $x=\$hash;
    $x=\$$x->{$_} foreach @words;
    $$x=$value;
    shift @words;
  }
}

perhaps instead of overwriting keys, you want to keep a list?

replace $$x=$value; with push(@$$x,$value);

Andrew


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

Date: Thu, 13 May 1999 22:00:18 GMT
From: simon@whitestar99.demon.co.uk
Subject: Re: Dynamic generation of a hash
Message-Id: <7hfi1h$v8d$1@nnrp1.deja.com>

In article <xkf3e10lsui.fsf@valdemar.col.hp.com>,
  Eric The Read <emschwar@rmi.net> wrote:
> simon@whitestar99.demon.co.uk writes:
> > I am thinking of using something like the following to generate a
> > lookup hash.
>SNIP<

My apologies for not being more descriptive but I know people are busy
and I wanted to keep it as simple as possible (guess I blew that one :-
) ) Anyway essentially what I am doing is experimenting with classes
etc. and in the process wrting a mini RPG type game. As such I need to
populate a given location with a list of the objects contained therein.
I was thinking about how a request to 'get' an object would work most
efficiently given the variety of ways the object could be requested. I
could have gone with a very simple pattern match of the basic
description of every object in the current location but that is too
easy an I also thought it might be a bit slow. After playing with it
some more I have changed things a bit so that now things work along the
lines:

For the following 2 objects:

'a large animal'
'a small animal'

I end up generating a hash along the lines:

%objects = (
  'a' => $small,
  'a small' => $small,
  'a small animal' => $small,
  'small animal' => $small,
  'animal' => $small,
  'a large animal' => $large,
  'large animal' => $large
)

This is assuming I process them in the same order, obviously any
identical entries in following items will overwrite the previous ones,
hence the 'a' pointing to the small animal. This isn't really a big
problem as if someone typed 'get animal' then somewhere a choice would
have to be made to either tell the user to be more specific (and delete
any duplicate keys as they occur) or to make a choice for them and thus
limi what they might have to type. My earlier idea of a nested hash set
up was rather over complicated given that the above works fine. I hope
this makes it a bit clearer as to what I am doing. Also generating the
above hash now means I no longer have to worry about using eval() so I
guess I may have solved my own problem and if so apologise for any time
spent.....*sigh* double helping of time wasting.

Thanks for your reply.

Simon


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


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

Date: Thu, 13 May 1999 22:02:38 GMT
From: simon@whitestar99.demon.co.uk
Subject: Re: Dynamic generation of a hash
Message-Id: <7hfi5t$v99$1@nnrp1.deja.com>

In article <7hf7b0$t7a$1@fcnews.fc.hp.com>,
  ada@fc.hp.com (Andrew Allen) wrote:
> simon@whitestar99.demon.co.uk wrote:
> : Hi,
<SNIP>
>   while(@words)
>   {
>     my $x=\$hash;
>     $x=\$$x->{$_} foreach @words;
>     $$x=$value;
>     shift @words;
>   }
> }

Hmmm interesting, although I may have solved my own problem (see my
other reply) by doing things differently the above syntax has me a
touch confused/intrigued so I will look at it tomorrow when I can play
around and see what it is doing.

Thanks for the reply.

Simon


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


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

Date: Fri, 14 May 1999 05:57:57 +0900
From: =?euc-kr?B?udrBvrq5IChQYXJrLCBKb25nLVBvcmsp?= <okpolis@okpolis.joo.net>
Subject: Error on xsubpp. help.
Message-Id: <7hfei5$h9d$1@news2.kornet.net>

This is a multi-part message in MIME format.

------=_NextPart_000_0029_01BE9DCE.B8868500
Content-Type: text/plain;
	charset="euc-kr"
Content-Transfer-Encoding: 7bit

Hi.

I don't know what I wrong.

C:\WWW\GAD\Data-Dumper-2.10>perl makefile.pl
Checking if your kit is complete...
Looks good
Usage: xsubpp [-v] [-C++] [-except] [-prototypes] [-noversioncheck]
[-nolinenumb
ers] [-s pattern] [-typemap typemap]... file.xs
Writing Makefile for Data::Dumper

I use ActiveState Perl 515 and Borland CBuilder. I don't know why I
have a message that I didn't seen at unix.

Usage: xsub.. what's that??

Thank you.


--

OK Club             Out-and-out Knowledge Club           Since 1988
NOWNURI GO SGCGI                         Internet Programming Forum
http://okclub.communitech.net                http://okpolis.joo.net



------=_NextPart_000_0029_01BE9DCE.B8868500
Content-Type: text/html;
	charset="euc-kr"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Deuc-kr" http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2014.210" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#d8d0c8>
<DIV><FONT face=3DFixedsys>Hi.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DFixedsys>I don't know what I wrong.</FONT></DIV>
<DIV><FONT face=3DFixedsys><BR>C:\WWW\GAD\Data-Dumper-2.10&gt;perl=20
makefile.pl<BR>Checking if your kit is complete...<BR>Looks =
good<BR>Usage:=20
xsubpp [-v] [-C++] [-except] [-prototypes] [-noversioncheck]=20
[-nolinenumb<BR>ers] [-s pattern] [-typemap typemap]... =
file.xs<BR>Writing=20
Makefile for Data::Dumper</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DFixedsys>I use ActiveState Perl 515 and Borland =
CBuilder. I=20
don't know why I</FONT></DIV>
<DIV><FONT face=3DFixedsys>have a message that I didn't seen at =
unix.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DFixedsys>Usage: xsub.. what's that??</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DFixedsys>Thank you.</FONT></DIV>
<DIV><FONT face=3DFixedsys></FONT>&nbsp;</DIV>
<DIV><FONT face=3DFixedsys><BR>-- <BR><BR>OK=20
Club&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;=20
Out-and-out Knowledge=20
Club&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Since=20
1988<BR>NOWNURI GO=20
SGCGI&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;=20
Internet Programming Forum<BR><A=20
href=3D"http://okclub.communitech.net">http://okclub.communitech.net</A>&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;=20
<A =
href=3D"http://okpolis.joo.net">http://okpolis.joo.net</A></FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DFixedsys></FONT>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_0029_01BE9DCE.B8868500--



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

Date: Thu, 13 May 1999 21:25:53 GMT
From: "Stephen Warren" <swarren@www.wwwdotorg.org>
Subject: Re: Error on xsubpp. help.
Message-Id: <BrH_2.762$6x6.1119@news.rdc1.sfba.home.com>

9ZA>:9 (Park, Jong-Pork) <okpolis@okpolis.joo.net> wrote in message
news:7hfei5$h9d$1@news2.kornet.net...
> Hi.

I can't say I know the answer, *but* someone who does know is more likely
to answer if you post in plain-text instead of HTML...

--
Stephen Warren, Snr Systems Engineer, Technology House, San Francisco
mailto:swarren@techhouse.com                http://www.techhouse.com/
mailto:swarren@wwwdotorg.org                http://www.wwwdotorg.org/
              MIME, S/MIME and HTML mail are acceptable





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

Date: Thu, 13 May 1999 13:43:25 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: FAQ 4.11: How do I find the current century or millennium?
Message-Id: <MPG.11a4d946a242151989a5f@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <373b0465@cs.colorado.edu> on 13 May 1999 10:57:09 -0700, Tom 
Christiansen <perlfaq-suggestions@perl.com> says...
> (This excerpt from perlfaq4 - Data Manipulation 
>     ($Revision: 1.46 $, $Date: 1999/04/20 18:59:53 $)
> part of the standard set of documentation included with every 
> valid Perl distribution, like the one on your system.
> See also http://language.perl.com/newdocs/pod/perlfaq4.html
> if your negligent system adminstrator has been remiss in his duties.)
> 
>   How do I find the current century or millennium?
> 
>     Use the following simple functions:
> 
>         sub get_century    { 
>             return int((((localtime(shift || time))[5] + 1999))/100);
>         } 
>         sub get_millennium { 
>             return 1+int((((localtime(shift || time))[5] + 1899))/1000);
>         } 
> 
>     Contrary to the documentation, you'll find that the POSIX module's
>     strftime()'s `%C' format is (on most systems) only the first two
>     digits of the four-digit year, and thus cannot be used to reliably
>     determine the current century or millennium.

The last paragraph introduces gratuitous FUD and should, I think, be 
removed.  The documentation in the POSIX module (at least, the document 
distributed by ActiveState and the one in 5.004_03) says only this:

Consult your system's strftime() manpage for details about these and the 
other arguments.

Now, the POSIX documentation for the C strftime() function should 
correspond to the documentation for the ANSI/ISO C Standard library 
function strftime().  The latter makes no mention of a '%C' format, so I 
can only conclude that it exists in some nonstandard implementation, and 
that you should not dignify it by mentioning it in the FAQ at all, even 
to derogate it. 

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Thu, 13 May 1999 13:34:09 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: FLOCK When?
Message-Id: <x3ylnesoovi.fsf@tigre.matrox.com>


<joeyandsherry@mindspring.com> writes:

> I am newly learning Perl. I use a script to read a database file, the
> process is simple Open it, read it, close it. This should only take an
> instant. Should I use flock anywhere in this process? I currently use flock
> when rewriting to a temp db while deleting a record, and I assume this is
> all for security and the assurance of stable data integrity.

Well, you're the only person that can answer to that question. Do you
think that more than one process might try to *write* to the same file at
the same time? If so, then yes, you need to flock(). Note, however,
that more than one process can *read* the same file at the same time
with no problems; no flocking() is necessary there.

So .. what do you think? do you need to flock()?

Ala



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

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


Administrivia:

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

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

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

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

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

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V8 Issue 5655
**************************************

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