[6262] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 884 Volume: 7

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Feb 2 18:10:32 1997

Date: Sun, 2 Feb 97 15:00:22 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sun, 2 Feb 1997     Volume: 7 Number: 884

Today's topics:
     $SIG{__DIE__} and eval (Piotr Piatkowski)
     Re: Anyone use cacheout.pl? <roderick@gate.net>
     Re: Commercial success stories using perl. (D. J. Hagberg)
     Re: Creation time and date of file <dean@tbone.biol.sc.edu>
     Re: foreach() vs while() (Jeffrey)
     Re: genetic algorithms (Jon Orwant)
     Re: Getting started (Radiology Website Construction Company)
     msgsnd() and pack() -- message type (Billy Chambless)
     Re: New version of perl new warnigns that I never saw b <roderick@gate.net>
     Re: Possible bug -- should I try to isolate it? (Ilya Zakharevich)
     Re: printing from <start> to <stop> tags only. (Jeffrey)
     Q: opening a file RW without deleting it. (Brian Sherwood)
     Re: Q: opening a file RW without deleting it. (Mike Stok)
     Re: Q: opening a file RW without deleting it. <merlyn@stonehenge.com>
     Re: Q: opening a file RW without deleting it. (Mike Stok)
     Re: Really, really BIG files with MacPerl (Eric Harley)
     Re: Really, really BIG files with MacPerl <neeri@iis.ee.ethz.ch>
     Re: regular expression syntax (Jeffrey)
     Re: Shadow passwords (Eric Harley)
     Re: Silly substitute question (Jeffrey)
     Re: space stripping (Chaim Frenkel)
     Re: space stripping <rootbeer@teleport.com>
     subprocess help <ez045864@peseta.ucdavis.edu>
     Re: URL Encoding (Jeffrey)
     Re: Win32::ODBC in Win95 <thayer@wcax.com>
     Re: Win32::ODBC in Win95 <rothd@roth.net>
     Digest Administrivia (Last modified: 8 Jan 97) (Perl-Users-Digest Admin)

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

Date: 2 Feb 1997 21:30:50 +0100
From: kompas@galaxy.uci.agh.edu.pl (Piotr Piatkowski)
Subject: $SIG{__DIE__} and eval
Message-Id: <5d2thq$b7k@galaxy.uci.agh.edu.pl>

Writing many CGI, I'm used to set my own die handler, which prints 
out pretty formatted html, with message for users ("fatal error, 
please contact..."), error message and stack trace (just like 
Carp::Croak does). 

Some day I have installed one of extra modules, and found that an error
occures in Autoloader, telling that it cannot find .../DESTROY.al.
First, I thought that it is some bug in this newly installed module.
After hours of debugging I've found, that this problem comes from my
die handler:

If die handler is not installed, errors (like calling undefined 
subroutine and so on) are fatal, but the very same errors inside of 
eval are not. But if I install such handler, it is called in both 
cases! So if I put something like:

$SIG{__DIE__} = { print "Content-type: text/plain\n\n$_[0]"; exit }

then all errors, including this in any eval, will make script exit.
This will sooner or later lead to problems with [non]standard modules, 
which try to eval something which could make fatal error (like 
Autoloader does).

I've made workaround, writing die handler this way:

sub die_handler {
  return if (caller(1))[3] eq "(eval)";
  ...
}

but I'm not sure if it shouldn't be done better, for example by some 
flag, which tells if die handler should be called also from inside of
evals (and which should defaults to false).

What do you think about it?

-- 
Piotr Pi1tkowski, Uczelniane Centrum Informatyki, AGH Krakow, POLAND


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

Date: 2 Feb 1997 14:06:07 -0500
From: Roderick Schertler <roderick@gate.net>
To: gmayle@fc.hp.com (Gary Mayle)
Subject: Re: Anyone use cacheout.pl?
Message-Id: <pz7mkrghh2.fsf@eeyore.ibcinc.com>

On 28 Jan 1997 19:58:00 GMT, gmayle@fc.hp.com (Gary Mayle) said:
> 
> The routine seems to open my files fine for me, but in testing I've
> found that I cannot exceed the system's max files configuration, which
> is what cacheout.pl is supposed to get around.  Any pointers?

I'd point out that it's just about impossible to guess what you're doing
wrong without knowing what you're doing.  Pare you code down to the
smallest program which will reproduce the problem, and then post the
code.

-- 
Roderick Schertler
roderick@gate.net


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

Date: 2 Feb 1997 19:57:57 GMT
From: hagberg@ece.arizona.edu (D. J. Hagberg)
Subject: Re: Commercial success stories using perl.
Message-Id: <hagberg-0202971256210001@10.0.2.15>

In article <32F1BAAF.3FCA@dynamicweb.com>, Steve Vanechanos
<stevev@dynamicweb.com> wrote:

> I am looking for significant commercial success stories where perl is
> being used.

I have no idea if Sybase has made any money off the product yet, but
their "web.sql" product uses perl/Sybperl extensively.  The Virtual Vineyards
uses this product, I believe, for all the active content on their web
page.  See somewhere on http://www.sybase.com

-=-                          D. J. Hagberg                        -=-
-=-                         dhagberg@gds.com                      -=-


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

Date: 02 Feb 1997 15:30:41 -0500
From: Dean Pentcheff <dean@tbone.biol.sc.edu>
Subject: Re: Creation time and date of file
Message-Id: <m1680b2bny.fsf@nauplius.psc.sc.edu>

prikryl@dcse.fee.vutbr.cz (Petr Prikryl) writes:
> Parmeshta Jain (jain@bcstec.ca.boeing.com) wrote:
> >I need to be able to print out the creation time and date of a file in
> >the following format.  Can someone help me with this?
> >The format is:
> >24 JAN 1997 AT 00:02:10 AM
> 
> I would recommend stat() and localtime() functions. The stat() function
> takes the name of the file and returns also time of the creation; however,
> usage of "time of modification" is more useful, in my opinion (also
> returned by stat()). The time is in seconds from 1 Jan 1970. You can
> pass this to localtime() to convert it to year, day, month, hour, minute, 
> sec... (basicaly the numbers). Then it is quite easy to convert the 
> numbers into strings like JAN, etc.

Though I agree that time of modification is often more useful, it is
also the only choice you have.  Unix does not store the creation time
of a file.  At all.  Anywhere.  (Though it is a common misconception
that it does.)  Three times are stored for every file, defined in the
following way (according to the SunOS stat(2) page):

     st_atime    Time when file data was last accessed.  This can
                 also  be  set explicitly by utimes(2).  st_atime
                 is not updated for directories  searched  during
                 pathname resolution.

     st_mtime    Time when file data was last modified.  This can
                 also  be set explicitly by utimes(2).  It is not
                 set by changes of owner, group, link  count,  or
                 mode.

     st_ctime    Time when file status was last  changed.  It  is
                 set  both  both by writing and changing the file
                 status information, such as  changes  of  owner,
                 group, link count, or mode.

It is commonly assumed that "ctime" refers to "creation time".  It
does not.  It only reflects the last time the file contents or its
permission/ownership status was changed.  

There is no way to get the file creation time under Unix.  That makes
modification time or change time much more useful...

-Dean
-- 
N. Dean Pentcheff   <pentcheff@acm.org>   WWW: http://tbone.biol.sc.edu/~dean/
Biological Sciences, Univ. of South Carolina, Columbia SC 29208 (803-777-3936)
PGP ID=768/22A1A015 Keyprint=2D 53 87 53 72 4A F2 83  A0 BF CB C0 D1 0E 76 C0 
Get PGP keys and information with the command: "finger dean@tbone.biol.sc.edu"


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

Date: 01 Feb 1997 21:47:10 GMT
From: jfriedl@tubby.nff.ncl.omron.co.jp (Jeffrey)
To: Mark Schwartz <fortune@in.net>
Subject: Re: foreach() vs while()
Message-Id: <JFRIEDL.97Feb2064710@tubby.nff.ncl.omron.co.jp>


[mail and post]

Mark Schwartz <fortune@in.net> wrote:
|> #!/usr/bin/perl -w
|> print "Enter a list of strings:\n"; @strings = <STDIN>;
|> foreach $_ (@strings) {
|>     print pop(@strings);
|> }
|
|> If I enter:
|> 1
|> 2
|> 3
|> ^D
|
|> I get:
|> 3
|> 2

Think about what the foreach() is doing: At first it sets its internal
pointer to the first element of the array, then does the block (which
happens to remove an element). Then the foreach bumps along to the next
position in the array and executes the block again (again, removing
an element).

At this point, there are only two elements.

When the foreach then tries to bump to the (non-existant) third element,
it finds that it's done.

What might be confusing you is that foreach doesn't make a private copy of
the list before it swings into action, nor does it ``lock in'' the list
length somehow. If you want to see what it would do were it to make a
private copy, change the @strings (on the foreach line) to @{[@strings]}.

	Jeffrey
----------------------------------------------------------------------------
Jeffrey Friedl <jfriedl@omron.co.jp> Omron Corp, Nagaokakyo, Kyoto 617 Japan
O'Reilly & Associates' _Mastering Regular Expressions_
                                   http://enterprise.ic.gc.ca/~jfriedl/regex/


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

Date: 02 Feb 1997 19:25:15 GMT
From: orwant@fahrenheit-451.media.mit.edu (Jon Orwant)
To: Alain.Deckers@man.ac.uk
Subject: Re: genetic algorithms
Message-Id: <ORWANT.97Feb2142515@fahrenheit-451.media.mit.edu>


Alain.Deckers@man.ac.uk (A. Deckers) writes:

   In <32EE3F98.31DF11A2@enteract.com>,
	   Eryq <eryq@enteract.com> wrote:
   >Brian Atkins wrote:
   >> 
   >> Has anyone done and of these in Perl? I'd love to see some source
   >> since I am just getting interested in this...
   >
   >Haven't tried it, but Perl should be a good language for
   >fooling around with GA, for the same reasons Lisp is: namely,
   >with garbage collection, variable-sized and typeless containers,
   >the ability to eval(), and OO when you want it, you can throw 
   >stuff together in a snap.

   I seem to remember that someone submitted a GA written in Perl to the
   3-sided prisoners dilemma competition in The Perl Journal #1.

Yup.  That was Peter Seibel.  Enclosed please find his code.
He placed 7th in the competition.

-Jon

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


>From seibel@organic.com Wed May  1 19:43:56 1996
Date: Wed, 1 May 1996 16:41:41 -0700 (PDT)
From: Peter Seibel <seibel@organic.com>
To: perl-journal-contest@perl.com
Subject: Prisoners' Dilemma Programming Contest
Reply-To: seibel@organic.com

# Peter Seibel <seibel@organic.com>
# My strategy, as you will see, is one of the two simplest possible -- 
# always testify. However I arrived at this strategy by dint of some
# slightly more complex programming, which is included here as part of my
# explanation.
#
# Basically I set out to breed strategies by letting random strategies
# compete against each other and crossing the most sucessful strategies
# to form the next generation. The code included here is the basic
# structure I used, however, due to being rather rushed I wasn't
# completely systematic let alone scientific in how I did my
# breeding. Some populations started out entirely randomly. Some were
# seeded with some proportion of the handwritten strategies, mean, nice,
# fool-me-twice, anti-fool-me-twice, and two versions of 3D tit-for-tat.
#
# Later I started from populations made up of the most successful
# critters from various strains. All of this chaotic evolution happened
# over two days on about five or six SPARCStation 5's.
#
# Anyway in the longest running strains, always testifying seems to win
# out as the most successful strategy. There are a number of
# possibilities why that might be, many of which could be due to
# stupidities on my part during the course of running this experiment.
# But there you have it. Code below, strategy at very bottom:

# package Player;

# #
# # $Id: Player.pm,v 1.3 1996/04/29 23:06:11 seibel Exp seibel $
# #

# use strict;
# use lib "/home/seibel/lib";

# use MethodMaker
#   (
#    'new_with_init'     => 'new',
#    'get_set' => [ qw / score rule name dna / ],
#   );

# sub init {
#   my ($self, $dna, $name) = @_;
#   $self->dna($dna);
#   $self->make_move($dna);
#   defined $name and $self->name($name);
# }


# sub moves { 
#   my ($self) = @_;
#   defined $self->{'moves'} or $self->{'moves'} = [];
#   return $self->{'moves'};
# }

# sub reset_moves { 
#   my ($self) = @_;
#   $self->{'moves'} = [];
# }

# sub reset {
#   my ($self) = @_;
#   $self->reset_moves;
#   $self->{'total_moves'} = 0;
#   $self->{'score'} = 0;
# }

# sub make_move {
#   my ($self, $dna) = @_;
#   my ($if_result, $rest) = split /:/, $dna;
#   my (@rules) = split /X/, $rest;

#   my $else_result = $if_result eq 'T' ? 'H' : 'T';
#   my (@if_exps) = ();
  
#   my $rule;
#   my $troika;
#   foreach $rule (@rules) {
#     my (@exps) = ();
#     my $extra;
#     if ($extra = length($rule) % 3) {
#       $rule .= '.' x (3 - $extra);
#     }

#     my $c = 0;
#     while ($troika = substr($rule, 0, 3)) {
#       push @exps, "defined \$m[$c] and \$m[$c] =~ /$troika/";
#       $c++;
#       substr($rule, 0, 3) = '';
#     }
#     if (@exps) {
#       my $exp = "(" . join(" and\n\t ", @exps) . ")";
#       push @if_exps, $exp;
#     }
#   }

#   my $if_clause = join("\n\t\tor\n\t", @if_exps) || '1';

#   my $func = <<'TOP';
#   sub {
#    my ($my_ref, $f1_ref, $f2_ref) = @_;
#     my @my_moves = reverse @$my_ref;
#     my @f1_moves = reverse @$f1_ref;
#     my @f2_moves = reverse @$f2_ref;

#     my @m = ();
#     while (scalar @my_moves) {
#       push @m, join '', pop @my_moves, pop @f1_moves, pop @f2_moves;
#     }
# TOP
  
#   $func .= <<MORE;
#     if ($if_clause) {
#       return '$if_result';
#     } else { 
#       return '$else_result';
#     }
# };
# MORE

#   # print "DNA: $dna\n";
#   # print $func;
#   eval qq{\$self->{'rule'} = $func}; $@ and die "$@";
#   # print $self->{'rule'}, "\n";
# }


# sub move {
#   my ($self, $m, $f1, $f2) = @_;
#   my $move = &{$self->{'rule'}}($m, $f1, $f2);
#   $self->{'total_moves'}++;
#   push @{$self->{'moves'}}, $move;
#   return $move;
# }

# sub success {
#   my ($self) = @_;
#   if ($self->{'total_moves'}) {
#     return $self->{'score'}/$self->{'total_moves'};
#   } else {
#     return 1;
#   }
# }

# sub mate {
#   my ($self, $mate) = @_;
#   my ($self_if, $self_rest) = split /:/, $self->{'dna'};
#   my ($mate_if, $mate_rest) = split /:/, $mate->{'dna'};
  
#   my $child_if = $self_if;
  
#   my $child_name = "$self->{'name'}+";

#   my @self_parts = &split_string($self_rest, 4);
#   my @mate_parts = &split_string($mate_rest, 4);

#   my $child_one = "";
#   my $child_two = "";

#   my $i;
#   for ($i = 0; $i < 4; $i++) {
#     if ($i % 2) {
#       $child_one .= $self_parts[$i];
#       $child_two .= $mate_parts[$i];
#     } else {
#       $child_two .= $self_parts[$i];
#       $child_one .= $mate_parts[$i];
#     }
#   }

#   rand(1000) < 1 and $child_if = 'H';
#   return (Player->new("$child_if:$child_one", $child_name),
# 	  Player->new("$child_if:$child_two", $child_name));
# }

# sub split_string {
#   my ($string, $num_of_parts) = @_;
#   my @parts = ();
#   while ($num_of_parts) {
#     my $length = int(rand(length($string)));
#     push @parts, substr($string, 0, $length); 
#     substr($string, 0, $length) = '';
#     $num_of_parts--;
#   }
#   @parts;
# }

# sub grab_chunk {
#   my ($string) = @_;
#   my $l = length $string;
#   my $start = int(rand($l));
#   my $length = int(rand($l - $start));
#   my $chunk = substr($string, $start, $length);
#   substr($string, $start, $length) = '';
#   $chunk;
# }
    

# 1;

# __END__


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

# #
# # $Id: game_master.pl,v 1.8 1996/04/30 16:52:39 seibel Exp seibel $
# #

# use strict;
# use Player;
# srand(time() ^ $$);

# my $continent = shift;
# -e $continent or mkdir $continent, 0777 or die "Can't mkdir $continent: $!";
# my $dir = sprintf("$continent/%02d-%02d-%02d-%02d.%02d.%02d",
# 		  (localtime)[5,4,3,2,1,0]);
# -e $dir or mkdir $dir, 0777 or die "Can't mkdir $dir: $!";

# my $POP_SIZE = shift || 100;

# @::PLAYERS = ();

# my $i = 0;

# for ($i = 0; $i < 4; $i++) {
#   push @::PLAYERS, Player->new("H:", "nice$i");
#   push @::PLAYERS, Player->new("T:", "mean$i");
#   push @::PLAYERS, Player->new("T:.TT", "fmt$i");
#   push @::PLAYERS, Player->new("H:.HH", "anti-fmt$i");
#   push @::PLAYERS, Player->new("T:.T.X..T", "tft_a$i");
#   push @::PLAYERS, Player->new("T:.TTX", "tft_b$i");
# }

# $POP_SIZE -= $i * 6;

# for ($i = 0; $i < 10; $i++) {
#   push @::PLAYERS, Player->new(&random_dna(int(rand(36))), $i);
# }

# $POP_SIZE -= $i;

# $i = 0;
# if (@ARGV) {
#   for (&start_from_fossils($POP_SIZE, @ARGV)) {
#     push @::PLAYERS, Player->new($_, $i++);
#   }
# } else {
#   for ($i = 0; $i < $POP_SIZE; $i++) {
#     push @::PLAYERS, Player->new(&random_dna(int(rand(36))), $i);
#   }
# }

# # print join " ", map { $_->name } @::PLAYERS;
# # print "\n";

# # exit;


# &evolve(@::PLAYERS);

# sub start_from_fossils {
#   my ($size, @files) = @_;
#   my @players;
#   my ($dna, $score);
#   my $file;
#   foreach $file (@files) {
#     print "Reading from $file\n";
#     open(IN, $file) or die "$!";
#     while (<IN>) {
#       chomp;
#       (undef, $dna, $score) = split /\t/;
#       push @players, [$dna, $score];
#     }
#   }
#   print "Sorting ...";
#   @players = sort { $::a->[1] <=> $::b->[1] } @players;
#   print " done.\n";
#   return map { $_->[0] } @players[0..($size - 1)];
# }

# sub evolve {
#   my (@p) = @_;
#   my $gen = 0;
#   while (1) {
# #    print join("\n", @p), $/;
#     &play_em(\@p);
#     &fossilize_population(\@p, $gen);
#     &get_new_generation(\@p);
#     $gen++;
#   }
# }

# sub play_em {
#   my ($p) = @_;
#   my @players = @$p;
#   my $total_games = scalar @players * 10;
  
#   for ($i = 0; $i < $total_games; $i++) {
#     my @p = &get_players(\@players);
#     printf("Playing: game %d of %d.\n", $i + 1, $total_games);
#     #$0 = sprintf("$dir: game %d or %d", $i + 1, $total_games);
#     #, join(", ", map { $_->name } @p), "\n";
#     foreach (@p) { $_->reset_moves; }
#     my $i;
#     for ($i = 0; $i < 100; $i++) {
#       &play(@p);
#     }
#     # foreach (@p) {
#     # print $_->score, "\t";
#     # }
#     # print "\n";
#   }
# }

# sub play {
#   my (@p) = @_;
#   my @m = ();
#   my $i = 0;
#   for ($i = 0; $i < 3; $i++) {
#     # the 'scalars' are becuase the method returns the list
#     # in an array context and a ref to the list in a scalar context.
#     $m[$i] = $p[$i]->move($p[$i]->moves,
# 			  $p[($i + 1) % 3]->moves,
# 			  $p[($i + 2) % 3]->moves);
#   }
#   #print join("\t", @m), "\n";
#   for ($i = 0; $i < 3; $i++) {
#     my $score = $p[$i]->score;
#     $score += &score($m[$i],
# 		     $m[($i + 1) % 3],
# 		     $m[($i + 2) % 3]);
#     $p[$i]->score($score);
#   }
# }

# sub score {
#   my ($my_move) = shift;
#   my $other_two = join '', sort @_;
#   if ($my_move eq 'T') {
#     $other_two eq 'HH' and return 0;
#     $other_two eq 'HT' and return 1;
#     $other_two eq 'TT' and return 4;
#   } else {
#     $other_two eq 'HH' and return 2;
#     $other_two eq 'HT' and return 5;
#     $other_two eq 'TT' and return 7;
#   }
# }

# sub get_players {
#   my ($p) = @_;
#   my @p = @$p;
#   my $l = scalar @p;
#   my @r = ();
#   push @r, (splice(@p, int(rand($l--)), 1),
# 	    splice(@p, int(rand($l--)), 1),
# 	    splice(@p, int(rand($l)), 1));
#   @r;
# }


# sub fossilize_population {
#   my ($p, $gen) = @_;
#   my $filename = sprintf("GEN_%06d", $gen);
#   open(OUT, "> $dir/$filename") or die "$!";
#   &sort_population($p);
#   foreach (@$p) {
#     print OUT join("\t", $_->name, $_->dna, $_->success), $/;
#   }
#   close OUT;
# }

# sub random_dna {
#   my ($max_length) = @_;
#   my $if_clause = int(rand(2)) ? 'T' : 'H';
#   my @alph = qw / T T T H H H . . . X /;
#   my @res;
#   my $i;
#   for ($i = 0; $i < $max_length; $i++) {
#     push @res, $alph[int(rand($#alph + 1))];
#   }
#   my $rest = join '', @res;
#   return "$if_clause:$rest";
# }

# sub get_new_generation {
#   my ($p) = @_;
#   &sort_population($p);
#   my $pop_size = scalar @$p;
#   my @new_gen = ();
#   my ($m1, $m2);
#   while (1) {
#     $m1 = shift @$p;
#     $m2 = shift @$p;
#     $m1->reset;
#     $m2->reset;
#     push @new_gen, $m1, $m2;
#     push @new_gen, $m1->mate($m2);
#     push @new_gen, $m2->mate($m1);
#     scalar @new_gen >= $pop_size and last;
#   }
#   @$p = @new_gen;
# }

# sub sort_population {
#   my ($p) = @_;
#   @$p = sort { $::a->success <=> $::b->success } @$p;
# }

# __END__

# Peter Seibel <seibel@organic.com>
# always testify
sub peter_seibel { return "T"; }

__END__
-- 
Peter Seibel            Perl/Java/English Hacker      seibel@organic.com




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

Date: Sun, 02 Feb 1997 18:44:27 GMT
From: websites@medsites.com (Radiology Website Construction Company)
Subject: Re: Getting started
Message-Id: <32f4e017.1021804156@news.nih.gov>

On Sun, 02 Feb 1997 13:33:47 -0500, Ryguy <midiman@hotmail.com> wrote:

>I need help getting started writting in perl...
>I would appriciate any help that I can get.
>Thank you

Go to the bookstore, and buy the book "Learning Perl" by O'Reilly and
Associates. Work through it and "just do it". This the "Llama book"
that many people start with. There are no worthwhile shortcuts. Good
luck.

Irwin


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

Date: 2 Feb 1997 19:19:24 GMT
From: billy@cast.msstate.edu (Billy Chambless)
Subject: msgsnd() and pack() -- message type
Message-Id: <5d2pbs$clk@NNTP.MsState.Edu>

I'm trying to use message queues to pass info bcak and forth between a
server and several clients. When I hard code the message type, using 
something like

$type = 2;
$message = "Your message here";
$message = pack("L a128", $type, $message);

everything works fine.

But for this server, I want to ahve clients send messages in the form:

"55555 This is what I have to say"

where "55555" is the client's PID or some other numeric identifier.

Somehow, when I get the PID from the client's message and pack it into
the message, it goes to 0. Experiments have shown that it doesn't happen
with a hardcoded value, and I've verified that I _am_ getting the number
form the client.

Here's the proverbial "sipmlest program that has the problem":

===== server program ======

#!/usr/local/bin/perl

# client sends message using :
# 

$queue = msgget(1234, IPC_CREAT | 0666);

if( msgrcv($queue,$buf,128,1,0) < 0) { die "$!";}

($pid,@rest) = split(/\s+/,$buf);
$msg = join(@rest);

print "pid: $pid msg: @rest\n";

# output:  pid: 2938 msg: says hello

$outbuf = pack("L a128",$pid,"got your message");

if( msgsnd($queue,$outbuf,0) < 0) { die "$!";}

($opid,$omsg) = unpack("L a128",$outbuf);
print "opid = $opid omsg = $omsg\n";


#  output: opid = 0 omsg = got your message

__END__

====== client program =======


#!/usr/local/bin/perl


$queue = msgget(1234,0666);

$outbuf = pack("L a128",1, "$$ says hello");
print "$outbuf\n";

if( msgsnd($queue,$outbuf,0) < 0) { die "$!";}

if( msgrcv($queue,$buf,128,$$,0) < 0) { die "$!";}

print "buf = $buf\n";

__END__

Any clues would be highly appreciated.

I've made this same concept work in C, but *shudder* I don't want
to do the project in C.






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

Date: 2 Feb 1997 13:56:15 -0500
From: Roderick Schertler <roderick@gate.net>
To: daku@nortel.ca (Mark Daku)
Subject: Re: New version of perl new warnigns that I never saw before how do I handle them.
Message-Id: <pzafpnghyu.fsf@eeyore.ibcinc.com>

On 21 Jan 1997 21:07:23 -0500, daku@nortel.ca (Mark Daku) said:
> 
> Also a varient for perl5.003_22+ 
>
> while ( defined( my($line) = <FILEHANDLE> )) {
>   ...
> }

Gack, don't do that!  The parens around $line screw you up in two
different ways:

  - Putting () in the my statement gives <FILEHANDLE> an array context,
    so it reads the whole file, assigns the first line to $line, and
    throws the rest away.

  - You're using defined() on an array assignment, not a scalar, and
    that isn't useful.  The defined() is always true.

You wanted to say

    while (defined(my $line = <FILEHANDLE>)) {
    	...
    }

-- 
Roderick Schertler
roderick@gate.net


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

Date: 2 Feb 1997 20:46:57 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Possible bug -- should I try to isolate it?
Message-Id: <5d2ug1$eha$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Andy Armstrong 
<andy@wonderworks.co.uk>],
who wrote in article <ouSAxTA3$J9yEwvq@wndrwrks.demon.co.uk>:
> I've recently been developing some code which did something like
> 
>    my $pos = pos $doc;
> 
>    # Do some munging around include m//g on $doc
> 
>    pos $doc = pos;
> 
> And found that Perl (NTPerl 5.001) was bombing on the assignment to pos.
> Unfortunately the problem slipped away from me before I'd bothered to
> take a copy of the afflicted code.
> 
> Q: Is this a known problem with 5.001? If so I won't bother to try and
> isolate it again.

Until recently (approx. 3_20?) lvalue-pos did not work in recursive subs.

Ilya


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

Date: 01 Feb 1997 21:53:42 GMT
From: jfriedl@tubby.nff.ncl.omron.co.jp (Jeffrey)
To: tim@regiononline.com (Timothy Lindgren)
Subject: Re: printing from <start> to <stop> tags only.
Message-Id: <JFRIEDL.97Feb2065342@tubby.nff.ncl.omron.co.jp>


Timothy Lindgren <tim@regiononline.com> wrote:
|> What I would ultimatily like is do is read the contents of a unix
|> directory, and for each file, open it, and append the headline only to
|> index.html. The headline is between <cutline> and </cutline>.

In short, you can probably do:

   perl -ne 'print if m:<cutline>: .. m:</cutline>:' files2search > index.html

(make sure to not use * for the files2search, or you'll search index.html
 as well!)

	Jeffrey
----------------------------------------------------------------------------
Jeffrey Friedl <jfriedl@omron.co.jp> Omron Corp, Nagaokakyo, Kyoto 617 Japan
O'Reilly & Associates' _Mastering Regular Expressions_
                                   http://enterprise.ic.gc.ca/~jfriedl/regex/


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

Date: 1 Feb 1997 19:25:09 GMT
From: root@babbage.esu.edu (Brian Sherwood)
Subject: Q: opening a file RW without deleting it.
Message-Id: <5d05al$ann$1@jake.esu.edu>

Hello.
	I would like to open a text file and only change one line
of the file.  Whenever I open the file for reading and writing the
file is truncated to zero bytes.  Is there a way to do something 
like the following without truncating the file?


#!/usr/local/bin/perl

$FILE="qwqwqwqw";

open (FILE,"+>$FILE");

#Make changes

close (FILE);

thanks in advance
Brian


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

Date: 2 Feb 1997 22:19:20 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Q: opening a file RW without deleting it.
Message-Id: <5d33t8$5lf@news-central.tiac.net>

In article <5d05al$ann$1@jake.esu.edu>,
Brian Sherwood <root@babbage.esu.edu> wrote:

>	I would like to open a text file and only change one line
>of the file.  Whenever I open the file for reading and writing the
>file is truncated to zero bytes.  Is there a way to do something 
>like the following without truncating the file?

You could try usinf +< in place of +>, the +> does the same as > except
that you also have read access to the file handle.  Try something like:

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

$file = 'test.txt';

open FILE, ">$file" or die "couldn't open $file to write ($!)\n";
foreach (0 .. 5) {
  print FILE "$_\n";
}
close FILE or die "couldn't close $file ($!)\n";

open FILE, "+<$file" or die "couldn't reopen $file (rw $!)\n";
scalar <FILE>;
scalar <FILE>;
print FILE "x\n";
seek FILE, 0, 0 or die "couldn't rewind $file ($!)\n";

print while <FILE>;

close FILE or die "couldn't close $file ($!)\n";

__END__

Hope this helps,

Mike



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

Date: 02 Feb 1997 15:41:34 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: mike@stok.co.uk
Subject: Re: Q: opening a file RW without deleting it.
Message-Id: <8clo96hlup.fsf@gadget.cscaper.com>

>>>>> "Mike" == Mike Stok <mike@stok.co.uk> writes:

Mike> scalar <FILE>;
Mike> scalar <FILE>;

What are those "scalars" doing in there?
Works just fine without them.  It's misleading this way.

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 575 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: 2 Feb 1997 22:47:40 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Q: opening a file RW without deleting it.
Message-Id: <5d35ic$76g@news-central.tiac.net>

In article <8clo96hlup.fsf@gadget.cscaper.com>,
Randal Schwartz  <merlyn@stonehenge.com> wrote:
>>>>>> "Mike" == Mike Stok <mike@stok.co.uk> writes:
>
>Mike> scalar <FILE>;

>What are those "scalars" doing in there?
>Works just fine without them.  It's misleading this way.

In what way is it misleading, not necessary, ugly, verbose, untidy I can
live with, but misleading?

Mike



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

Date: Sun, 02 Feb 1997 09:05:27 -0800
From: erich@powerwareintl.com (Eric Harley)
Subject: Re: Really, really BIG files with MacPerl
Message-Id: <erich-0202970905270001@ppp-207-104-16-33.snrf01.pacbell.net>

In article <32F3A155.886@fas.harvard.edu>, megason@fas.harvard.edu wrote:

> Hello all! I'm working on a project for which I'll need to be able
> process a really big file (3 GB). I've convinced my boss to buy a big
> hard drive, but I wanted to make sure that MacPerl and MacOS can handle
> a file that big so I don't look like a fool if it can't. 
> 
> Does anyone know if file pointers or anything else in MacPerl or MacOS
> max out at some point so that they can't handle a 3 GB file??
> 
MacOS shouldn't have a problem with a file that big. The PowerMacs have a
memory address space of about 9GB so the pointers wont be a problem.
MacPerl is another story though.


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

Date: 02 Feb 1997 21:44:17 +0100
From: Matthias Neeracher <neeri@iis.ee.ethz.ch>
Subject: Re: Really, really BIG files with MacPerl
Message-Id: <86bua39bvi.fsf@iis.ee.ethz.ch>

erich@powerwareintl.com (Eric Harley) writes:
> In article <32F3A155.886@fas.harvard.edu>, megason@fas.harvard.edu wrote:
> 
> > Hello all! I'm working on a project for which I'll need to be able
> > process a really big file (3 GB). I've convinced my boss to buy a big
> > hard drive, but I wanted to make sure that MacPerl and MacOS can handle
> > a file that big so I don't look like a fool if it can't. 
> > 
> > Does anyone know if file pointers or anything else in MacPerl or MacOS
> > max out at some point so that they can't handle a 3 GB file??
> > 
> MacOS shouldn't have a problem with a file that big. The PowerMacs have a
> memory address space of about 9GB so the pointers wont be a problem.
> MacPerl is another story though.

I suspect it's the other way around. MacPerl should have no inherent limits,
so if you have enough RAM, it will work.

However, at least some versions of MacOS cannot handle files bigger than 2G,
so you probably should ensure that current versions can (I've never tried
myself).

Matthias

-----
Matthias Neeracher   <neeri@iis.ee.ethz.ch>   http://www.iis.ee.ethz.ch/~neeri
   "I'm set free to find a new illusion" -- Velvet Underground


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

Date: 01 Feb 1997 22:06:58 GMT
From: jfriedl@tubby.nff.ncl.omron.co.jp (Jeffrey)
To: tloser@valdemar.microserve.com (Thomas A. Loser)
Subject: Re: regular expression syntax
Message-Id: <JFRIEDL.97Feb2070658@tubby.nff.ncl.omron.co.jp>


[mail and post]

Thomas A Loser <tloser@valdemar.microserve.com> wrote:
|>   Given the name of a file I need to scan it and find and retrieve the
|>   text between "<title>" and "</title>" (case may vary).

Consider:

	$/ = undef;
	while (<>) {
	    print "$1\n" if m!<title>(.*?)</title>!si;
        }

The $/ causes the <> to go into fileslurp mode (reading the whole file as
one string -- then, the m!...! regex match can search the whole string.

That m!...! will fill $1 with the title, if found, and print it with a
newline. Two modifiers are used, /s and /i (written after the 2nd '!'). The
/s tells dot (.) to match any byte (normally, it matches any byte except a
newline). the 'i' tells the whole thing to be done without regard to
capitalization.

|> (I have even ordered the new Nutshell book "Mastering Regular Expressions"

Why, Thank you Tom. I hope it will help.

	Jeffrey
----------------------------------------------------------------------------
Jeffrey Friedl <jfriedl@omron.co.jp> Omron Corp, Nagaokakyo, Kyoto 617 Japan
O'Reilly & Associates' _Mastering Regular Expressions_
                                   http://enterprise.ic.gc.ca/~jfriedl/regex/


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

Date: Sun, 02 Feb 1997 09:07:11 -0800
From: erich@powerwareintl.com (Eric Harley)
Subject: Re: Shadow passwords
Message-Id: <erich-0202970907110001@ppp-207-104-16-33.snrf01.pacbell.net>

In article <Pine.GSO.3.95.970201072710.19573D-100000@linda.teleport.com>,
Tom Phoenix <rootbeer@teleport.com> wrote:

> On Thu, 30 Jan 1997, Dan Busarow wrote:
> 
> > Does perl have a function like getspnam() to read the shadow 
> > password file?  getpwnam is just returning an "x" 
> 
> As I understand it, Perl is at the mercy of your system's getpwnam(3) 
> library function, which should be clever enough to find your password
> file, wherever it is. If it's not that smart, see whether your vendor can
> help, or you might need to code up a module to call getspnam directly. 
> Good luck! 
He should try running the script as root. That works for me on FreeBSD 2.1.5R


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

Date: 01 Feb 1997 21:38:04 GMT
From: jfriedl@tubby.nff.ncl.omron.co.jp (Jeffrey)
To: t_jharki@qualcomm.com (Jim Harkins)
Subject: Re: Silly substitute question
Message-Id: <JFRIEDL.97Feb2063804@tubby.nff.ncl.omron.co.jp>


[mail and post]

Jim Harkins <t_jharki@qualcomm.com> wrote:
|> foo bar blatz fred
|> foo bar blatz qwurp
|> foo bar blatz snurk
|> 
|> I've got a bee up my ass to do something like
|> 	s/foo bar blatz (*)/\1 = "0x0"/

Try:
	s/foo bar blatz.*/foo bar blatz 0x0/;

or, if you like,

	s/(foo bar blatz).*/$1 0x0/;

Note #1: These are full regexes, not file globs.
         Use .* to mean ``most anything''
Note #2: \1 is used only within a regex.
         $1 is used elsewhere (including the replacement string).

Jeffrey
----------------------------------------------------------------------------
Jeffrey Friedl <jfriedl@omron.co.jp> Omron Corp, Nagaokakyo, Kyoto 617 Japan
O'Reilly & Associates' _Mastering Regular Expressions_
                                   http://enterprise.ic.gc.ca/~jfriedl/regex/


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

Date: 2 Feb 1997 19:15:39 GMT
From: Chaimf@cris.com (Chaim Frenkel)
Subject: Re: space stripping
Message-Id: <5d2p4r$1fb@chronicle.concentric.net>

How does that maintain the line numbers?

Randal Schwartz (merlyn@stonehenge.com) (comp.lang.perl.misc <8csp3f5gin.fsf@gadget.cscaper.com>) wrote:
: 
: [slightly revised, now that I've had my caffiene...]
: 
: >>>>> "Bennett" == Bennett Todd <bet@nospam.interactive.net> writes:
: 
: Bennett> I tend to use, as an idiom,
: 
: Bennett> 	s/#.*$//;s/\s+$//;next if /^$/;s/^\s+//;s/\s+/ /g;
: 
: Bennett> which canonicalizes whitespace and strips #-to-eol
: Bennett> comments. The one thing I haven't quite settled on is what's
: Bennett> the best way to do "\" line continuation --- when the last
: Bennett> character is "\", extend the line. I would love to duplicate
: Bennett> the syntax that shells use, and I also want to report error
: Bennett> messages with original input line numbers when I see a syntax
: Bennett> error in the file, and I haven't found an idiom for input
: Bennett> thagomizing that does all these perfectly. Oh well, perhaps
: Bennett> perfection is not for this life.
: 
: From one of the slides in my class:
: 
: 	while (<>) {
: 		s/#.*//; # kill comments
: 		next if /^\s*$/; # skip blanks
: 		redo if s/\s*\\\s*\n$/<>/e; # fold \
: 		s/^\s+//; # kill prefix whitespace
: 		s/\s+$//; # and suffix whitespace
: 		...
: 	}
: 
: Yours, for free. :-)


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

Date: Sun, 2 Feb 1997 11:43:03 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Chaim Frenkel <Chaimf@cris.com>
Subject: Re: space stripping
Message-Id: <Pine.GSO.3.95.970202113917.13385D-100000@linda.teleport.com>

On 2 Feb 1997, Chaim Frenkel wrote:

> How does that maintain the line numbers?

It doesn't. Unless you use $. , which may or may not give you the number
you want. But it's pretty tough for a program to tell what line had the
original syntax error after you've combined several lines for parsing. Oh,
well!

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: Sun, 2 Feb 1997 13:35:58 -0800
From: "D. M. Johnson" <ez045864@peseta.ucdavis.edu>
Subject: subprocess help
Message-Id: <Pine.GSO.3.95.970202133421.22709C-100000@boris.ucdavis.edu>

I need to run spell from inside a program, passing it the contents of
$var1.  Everytime I try I get an empty variable as the return, even if the
word is mispelled.  Thanks.



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

Date: 01 Feb 1997 22:11:22 GMT
From: jfriedl@tubby.nff.ncl.omron.co.jp (Jeffrey)
To: icculus@student.umass.edu
Subject: Re: URL Encoding
Message-Id: <JFRIEDL.97Feb2071122@tubby.nff.ncl.omron.co.jp>


[mail and post]

Neal Kaiser <icculus@student.umass.edu> wrote:
|> How would I ENCODE a URL, much like the way netscape does when your
|> form input type is GET??
|
|> But, I can't seem to reverse this to encode it.  I know how to reverse
|> the first step, but the second one is giving me problems.

I use:
    $text =~ s/([^\w])/sprintf("%%%02x", ord($1))/ge;

It's a bit overzealous in that it encodes things that don't need to be, but
it doesn't hurt. To leave other things unencoded, just add them to the
negated character class (ease of adding is why I didn't just use \W in the
first place).

	Jeffrey
----------------------------------------------------------------------------
Jeffrey Friedl <jfriedl@omron.co.jp> Omron Corp, Nagaokakyo, Kyoto 617 Japan
O'Reilly & Associates' _Mastering Regular Expressions_
                                   http://enterprise.ic.gc.ca/~jfriedl/regex/


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

Date: Sun, 02 Feb 1997 14:21:46 -0500
From: Tim Thayer <thayer@wcax.com>
Subject: Re: Win32::ODBC in Win95
Message-Id: <32F4E94A.6647@wcax.com>

SANJAY SINGH wrote:
> 
> I am trying to use Win32::ODBC with Perl5 in Windows 95. As soon as I
> include a statement like 'use Win32::ODBC', I get an error saying
> 'Cannot locate DynaLoader.pm in @INC ...'.
> 
> I would really appreciate if someone can help me.
> 
> Thanks.
> Sanjay Singh
> e-mail: sanjays@earthlink.net

I had the same problem a month ago - the filename dynaloader.pm
is not named that in the distribution - it seems to be called
dynaload.pm
 - change it's name and follw normal installation, this fixed it for me
on NT4.

thayer@wcax.com


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

Date: 2 Feb 1997 20:38:10 GMT
From: "Roth Consulting" <rothd@roth.net>
Subject: Re: Win32::ODBC in Win95
Message-Id: <01bc1148$92d680e0$0100a8c0@www>

It sounds like you installed perl using something like pkunzip; something
that does not support long file names.
You may want to reinstall win32 perl or rename the file dynaxxxx.pm to
dnyaloader.pm in your lib directory.
dave
-- 
================================================================
Dave Roth                             ...glittering prizes and
Roth Consulting                     endless compromises, shatter
rothd@roth.net                        the illusion of integrity

****************************************************************
Use of  this message or  email address  for commercial  purposes
(including "junk" mailings) is strictly prohibited and protected
under  current  international  copyright laws  and United States
Code, Title 47, Chapter 5, Subchapter II.


SANJAY SINGH <sanjays@earthlink.net> wrote in article
<32F3CA45.104@earthlink.net>...
> I am trying to use Win32::ODBC with Perl5 in Windows 95. As soon as I
> include a statement like 'use Win32::ODBC', I get an error saying
> 'Cannot locate DynaLoader.pm in @INC ...'. 
> 
> I would really appreciate if someone can help me.
> 
> Thanks. 
> Sanjay Singh
> e-mail: sanjays@earthlink.net
> 


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

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

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 V7 Issue 884
*************************************

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