[7115] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 740 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 17 08:17:14 1997

Date: Thu, 17 Jul 97 05:00:57 -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           Thu, 17 Jul 1997     Volume: 8 Number: 740

Today's topics:
     Re: ? typeglob of a hash in a hash.  woo! <rootbeer@teleport.com>
     Re: Backtick Commands in Server Apps (Ilya Zakharevich)
     Building a perl hash in C using hv_store_ent() <mmoreno@cas.org>
     Re: chmod <rootbeer@teleport.com>
     Re: Cookie <mattias.lonnqvist@uidesign.se>
     Re: en francais <merlyn@stonehenge.com>
     GET FREE 2100 $ex-Web$Sites FREE! @? 098723489763278@compuserve.com
     Re: help using ~s/ / / please! <usenet-tag@qz.little-neck.ny.us>
     How to mail files uuencoded? <bart_mitzvah@spam-is-not.kosher.com>
     Re: How to round numbers in perl (M.J.T. Guy)
     Re: How to round numbers in perl (M.J.T. Guy)
     Re: How to search ****** (Chris Schleicher)
     Re: Is remote registry administration possible for Wind (Mark Nielsen)
     Re: Lotus Notes && PERL (Jon Orwant)
     major tech support site <defaultuser@domain.com>
     Re: mooshing files, 2 > 1 (Mark Katz)
     None zipped modules <jxn@realtime.demon.co.uk>
     Read a hash within a hash <mortensi@idt.ntnu.no>
     read last line without reading previous lines, how? (Chuan Wang)
     Re: regex expression to extract data from a string (Tung-chiang Yang)
     RFC: prop. for overloading 'next' keyword (Jeremy D. Impson)
     Seriol Communication <helmrl@aur.alcatel.com>
     Re: substition question (Greg Bacon)
     Why doesn't MAKEFILE work on Win95? (Anonymous)
     windows 95 perl <addadi@ibm.net.il>
     Writing perl modules. <pxa7@cac.psu.edu>
     Yacc Syntax File for Perl (Mukesh Patel)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Wed, 16 Jul 1997 13:26:36 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Chad <cm0x1a@lauren.surfsouth.com>
Subject: Re: ? typeglob of a hash in a hash.  woo!
Message-Id: <Pine.GSO.3.96.970716132321.6690E-100000@kelly.teleport.com>

On Wed, 16 Jul 1997, Chad wrote:

> I want 
> 
> $idhash{$id}{"element2"}
> 
> to be a synonym of 
> 
> $idhash{$id}{"element1"}

I'm going to cautiously say that it's possible, but not easy. I think
you'd have to do this with a tied hash. I think that's the only way, but
I'm willing to be taught. :-)

What would perhaps be easier (both to do and to understand) would be to
store in those locations a reference to the actual value you want. Then,
it's no trouble to give two locations the same reference. 

Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: 16 Jul 1997 18:47:22 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Backtick Commands in Server Apps
Message-Id: <5qj4vq$om6@agate.berkeley.edu>

In article <Pine.GSO.3.96.970715120252.7560F-100000@kelly.teleport.com>,
Tom Phoenix  <rootbeer@teleport.com> wrote:
> On 14 Jul 1997, Gary Chambers wrote:
> 
> > I'm using the following command line (also right out of the Camel book)
> > in my script:
> > 
> > my ($one, $five, $fifteen) = (`uptime` =~ /(\d+\.\d+)/g);
> 
> Hmmm... That works for me. One thing which could go wrong, though, is that
> the setting of your PATH must be sufficient to tell Perl where to find
> uptime. 
> 
> > The errors I receive are:
> > 
> > Use of uninitialized value at /home/geecee/bin/loadd line 32.
> > Use of uninitialized value at /home/geecee/bin/loadd line 32.
> > Unable to create sub named "" at /home/geecee/bin/loadd line 32.
> 
> Hmmm.... Those are odd errors. (That is, they're not from a mis-set PATH,

Nothing odd.  Just an old buggy perl.  Upgrade.

The messages read: "You got a signal".

Ilya



















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

Date: Wed, 16 Jul 1997 23:03:15 -0400
From: Marco Moreno <mmoreno@cas.org>
Subject: Building a perl hash in C using hv_store_ent()
Message-Id: <33CD8B73.21A2@cas.org>

In C, I am attempting to embed perl, construct a perl hash, push a
reference
to it on the stack, manipulate the hash via a perl subroutine call and
return the results back to C via the stack.

Though I've read perlembed, perlcall and perlguts I have not found any
good
examples of hash manipulation.  I've been successful in using an array,
but
I keep getting segmentation faults when trying to do it with a hash.
(I derived the code from the examples in TPJ vol.1 iss.4.)

Can anyone show me what I'm doing wrong or point me to some examples of
how
to do this?

Any help would be greatly appreciated!

TIA,

Marco Moreno
mmoreno@cas.org


Here's the C code in buildhash.c:

/* buildhash.c */
#include <stdio.h>
#include <EXTERN.h>
#include <perl.h>
static PerlInterpreter *my_perl;

static int buildhash(SV *hash_ref, char *string)
{

   dSP;                            /* initialize stack pointer      */
   ENTER;                          /* everything created after here */
   SAVETMPS;                       /* ...is a temporary variable.   */
   PUSHMARK(sp);                   /* remember the stack pointer    */

   XPUSHs(hash_ref);               /* push hash reference onto the stack
*/

   PUTBACK;                        /* make local stack pointer global */

   perl_call_pv("hash2string", G_SCALAR); /* call perl sub */

   SPAGAIN;                        /* refresh stack pointer         */

   string = POPp;                  /* get and print the string generated
*/
   printf("string: %s\n", string); /*  by the perl sub */

   PUTBACK;
   FREETMPS;                       /* free that return value        */
   LEAVE;                          /* ...and the XPUSHed "mortal"
args.*/

   return 0;
}

main (int argc, char **argv, char **env)
{
   char *embedding[] = { "", "./hash2string.pl" };
   char *string;

   HV *hash = newHV();
   SV *hash_ref = newRV_noinc((SV*) hash);  /* should this be
newRV_inc??? */

   SV *key = sv_2mortal(newSVpv("Song", 0));
   SV *val = sv_2mortal(newSVpv("Mary had a little lamb", 0));

   hv_store_ent(hash, key, val, 0);

   my_perl = perl_alloc();
   perl_construct( my_perl );
   perl_parse(my_perl, NULL, 2, embedding, NULL);

   perl_run(my_perl);

   buildhash(hash_ref, string);

   perl_destruct(my_perl);
   perl_free(my_perl);
}

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

And the perl code in hash2string.pl:

# hash2string.pl

use strict;

sub hash2string {
    my($hash_ref) = @_;
    my($key) = keys %$hash_ref;
    return "A key is '$key' and its value is '$hash_ref->{$key}'";
}

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

I compiled it with:

cc -g -o buildhash buildhash.c `perl -MExtUtils::Embed -e ccopts -e
ldopts`


and I get a segmentation fault:

>>>-projects/perl_embed-> ./buildhash
Segmentation Fault(coredump)

>>>-projects/perl_embed-> dbx buildhash core
Reading symbolic information for buildhash
core file header read successfully
Reading symbolic information for rtld /usr/lib/ld.so.1
Reading symbolic information for libsocket.so.1
Reading symbolic information for libnsl.so.1
Reading symbolic information for libdl.so.1
Reading symbolic information for libm.so.1
Reading symbolic information for libc.so.1
Reading symbolic information for libintl.so.1
Reading symbolic information for libmp.so.1
Reading symbolic information for libw.so.1
program terminated by signal SEGV (no mapping at the fault address)
Current function is main
   44      hv_store_ent(hash, key, val, 0);
(dbx) where
  [1] Perl_share_hek(0xba408, 0x4, 0x2f6a37, 0x0, 0x0, 0xb9469), at
0x54ca4
  [2] Perl_hv_store_ent(0xbb408, 0xb9464, 0xb9408, 0x2f6a37, 0xba408,
0x1), at 0x534d4
=>[3] main(argc = 1, argv = 0xefffed54, env = 0xefffed5c), line 44 in
"buildhash.c"
(dbx)

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

Here is virtually identical code that works by doing it with an array
reference instead of a hash.

The C code in buildarray.c:

/* buildarray.c */
#include <stdio.h>
#include <EXTERN.h>
#include <perl.h>
static PerlInterpreter *my_perl;

static int buildarray(SV *array_ref, char *string)
{

   dSP;                            /* initialize stack pointer      */
   ENTER;                          /* everything created after here */
   SAVETMPS;                       /* ...is a temporary variable.   */
   PUSHMARK(sp);                   /* remember the stack pointer    */

   XPUSHs(array_ref);              /* push array reference onto the
stack */

   PUTBACK;                        /* make local stack pointer global */

   perl_call_pv("list2string", G_SCALAR); /* call perl sub */

   SPAGAIN;                        /* refresh stack pointer         */

   string = POPp;                  /* get and print the string generated
*/
   printf("string: %s\n", string); /*  by the perl sub */

   PUTBACK;
   FREETMPS;                       /* free that return value        */
   LEAVE;                          /* ...and the XPUSHed "mortal"
args.*/

   return 0;
}

main (int argc, char **argv, char **env)
{
   char *embedding[] = { "", "./list2string.pl" };
   char *string;

   AV *array = newAV();
   SV *array_ref = newRV_noinc((SV*) array); /* should this be
newRV_inc??? */

   SV *key = sv_2mortal(newSVpv("Song", 0));
   SV *val = sv_2mortal(newSVpv("Mary had a little lamb", 0));

   av_push(array, key);
   av_push(array, val);

   my_perl = perl_alloc();
   perl_construct( my_perl );
   perl_parse(my_perl, NULL, 2, embedding, NULL);

   perl_run(my_perl);

   buildarray(array_ref, string);

   perl_destruct(my_perl);
   perl_free(my_perl);
}

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

And my perl code in list2string.pl:

# list2string.pl

use strict;

sub list2string {
    my($array_ref) = @_;
    my($key, $val) = @$array_ref;
    return "A key is '$key' and its value is '$val'";
}

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

Compiled identically, it gives me:

>>>-projects/perl_embed-> ./buildarray
string: A key is 'Song' and its value is 'Mary had a little lamb'


BTW, here is perl -V if it helps:

Summary of my perl5 (5.0 patchlevel 4 subversion 1) configuration:
  Platform:
    osname=solaris, osvers=2.4, archname=sun4-solaris
    uname='sunos cwu25awm 5.4 generic_101945-41 sun4m sparc '
    hint=recommended, useposix=true, d_sigaction=define
    bincompat3=y useperlio= d_sfio=
  Compiler:
    cc='cc', optimize='-O', gccversion=
    cppflags=''
    ccflags =''
    stdchar='unsigned char', d_stdstdio=define, usevfork=false
    voidflags=15, castflags=0, d_casti32=define, d_castneg=define
    intsize=4, alignbytes=8, usemymalloc=y, randbits=15
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib /usr/ccs/lib
    libs=-lsocket -lnsl -ldl -lm -lc -lcrypt
    libc=/lib/libc.so, so=so
    useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=, ccdlflags=' '
    cccdlflags='-Kpic', lddlflags='-G -L/usr/local/lib'


Characteristics of this binary (from libperl):
  Built under solaris
  Compiled at Jun 16 1997 11:52:51
  @INC:
    /usr/perl5/lib/sun4-solaris/5.00401
    /usr/perl5/lib
    /usr/perl5/lib/site_perl/sun4-solaris
    /usr/perl5/lib/site_perl
    .


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

Date: Wed, 16 Jul 1997 14:07:54 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Shane Furlong <psf@evolving.com>
Subject: Re: chmod
Message-Id: <Pine.GSO.3.96.970716140237.6690L-100000@kelly.teleport.com>

On 16 Jul 1997, Shane Furlong wrote:

>    opendir DIR, "/some/dir/path";
>    @files = grep !/^\./, readdir DIR;
>    foreach $file (@files) {
>       chmod 755, $file;
>    }
> 
> The problem is that you are not in the directory and so you are not
> changing the file. 

The other problem is that you're trying to set the mode to 01363 instead
of 0755.  Don't forget to use octal. I always do. :-) 

And, of course, the _other_ problem is that you're not checking that the
operation succeeded. This may or may not matter when everything is
working, but it's vital when debugging.

	chmod 0755, "$path/$file"
	    or warn "Couldn't chmod '$path/$file': $!";

Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 16 Jul 1997 14:19:34 +0200
From: Mattias Lvnnqvist <mattias.lonnqvist@uidesign.se>
Subject: Re: Cookie
Message-Id: <33CCBC56.5BDF@uidesign.se>

Benjamin Osyp Beracasa wrote:
> 
> Does anyone now how to set a cookie with perl.

Yes. 
print "Content-type: text/html\n";
print "Set-Cookie: basket=-1:EMPTY:-1; expires=Wed, 09-Nov-1999 00:00:00
GMT;\n\n";
                                       ^^^^^^^^^^
Note that the above is bad style. One should never set a cookie to last
this long.
Its only lazy programming from me when I configured the script.

> And Anyone now how to configure the matts cookie script

Its described in the code. And the README file says even more.


None of these questions should have been posted here, but rather in 
comp.infosystems.www.authoring.cgi


/Mattias

-- 
Mattias Lonnqvist * M.Sc. * Software consultant * malo@uidesign.se
Main coder MiT * tyme.envy.com 6969 * mattias@tyme.envy.com
Unsolicited commercial email is subject to an archival fee of $400.
See <http://www.uidesign.se/~malo/mail.html> for more info.


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

Date: 16 Jul 1997 03:53:43 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: mupe@desk.nl (M. muPe)
Subject: Re: en francais
Message-Id: <8cen8z6zew.fsf@gadget.cscaper.com>

>>>>> "M" == M muPe <mupe@desk.nl> writes:

M> In article <33CC0457.5D5F@ti.com>, cmason@ti.com wrote:
>> 
>> Does anyone know if the perl man pages have been translated into, say,
>> french?
>> 
>> (Est-que personne ne sait si la documentation Perl a ete traduise a des
>> autres langages, comme francais?)

M> Sounds like a good idea to translate the manuals to different languages.
M> (for example, as a native dutch person I still have to read twice 
M> the phrase  'instances of a class' ... Instant klas = Ready made classroom, 
M> just add water..)

I just got a box containing the *Italian* (I presume :-) Blue Camel,
and added that to my shelf with the German, French, and (ugh one other
I forget and it's 2400 miles away) Blue Camels.

So, yes, there *are* translated documents.  You'll just have to pay a
little bit for them.  And being from ORA, they're probably pretty good
translations.  I dunno... I'm an American, so I speak only one (human)
language. :-)

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 412 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: 17 Jul 1997 05:44:06 GMT
From: 098723489763278@compuserve.com
Subject: GET FREE 2100 $ex-Web$Sites FREE! @?
Message-Id: <5qkbf6$ln6@news1-alterdial.uu.net>


http://www.2bornot2b.com/password

Protect Your Children From Viewing ADULT XXX Material
and at the same time get UNLIMITED FREE ACCESS to
over 1200 of the Hottest Adult Sites on the Web.

Also get FREE UNLIMITED Live Video Sex and FREE XXX
rated chat room access.  

Stop paying to get into Adult Sites.  This secret password gets
you into them for FREE!!!  

I posted all the info at the URL above.



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

Date: 15 Jul 1997 17:31:23 GMT
From: Eli the Bearded <usenet-tag@qz.little-neck.ny.us>
Subject: Re: help using ~s/ / / please!
Message-Id: <eli$9707151318@qz.little-neck.ny.us>

Posted and mailed.

shane whinfrey <oa32@dial.pipex.com> wrote:
>which works great. but when i try to reverse the process and put \r
>and \n back in place, like this:-
>
>    $print_address =~s/*!*/\r/g;
>    $print_address =~s/*!!*/\n/g;

'*' is a special character in regexps, you must escape it
somehow. Any one of these, for example:

	$print_address =~s/\*!\*/\r/g;
	$print_address =~s/\Q*!*\E/\r/g;
	$print_address =~s/[*]![*]/\r/g;

The first and second sections of an s/// operand have lots of 
differences. Read the perlre page and the perlop page for more
information.

Elijah
------
and the command is not "~s///": the "~" is part of "=~"


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

Date: Tue, 15 Jul 1997 16:19:35 GMT
From: Joe Stewart <bart_mitzvah@spam-is-not.kosher.com>
Subject: How to mail files uuencoded?
Message-Id: <33cda20c.80232872@news.infoave.net>

How can I change this mailfile script so that
it uuencodes the files before sending them?


sub send_mail {
   if ($form_letter ne "") {
      push (@files,$form_letter);
   }
   foreach $file (@files) {
      if (-e "$filebase/$file") {
         open(MAIL,"|$mailprog -t");

         print MAIL "To: $email ($realname)\n";
         print MAIL "From: $fromaddr ($fromname)\n";
         if ($organization) {
            print MAIL "Organization: $organization\n";
         }
         else {
            print MAIL "Organization: Auto Sent File\n";
         }
         print MAIL "Subject: $file\n";
         print MAIL "X-Courtesy-Of: SendIt! 1.0\n\n";
         open(INPUT,"$filebase/$file")||&error;
         while (<INPUT>) {
            chop $_;
            print MAIL $_,"\n";
         }
         close (INPUT);
         close (MAIL);
      }
      else { yadda yadda yadda...

TIA
-Joe



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

Date: 16 Jul 1997 17:28:30 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: How to round numbers in perl
Message-Id: <5qj0bu$b5d@lyra.csx.cam.ac.uk>

Brand and Karina Hilton <bkhilton@netcom.com> wrote:
>In article <5qg7l7$bhn@lyra.csx.cam.ac.uk>,
>M.J.T. Guy <mjtg@cus.cam.ac.uk> wrote:
>>
>>In article <5qg1ih$j0j$9@nntp2.ba.best.com>, Zenin  <zenin@best.com> wrote:
>>>
>>>	Boy, you work to hard...
>>>
>>>	$Float      = 1.2;
>>>	$RoundInt   = int ($Float + 0.5);
>>
>>And you work inaccurately.   Think about negative numbers.
>
>Unfortunately, your solution doesn't do much better for negative numbers.
>(e.g., round -1.7 returns -1 and round -2.7 returns -2)

Eh?   I didn't offer a solution.   If you mean that Zenin's solution may
be incorrect for negative numbers, that's exactly what I was saying.


Mike Guy


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

Date: 15 Jul 1997 16:14:31 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: How to round numbers in perl
Message-Id: <5qg7l7$bhn@lyra.csx.cam.ac.uk>

In article <5qg1ih$j0j$9@nntp2.ba.best.com>, Zenin  <zenin@best.com> wrote:
>
>	Boy, you work to hard...
>
>	$Float      = 1.2;
>	$RoundInt   = int ($Float + 0.5);

And you work inaccurately.   Think about negative numbers.


Mike Guy


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

Date: 15 Jul 1997 11:08:09 -0700
From: chrissch@cs.uoregon.edu (Chris Schleicher)
Subject: Re: How to search ******
Message-Id: <5qgea9$f1g@psychotix.cs.uoregon.edu>

In article <33CAFAC4.2013B7C3@csc.albany.edu>,
Chao Shao-ju  <sc7489@csc.albany.edu> wrote:
>I tried to search a line that contains more than one star (*)  , using:
>
>if ($line =~ /\*\*/)
>{
>................
>}
>
>But it does not work. Could anyone......thanks.

What doesn't work?  This matches a line containing two (or more)
consecutive asterisks.  You could write it as:

    ... if $line =~ /\*+/;

or

    ... if $line =~ /[*]+/;

or for non-consecutive asterisks

    ... if ($line =~ tr/*/*/) > 1;


Regards,


--chris
-- 
     Chris Schleicher                      Office:  541/346-3998
     Univ of Oregon CIS GTF                email: chrissch@cs.uoregon.edu
                URL: http://www.cs.uoregon.edu/~chrissch/


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

Date: 16 Jul 1997 15:30:38 -0400
From: men2@auto.med.ohio-state.edu (Mark Nielsen)
Subject: Re: Is remote registry administration possible for WindowsNT?
Message-Id: <5qj7gu$3jq$1@auto.med.ohio-state.edu>

I found the website and looked at the hack to connect to computers
remotely. I had to change a few simple things, but I did manage to
download registries from other computers. I didn't upload anything, which
will be my next task, 

Mark

In article <5qdohn$huk$1@auto.med.ohio-state.edu>,
Mark Nielsen <men2@auto.med.ohio-state.edu> wrote:
>I found a good ewbpage about using perl modules with WindowsNt. 
>
>http://www.inforoute.cgs.fr/leberre1/main.htm
>
>>I downloaded the latest version of perl for WindowsNT and looked at the
>>Win32 module. It has some abilities to change registry locally, but it would
>>be cool if it could change it remotely. 




-- 
---------------------------------------------------------------------------
Mark Nielsen	men2@auto.med.ohio-state.edu or gytres+@osu.edu
Systems Specialist
The Ohio State University


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

Date: 16 Jul 1997 21:57:06 GMT
From: orwant@fahrenheit-451.media.mit.edu (Jon Orwant)
To: Olaf Menzel <menzel@anastasis.hebron.lnet>
Subject: Re: Lotus Notes && PERL
Message-Id: <ORWANT.97Jul16175706@fahrenheit-451.media.mit.edu>


Olaf Menzel <menzel@anastasis.hebron.lnet> writes:

   I am writing on a project for solving the IP-traffic of our LAN.
   Therefore I have a Accounting Daemon working on a UNIX machine. I ist
   written in PERL.
   I like to put the accouting data to a Notes database. Does anybody know of a
   PERL - Notes API. I don't like to put the data first to SQL-Database, like
   DB-2 or Sybase and import the data from Sybase with Notes.

It doesn't exist yet, but look for an entry on the Perl Module List in
the coming months.  It will probably be an XS bridge to the Notes C++ API.

-Jon

----------------
Jon Orwant
The Perl Journal
http://tpj.com/


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

Date: Wed, 16 Jul 1997 15:40:23 -0700
From: Dan Aaronson <defaultuser@domain.com>
Subject: major tech support site
Message-Id: <33CD4DD7.96CA5E6E@domain.com>

Largest Computer site on the Net. Has technical support for all
computer: PC, MAC, networks, software, & peripherals, FREE Delphi
technical forums for our users. Check us out: http://www.supporthelp.com




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

Date: Tue, 15 Jul 97 14:49:53 GMT
From: mark@ispc001.demon.co.uk (Mark Katz)
Subject: Re: mooshing files, 2 > 1
Message-Id: <868978193snz@ispc001.demon.co.uk>

In article <5qelu8$mc7@nntp02.primenet.com>
           yesno@primenet.com "John Bergmayer" writes:

>I have files foo and bar.
>
>foo is of format:
>partnumber  qty  jobnumber
>
>bar is of format:
>partnumber   price
>
>partnumber would not be repeated in bar, but it may be in foo. 
>
>i want a fourth field added to foo.  this field would be the price.  i
>want the price to come from bar, that is, look at partnumer in foo, if
>there is the same partnumer in bar add the price in field 4.  if not, put
>in a N/A.  i also want the price to reflect the quantity.  that is:
>
>foo entry:
>S9413-554     4   A97-0029
>S9413-554     1   W96-0030
>
>bar entry:
>S9413-554     .32
>
>would become:
>S9413-554     4   A97-0029   1.28  
>S9413-554     1   W96-0030   .32
>
>what would be my best bet for doing this?

Notwithstanding the 'clever' solutions in perl, Unix/join and other
programming 'languages' I respect the name of this newsgroup
and assume readers are looking for awk solutions !!

Try this
awk -f prog1.awk bar foo
Where prog1.awk contains
{
 if (FILENAME == "bar") {price[$1]=$2; next}
 print $1, $2, $3, $2*price[$1]}

Mark
--
Mark Katz
ISPC, London - Innovation in data-delivery tools
Tel: (44) 181-455 4665, Fax (44) 181-458 9554
** Visit our website on http://www.efiche.com/efiche **



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

Date: Tue, 15 Jul 1997 17:16:57 +0000
From: John Nightingale <jxn@realtime.demon.co.uk>
Subject: None zipped modules
Message-Id: <33CBB089.77B0@realtime.demon.co.uk>

Could anyone point me in the direction of Perl modules that aren't
tarred and gzipped. I'm specifically interested in the Penguin stuff and
can't find the decompressors handy for my machine.

I'm sure other people have similar problems, or is it just me?

Thank in advance,

John Nightingale.

Ah, It's good to be back on the news server.


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

Date: 15 Jul 1997 16:41:12 GMT
From: Morten Simonsen <mortensi@idt.ntnu.no>
Subject: Read a hash within a hash
Message-Id: <5qg978$bsr@due.unit.no>

Hi

I have created a hash with values that again are hash.
Lets say I have this situation:

%hash1 = (); %hash2=();

$hash1{'test1'} = \$hash2;
$hash2{'test2'} = "test3";

How can I easily print out the content of $hash2? 
Of course by using hash1, hash2 will be hidden later
on. Maybe it was silly in the first place to think of this, so
any other proposal on how I can have a key with several
subkeys within the same hash, is welcome. I could of
course do this by making a parse pattern in the
value of the first key, but I thought I would try to
avoid that this time. It so very elegant I think...
My best shot for a solution of the above problem was 
this:

print "HASH: $$hash1{'test1'}{'test2'}\n";

Not with any success so far..
Help would be appreciated

Morten Simonsen


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

Date: 16 Jul 1997 22:48:28 GMT
From: chuan@engr.mun.ca (Chuan Wang)
Subject: read last line without reading previous lines, how?
Message-Id: <5qjj3s$11$1@coranto.ucs.mun.ca>

Hi,

I wonder how to reading the last line of a text file, without going through
the previous lines.  Thanks.




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

Date: Thu, 17 Jul 1997 01:02:12 GMT
From: tcyang@netcom.com (Tung-chiang Yang)
Subject: Re: regex expression to extract data from a string
Message-Id: <tcyangEDFuvo.6t7@netcom.com>

It might not be a good idea to abuse .* because the greedy gourmet might
eat everything you have in your $string.  Try

   $string =~ s/^.*<TAG1>/<TAG1>/;
   $string =~ s/<TAG2>.*$/<TAG2>/;

I am sorry that I did not check what the 'm' option means because I
don't have the book at my hand now.

===================================
mmcint@amex-trs.com wrote after zapping the scum of the universe:

: Can someone help me solve this problem:

: After loading $string with a text file I'm tring to extract a range of
: text between TAG1 and TAG2. Therefore I want to eliminate all text before
: and after those two tags. The problem is that my regular expression is not
: matching the .* pattern as the first character in the string. Here's what
: I got:

: $string =~ s#(.*)(<TAG1>.*<TAG2>)(.*)#$2#gm;

: I thought this would perform the match, but it doesn't. Can anyone help?
: Does this make sense? Should I give up and go eat supper?

--
====== Try the low-crossposting robomoderated 'alt.culture.taiwan' ======

soc.culture.taiwan, soc.culture.china (by SCC FAQ Team) FAQ's:
   http://www.iglou.com/tcyang/Taiwan_faq.shtml, China_faq.shtml


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

Date: 16 Jul 1997 20:54:31 GMT
From: jdimpson@newstand.syr.edu (Jeremy D. Impson)
Subject: RFC: prop. for overloading 'next' keyword
Message-Id: <5qjce7$pv9@newstand.syr.edu>

Hi!

In the spirit of 'There's More Than One Way To Do It...", this is a
proposal/request for comments for a way to overload the 'next'
keyword.  Its just an idea, and may not even be a good one.  I'm just
curious as to what other people think.

[note: I'm neither a programming languages expert, have I ever even looked
at the perl core, so I probably haven't thought out all the implication of
this proposal, and I don't kow how efficiently it could be implemented
into the perl distribution.]

I've been doing a lot of coding that reads in stanzas into data
structures lately.

When I say 'stanza', I mean stuff like this:

keyword0:
  info0 relative to keyword0
  info1 relative to keyword0
  info2 relative to keyword0

keyword1:
  info0 relative to keyword1
  info1 relative to keyword1
  info2 relative to keyword1

keyword2:
  info0 relative to keyword2
  info1 relative to keyword2
  info2 relative to keyword2


where I'll be reading this information in from a file in a while loop,
then use regexp's to determine what keyword the current line is.  Example:

while(<FILE>) { # or foreach (@lines)

  /^keyword0:/ and do {

    # do something to note that we are in stanza 'keyword0'

  };

  /^keyword3:/ and do {
  
    # do something to note that we are in stanza 'keyword1'

  };

  /^keyword2:/ and do {
  
    # do something to note that we are in stanza 'keyword2'

  };
}

However, when I'm in the body of the 'do' statements, I'd like to be able
to get at the next line (or two, or three), because they contain the
information relevant to the keyword that matched the regexp pattern. 
Currently, I'll set a variable (like '$seenkeywordX') to true and do a
'next'. The next time through (ususally before doing any more pattern
matches), I'll check to see if that variable is true, and if it is, I'll
know that the last time through, I saw keywordX, and will know
that the current line is associated with that keyword.  I can now execute
an expression knowing what stanza I'm in. (It becomes a little trickier
when there are multiple lines of data for each keyword, but it is doable).

My proposal is to allow something like this:

while(<FILE>) {  # or foreach (@lines)

  /^keyword0:/ and do {

    $keyword[0]->[0] = next;
    $keyword[0]->[1] = next;
    $keyword[0]->[2] = next;
    next; # standard version
  
  };

}

so that now $keyword[0]->[0] has the first line of under of data after the
line that matched /^keyword0:/ .  Every call to 'next' that expects to be
in a scalar context (as opposed to a void context, which is how it works
now) will also set it up so that the next time it is called, or when the
bottom of the loop is reached, the next line of input after the line we
'stole' from the input queue is ready to be placed into '$_' (or whatever
variable in use). 

This sort of makes sense.  Standard 'next' would be like '$_ = next;',
except that it doesn't start at the top of the while (or foreach) loop
(which kinds of breaks the parallelism...)  Maybe using 'next' isn't a
good idea (although I think it is), but the concept bears some thought.

This examples assumes that there are always three lines for every stanza.
If there were a variable number, then some sort of test would need to be
done on the return from 'next' to see if the stanza is complete.  In my
example, if the next line was blank, we'd know we were done with that
stanza.  If there are no blank lines, I'm not sure what we could do.

I realize that this sort of breaks the 'streams' approach, but only in
that for each line of input we aren't necessarily starting at the top of
the control loop.  It isn't trying to put data back into input stream, or
anything like that.

Am I making any sense?

Of course, there may be a better way to do this that is already part of
Perl.  If there is, I'd appreciate someone pointing it out.  

--Jeremy

--
Jeremy Impson		       http://web.syr.edu/~jdimpson/

	Undergraduate, Syracuse University, Syracuse, NY
	Computer Science and Spanish Literature & Language		
	SysAdmin, Orange Source On-Line Publication
			


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

Date: Tue, 15 Jul 1997 12:45:51 -0400
From: "Ron L. Helms" <helmrl@aur.alcatel.com>
Subject: Seriol Communication
Message-Id: <33CBA93E.41C67EA6@aur.alcatel.com>

I am in way over my head, and I have RTFM. I need to communicate with a
craft port (list as crw on unix), which is similar to a serial port. I
have tried various things, and am now trying to do it using ioctl calls
(Yuk!). My question is how is the easiest way to connect to a serial
port and have it open for reading and writing. I do not know if it is
blocking. 
There is a serial port simulator that does the job through an xterm, and
I tried to get the info going to the screen of the xterminal, but could
not get at it.
Any help would be greatly appreciated. If this post is vague, please let
me know what I can do to clear it up. If there are any books (I have the
llama and camel book for perl 4), or any docs that I need to reread, let
me know.

Ron Helms
helmrl@aur.alcatel.com
rhelms@pagesz.net


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

Date: 16 Jul 1997 23:30:23 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
To: "Brian Watson" <brian.watson@amd.com>
Subject: Re: substition question
Message-Id: <5qjlif$orj$2@info.uah.edu>

[Posted and mailed]

In article <01bc9238$b2f7f630$0517b5a3@mitymous>,
	"Brian Watson" <brian.watson@amd.com> writes:
: Is there a way to assign what gets matched during a substitution to a
: variable?
: 
: Example:
: 
: s/OPH.*//;
: 
: I would like the match from OPH to end of the line to get assigned to a
: variable.

    s/(OPH.*)//;
    $var = $1;

I strongly recommend a good read of the perlre(1) manpage.  If you don't
have it installed somewhere on your system, you can also check it out at

    http://www.perl.org/CPAN/doc/manual/html/perlre.html

The perlfaq manpages would also be a good start.  You can find them in
the same directory.  Look for perlfaq.

Hope this helps,
Greg
-- 
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF


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

Date: Tue, 15 Jul 1997 19:35:05 +0200 (MET DST)
From: nobody@REPLAY.COM (Anonymous)
Subject: Why doesn't MAKEFILE work on Win95?
Message-Id: <199707151735.TAA24139@basement.replay.com>

Also why can't it find xx.pm modules?  The path fuction within Perl doesn't seem to work on IBM Win95 versions.

Any way to fix this?



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

Date: Sun, 13 Jul 1997 20:05:35 +0300
From: "IBM Israel" <addadi@ibm.net.il>
Subject: windows 95 perl
Message-Id: <5qb24u$12ig$1@news.ibm.net.il>

Hi all,
Where can I get the window 32/NT/95 version for perl 5? (And I mean really
download cause all the links from yahoo -> perl are borken)
Please mail me at:
addadi@ibm.net.il

Thanks
Guy Addadi




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

Date: Wed, 16 Jul 1997 20:30:29 -0400
From: Pawan Agnihotri <pxa7@cac.psu.edu>
Subject: Writing perl modules.
Message-Id: <Pine.SUN.3.93.970716200716.6318E-100000@vidya>


Hi guru's,

I need to write a perl extension module calling a 'C' function with a
complex data type as an argument and getting the 'C' function to fill in
the data type.

The C code would look as follows.

typedef struct mystruct {
	int a;
	int *b
	char y;
	char *z;
	char **names;
	people *n;
}mystruct;
	
typedef struct people {
	char *name;
	address *address;
}people;

These are a couple of nested data structures. The prototype for the C
function looks as follows. 

int somefun(mystruct *ptr);

the function allocates memory for *ptr and fills in the values. I need
to access these values from within perl. 

I have read the perlxs, perlxstut and
perlguts man pages. I have written the code but when I call the
function from within the perl script I get errors like
bash-2.00$ ./PINFO.pl
info is not a reference at ./PINFO.pl line 7.

I think it is to do with the way i write the typemap. right now It looks
like
mystruct * T_PTRREF

I am pretty sure this is wrong but I am confused as to where to go from
here. 
Advise on how to go about doing this would be appreciated.
Thanks to all who came this far in reading this,
Pawan



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

Date: Wed, 16 Jul 97 11:39:04 GMT
From: mpatel@indev.demon.co.uk (Mukesh Patel)
Subject: Yacc Syntax File for Perl
Message-Id: <869053144snz@indev.demon.co.uk>


  It seems (from the Perl source) that Perl uses Yacc to parse
  the input. I could not find the Yacc syntax file for Perl in the
  source though. Does anyone know where it is?
  
  Thanks


-- 
Mukesh Patel



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

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

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