[7126] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 751 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 21 04:08:31 1997

Date: Mon, 21 Jul 97 01:00:41 -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           Mon, 21 Jul 1997     Volume: 8 Number: 751

Today's topics:
     Re: 2 xor 0 -> 1 (??) <dav@umiacs.umd.edu>
     Re: ? typeglob of a hash in a hash.  woo! (Jahwan Kim)
     Any way to automatically stack trace on die? (Nathan Neulinger)
     Basic Help Wanted (Markus Ludwig)
     Re: bizarre regexp behaviour with split (Even Holen)
     Re: Can this regexp loop be improved? <Jan.Krynicky@st.mff.cuni.cz>
     Re: Canonical List of One-Liners (Jeff Stampes)
     CHALLENGE!!!! streaming text for cgi web based chat ser <sysadm@twd.net>
     Re: Creating a file, only if the file handle is 'used' (Scott McMahan)
     GGAAAAKK!! Bad Perl week - now DBD Oracle troubles <chris@ixlabs.com>
     Re: Global Vars : Why would I want to use "use strict" <jason@dtlweb.com>
     Index a hash by a regex ? <sfairey@adc.metrica.co.uk>
     Re: Learning Perl ..Help?? (Charles Lin)
     Merging large complex data structures (Chris Sherman)
     Newbie Help..please??? :) (Jye Tucker)
     Re: Newbie Problem - IE/Netscape differences <Jan.Krynicky@st.mff.cuni.cz>
     Newbie question, but... <serginho@alpha.hydra.com.br>
     Re: Newbie question, but... <sfairey@adc.metrica.co.uk>
     Perl and Expect problems? (Justin B. Harvey)
     Re: Perl for DOS (Ilya Zakharevich)
     perl5.003 <cpeterma@emerald.tufts.edu>
     Problem with HTML counter <Katie.Wright@asg.unb.ca>
     Re: Problem with HTML counter <mgjv@comdyn.com.au>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Thu, 17 Jul 1997 09:45:57 -0400
From: "David J. Clark" <dav@umiacs.umd.edu>
Subject: Re: 2 xor 0 -> 1 (??)
Message-Id: <33CE2214.4BBB7F66@umiacs.umd.edu>

Damian Conway wrote:

> mjtg@cus.cam.ac.uk (M.J.T. Guy) writes:

<snip>

> >Because there isn't a valid analogy between the cases.   "and" and
> "or"
> >are "short cut" operators which only evaluate as many of their
> arguments
> >as they need.    "xor" always depends on all its arguments, so there
> is
> >no sensible meaning to returning a particular argument.
>
> Sure there is. The xor operator returns true if and only if exactly
> one of its operands is true. It would seem perfectly reasonable to
> return that one true operand in this case.

 The problem isn't with the single xor statement, it's when you have a
string of them, as in
2 xor 'two' xor 'too' == 1
What would be a more sensible thing to return in this case?  (I can't
think of any)

-dav



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

Date: 18 Jul 1997 00:24:47 GMT
From: jahwan@supernova.math.lsa.umich.edu (Jahwan Kim)
Subject: Re: ? typeglob of a hash in a hash.  woo!
Message-Id: <slrn5stduf.26s.jahwan@supernova.math.lsa.umich.edu>

On Wed, 16 Jul 1997 14:55:32 -0400, Chad <cm0x1a@lauren.surfsouth.com> wrote:
> I call myself a semi-well-versed perl theologean, but I'm stumped.
> 
> My paradox inside an enigma within a riddle involves a typeglob of 
> a hash of a hash.
> 
> 
> I want 
> 
> $idhash{$id}{"element2"}
> 
> to be a synonym of 
> 
> $idhash{$id}{"element1"}
> 
> 
> Just to show how interesting this is,   $idhash{$id){"element1"}  is
> [tense?] a list, which isn't yet defined anyway, in a way.  I could
> push a dummy value into it, if it'll make things easier (pronounced 
> "possible").
> 
> How would this be done?
> 
> 				just a wannabe perl hacker,
> 					Chad
> 
> --
> Chad Miller   --  cmiller at surfsouth dot com

    OK, I read several followups, and now know how to work it out.  But
while we're on the subject, how do you make $idhash{"element1"} to be a
synonym of $idhash{"element2"}, using typeglob?

just wanna know a little bit more about typeglobs...
jahwan


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

Date: Thu, 17 Jul 1997 19:40:48 -0500
From: nneul@umr.edu (Nathan Neulinger)
Subject: Any way to automatically stack trace on die?
Message-Id: <nneul-1707971940480001@dialup-pkr-10-42.network.umr.edu>

Is there any way to cause perl to do an automatic stack trace upon die'ing
(and potentially upon warns as well.)

On a related note, I have a module that uses DBI. If an error occurs in
DBI from one of the routines I call, I get an error message indicating
where in my module the error occurred. This doesn't really tell me much,
cause the error is in parameters given to the routines in my module. The
above desire for a automatic stack trace would take care of this. 

What I would like is to be able to do something like:

# Cause an automatic stack trace whenever die or warn called.
use Devel::AutoStackTrace 'warn', 'die';

I'm not sure if this sort of thing is possible. Any pointers would be
appreciated.

-- Nathan

------------------------------------------------------------
Nathan Neulinger                  Univ. of Missouri - Rolla
EMail: nneul@umr.edu                  Computing Services
WWW: http://www.umr.edu/~nneul      SysAdmin: rollanet.org


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

Date: Fri, 18 Jul 1997 05:16:28 GMT
From: Markus.ludwig@lrz.uni-muenchen.de (Markus Ludwig)
Subject: Basic Help Wanted
Message-Id: <33ce8737.8264465@news.muenchen.org>

Hello,

because of over 8000 incoming mails after subscribing here, please
answer per e-mail only. Thank You!

I#m very new on the wide area of perl, und perhaps someone could
answer me the following questions:

1. Is there a place to get the newest version of perl for win95 which
is REALLY reachable?

2. Is there a good documentation available (perhaps html format?),
that might guide me through my starter attempts and that can complete
the knowledge I got from my books?

Thanks to everyone writing back!


Altavista,

      Markus


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

Date: 17 Jul 1997 15:30:58 GMT
From: evenh@ra.pvv.ntnu.no (Even Holen)
Subject: Re: bizarre regexp behaviour with split
Message-Id: <slrn5ssei9.qav.evenh@ra.pvv.ntnu.no>

In article <868986581.12052@dejanews.com>, web@calarts.edu wrote:
>#Can anyone explain to me why
>
>split /\Q$delimiter\E/;
>
>#and
>
>split /(\Q$delimiter\E)/;
>
>#behave differently? 


If you look up the manpage of perlfunc then you find the following under
the description of split:

|   If the PATTERN contains parentheses, additional
|   array elements are created from each matching
|   substring in the delimiter.
|
|      split(/([,-])/, "1-10,20", 3);
|
|   produces the list value
|
|      (1, '-', 10, ',', 20)

I guess the differeces is that when using parentheses in the pattern you
also gets to save the actual thingy which delimited your fields. In case
you wanted to now whether it was a range (delimited by -) or a new
number (delimited by , ).

Hope this helps and explains the difference. And as a reminder:
Rembember to read the documentation before asking. If question about
functions try 'man perlfunc'!!

Regards,
Even Holen
-- 
<><   Even Holen, evenh@pvv.ntnu.no, http://www.pvv.ntnu.no/~evenh/   :-)


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

Date: Thu, 17 Jul 1997 21:03:10 -0700
From: Jan Krynicky <Jan.Krynicky@st.mff.cuni.cz>
To: Simon Fairey <sfairey@adc.metrica.co.uk>
Subject: Re: Can this regexp loop be improved?
Message-Id: <33CEEAFE.1FD0@st.mff.cuni.cz>

Simon Fairey wrote:
> 
> Hi,
> 
> After looking at this for a while and not bieng in a position to change
> the way the surrounding processing works, I am trying to find a way to
> speed up this small loop.
> 
> foreach $regexp ( @regexps ) {
>   $i = 0;
>   foreach( @names ) {
>     /^${regexp}$/i and push( @indexs, $i );
>     $i++;
>   }
> }
> 
> I tried this ( taken from the FAQ ) but it turned out to be slower
> according to the profiler.
> 
> my $expr = join " or " => map { "/^\$regexps[$_]\$/io" } (0..$#regexps);
> 
> $i = 0;
> foreach( @names ) {
>   eval "$expr" and push( @indexs, $i );
>   $i++;
> }
> 
> Any help would be appreciated.
> 
> Simon


#/bin/perl
=pod

Let's have arrays :

=cut

@arr = ('a.*b','(b|c).*a','a.*a$','b.*?b','a.b.*a');

@strings=("dfsdb","fsavdfgbdc","fgasdf","fgdfgadfgdadfgb",
 "dfgajhsdm sdbff","fbdskjasfb","cvsdfbfgdfbdga", 
 "facbddafbxeesda bcss");

=pod

We want to check all the strings against all teh regexps.
We should compile all the regexps only once so let's prepare
a list of matching functions.

=cut

@regexps = ();
foreach $exp (@arr) {
 my $reg;
 eval "\$reg = sub {\$_[0] =~ /$exp/;}";
 push @regexps,$reg;
}

=pod

And on to the testing.

My version :

=cut

$time=time;

for($n=0;$n<10000;$n++) {

 foreach $string (@strings) {
  $i=0;
  foreach $regexp (@regexps) {
#   print "Regexp number $i : ";
   if (&$regexp($string)) {
#    print "$str matches.\n";
   } else {
#    print "$str doesn't match.\n";
   } 
   $i++;
  }
 }

}

print "My lasted ",time-$time," seconds.\n";

=pod

and the simple one

=cut

$time=time;

for($n=0;$n<10000;$n++) {

foreach $string (@strings) {
 $i=0;
 foreach $regexp (@arr) {
#  print "Regexp number $i : ";
  if ($string =~ /$regexp/) {
#    print "$str matches.\n";
  } else {
#    print "$str doesn't match.\n";
  }
  $i++;
 }
}

}

print "The simple lasted ",time-$time," seconds.\n";


=pod

Results :


My lasted 50 seconds.

real    0m50.330s
user    0m49.880s
sys     0m0.160s


The simple lasted 93 seconds.

real    1m33.560s
user    1m31.980s
sys     0m0.160s                                              


A little difference.

Tested on Solaris 2.3.

=cut

__END__

Hi, Jenda


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

Date: 17 Jul 1997 16:03:39 GMT
From: stampes@xilinx.com (Jeff Stampes)
Subject: Re: Canonical List of One-Liners
Message-Id: <5qlfor$npo$1@neocad.com>

Clark Dorman (clark@s3i.com) wrote:
: 	Tom C once posted such a list of one-liners

And here it is:

    # run contents of "my_file" as a program
    perl my_file

    # run debugger "stand-alone"
    perl -d -e 42

    # run program, but with warnings
    perl -w my_file

    # run program under debugger
    perl -d my_file

    # just check syntax, with warnings
    perl -wc my_file

    # useful at end of "find foo -print"
    perl -nle unlink

    # simplest one-liner program
    perl -e 'print "hello world!\n"'

    # add first and penultimate columns
    perl -lane 'print $F[0] + $F[-2]'

    # just lines 15 to 17
    perl -ne 'print if 15 .. 17' *.pod

    # in-place edit of *.c files changing all foo to bar
    perl -p -i.bak -e 's/\bfoo\b/bar/g' *.c

    # command-line that prints the first 50 lines (cheaply) 
    perl -pe 'exit if $. > 50' f1 f2 f3 ...

    # delete first 10 lines
    perl -i.old -ne 'print unless 1 .. 10' foo.txt

    # change all the isolated oldvar occurrences to newvar
    perl -i.old -pe 's{\boldvar\b}{newvar}g' *.[chy]

    # command-line that reverses the whole file by lines
    perl -e 'print reverse <>' file1 file2 file3 ....

    # find palindromes
    perl -lne 'print if $_ eq reverse' /usr/dict/words

    # command-line that reverse all the bytes in a file
    perl -0777e 'print scalar reverse <>' f1 f2 f3 ...

    # command-line that reverses the whole file by paragraphs
    perl -00 -e 'print reverse <>' file1 file2 file3 ....

    # increment all numbers found in these files
    perl i.tiny -pe 's/(\d+)/ 1 + $1 /ge' file1 file2 ....

    # command-line that shows each line with its characters backwards
    perl -nle 'print scalar reverse $_' file1 file2 file3 ....

    # delete all but lines beween START and END
    perl -i.old -ne 'print unless /^START$/ .. /^END$/' foo.txt

    # binary edit (careful!)
    perl -i.bak -pe 's/Mozilla/Slopoke/g' /usr/local/bin/netscape

    # look for dup words
    perl -0777 -ne 'print "$.: doubled $_\n" while /\b(\w+)\b\s+\b\1\b/gi'

    # command-line that prints the last 50 lines (expensively)
    perl -e '@lines = <>; print @lines[ $#lines .. $#lines-50' f1 f2 f3 ...



--
Jeff Stampes -- Xilinx, Inc. -- Boulder, CO -- jeff.stampes@xilinx.com


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

Date: Thu, 17 Jul 1997 12:16:02 -0400
From: Eric Blue <sysadm@twd.net>
Subject: CHALLENGE!!!! streaming text for cgi web based chat server
Message-Id: <33CE4542.7490@twd.net>

Ok, PERL gurus! I am working on a project to allow
               streaming(scrolling) text for a cgi chat server in a 
               multi-framed HTML document. I have seen several
               client / server models and sample code, but cannot seem
               to get it straight. The problem I see with many of the 
               sample daemons is that they create way too much server

               load. ex. The have to spawn a child process to 
               communicate with a newly opened socket. I need a 
               server to accept incoming sockets and to print messages 
               recieved from a socket to all other open connections 
               from ONE process(I guess this would be similar to the 
               innd process). I will be INCREDIBLY grateful for some 
               advice as this is an extremely important feature for me
to

               add. Thank you very much. 


               ------ Text Omitted .... Code needing fixed is listed
below



               I feel the code is almost there, but it has bugs in it.
I've
               set the server to listen on a particular port. Rather
then
               writing the client, I've just telneted in to test the 
               response. Once the socket is opened, I type in data(then
               of course the steam will be ended via a \n) and the data
               is sent back to my socket and it is then closed. For some 
               reason the text is not being broadcasted to other open
               connections. I'd really appreciate further help if it is
               possible. Also, once completed this version should be 
               able to support up to and even beyond 50 - 100
               simultaneous users. Is this feasable with this
               implementation. Here is my code so far. Also The cgi
               web-based interface will be in a 
               3 frame window. The upper left frame will recieve all
               new 
               text written by other chatters. The lower frame will
allow
               the user to add new text, which will in turn be sent to
the
               upper right frame. The third frame will be used for
               customizable options. 
               Thank you greatly! - Eric 

                   #!/usr/bin/perl 
                   
                   ($port) = @ARGV; 
                   $port = 2345 unless $port; 
                   
                   $AF_INET = 2; 
                   $SOCK_STREAM = 1; 
                   
                   $sockaddr = 'S n a4 x8'; 
                   
                   ($name, $aliases, $proto) = getprotobyname('tcp'); 
                   if ($port !~ /^\d+$/) { 
                   ($name, $aliases, $port) = getservbyport($port,
               'tcp'); 
                   } 
                   
                   print "Port = $port\n"; 
                   $this = pack($sockaddr, $AF_INET, $port,
               "\0\0\0\0"); 
                   
                   socket(LISTEN, $AF_INET, $SOCK_STREAM,
               $proto) || die "socket: $!"; 
                   bind(LISTEN,$this) || die "bind: $!"; 
                   listen(LISTEN,5) || die "connect: $!"; 
                   
                   select(LISTEN); $| = 1; select(stdout); 
                   
                   print "Listening for connections....\n"; 
                   
                   while (1) { 
                   # each time, create the select bit array 
                   $bits = 0; 
                   for (@CLIENTS) { 
                   vec ($bits, fileno ($_), 1) = 1; 
                   } 
                   vec ($bits, fileno (LISTEN), 1) = 1; 
                   
                   #OK, wait until something comes in. 
                   $nfound =
               select($rbits=$bits,undef,$ebits=$bits,undef); 
                   
                   #OK, something woke us up. 
                   # see if it is a new connection... 
                   if (vec($rbits, fileno(LISTEN), 1)) { 
                   # new connection 
                   accept (NS, LISTEN); 
                   push (@CLIENTS, NS); } 
                   
                   #no, try the clients 
                   $incoming = undef; 
                   for (@CLIENTS) { 
                   if (vec ($rbits, fileno ($_), 1)) { 
                   #OK, this client's got something, read a line... 
                   $incoming .= <$_>; } } 
                   
                   # next, send $incoming to all clients... 
                   if ($incoming) { 
                   for (@CLIENTS) { 
                   print $_ "$incoming\n"; } } 
                   } 

Please leave any replies to sysadm@twd.net.  Thanks!


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

Date: 17 Jul 1997 19:43:50 GMT
From: scott@lighthouse.softbase.com (Scott McMahan)
Subject: Re: Creating a file, only if the file handle is 'used'
Message-Id: <5qlslm$aec$2@mainsrv.main.nc.us>

Andrew Dear (dear_andrew@jpmorgan.com) wrote:
: I want to redefine STDERR to a file eg.

: 	open STDERR, ">my_file";

: However I would like to avoid any overhead, and avoid actually
: creating the empty file "my_file" if STDERR is not used.

: Does anybody know if this is possible?

If you have enough memory (and how much are you going to be writing to
stderr? shouldn't be much), push everything you'd write to STDERR onto
an array instead. At the end of execution, if there's anything in the
array, write it to the file. Otherwise, skip that step.

Ex:

	$rc = do_something();
	push STDERRARR, ("An error occurred:\n", 
			"\t Error in module do_something\n",
			"\treturn code = ($rc)\n")
		if $rc;

	# much later
	if (defined (@STDERRARR)) {
		# open file
		print STDERR @STDERRARR
		# close file
	}

Scott


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

Date: Thu, 17 Jul 1997 19:27:55 -0700
From: Chris Schoenfeld <chris@ixlabs.com>
Subject: GGAAAAKK!! Bad Perl week - now DBD Oracle troubles
Message-Id: <33CED4AB.17B0@ixlabs.com>

Earlier this week I installed DBI/DBD Oraperl into 2 brand-spanking new
Perl installations (5.003/5.003_07) on a Sun Sparc 20 running Solaris
2.5.

Worked great!

Now I have installed 2 more Perls on the same box - 5.004 and 5.004_01,
and DBD Oraperl 'make test' dumps core with BOTH of them - WAA!!!

Any ideas?

I think I'm going to go home and drink. This 5.003->5.004 migration has
been a nightmare from start to finish.

-c


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

Date: Thu, 17 Jul 1997 17:15:00 -0400
From: Jason Duell <jason@dtlweb.com>
Subject: Re: Global Vars : Why would I want to use "use strict"
Message-Id: <33CE8B53.28B9CDA2@dtlweb.com>

> : them. So if I use the 'use strict;' command, which forces me to
> declare all
> : my variables with 'my()' then I can't use global variables right??
>
> Nope...see 'use vars':
>
> use strict;
> use vars qw($foo %hash @an_array);

NOTE: you may not even need to do this to get your variables as "global"
(wink wink, nudge nudge..) as you need them in small, single-file
scripts. I gather from your post that you are concerned that if you use
"my($foo)" at the beginning of your program, outside of any subroutines,
$foo won't be visible to your subroutines. Not necessarily true! As
noted in the Camel book, p 108, the scope of a my() variable is "the
enclosing block, subroutine, eval, or file". What this seems to mean
(I've tried it a few times, and it does indeed seem to work this way) is
that my() variables that are declared at file scope (outside of any
braces or subs) will be visible to any subroutines that are defined in
the same file. (see Camel book, p 106).
    The following program, for instance, defines "my($foo)" outside of
any subs, and then successfully prints its value inside of subroutine
"bar()":

#############################
#!/usr/bin/perl -w

my($foo) = "bar";
baz();

sub baz {
        print "\$foo is $foo";
}
##### output : "$foo is bar" #####

Understanding this point has made me realize that "local()" is indeed
seldom needed, as all the books I have read keep stating. I had
previously thought that I would need "local" to do exactly what "my"
does in the program above....

I am disabused!

Jason Duell



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

Date: Thu, 17 Jul 1997 12:36:00 +0100
From: Simon Fairey <sfairey@adc.metrica.co.uk>
Subject: Index a hash by a regex ?
Message-Id: <33CE03A0.41C6@adc.metrica.co.uk>

Hi,

I am wondering if it is possible to index a hash by a regex. Currently I
am using grep to generate an array of keys which match the regex and
then using that array to index the hash and return an array of the
values. i.e.

@names = grep( /something/, keys %hash );
@values = @hash{@names};

Basically I am looking into ways of speeding up the above.

Thanks

Simon


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

Date: 17 Jul 1997 16:32:06 GMT
From: clin@cs.umd.edu (Charles Lin)
Subject: Re: Learning Perl ..Help??
Message-Id: <5qlhe6$pv7@mimsy.cs.umd.edu>

Boris Tabenkin (bat@unifi.com) wrote:
|| (On soap box)
|| Not to sound like  I am sucking up, but the PERL book is one of the best
|| computer books ever written. I hate those learn anything in 7 days
[...]

    Which PERL book is that?   There are two by O'Reilly (publishing).

    Anyway, the reason there are so many "learn blah in 7 days" is 
precisely because people learn differently.   Personally, I'm happy
those books exists.   I'm also happy the O'Reilly books exist too 
because they try to be more complete, and not leave out things just
because it will scare away readers.   If I had to recommend a book
on Perl, I'm sure I'd suggest Learning Perl.    It's one of the better
books in the O'Reilly series.

    I'll tell you the reason I had difficulties initially with Programming
Perl.   Although I already knew C and C++, I had never really done any
shell programming, nor awk or sed.   That hindered me in one way:
I didn't really understand the philosophy of shell programming.  Shell
programming is useful for certain kinds of problems, primarily those 
dealing with file processing and output processing (which can be thought
of as file processing).    

    As I recall, Programming Perl has a rather cavalier writing style
(perhaps an exaggeration), as the author(s) try to tell you neat things
about the language.   I usually go in with the mindset that I am trying
to learn how to program the language in the first chapter, not "look
at what this language can do for me".  Perhaps that's the wrong
way to approach that chapter.   Anyway, such notions as associative
arrays were somewhat foreign to me.   While I was being shown its *use*,
I wanted a more formalized description of what an associative array
was, what syntax to use, and so forth.   I was frustrated at the informal
approach in the first chapter because I wasn't getting a real understanding
of how to write code.

    Now, I will say that some of these "learn in blah days" books aren't
always very good.   Sometimes the authors mistake "hip talk" and using
"cute examples" for really explaining the subject.   To cite a different
example, I'm looking at "Apache: The Definitive Guide" which is another
O'Reilly book.    I find this very frustrating to read.   Now, partly,
I'm a slow learner when it comes to technical books, but partly, I think
it doesn't do a good job of explaining things.   The fortunate thing is
that there is a lot of stuff in the book that is useful, but it takes
a while to understand it.   Unfortunately, this appears to be one of
two books on Apache, and the Apache web site really has a bad excuse
for a FAQ, not to mention no tutorials, but that's a side gripe.

    This is why I find it interesting when someone asks "Can someone
recommend a good book on blah....?".    The answer is "it depends on
what you like to read".   For example, in C++, some people want the
original Stroustrup book.   Others want a "Who's Afraid of C++?" 
(this is a book where the author talk to a novice, and there is
a back and forth exchange as she gets confused, and he gives her
answers to clear things up).   Still others might be happy with
some ANSI draft, "formal" spec of the language.   There's often a
tradeoff between ease of reading, and completeness, as well as
accuracy.   I think we should all be happy that learn blah in N
days books exist.   It makes computers accessible to a much wider
population rather than to a narrow group of bright programmers who
can read between the lines, and toy around with the language, using
their previous experience to help out.   Not everyone fits in that
category.

--
Charles Lin
clin@cs.umd.edu



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

Date: Thu, 17 Jul 1997 20:12:43 GMT
From: sherman@unx.sas.com (Chris Sherman)
Subject: Merging large complex data structures
Message-Id: <EDHC57.4J3@unx.sas.com>

Sometimes, I just don't see it...

I want to merge two complex data structures into a new variable.

For instance (from the book):

   %TV1 = (
     flintstones => {
       series   => "flintstones",
       nights   => [ qw(monday thursday friday) ],
       members  => [
          { name => "fred",   role => "lead", age 36,},
       ],
     }
   )

And suppose I had in a separate file somewhere:

   %TV2 = (
     jetsons => {
       series   => "jetsons",
       nights   => [ qw(wednesday saturday) ],
       members  => [
          { name => "george",   role => "lead", age 41,},
       ],
     }
   )

Now, I want something called %TV, which is a merging of both 
data structures from above.

So, in effect, I want to do:

  %TV = %TV1 + %TV2;   # thinking of '+' as a union operator

How can I do that?  I just don't see the obvious solution, 
other than manually stepping through both structures and setting
every element of the third by hand.  There has to be a better way...

Thanx!!!

-- 
     ____/     /     /     __  /    _  _/    ____/
    /         /     /     /   /      /     /          Chris Sherman
   /         ___   /        _/      /          /
 _____/   __/   __/   __/ _\    _____/   _____/           sherman@unx.sas.com


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

Date: Fri, 18 Jul 1997 10:05:47 +1000
From: odeon@mailbox.uq.edu.au (Jye Tucker)
Subject: Newbie Help..please??? :)
Message-Id: <odeon-ya023180001807971005470001@news.uq.edu.au>

Hi there,

I am incredibly new to Perl programming and have decided to jump into the
deep end with programming a mini-search engine. I have done really well so
far (so I think anyway:) but there is just one element of the program that
I would like help with. Basically I have a file with lines ...

$filekey:$filedate:$fileband:$filevenue:$fileinfo:$fileurlband:$fileurlvenue 

eg. 3:8/9/1997:Bruiser:Festival Hall:Free entry for
students:www.bruiser.com:www.festival.com

I have made the search engine able to search for entries in the $filedate,
$fileband, and $filevenue fields, however, when the search is done on
either the $fileband or $filevenue fields, the results returned are not in
chronological order (as I would like) but in the order that they are
displayed in the file. Since this is a web based search engine, I would
like to sort the actual file chronologically when I put data in instead of
sorting the output when a user queries the engine.

I have included the code for the entire script below that processes the
data entered. Any suggestions at all would be appreciated. Any suggestions
regarding how to sort the lines in GIGFILE by date and remove information
that has expired (i.e. $filedate is less than the current date) would be
even more appreciated :))

Gosh I hope that made sense....  ;)

Could you please reply through email to Jye.Tucker@mailbox.uq.edu.au or
odeon@mailbox.uq.edu.au? I don't often get the opportunity to check
newsgroups. :(

<----Start of code----->

#!perl

require "cgi-lib.pl";

# Get the new information

&ReadParse;
open(GIGFILE,"gigfile") || die "cannot open gigfile";
open(GIGFILEWRITE, ">>gigfile") || die "cannot open write gigfile";
$newkey=1;
$y=0;
while (<GIGFILE>) {
chop;
($filekey,$filedate,$fileband,$filevenue,$fileinfo,$fileurlband,
$fileurlvenue) = split(/:/);
$newkey=($filekey+1);
if ($in{'band'} eq $fileband) {
$got="true";}
$namesarray[$y]=$fileband;
$y++;
}


if ($got ne "true") {
push(@namesarray,($in{'band'}));
}

# Get all band names in alphabetical order ready to be stored in a file

@sortarray=sort(@namesarray);
$x=0;
$z=1;
$b=0;
while ($sortarray[$x] ne "") {
if ($sortarray[$x] ne $sortarray[$z]) {
$uniquearray[$b]=$sortarray[$x];
$b++;
}
$x++;
$z++;
}

# Keep a record of all bands ready to be cut'n'pasted to a form pop-up menu 
(This is what I'm taking on next - how to get the script to automatically
update the actual HTML file)

$a=0;
if ($got ne "true") {
open(WRITEBANDLIST, ">bandlist") || die "cannot open writebandlist";
while (@uniquearray[$a] ne "") {
print WRITEBANDLIST "<OPTION>@uniquearray[$a]</OPTION>\n";
$a++}
close(WRITEBANDLIST)
}

#Search for a url record for $in{'band'} or $in{'venue'}

open(URLFILE, "urlfile");
while (<URLFILE>) {
chop;
($urlkey,$urlname,$urlloc)=split(/:/);
if ($in{'band'} eq $urlname) {$nuband=$urlloc}
if ($in{'venue'} eq $urlname) {$nuvenue=$urlloc}
}
close(URLFILE);

$newinput=($newkey.":".$in{'date'}.":".$in{'band'}.":".
$in{'venue'}.":".$in{'info'}.":".$nuband.":".$nuvenue);

# Add the new information to the records

print GIGFILEWRITE "$newinput\n";
close(GIGFILE);
close(GIGFILEWRITE);

# Print the response

print "
<HTML>
<HEAD>
<TITLE>Records added</TITLE>
</HEAD>
<BODY>
The following records were added to the Gig Guide database:<BR>
<P>
$newinput</P>
refers to the following data:<BR>
<P>
Key: $newkey<BR>
Date: $in{'date'}<BR>
Band: $in{'band'}<BR>
Venue: $in{'venue'}<BR>
Additional Info: $in{'info'}<BR>
Band URL: $nuband<BR>
Venue URL: $nuvenue<BR>";
if ($got ne "true") {print "<P>and the band ".$in{'band'}.
" was added to the band lists</p>"}
print "</BODY></HTML>"

<-----End of Code----->


thanks heaps,

Jye Tucker

-- 
Odeon Designs - http://www.odeon.com.au


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

Date: Thu, 17 Jul 1997 22:28:16 -0700
From: Jan Krynicky <Jan.Krynicky@st.mff.cuni.cz>
To: Robert Stewart <robert@osk0.attnet.or.jp>
Subject: Re: Newbie Problem - IE/Netscape differences
Message-Id: <33CEFEEF.195F@st.mff.cuni.cz>

Robert Stewart wrote:
> 
> I hope someone can help me with this.
> 
> A Japanese friend wrote a perl script (5.00) to handle a simple HTML
> form.
> 
> If the form page is viewed using IE (v3.02) and the submit button is
> hit, the form operates as expected.
> 
> However viewing the same form under Netscape (v3.0 and Communicator4.01)
> it crashes.  An MS-DOS window briefly appears, the Perl script appears
> and then the MS-DOS window disappears again, returning us to the form
> page.
> 
> Does anyone have a suggestion why this form behaves differently under
> the 2 browsers.
> 
> Perl script is on an NT machine running IIS3.0, the client is running
> Windows 95.
> 
> Robert Stewart

Where does the DOS window appear? On the server?

If so run regedt32.exe
go to 
HKLM\SYSTEM\Services\W3SVC\Parameters

 There should be a value
   CreateProccessWithNewConsole:REG_DWORD:0

If it's not, then add it.


If it shows on the client, you probably didn't send propper headers.
It seems that Netscape thinks he should run the page instead of showing
it
and uses the file extension mapping, ie uses perl.exe.

The first text your script MUST print out is "Content-type:
text/html\n\n".

Hope that helps.

Jenda


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

Date: 17 Jul 1997 19:19:20 GMT
From: "Sergio Stateri Jr" <serginho@alpha.hydra.com.br>
Subject: Newbie question, but...
Message-Id: <01bc92e6$bf45fe60$6875e7c8@Term104>

Hi ! What's the difference between .pm and .pl files ? Please, I'm asking
this because I install Perl for Win 32 today. I used Perl for NWS 3.01 and
I never see the .pm files...

regards,

-- 
--------------------------------------------
Sergio Stateri Jr
Sco Paulo (SP) - Brazil
e-mail: serginho@usa.net
--------------------------------------------


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

Date: Fri, 18 Jul 1997 09:18:11 +0100
From: Simon Fairey <sfairey@adc.metrica.co.uk>
To: Sergio Stateri Jr <serginho@alpha.hydra.com.br>
Subject: Re: Newbie question, but...
Message-Id: <33CF26C2.1CB74007@adc.metrica.co.uk>

Sergio Stateri Jr wrote:

> Hi ! What's the difference between .pm and .pl files ? Please, I'm
> asking
> this because I install Perl for Win 32 today. I used Perl for NWS 3.01
> and
> I never see the .pm files...
>
> regards,
>
> --
> --------------------------------------------
> Sergio Stateri Jr
> Sco Paulo (SP) - Brazil
> e-mail: serginho@usa.net
> --------------------------------------------

General .pm files contain Perl Modules for use by Perl scripts (.pl),
they are rather like libraries of functions or class definitions and
methods. There is no hard and fast rule as to file extensions but in
general .pm and .pl are the standard ones.

Simon



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

Date: 18 Jul 1997 03:05:03 GMT
From: jbharvey@gte.net (Justin B. Harvey)
Subject: Perl and Expect problems?
Message-Id: <5qmmgv$h19$1@gte1.gte.net>

Anyone experienced any problems with spawning an expect script via
system or system calls via backticks?

j
--
Justin B. Harvey
jbharvey@gte.net
http://home1.gte.net/jbharvey


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

Date: 18 Jul 1997 00:05:30 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Perl for DOS
Message-Id: <5qmc0a$34@agate.berkeley.edu>

In article <33cf3eb4.2999069@news.tornado.be>,
Bart Lateur <bart.mediamind@tornado.be> wrote:
> A friend <masses@et.byu.edu> wrote:
> 
> >Has anyone seen perl for DOS?  No, Win32 doesn't work.
> 
> Look in CPAN for the OS/2 port. This can be patched to work under DOS.
> I've recently done that, and it seems to work ok.
> 
>  See the file DOSPERLP.TXT (or WINPERLP.TXT) which describes what has to
> be done.
> 
> I just wish the patched version was avilable on CPAN as well.

EMX-compiled Perl (called OS/2 port in your message) requires no
patching to work under DOS.

Hope this helps,
Ilya








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

Date: 17 Jul 1997 16:08:29 GMT
From: C4@r!3$  <cpeterma@emerald.tufts.edu>
Subject: perl5.003
Message-Id: <5qlg1t$oku$1@d2.tufts.edu>

Anyone know where I can find the src code for this ??  I need to reinstall
the old version to clean up some fubar over here.....


-- 
In the end we all know what we've done,                 Computer Engineer
but how many of us can say                                     Vegetarian
we know what we are doing now?                             Weight Trainer
Charles Peterman        Tufts University       cpeterma@emerald.tufts.edu
    


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

Date: Thu, 17 Jul 1997 15:33:55 -0300
From: Katie Wright <Katie.Wright@asg.unb.ca>
Subject: Problem with HTML counter
Message-Id: <33CE6593.9DC009AA@asg.unb.ca>

I am working on a Perl counter program but I have came across a
stumbling block.

I don't want to use SSI includes and I don't want to have to run a
program that prints out the entire page including the counter value.

I want to use the <IMG SRC="mycounter.pl">

Here is the pseuducode:

Open the counter file containing only a value and read it
Increment the value
Divide the value into separate characters
For every character find out which number image gif corresponds with the
character (1.gif, 2.gif, 3.gif, etc) and then print it.

The problem is that if I have a two digit number say 10, I am only
getting the 1.

I figure that I am going to have to some how add the gif files together
and then print but I don't know how.

Any assistance is appreciated.

Katie Wright
Katie.Wright@asg.unb.ca



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

Date: Fri, 18 Jul 1997 13:08:43 +1000
From: Martien Verbruggen <mgjv@comdyn.com.au>
Subject: Re: Problem with HTML counter
Message-Id: <33CEDE3B.531C@comdyn.com.au>

Katie Wright wrote:

> I figure that I am going to have to some how add the gif files together
> and then print but I don't know how.

Yep, that is what you will have to do. Have a look at the GD module. It
has a few methods that will allow you to read in pre-existing GIFs and
either use them as a brush, or just paste them on a new canvas.
Pre-calculate the size of the canvas you need, read in the GIFs one by
one, and place them on the canvas, then return the GIF data.

Martien
-- 
Martien Verbruggen                      |
Webmaster www.tradingpost.com.au        | "In a world without fences,
Commercial Dynamics Pty. Ltd.           |  who needs Gates?"
NSW, Australia                          |


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.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 751
*************************************

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