[7425] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1050 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 19 17:17:26 1997

Date: Fri, 19 Sep 97 14: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, 19 Sep 1997     Volume: 8 Number: 1050

Today's topics:
     Re: '0': string or number? you make the call! (Jason Gloudon)
     'tie' a class to an SDBM file <app1tam@air.ups.com>
     bitwise xor of strings <stirra@wwc.edu>
     Buggy SDBM_File (Solaris and Win32) randy@geopower.com
     Calling a program from Perl script <YDesfosses@videotron.ca>
     Re: Calling a program from Perl script (Jeremy D. Zawodny)
     Re: can I continuously read & empty logfile? (Matthew D. Healy)
     Re: Deleting temp files with perl (Aaron Sherman)
     entering debugger programmatically? (Ken Trebus)
     FILEHANDLE test wierdness (Martin Brown)
     Re: FILEHANDLE test wierdness (Jason Gloudon)
     Help with file I/O problems. <icepick@NOSPAMpclink.com>
     HELP! Problems with memory allocation w/PERL (Yangmar)
     Is there a way to remove nested comments from C code? <geistj@genrad.spam>
     Re: Parsing e-mail folder (newbie) <suqstmbl@reading.ac.uk>
     Re: pattern matching <jjune@midway.uchicago.edu>
     Perl <=> C Server (Gary Mui)
     Re: Perl <=> C Server (Andrew M. Langmead)
     Re: Shell scripts from Unix to WinNT (Gerben Vos)
     spell check? <nikhil@backlash.net>
     Re: STDOUT not working properly... i think <mcravit@shell3.ba.best.com>
     Re: STDOUT not working properly... i think (Scott DiNitto)
     Web Statistics <nmahesh@nortel.ca>
     Re: while (/\b([A-Z])\l\1(.*?)\b/g) { print "$&\n"; } <kshaw@plight.lbin.com>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 19 Sep 1997 18:59:34 GMT
From: jgloudon@bbn.com (Jason Gloudon)
Subject: Re: '0': string or number? you make the call!
Message-Id: <5vui2m$c58$1@daily.bbnplanet.com>

In article <3422B94C.B606A76A@ixl.com>, Dan Boorstein  <danboo@ixl.com> wrote:
>hello all,
>
>first off here is the code and results which confuse me:
>
>danboo> cat test.pl
>#!/usr/bin/perl -w
>
>$test0 = '0';
>$test00 = '00';
>
>$test0 && print "test0\n";
>$test00 && print "test00\n";
>danboo> ./test.pl
>test00
>
>now, here is what i thought would happen:
>
>$test0 would be assigned a string with the value '0'
>$test00 would be assigned a string with the value '00'
>
>$test0 would be defined as a non-empty string and print "test0\n"
>$test00 would be defined as a non-empty string and print "test00\n"
>
>as you can see, only "test00\n" was printed. so, is the string '0'
>a "failure/false" condition, or is it being evaluated as a numeric?
>i tried using the debugger to follow along but had little success.
>

It's simple:

The string "0", or a numeric zero value 0 is false in Perl.
Anything else, including the string "00" or "0.0" is not false.


Jason Gloudon


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

Date: Fri, 19 Sep 1997 14:52:37 -0400
From: "Thomas A. Mills" <app1tam@air.ups.com>
Subject: 'tie' a class to an SDBM file
Message-Id: <3422C9F5.6B85@air.ups.com>

I don't have a database I can use so I wanted to use SDBM in Perl. 
Could someone point me to an example of using tie to link a class to an
SDBM file?

I've read the Perl5 camel book, the FAQs, the FMTEYEWTKs, and everything
I could find.  So far the tie documentation has only confused me.  The
SDBM documentation is almost non-existant.

Here's what I do know already:

1) I've figured out how to use dbmopen to tie a hash to a SDBM file. 
And I'm unpacking my data into an array to represent a record.  But this
all seems awfully close to tie'ing a class to an SDBM file.  

2) I've seen how to tie a hash to a class (the Perl5 camel book covers
that pretty well).

Any suggestions on how to put the two together?  If you could e-mail me
I'd get your response much sooner.  Thanks!
--
Drew Mills <*>
app1tam@air.ups.com


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

Date: Fri, 19 Sep 1997 10:37:12 -0700
From: Ralph Stirling <stirra@wwc.edu>
Subject: bitwise xor of strings
Message-Id: <3422B848.41C67EA6@wwc.edu>

Bitwise exclusive-or on strings does not seem to work as
advertised in Prog Perl 2nd Ed. page 88.  Both AND and OR
work properly under Perl 5, and Perl 4 at least tries to
get XOR (just leaves off the MSB when a zero), but XOR fails
completely under Perl 5:

        $b = "0101";
        $c = "0011";
 
        $d = $b ^ $c; 
 
        print "(1) $b ^ $c=",$b ^ $c,"\n";
        print "(2) $b & $c=",$b & $c,"\n";
        print "(3) $b | $c=",$b | $c,"\n";
        print "(4) $b ^ $c=$d (ord($b ^ $c)=",ord($d),")\n";
 
The output from this code, run under Perl 5.00x on SunOS4.1.4,
Solaris 2.5.1, and Linux 2.0.29 is:

(1) 0101 ^ 0011=				# WRONG
(2) 0101 & 0011=0001				# RIGHT
(3) 0101 | 0011=0111				# RIGHT
(4) 0101 ^ 0011= (ord(0101 ^ 0011)=0)		# scalar 0, not a string
 
Under Perl 4.036, the output is: 

(1) 0101 ^ 0011=110 			# RIGHT, but no leading 0's
(2) 0101 & 0011=1 			# RIGHT, ditto
(3) 0101 | 0011=111 			# RIGHT, ditto
(4) 0101 ^ 0011=110 (ord(0101 ^ 0011)=49)

The only way I can figure to perform a bitwise XOR on bitstrings
is to pack them, XOR, then unpack.  Anyone know of another
solution, patch, or misunderstanding on my part?

Thanks,
-- Ralph Stirling

=======================================================================
|  Ralph Stirling			Project Engineer		
|  stirra@wwc.edu			Walla Walla College		
|  www.wwc.edu/staff/stirra/welcome	School of Engineering		
|  509/527-2071				204 S.College Ave		
|  FAX: 509/527-2253			College Place, WA  99324	
=======================================================================


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

Date: Fri, 19 Sep 1997 15:02:00 -0600
From: randy@geopower.com
Subject: Buggy SDBM_File (Solaris and Win32)
Message-Id: <874698919.29926@dejanews.com>

If I run this script and 'myfile' resides on the hard drive, everything
is fine. If 'myfile' resides on tmpfs, it produces erratic results.

##
#
use NDBM_File;
#use Fcntl;

sub O_CREAT {0x0100}
sub O_BINARY {0x8000}
sub O_RDWR {0x0002}

tie( %myhash, "NDBM_File", 'myfile', O_RDWR | O_CREAT | O_BINARY, 0666) ||
        die "Can't tie: $!\n";

for ($count = 1; $count < 8000; $count++) {
        $myhash{"$count"} = 8000 - $count;
        next if $count % 100;
        $keycount = scalar keys %myhash;
        print "Count $count = Keycount $keycount",
                ($keycount == $count) ? "\n" : "...not!\n";
}
untie %myhash;
#
##

It also produces flaky results under Win32 (5.004).

Changing SDBM_File to NDBM_File works fine.


I know others have had SDBM problems - is there a known fix?

--randy

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet


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

Date: 19 Sep 1997 18:50:25 GMT
From: "MetaLink" <YDesfosses@videotron.ca>
Subject: Calling a program from Perl script
Message-Id: <01bcc52d$6752a180$1301010a@beck.metalink.ca>


Yes, I would like to call a program that I did in C on Unix,
In my Perl I want to catch the return value and do different
thing depending on the value.

Does anyone can Help me?

Please E-mail me

Yves Desfosses
desfosses@metalink.ca



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

Date: Fri, 19 Sep 1997 20:30:36 GMT
From: zawodny@hou.moc.com (Jeremy D. Zawodny)
Subject: Re: Calling a program from Perl script
Message-Id: <3422e0d7.284778039@igate.hst.moc.com>

[cc'd automagically to original author]

On 19 Sep 1997 18:50:25 GMT, "MetaLink" <YDesfosses@videotron.ca>
wrote:

>Yes, I would like to call a program that I did in C on Unix,
>In my Perl I want to catch the return value and do different
>thing depending on the value.
>
>Does anyone can Help me?

Check the perlfunc manpage for the system() function.

Jeremy
-- 
Jeremy Zawodny
Internet Technology Group
Information Technology Services
Marathon Oil Company, Findlay Ohio

http://www.marathon.com/

Unless explicitly stated, these are my opinions only--not those of my employer.


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

Date: Fri, 19 Sep 1997 16:12:29 -0500
From: Matthew.Healy@yale.edu (Matthew D. Healy)
Subject: Re: can I continuously read & empty logfile?
Message-Id: <Matthew.Healy-1909971612290001@pudding.med.yale.edu>

In article <Pine.SOL.3.96.970916171901.12884V-100000@suma3.reading.ac.uk>,
John Stumbles <suqstmbl@reading.ac.uk> wrote:

> Problem: I have a log file, written by a separate process (which I have to
> treat as unmodifiable) and I want to get the log records out of the file
> and into my perl script, and close up the file as I go. The log file is on
> a unix (SunOS 4.something, not Solaris) filesystem. 
> 

Is your "separate process (which I have to treat as unmodifiable)" one
of the standard Unix daemons, such as httpd or syslogd or whatever?

In that case, read the docs for your daemons with close attention
to determine whether the following procedure will work:

   1. mv logfile logfile.old

   2. touch logfile

   3. chown logfile to whatever

   4. kill -HUP XXX, where XXX is the PID of the daemon

   5. cp logfile.old whatever

   6. rm logfile.old

What's going on here is the following: most standard Unix daemons keep
their logfiles open all the time, so renaming the logfile in step 1 does
NOT stop the daemon from continuing to write entries in the old logfile
until the HUP signal is sent in step 4.  At this point, the daemon will
stop and restart itself, and all further logging will go to the new
logfile without missing a beat!

Here's an actual working "newsyslog" script from a Sun workstation; we
run this once a week from the crontab:

#! /bin/sh
#
#
LOG=messages
cd /var/adm
test -f $LOG.2 && mv $LOG.2 $LOG.3
test -f $LOG.1 && mv $LOG.1 $LOG.2
test -f $LOG.0 && mv $LOG.0 $LOG.1
mv $LOG   $LOG.0
cp /dev/null $LOG
chmod 644    $LOG
#
LOGDIR=/var/log
LOG=syslog
if test -d $LOGDIR
then
        cd $LOGDIR
        if test -s $LOG
        then
                test -f $LOG.6 && mv $LOG.6  $LOG.7
                test -f $LOG.5 && mv $LOG.5  $LOG.6
                test -f $LOG.4 && mv $LOG.4  $LOG.5
                test -f $LOG.3 && mv $LOG.3  $LOG.4
                test -f $LOG.2 && mv $LOG.2  $LOG.3
                test -f $LOG.1 && mv $LOG.1  $LOG.2
                test -f $LOG.0 && mv $LOG.0  $LOG.1
                mv $LOG    $LOG.0
                cp /dev/null $LOG
                chmod 666    $LOG
                sleep 40
        fi
fi
#
kill -HUP `cat /etc/syslog.pid`
--------
Matthew.Healy@yale.edu           http://ycmi.med.yale.edu/~healy/
As of 9 Sep 1997, only 843 days until Y2K....
Resistance _is_ futile! I have been absorbed by the BORG!  After
years of Unix and MacOS, I just got myself a home Windoze Box :-(


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

Date: 19 Sep 1997 15:35:01 -0400
From: ajs@lorien.ajs.com (Aaron Sherman)
Subject: Re: Deleting temp files with perl
Message-Id: <5vuk55$fvl@lorien.ajs.com>

Jason Gloudon <jgloudon@bbn.com> wrote:
>Petri Backstrom  <petri.backstrom@icl.fi> wrote:
>>Matt Weber wrote:
>>> 
>>> What commands do I use in a perl script to delete a temporary file?
>>
>A useful trick from C coding is to unlink a temporary file right after you 
>open it, so that it goes away for _certain_ when it is closed. You don't have 
>to worry about unlink'ing it afterwards that way if you have multiple exit
>points in the program. 

That "useful trick" will certainly get you into enough trouble.

How about something a little more general (this is just a sketch, you
may have to modify it to get it to work):

package TempFile;
require Exporter;
require IO::File;
@ISA=qw(Exporter);
sub new {
	return((bless {}, $_[0])->init());
}
sub init {
	my $self = shift;
	$self->{handle}=IO::File->new();
	my $path=$TempDir.$PathSep."tempfile.$$aaa";
	$path++ while -e $path;
	$self->{handle}->open(">$path") || die("Cannot create tmpfile: $!");
	$self->{path} = $path;
	return $self;
}
sub handle {
	return $_[0]->{handle};
}
sub path {
	return $_[0]->{path};
}
sub DESTROY {
	$_[0]->{handle}->close;
	unlink $_[0]->{path};
}

__END__

You use it like so:

	my $tmp = TempFile->new;
	my $fh = $tmp->handle;
	print $fh "Temp data...";

$tmp will be destroyed, when it goes out of scope, and you don't have to
worry about what happens to the file. You know that it will be deleted
unless perl crashes.

Of course, what you want to do, is derive this directly from IO::File, but
that won't work because IO::File doesn't give you anywhere to store private
data.

			-AJS



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

Date: 19 Sep 1997 20:05:17 GMT
From: ktrebus@news.austx.tandem.com (Ken Trebus)
Subject: entering debugger programmatically?
Message-Id: <5vultt$d59$1@chronicle.austx.tandem.com>

Is there sny way to enter the debugger programmatically. I.E., issue a command
in the Perl program that will cause it to enter the debugger? I can't just run
perl -d on the file because it is part of a big build process and perl is called
many times. Any help would be appreciated. Thanks.

Ken


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

Date: 19 Sep 1997 11:44:00 -0700
From: mjbjr@primenet.com (Martin Brown)
Subject: FILEHANDLE test wierdness
Message-Id: <5vuh5g$7q1@nntp02.primenet.com>


I have a script that will be run by 'crond', and it has many subs to do
various things, with each sub writing to 'results.log' to keep track of
what's done.  I open the 'results.log' file early and get a filehandle.

If the filehandle doesn't exist, each sub is to do its work anyhow, as
it's just a log.  So, each sub tests for the existence of the filehandle
before writing, suing the following:

if(-e RESULTS_DB_FH)
{
   # print some info to the log file here
}


The problem is, when I create a condition where the filehandle
doesn't exist using the above returns the following:

Read on closed filehandle <RESULTS_DB_FH> at ./t1 line 132 (#1)
    (W) The filehandle you're reading from got itself closed sometime
before now.

    Check your logic flow.


I'm using '-w', 'strict' and 'diagnostics'.

It seems to me that I should not be getting this error.  The filehandle
doesn't exist, so don't do the writes, and move on to the next item.

What gives?

Thanx.


--
                            - Martin J. Brown, Jr. -  

                               mjbjr@primenet.com
                      PGP public key available via finger


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

Date: 19 Sep 1997 19:43:43 GMT
From: jgloudon@bbn.com (Jason Gloudon)
Subject: Re: FILEHANDLE test wierdness
Message-Id: <5vuklf$gpk$1@daily.bbnplanet.com>

In article <5vuh5g$7q1@nntp02.primenet.com>,
Martin Brown <mjbjr@primenet.com> wrote:
>
>I have a script that will be run by 'crond', and it has many subs to do
>various things, with each sub writing to 'results.log' to keep track of
>what's done.  I open the 'results.log' file early and get a filehandle.
>
>If the filehandle doesn't exist, each sub is to do its work anyhow, as
>it's just a log.  So, each sub tests for the existence of the filehandle
>before writing, suing the following:

-e doesn't test whether the filehandle exists but whether the file 
associated with it exists. Doing -e on a filehandle which hasn't been opened
or which has been close is a bit fuzzy, hence the warning when run with
-w.

Saving the return value from open in a variable and testing that
would be closer to what you want.

>
>if(-e RESULTS_DB_FH)
>{
>   # print some info to the log file here

Jason Gloudon


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

Date: Tue, 16 Sep 1997 20:33:54 GMT
From: "Icepick" <icepick@NOSPAMpclink.com>
Subject: Help with file I/O problems.
Message-Id: <01bcc2e7$18352020$45010bce@jdmathew.sprintspectrum.com>

Okay, quick and dirty background.  I'm new to perl, and working on
various projects just to learn.  More or less the jump in first then
learn to swim method of self teaching.

I'm currently working on a program that reads in a file called "text"
and stores it in an @ array, one character per element, then XOR's
each character with a value, then writes it all out to another
file "output"  It's the begining of a simple crypto script I'm 
messing with.

My problem is that the output file is longer than the input file, and
I can't figure it out.  Also, when the output file is renamed to "text"
and run through the script again, it should yield back the orginal
"text" file.  Alas, it doesn't.  It does, however, work on the first
portion of the file.  Strange.

Here's the relevant portions of the script (just cut and paste, should
work for you) and the "text" file.  Any suggestions?

----------begin script-------

#/usr/bin/perl -w
# get the data

print "Getting the text from \"text\"\n";

open (INP, "text") || die "can't open \"text\""; # open the file (nicely)

$i=0;

while (defined ($p[$i]=<INP>)) {
  $i++;
 }

$lines=$i;              # number of lines of data
$len=0;

for ($i=0;$i<=$lines;$i++) {
 for ($j=0;$j<=length($p[$i]);$j++) {
   $plain[$len]=ord(substr($p[$i],$j,1));    # convert to ascii
   $len++;
 }
}

close (INP) || die "can't close \"text\"";       # and close it (nicely)

print "$lines lines    $len  chars\n";

# do the encryption

print "Encrypting...\n";

$jj=0;

while ($jj<$len) {     # while the number of bytes done is <=
                        # the length of the plaintext

$cipher[$jj]=$plain[$jj]^$jj ;   
$jj++;
}

# all done, now write it to output

print "Outputing to \"output\"\n";

print $len;

open (OUTP, ">output") || die "can't open \"output\"";

for ($i=0;$i<=$len;$i++) {
  print OUTP chr($cipher[$i]);
}

close (OUTP) || die "can't close \"output\"";

----------- end script  -----------


---------- begin test "text" file ---------

another
 line in
 the works this is going to be
  a really really really really long line
   with no cairage s returns or line breaks or
    line feeds or any of

1234567890 !@#$%%^^&&*(())

     that other silly nonsense
that messes things up.
      
----------------- end "text" file --------------



-- 
no more no less no fear no need no height no depth too great godspeed
Want $1000??  Help break RC5!  http://rc5.distributed.net/



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

Date: 19 Sep 1997 18:45:18 GMT
From: yangmar@aol.com (Yangmar)
Subject: HELP! Problems with memory allocation w/PERL
Message-Id: <19970919184501.OAA20664@ladder02.news.aol.com>

Hi
We are experiencing memory problems when executing our Perl scripts. We
are executing data conversion programs, moving large amounts of data from a
text file to Oracle 7.2 tables.  Source files consist of 30,000 records..we
encounter Oracle memory errors halfway to 30000.  We are running scripts in
UNIX on a DEC Alpha machine.  We have speculated that this could be
problems with memory on the DEC Alpha but we are not sure if PERL requires
deallocation of memory while executing the PERL programs.

Can anyone shed some light on whether PERL deallocates memory as it
sequentially processes records or does that need to be programmed into the
script.  Any help would be appreciated.

Please respond to :   darrell_lee@notes.pw.com

Thanks   


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

Date: Fri, 19 Sep 1997 14:52:19 -0400
From: "Jerry G" <geistj@genrad.spam>
Subject: Is there a way to remove nested comments from C code?
Message-Id: <5vuhpu$6te@news.genrad.com>

 Although contrary to ANSI C, we have nested comments and we wish to remove
all instances of comments althogether.  Is this an easy thing to do in perl?





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

Date: Fri, 19 Sep 1997 17:55:56 +0100
From: John Stumbles <suqstmbl@reading.ac.uk>
To: dave@hmw.com
Subject: Re: Parsing e-mail folder (newbie)
Message-Id: <Pine.SOL.3.96.970919175135.23581A-100000@suma3.reading.ac.uk>

> In article <341E36FA.A7AE5A41@pplus.best.com>,
>   dave@hmw.com wrote:
> >
> > In the next few days I will need to create (or help create) a script
> > that will parse the e-mail folder file on a UNIX (actually, SGI IRIX)
> > system to get the most recent message and output that message to an
> > external text file. The file will be inserted (via server-side include)
> > into an HTML file.

--- 8< ---

> > I'm not looking for a complete solution, but if anyone has/can explain
> > how to create a script that will parse the mail folder file and extract
> > the most recent message, it would be tremendous help.

I have a script I use to kind-of html-ise mail folders which are in bog
standard unix mbox format - you might find it useful to hack up what you
want. See the DIY page on my url below. 

--
John Stumbles                                      j.d.stumbles@reading.ac.uk
Computer Services, University of Reading       http://www.rdg.ac.uk/~suqstmbl 
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+



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

Date: Fri, 19 Sep 1997 18:50:34 GMT
From: Joseph June <jjune@midway.uchicago.edu>
To: Martin Str|mberg <ams@ludd.luth.se>
Subject: Re: pattern matching
Message-Id: <Pine.GSO.3.95.970919134800.15847A-100000@harper.uchicago.edu>

Thank you so much for your kind response.  I have tried implementing the
suggested snip, but I still could not make a successful match.  I have
trying to get this multiple like matching down... but without much success
so far.  

When I am implementing this... are there certain things i should
definitely watch out for?  Such as.. do I need to match the tabs and
spaces exactly as the original text file... or sill \s+ take care of that?

Thank you so much for your kind help.


On 17 Sep 1997, Martin Str|mberg wrote:

> Joseph June (jjune@midway.uchicago.edu) wrote:
> 
> [Klippa, klapp, kluppit perlisms.]
> 
> : Obviously I have no problem matching X-AAAAAAAA... but after getting the
> : match... i need to move up a few line before start generating the new
> : set... or else the old set's beginning will be left and mixed up with the
> : new one..
> : 
> : another possiblity is to do a multiple line match... like match 
> : 
> :         :rule_adtr (
> :                 :src_adtr (  
> :                         : Sever_Name
> :                 )
> :                 :dst_adtr (
> :                         : X-AAAAAAAAA
> : 
> : 
> : 
> : instead of just X-AAAAAAAAA... which I do not know how to do either... 
> : if anyone has any idea... it will be most appreciate it... 
> : Regards,
> : Joseph June
> : 
> 
> Yes, I think multiline match is best here, IMHO. Something along these
> lines:
> 
> if($input =~ m/:rule_adtr\s+\(
> 			\s+:src_adtr\s+\( # Beginning of src_adtr found.
> 				\s+:\s+Sever_Name # Sever_name found.
> 			\s+\)		# End of src_adtr.
> 			\s+:dst_adtr\s+\( # Beginning of dst_adtr found.
> 				\s+:\s+X-AAAAAAAAA  # Aaaah, this
> 						    # we'll exchange
> 						    # for GK! 
> and tail matches as well perhaps		# More nice comments
>                /sx # s for pretending it's a single line while it
>                    # isn't and x for nice layout with comments.
> 	
>    ) # End of if($input.
> {
> 	# Match found some prints perhance?
> }
> 
> 
> 



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

Date: 19 Sep 1997 18:09:05 GMT
From: gmui@jpmorgan.com (Gary Mui)
Subject: Perl <=> C Server
Message-Id: <5vuf41$6ke$1@hardcopy.ny.jpmorgan.com>

Is it possible to have a perl program talk to a server written 
in C that reads and writes normal C structures (as opposed
to parseable text)?  

Thanks,
Gary Mui
gmui@jpmorgan.com




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

Date: Fri, 19 Sep 1997 20:41:37 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Perl <=> C Server
Message-Id: <EGrw5E.3A3@world.std.com>

gmui@jpmorgan.com (Gary Mui) writes:

>Is it possible to have a perl program talk to a server written 
>in C that reads and writes normal C structures (as opposed
>to parseable text)?  

You might want to make an xs module that takes a data read from the
server and converts it to a list of perl scalars. If you have the
identical boxes and compilers, it should match up the struct's field
boundries. (Many people have given up on writing out structures
directly because of these vagaries. Things like endian and struct
padding can make such a mess.)

Otherwise take a look at the "pack" and "unpack" functions. Something
like this:

struct foo {
  char name[32];
  int id;
};

could be converted like this:

  ($name, $id) = unpack 'A32I', $data;
-- 
Andrew Langmead


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

Date: 19 Sep 1997 18:05:58 GMT
From: gerben@cs.vu.nl (Gerben Vos)
Subject: Re: Shell scripts from Unix to WinNT
Message-Id: <5vueu6$c0f$1@star.cs.vu.nl>

"zserge" writes:

>I have one problem I can't solve-
>how to set the enviromental variable in WinNT
>from a C program?
>I've tried to use system()  

>system("set TEMP=C:\TEMP");

I trust that you actually wrote this:

	system("set TEMP=C:\\TEMP");
	#		   ^^ note the double backslash

What you're doing here is starting a process that runs the command
shell, CMD.EXE, and making it set its environment. As soon as CMD.EXE
exits, its environment is deleted, because every process has its own
environment. Even your Perl script won't see the changed environment.

If you want to change the environment for your Perl script and all
processes started from within it, use

	$ENV{TEMP}= "C:/TEMP";
	#	       ^ forward slashes work just as well

There is a way to change your startup environment in NT, but you'll
have to ask about that elsewhere (comp.os.ms-windows.programmer.win32
for example).

I've read about a way to change the environment and broadcasting the
change to all currently running processes, but i also read that Windows
Explorer is about the only program that actually listens to that
broadcast.

Oh, i now see you're asking about C, not Perl. Most of the advice
above is still valid, but use putenv() instead of $ENV{}. And post your
question to another newsgroup next time.

g e r b e n @ c s . v u . n l . . . . . . . . . . . . G e r b e n   V o s   <><
Join the Coalition Against Unsolicited Commercial Email!  http://www.cauce.org/
Ceci n'est pas une .signature .


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

Date: Fri, 19 Sep 1997 14:31:21 -0500
From: Nik Trivedi <nikhil@backlash.net>
Subject: spell check?
Message-Id: <3422D309.FB4D3480@backlash.net>

Is there a perl module that will spell check form data?  Is there
another way to do this that is already built into perl?  How can I do
this?

Nik Trivedi
nikhil@backlash.net



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

Date: 19 Sep 1997 10:57:08 -0700
From: Matthew Cravit <mcravit@shell3.ba.best.com>
Subject: Re: STDOUT not working properly... i think
Message-Id: <lwhk9gdb30r.fsf@shell3.ba.best.com>

scott@engus.kronos.com (Scott DiNitto) writes:

> example, if I execute the command alone, I get:
> 
> ufs fsck: sanity check: /dev/rdsk/c0t0d0s0 needs checking
> ufs fsck: sanity check: /dev/rdsk/c0t0d0s7 already mounted
> 
> where as when I redirect the output, I get:
> 
> **/dev/rdsk/c0t0d0s0
> **/dev/rdsk/c0t0d0s7 
> 
> What is going on here? Am I wrong to assume simply redirecting the
> file will catch all the content that will be printed to screen? When I

Yes. Most programs print out information on either or both of two
output streams (independant of any other files they open): STDOUT and
STDERR. If you want to redirect both of these from the shell, you need
to do:

	command -opt -opt > /path/to/file 2>&1	(sh/ksh/bash shells)
	command -opt -opt >& /path/to/file      (csh/tcsh shells)*

(Note: I might be misremembering the syntax in csh/tcsh, as I don't
use them as my shell).

To get the same effect in perl, you can do one of a couple of things:

1. Use something like:
	$output = `command -opt -opt 2>&1`;

2. Use something like:
	open(FOO, "command -opt -opt 2>&1|') or die;
	while (<FOO>) {
		# Get both stdout and stderr here
	}
	close FOO;

3. Use the IPC::Open3 module to attach to STDIN, STDOUT and STDERR on
   your called program. Probably not worth it unless you need to feed
   that program input too.

Hope this helps.

/MC

-- 
Matthew Cravit, N9VWG               | Experience is what allows you to
E-mail: mcravit@best.com (home)     | recognize a mistake the second
        mcravit@taos.com (work)     | time you make it.


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

Date: Fri, 19 Sep 1997 18:41:38 GMT
From: scott@engus.kronos.com (Scott DiNitto)
Subject: Re: STDOUT not working properly... i think
Message-Id: <3422c751.21101127@beavis.kronos.com>

On 19 Sep 1997 10:57:08 -0700, Matthew Cravit
<mcravit@shell3.ba.best.com> wrote:

>scott@engus.kronos.com (Scott DiNitto) writes:
>
>> example, if I execute the command alone, I get:
>> 
>> ufs fsck: sanity check: /dev/rdsk/c0t0d0s0 needs checking
>> ufs fsck: sanity check: /dev/rdsk/c0t0d0s7 already mounted
>> 
>> where as when I redirect the output, I get:
>> 
>> **/dev/rdsk/c0t0d0s0
>> **/dev/rdsk/c0t0d0s7 
>> 
>> What is going on here? Am I wrong to assume simply redirecting the
>> file will catch all the content that will be printed to screen? When I
>
>Yes. Most programs print out information on either or both of two
>output streams (independant of any other files they open): STDOUT and
>STDERR. If you want to redirect both of these from the shell, you need
>to do:
>
>	command -opt -opt > /path/to/file 2>&1	(sh/ksh/bash shells)
>	command -opt -opt >& /path/to/file      (csh/tcsh shells)*
>
>(Note: I might be misremembering the syntax in csh/tcsh, as I don't
>use them as my shell).
>
>To get the same effect in perl, you can do one of a couple of things:
>
>1. Use something like:
>	$output = `command -opt -opt 2>&1`;
>
>2. Use something like:
>	open(FOO, "command -opt -opt 2>&1|') or die;
>	while (<FOO>) {
>		# Get both stdout and stderr here
>	}
>	close FOO;
>
>3. Use the IPC::Open3 module to attach to STDIN, STDOUT and STDERR on
>   your called program. Probably not worth it unless you need to feed
>   that program input too.
>
>Hope this helps.
>
>/MC
>
>-- 
>Matthew Cravit, N9VWG               | Experience is what allows you to
>E-mail: mcravit@best.com (home)     | recognize a mistake the second
>        mcravit@taos.com (work)     | time you make it.

Thank you it worked!!

SD


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

Date: Fri, 19 Sep 1997 16:21:53 -0400
From: Mahesh Narkar <nmahesh@nortel.ca>
Subject: Web Statistics
Message-Id: <3422DEE1.62C8D3D2@nortel.ca>

Hi,
I am a newbie at perl, hence this.
Is there a module or a tool that I can use to analyse the hits on web
pages? I would be highly obliged if you could point me in the right
direction. ( I looked on CPAN, but couldn't find anything suitable... if
there is, please attribute the above remark to my ignorance!!!) . The
platform would be UNIX

Apologize for the inconvenience,
Thanks in advance

Mahesh Narkar

p.s.: please cc your reply to me email id: nmahesh@nortel.com



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

Date: 19 Sep 1997 11:32:37 -0700
From: kendall shaw <kshaw@plight.lbin.com>
Subject: Re: while (/\b([A-Z])\l\1(.*?)\b/g) { print "$&\n"; }
Message-Id: <5267rxgnne.fsf@plight.lbin.com>

Phil Abercrombie <Philip.Abercrombie@MCS.VUW.AC.NZ> writes:

> What do you mean "like Llewelyn"?
> 
> If you mean that they start with a repeated letter, first uppercase
> then lowercase, (which is what I'm guessing from your regex), 

you're right

> then you could either construct a very big r.e. to do it or you could
> write it like this:
> 
> while(/\b(\w)(\1).*?\b/gi) { 
>         next unless $1 eq uc $2 && $2 eq lc $1;
>         print $&;
> }

Of course... (except I would need to use [a-zA-Z]). Thanks!

What's wrong with my regular expression though?

while(/\bA\lA(.*?)\b/g) {
		print "$&\n";
}

prints out Aaron but not AARON. So why doesn't it work with a back
reference?



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

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

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