[10144] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3737 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 17 07:07:18 1998

Date: Thu, 17 Sep 98 04:00:20 -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 Sep 1998     Volume: 8 Number: 3737

Today's topics:
        A mail reading problem <kar@webline.dk>
    Re: assigning file contents to a string <aqumsieh@tigre.matrox.com>
        Bizarre copy problem wayne_allison@hotmail.com
    Re: Bizarre copy problem (David A. Black)
        DBD::ODBC adding blob data error to Informix Db andy_williams@my-dejanews.com
        DBD::ODBC adding blob data error to Informix Db andy_williams@my-dejanews.com
    Re: DBD::ODBC adding blob data error to Informix Db andy_williams@my-dejanews.com
        Extending Perl-Win32 by ActiveState? pds@datcon.co.uk
    Re: Extending Perl-Win32 by ActiveState? jbrokamp@gmx.de
    Re: finding out yesterdays date greenej@my-dejanews.com
        How to check a file is already open (PERL 4) ? <tibiweb@chez.com>
        How to test a files is already open (PERL 4) ? <blind@icfonline.com>
    Re: ifdef in Perl <pai@cadence.com>
        Javascript or Perl or Java? laksh5614@my-dejanews.com
        Memory being eated...  (Lozano Mosterin, Jesus)
        oraperl <rolf.rettinger@desy.de>
    Re: Perl & Java - differences and uses <dalke@bioreason.com>
    Re: Perl & Java - differences and uses <dalke@bioreason.com>
    Re: Perl & Java - differences and uses <dalke@bioreason.com>
        Perl write data into text file <kotaro@geocities.com>
        require does not work <dan.albertsson@swipnet.se>
    Re: Style question re ($k => $v) (Larry Rosler)
        system() and `` on Win32 (Chris Day)
    Re: Tie STDOUT (Honza Pazdziora)
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Thu, 17 Sep 1998 09:00:20 +0200
From: Kaare Rasmussen <kar@webline.dk>
Subject: A mail reading problem
Message-Id: <3600B383.B6B06F76@webline.dk>

I am trying to read my mailbox in order to sort it according to date and
so forth. To that purpose I would use the Mail:: modules, but I have
some problems. Does anybody know these modules enough to tell if there's
anything wrong with this?

#!/usr/bin/perl -w
use Mail::Internet;
use Mail::Util qw(read_mbox);

$wrkfile="a_mailbox";
@mails=read_mbox($wrkfile);
for $mails (@mails) {
 $m = Mail::Internet->new($mails);

 $m->remove_sig;
 $m->tidy_body;
 $m->print_header;
 $m->print_body;
}

I get what I expect for the most part. But in a mailbox with 8 messages,
I only get 6 printed with this approach. A mailbox with 98 messages is
down to 92.



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

Date: 16 Sep 1998 17:17:22 -0400
From: Ala Qumsieh <aqumsieh@tigre.matrox.com>
Subject: Re: assigning file contents to a string
Message-Id: <x3yr9xbhi59.fsf@tigre.matrox.com>


linberg@literacy.upenn.edu (Steve Linberg) writes:

> 
> In article <6tlp2m$rn8$1@nnrp1.dejanews.com>, avern@hotmail.com wrote:
> 
> > I know this is a very newbie-ish question, but I've already checked the FAQ. 
> > Does any know a very concise way (say, 1 line) to assign the contents of a
> > file to a string variable? I've seen instructions on processing a file
> > line-by-line or paragraph-by-paragraph, but I don't want to manipulate the
> > file contents in any way.  I just want to store the entire file in a
> > variable, so that I can later refer to the variable in a print statement. 
> > Can this be done without creating a sub-procedure?
> 
> $bigstring = join ('', <FILE>);

This is very slow and very non-Perlish.

{ undef $/; $string = <FILE> }

Hope this helps,
-- 
Ala Qumsieh             |  No .. not Just Another
ASIC Design Engineer    |  Perl Hacker!!!!!
Matrox Graphics Inc.    |
Montreal, Quebec        |  (Not yet!)


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

Date: Thu, 17 Sep 1998 09:19:03 GMT
From: wayne_allison@hotmail.com
Subject: Bizarre copy problem
Message-Id: <6tqk66$d5b$1@nnrp1.dejanews.com>

Dear all,
I've never bothered with Prototypes before and now I've tried I'm confused.
When using this piece of code I get the message at the end.
I'd imagine that @some_people should be able to be assigned to @_.
Both sub calls should see the args after the first in
a list context.
So why does the second call to myfunc() fail so badly.
If anyone could give me an answer I'd be thankful and it
would save my hair from being pulled out.
Thanks in advance
Wayne Allison.

#Perl Code Begin
use strict;
use diagnostics;

sub myfunc (\$@)
{
my ( $time, @some_people ) = @_; # LINE 8
print "It's $$time for these ", join ( ",", @some_people ) , "\n";
}

my $now    = "10:23";
my @people = qw ( john mary fred polo );
myfunc $now, split " ", join ( " ", @people ); # OK
myfunc $now, @people;                          # BAD
__END__;

# Results in. It's 10:23 for these john,mary,fred,polo Bizarre copy of ARRAY
in aassign at tt.pl line 8 (#1)  (P) Perl detected an attempt to copy an
internal value that is not copiable. Bizarre copy of ARRAY in aassign at
/software/perl5.004_04/lib/Carp.pm line 97. #Perl Code End

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Thu, 17 Sep 1998 06:28:50 EDT
From: dblack@saturn.superlink.net (David A. Black)
Subject: Re: Bizarre copy problem
Message-Id: <6tqo92$9ci$1@earth.superlink.net>

Hello -

wayne_allison@hotmail.com writes:

>#Perl Code Begin
>use strict;
>use diagnostics;

>sub myfunc (\$@)
>{
>my ( $time, @some_people ) = @_; # LINE 8
>print "It's $$time for these ", join ( ",", @some_people ) , "\n";
>}

>my $now    = "10:23";
>my @people = qw ( john mary fred polo );
>myfunc $now, split " ", join ( " ", @people ); # OK
>myfunc $now, @people;                          # BAD
>__END__;

># Results in. It's 10:23 for these john,mary,fred,polo Bizarre copy of ARRAY
>in aassign at tt.pl line 8 (#1)  (P) Perl detected an attempt to copy an
>internal value that is not copiable. Bizarre copy of ARRAY in aassign at
>/software/perl5.004_04/lib/Carp.pm line 97. #Perl Code End

I can't duplicate your error:

candle:~/hacking/perl$ perl -w
use strict;
use diagnostics;

sub myfunc (\$@)
{
my ( $time, @some_people ) = @_; # LINE 8
print "It's $$time for these ", join ( ",", @some_people ) , "\n";
}

my $now    = "10:23";
my @people = qw ( john mary fred polo );
myfunc $now, split " ", join ( " ", @people ); # OK
myfunc $now, @people;                          # BAD
__END__;

It's 10:23 for these john,mary,fred,polo
It's 10:23 for these john,mary,fred,polo


Same results with 5.005_02 and 5.004_64 and 5.004_71, if that
helps.

David Black
dblack@saturn.superlink.net



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

Date: Thu, 17 Sep 1998 08:39:11 GMT
From: andy_williams@my-dejanews.com
Subject: DBD::ODBC adding blob data error to Informix Db
Message-Id: <6tqhrf$a0f$1@nnrp1.dejanews.com>

I get the following error when attempting to add blob data to my informix
database via my perl script. This only happens using INTERSOLV 3.01 32bit ODBC
driver. It works
using version 2.80 (Unfortunately I have an other problem with this driver).

"DBD::ODBC::st execute failed: [INTERSOLV][ODBC Informix
driver][Informix]Illegal attempt to convert Text/Byte blob type."

The code is listed below.

Please help

Andy

print "Reading data...\n";
open(FH, "test.txt") or die "$!\n";
@lines = <FH>;
close FH;
$blobdata = join("",@lines);
undef @lines;

print "Create Table.......";
$sth = $dbh->prepare("create table test \(name CHAR\(20\) PRIMARY KEY, age
INTEGER, type CHAR\(1\) DEFAULT 'A', tblob TEXT in TEXT1\)");
die "Prepare failed " . $dbh->errstr . "\n" if $dbh->errstr;
$sth->execute;
die "Execute failed " . $dbh->errstr . "\n" if $dbh->errstr;
print "Ok\n\n";

$sth = $dbh->prepare("insert into test \(name,age,type,tblob\) values \('Fred
Bloggs', '98', 'A', ?\)"); die "Prepare failed " . $dbh->errstr . "\n" if
$dbh->errstr; $sth->execute($blobdata); die "Execute failed " . $dbh->errstr
 . "\n" if $dbh->errstr; # The Error occurs  # Here print "Ok\n\n";

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Thu, 17 Sep 1998 08:35:48 GMT
From: andy_williams@my-dejanews.com
Subject: DBD::ODBC adding blob data error to Informix Db
Message-Id: <6tqhl4$9uk$1@nnrp1.dejanews.com>

I get the following error when attempting to add blob data to my informix
database. This only happens using INTERSOLV 3.01 32bit ODBC driver. It works
using version 2.80 (Unfortunately I have an other problem with this driver).

"DBD::ODBC::st execute failed: [INTERSOLV][ODBC Informix
driver][Informix]Illegal attempt to convert Text/Byte blob type."

The code is listed below.

Please help

Andy

print "Reading data...\n";
open(FH, "test.txt") or die "$!\n";
@lines = <FH>;
close FH;
$blobdata = join("",@lines);
undef @lines;

print "Create Table.......";
$sth = $dbh->prepare("create table test \(name CHAR\(20\) PRIMARY KEY, age
INTEGER, type CHAR\(1\) DEFAULT 'A', tblob TEXT in TEXT1\)");
die "Prepare failed " . $dbh->errstr . "\n" if $dbh->errstr;
$sth->execute;
die "Execute failed " . $dbh->errstr . "\n" if $dbh->errstr;
print "Ok\n\n";

$sth = $dbh->prepare("insert into test \(name,age,type,tblob\) values \('Fred
Bloggs', '98', 'A', ?\)"); die "Prepare failed " . $dbh->errstr . "\n" if
$dbh->errstr; $sth->execute($blobdata); die "Execute failed " . $dbh->errstr
 . "\n" if $dbh->errstr; # The Error occurs  # Here print "Ok\n\n";

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Thu, 17 Sep 1998 10:36:36 GMT
From: andy_williams@my-dejanews.com
Subject: Re: DBD::ODBC adding blob data error to Informix Db
Message-Id: <6tqonk$ij3$1@nnrp1.dejanews.com>

I have tried using
$quotedblob = $dbh->quote($blobdata);
$sth = $dbh->do("insert into test (name,age,type,tblob) values ('Fred Bloggs',
'98', 'A', $quotedblob)");

and this seems to work for the TEXT data type, but I get a Syntax error for
the BYTE data type.

Still need help

Thanks

Andy


In article <6tqhl4$9uk$1@nnrp1.dejanews.com>,
  andy_williams@my-dejanews.com wrote:
> I get the following error when attempting to add blob data to my informix
> database. This only happens using INTERSOLV 3.01 32bit ODBC driver. It works
> using version 2.80 (Unfortunately I have an other problem with this driver).
>
> "DBD::ODBC::st execute failed: [INTERSOLV][ODBC Informix
> driver][Informix]Illegal attempt to convert Text/Byte blob type."
>
> The code is listed below.
>
> Please help
>
> Andy
>
> print "Reading data...\n";
> open(FH, "test.txt") or die "$!\n";
> @lines = <FH>;
> close FH;
> $blobdata = join("",@lines);
> undef @lines;
>
> print "Create Table.......";
> $sth = $dbh->prepare("create table test \(name CHAR\(20\) PRIMARY KEY, age
> INTEGER, type CHAR\(1\) DEFAULT 'A', tblob TEXT in TEXT1\)");
> die "Prepare failed " . $dbh->errstr . "\n" if $dbh->errstr;
> $sth->execute;
> die "Execute failed " . $dbh->errstr . "\n" if $dbh->errstr;
> print "Ok\n\n";
>
> $sth = $dbh->prepare("insert into test \(name,age,type,tblob\) values \('Fred
> Bloggs', '98', 'A', ?\)"); die "Prepare failed " . $dbh->errstr . "\n" if
> $dbh->errstr; $sth->execute($blobdata); die "Execute failed " . $dbh->errstr
> . "\n" if $dbh->errstr; # The Error occurs  # Here print "Ok\n\n";
>
> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum
>

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Thu, 17 Sep 1998 07:42:05 GMT
From: pds@datcon.co.uk
Subject: Extending Perl-Win32 by ActiveState?
Message-Id: <6tqegd$754$1@nnrp1.dejanews.com>

Does anyone know how to extend the current version of Perl-Win32 from
ActiveState?  I would like to add support for RAS.  I see that the Win32
modules which ActiveState provide use .PLL files (DLLs under a Perl
pseudonym) so it must be possible but ActiveState tell me that using the
xbsupp approach doesn't work.

Anyone know how to achieve this, preferably with a quick example?

Please copy me by e-mail at pds@datcon.co.uk as I don't have direct NEWS
access..

Thanks,
Paul DS.

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Thu, 17 Sep 1998 09:43:12 GMT
From: jbrokamp@gmx.de
Subject: Re: Extending Perl-Win32 by ActiveState?
Message-Id: <6tqljf$f3d$1@nnrp1.dejanews.com>

In article <6tqegd$754$1@nnrp1.dejanews.com>,
  pds@datcon.co.uk wrote:
> Does anyone know how to extend the current version of Perl-Win32 from
> ActiveState?  I would like to add support for RAS.

Look at members.aol.com/jbrokamp to download my ras modul to establishes
a connection beween a ras client and server or look for Win32::RasAdmin
from Dave Roth.



-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Thu, 17 Sep 1998 08:12:33 GMT
From: greenej@my-dejanews.com
Subject: Re: finding out yesterdays date
Message-Id: <6tqg9f$8nj$1@nnrp1.dejanews.com>

In article <35fd5a3e.8691503@news.ais.net>,
  syarbrou@ais.net (Steve .) wrote:
> I have a system that outputs a comma delimited file and then is passed
> to my linux box.  The first field is the date like 09/14/98.  The date
> is actually the next days date since it passes the data at midnight.
> The program has to do this because that's how it works so I can't set
> it to send at 11:59.  I want to be able to reset the dates that are
> sent to one day less.  Is there somthing to do this?  So if the date
> is stamped 09/14/98 I want it to be 09/13/98.  Thanks.

Aside from the obvious Y2K issues, one way is (assuming your value of
"09/14/98" is in the variable $date)...

  use Time::Local;
  ($mon, $day, $yr) = split '/', $date;
  $yesterday = timelocal(0,0,0,$day, $mon-1, $yr) - (60*60*24);
  ($day, $mon, $yr) = (localtime($yesterday))[3..5];
  printf("%d/%d/%d\n", $mon+1, $day, $yr);

In other words, use timelocal() to convert the date into the number of
seconds since the epoch (1.1.1970 on most systems), subtract the number of
seconds in 24 hours, then use localtime() to split this value into mon/day/yr
values.

Be sure to 'tweek' the month value by one, since both timelocal() and
localtime() assume the months 0=Jan .. 11=Dec.

Hope this helps...

JAGreene
--
# James Greene - Informatics Consulting - D-79539 Loerrach, Germany
# Internet: www.gucc.org/greene/consult - greene@gucc.org
# PGP Fingerprint: CA88 9BE2 92B3 3162 DF6B  7080 2F9E A97E F25C 5972
perl -we "$_=join'<',qw{d2by' f5e;f4z($iu w0@86yo=&ae b!097)l(&aa8vme
b$*};$_=unpack'u*',uc;print"

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Thu, 17 Sep 1998 11:14:42 +0200
From: "titi" <tibiweb@chez.com>
Subject: How to check a file is already open (PERL 4) ?
Message-Id: <6tqjrg$44l$1@ubnnews.unisource.ch>

I planed to run a batch deamon under Unix 10.10 wtitten in PERL 4.
The rule of this deamon is to scan a directory awaiting files.
If a file matches it runs specific application depending the file name.

My question :

How can I test if the incomming file (it's FTP from a distant server)
is already closed ?

I try -t file test operator, but it don't work.

Tnx for your help.

eMail : tblind@icfonline.com






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

Date: Thu, 17 Sep 1998 11:18:02 +0200
From: "titi" <blind@icfonline.com>
Subject: How to test a files is already open (PERL 4) ?
Message-Id: <6tqk1n$4bl$1@ubnnews.unisource.ch>

I planed to run a batch deamon under Unix 10.10 wtitten in PERL 4.
The rule of this deamon is to scan a directory awaiting files.
If a file matches it runs specific application depending the file name.

My question :

How can I test if the incomming file (it's FTP from a distant server)
is already closed ?

I try -t file test operator, but it don't work.

Tnx for your help.

eMail : tblind@icfonline.com








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

Date: Thu, 17 Sep 1998 14:09:38 +0531
From: "Narasimha G. Pai" <pai@cadence.com>
Subject: Re: ifdef in Perl
Message-Id: <3600CA8E.3F5F9D63@cadence.com>

>          I want something like :
>
>          if($os eq 'NT'){
>          use Win32 ;
>          }
>          if($os eq 'UNIX'{
>          #do nothing
>          }
>
>   However it does not work . It fails before evaluating $os ( ie at
> compile time ) .

Hmm, since you do not set $os anywhere, I woudn't expect it to work,
even if it could.

To check on compile time, what platform you are running on, use BEGIN:

BEGIN { if ($^O =~ /Win32/) { eval 'use Win32;' } }

Take care (and do not post the HTML part next time).



Hi ,

     Thanks for the solution . It works except for one thing . I am
trying to determine $os
     by calling a function . Do I have to put that in the BEGIN block
too ?

   BEGIN{

    $os = $ctfGetOSName ;

    if( $os eq "WINDOWSNT"){

   eval 'use Win32::AdminMisc' ;
   eval 'use Win32 ';

   }




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

Date: Thu, 17 Sep 1998 09:46:35 GMT
From: laksh5614@my-dejanews.com
Subject: Javascript or Perl or Java?
Message-Id: <6tqlpq$fga$1@nnrp1.dejanews.com>

Please can somebody clarify the difference between  using Javascript, Java,
Perl? As a Beginner what should a person know to start off with Internet
Programming?

Thanks a ton for your oncoming reply.

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: 17 Sep 98 11:00:08 +0200 (MET)
From: lozano@opalo.etsiig.uniovi.es (Lozano Mosterin, Jesus)
Subject: Memory being eated... 
Message-Id: <MwGfZ5x4skvJ@opalo.etsiig.uniovi.es>

perl -v
This is perl, version 5.005 built for i586-linux

This routine is eating me up all the memory. I don't know why...

print <<TIA

sub 
remove_one_and_only_one_byte_first_BYTE_on_array_DO_IT_DO_IT_ARGGG {
     if (length($temp[0])>1){
        $temp[0] =~ s/(^.)(.*)/$2/;
        if ($1 eq '1') {
           $tac--;
        }
     }else{
        if ($temp[0] eq '1'){
           $tac--;
        }
        shift @temp;
     }
     $len--;
}

TIA;



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

Date: Thu, 17 Sep 1998 12:13:22 +0200
From: "Rolf Rettinger" <rolf.rettinger@desy.de>
Subject: oraperl
Message-Id: <6tqnde$pop$1@claire.desy.de>

I am looking for an oraperl module running with oracles ora73.dll for
windowsNT.

Rolf




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

Date: Thu, 17 Sep 1998 02:29:07 -0700
From: Andrew Dalke <dalke@bioreason.com>
Subject: Re: Perl & Java - differences and uses
Message-Id: <3600D663.22467B44@bioreason.com>

abigail@fnx.com (Abigail) replied to my question about how to
get the list of matches from an re match:

> if (@matches = $str =~ /$term->[0]/) {
>    $term -> [1] -> ($str, @matches);
> }
> 
> There is one catch though. If $term->[0] doesn't contain parens, and
> the regex matches, @matches will be (1) - as if the regex had on set
> of parens, with captured '1'.

Thanks for the info.  The scary thing is four months ago I knew
this (well, not the catch part).  I think one of the reasons I
switched to Python was I get about the same amount of power and I
don't have to remember all these details.

						Andrew Dalke
						dalke@bioreason.com


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

Date: Thu, 17 Sep 1998 02:53:55 -0700
From: Andrew Dalke <dalke@bioreason.com>
Subject: Re: Perl & Java - differences and uses
Message-Id: <3600DC33.F878C208@bioreason.com>

> : For example, you cannot make a list of regular expressions.
> 
>         Sure you can, even in perl 4.  They are only strings after
>         all.
> 
>         my @list_o_patterns = qw(this that dog (?i)insensitive);
> 
>         foreach my $pat (@list_o_patterns) {
>             something() if ($string =~ /$pat/);
>         }

True, and I've been smacking myself on the head forgetting that. 
But it isn't the same since it recompiles the pattern every time
it is used. (Wait, I seem to remember something about if a string
is used as an re, then the compiled pattern is stored until the
string changes, In that way, if the string is used as a pattern again
it doesn't need to recompile.  Don't know if it's true, but it
could happen.)

> But if you changed qr() to q() it would work in all 5.*
> versions (maybe 4.*?), even if a little slower.

Excepting that possible optimization, that's why "q()" is not a
replacement for "qr()"

Besides, if I really wanted to force the issue, I'll say
that my code has to support both POSIX regular expressions
(implemented in some re library; and POSIX semantics are different
than perl's) and perl5 REs, so I cannot put the =~ in the "search"
routine.  The python code doesn't change much.  The perl code
changes a lot.

> In a language that relies entirely on magic whitespace for block
> roles, isn't a 2 space indent a really bad idea, readability and
> maintainance wise?

  I've been trying to understand, given the many things in perl
that are labeled "magic," if "magic whitespace" is meant to be
praising or chiding.  :)

  My normal code environment is xemacs and I would usually just
hit tab to get the indentation right.  Alas, I do news with
Netscape and don't feel like banging my thumb that often against
the space bar.

>  @patterns   = ();   ## Global?  Bad form.  I'd pass by ref myself.

My, aren't we picky.  This is example code to show a certain
construct and I didn't want extra parameter casting to get in the
way.

> Does Python really need the archaic "count = count + 1"?

Dude, with words like that you're pushing close to the language
war button.  It's for the exact same reason in perl this:

$b = 5;
$arr{$b} = "Hello";
$b++;
print keys %arr;

gives you "5" instead of "6"  (If "++" existed in Python as
you think it should, the python code would return 6).  It's
the difference between a pass-by-value language and a
pass-by-reference language.  Which is the reason why in
python I pass multiple lists without needing the reference.

@a = split;
@b = split;
@c = &vector_add(\@a, \@b);

as compared to
a = split(line)
b = split(line)
c = vector_add(a, b)

I dunno, seems kinda archaic to me :)

> : and the requirement that "add_pattern" know the
> : local variable names used in "search".
> 
>        You say this, but you use a global pattern list in both
>        functions in both languages?

You don't get it, do you?  That's almost the exact code that would
fit inside a class definition, but since there's no need for a class,
I don't worry about it.  Converting to a proper definition is straight
forward.  Here (realizing I'm tossing some comments for a smaller post):

class PatternMatch:
    def __init__(self):
        self.patterns = []
    def add_pattern(self, matcher, label):
        self.patterns.append( (matcher, label) )
    def search(self, str):
        count = 0
        for pattern in self.patterns:
            if pattern[0].search(str):
                 print "Found", pattern[1]
                 count = count + 1
        return count

class SumsGreaterThan:          # Tossing in a silly class definition
    def __init__(self, thresh): # that can be used where we need the re.
        self.thresh = thresh    # It sums up the terms and returns 1 if
    def search(self, str):      # the sum exceeds the original threshold.
        try:                    # If not, or if there is an error,
            return eval(str) > self.thresh   # returns 0.
        except:
            return 0

if __name__ == "__main__":
    import re  # ,posixre  -- assumes a mythical "posixre"
    posixre = re  # instead, I'll use re to test it.
    pm = PatternMatch()
    pm.add_pattern(re.compile("^h[1-9]"), "header")
    pm.add_pattern(posixre.compile("[Aa]ndrew"), "name")
    pm.add_pattern(SumsGreaterThan(100), "adds up")
    print pm.search("h1 Andrew")
    print pm.search("50 - 5 + 90")

which prints:
Found header
Found name
2
Found adds up
1

What's the same in perl?  Assuming a posix re class, you'll need to
wrapper the exising re so you can use it in a generic framework.
You'll also need to split this across several files since (as I
recall, prices subject to change without notice) perl only allows
one class definition per file.

>        "break"?  What language is this in again? :-)

I'm not even going to try a perl implementation since my languages
seem to be leaking together today  -- my excuse is I just came back
from vacation and haven't coded in almost two weeks :)


						Andrew
						dalke@bioreason.com


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

Date: Thu, 17 Sep 1998 03:33:56 -0700
From: Andrew Dalke <dalke@bioreason.com>
Subject: Re: Perl & Java - differences and uses
Message-Id: <3600E594.569FC7A5@bioreason.com>

Zenin <zenin@bawdycaste.org> said (in response to me):
> : As long as I'm here, there's what I consider to be the number one
> : bug in Perl code that deals with files -- how do you read from the
> : file " spaces " (with the leading and trailing space characters). 
> 
>         $ cat foo.pl
>         #!/usr/local/bin/perl
>         
>         use Fcntl;
>         sysopen SESAME, " spaces ", undef, O_RDONLY
>             or die "open: $!";

This is completely true, and not really the point.  Most people,
when they want to open a file, use open and not sysopen.  That's
why I say it is the most common file handling bug I've seen.


I also said:
> some of the standard Perl libraries have bugs in
> them, like File/Compare.pm's "compare".

to which you replied:
> :         open(FROM,"<$from") or goto fail_open1;
> 
>         Duh!  I guess that's what happens when one gets too used
>         to working on real systems (insert OS flame war here). :-)

I'm stumped.  Why is a real system like BSD any different in this
regard than a play one like SysV?  (Replace names at will :)


I sent this in to perlbug and got the response from
on high^UTom Christiansen:

> A perl file spec, whether in a library module or the core, should be
> the kind given to open.  No more, no less.  It is totally
> frustrating experience to have some library function that refuses
> to accept argument like "-" or "foo|bar|" or "&<DATA".  That's
> anti-convenience.

(Which implies you should refrain from using sysread :)
Part of my reply, BTW, is:
===========================================================
That being the case, is
the implementation of "File::Copy's copy" incorrect as it does not
allow the above example of "foo|bar|" ?

>    if ($from_a_handle) {
>        *FROM = *$from{FILEHANDLE};
>    } else {
>        $from = "./$from" if $from =~ /^\s/;
>        open(FROM, "< $from\0") or goto fail_open1;
>        binmode FROM or die "($!,$^E)";
>        $closefrom = 1;
>    } 


Similarly, is File::Compare's "compare" incorrect as I cannot
do:

  use File::Compare;
  print compare("grep dalke file1|", "grep dalke file2|"
);
-1

and the compare causes $! to be set to "No such file or directory"

This is due to compare's "open" which forces the use of '<' ?
        open(FROM,"<$from") or goto fail_open1;
   ...
        open(TO,"<$to") or goto fail_open2;


The default in perl is to read from stdin, there should
be no need to have the '<' at all, and having it restricts me from
inputs of the form "foo|bar|" .

Indeed, removing the two '<' allows me to do:
bioreason8> perl -e 'use File::Compare; print \
 compare("cat /etc/passwd|", "cat /etc/passwd|");'
0
bioreason8>perl -e 'use File::Compare; print \
 compare("cat /etc/passwd|", "cat /etc/resolv.conf|");'
1

Also, I see that Term::Cap's "Tgetent" uses
        open(TERMCAP,"< $TERMCAP\0") || croak "open $TERMCAP: $!";

Should that "\0" be present?  If so, I am at a loss as to when
"\0" is used and when it is not.
=======================================================

It isn't as simple as Zenin says:
>        open() is a short cut for 99% of common usage.  It's just a map to
>        fopen(3) which is a wrapper over open(2), and was made for the
>        same reason.

and that's where the problem lies -- open will call popen (or maybe
pipe and system) and not use fopen during:  open(FOO, "cat /etc/passd|")

You have to know exactly where you have a file name (as compared to
a pipe or handle) and hence when to escape appropriate characters. 
This isn't easy, as I believe the confusion I have with the standard
perl library shows.  In fact, after thinking about it for a little,
it seems well neigh impossible unless you ask the user "is this a
file" (eg, how does the script know to copy from the file
"cat /etc/passwd|" as compared to opening a pipe reading from
"cat /etc/passwd" ?).

I think next time I want to annoy my sys admin I'll have some
nasty files like "  cat /dev/zero|" :P


Zenin also asked:
> : According to the perl manual, you should do:
> :   $file =~ s#^\s#./$&#;
> :   open(FO, "< $file\0");
> 
>         Hmm, now that is ugly.  It even uses $&.... :-(
> 
>         Which man page has this? -I'd like to submit a doc patch
>         if 5.005 hasn't fixed this already.

  Just checked.  That was from my Camel book, v1.  The current
perldoc perlfunc says:
>    $file =~ s#^(\s)#./$1#;
>    open(FOO, "< $file\0");

I'm just an old fogey and haven't updated my manuals in a while :)

						Andrew
						dalke@bioreason.com
P.S.
  I removed the java newsgroup from the xrefs.


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

Date: Thu, 17 Sep 1998 15:53:10 +0700
From: Kotaro Yama <kotaro@geocities.com>
Subject: Perl write data into text file
Message-Id: <3600CDF6.9C8CDDD0@geocities.com>

Hello Everybody,
    How can i write perl5.005 command to write data in text file ?
It is need exclusive lock file before write data in this file.
How to use exclusive lock file ?
I use perl on Unix (Sun2.6) Environment.

Thanks a lot
Kotaro.







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

Date: 17 Sep 98 10:04:06 GMT
From: "Dan Albertsson" <dan.albertsson@swipnet.se>
Subject: require does not work
Message-Id: <01bde222$9c53e070$5701a8c0@dan>

When trying to call functions in other perl files I use for example:

require 'test1.sub';

And then call functions in that file.

This works fine running perl stand-alone in Windows95, NT and Unix
environment.
It also works fine when called as a cgi-script on my apache webserver.

But it does not work when called as a cgi-script on my Microsoft IIS
webserver. My webbrowsers only response is something like:

------------------------------------------------------------------
CGI Error

The specified CGI application misbehaved by not returning a complete set of
HTTP headers. The headers it did return are:

Can't locate test1.pl in @INC at E:\Webscripts\testing\test2.pl line 7.

------------------------------------------------------------------
Why? I have tried to change the syntax for "require" in all sorts of ways.

/dan



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

Date: Thu, 17 Sep 1998 01:31:02 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Style question re ($k => $v)
Message-Id: <MPG.106a68a1b6eb6084989861@nntp.hpl.hp.com>

In article <6tq2b5$2r0$3@client3.news.psi.net> on 17 Sep 1998 04:14:29 
GMT, Abigail <abigail@fnx.com> says...
> Mark-Jason Dominus (mjd@op.net) wrote on MDCCCXLIII September MCMXCIII in
> <URL: news:6tprqp$8ob$1@monet.op.net>:
 ...
> ++ Lately I've found myself writing
> ++ 
> ++ 	while (($k => $v) = each %h) {
> ++ 	  ...
> ++ 	}
> ++ 
> ++ Does anyone have any comments about this?
 ...
>      split /regex/ => $string;
>      join  "" => @list;
>      %hash = map {$_ => 1} @list;
>      sprintf "format" => $arg1, $arg2, $arg3;

> I tend to use it in cases where the first argument of a function
> has a very different role than the others. => makes a bigger
> visual impact than a , tucked against the operand.

I use all of those, for that reason.  In addition, these follow the same 
model as 'join' and 'sprintf':

   grep EXPR => LIST
   map  EXPR => LIST

One way of reading this '=>' is 'applied to' ...

And, finally,

   rename NAME1 => NAME2
   utime EXPR, EXPR => NAME

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


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

Date: 17 Sep 1998 05:53:10 -0500
From: chrisday@cs.utexas.edu (Chris Day)
Subject: system() and `` on Win32
Message-Id: <6tqpmm$1f4$1@sombrero.cs.utexas.edu>


Hello, I've recently installed Perl 5.004_02 on my Win95 web server and
have hit a rather odd bug when using system() or `` to execute any shell
commands.  Whenever either is used, Perl attempts to access the floppy
drive (a:) on my system, and although it typically functions correctly
other than this, sometimes it will print "Invalid switch" in addition.

My first thought was that it was checking all directories in my PATH for
the commands, however I soon realized that a:\ was nowhere to be seen in
my PATH, and I've been unable to figure out why Perl is accessing the
drive.  It's not the biggest problem in the world, but the noise it makes
when the drive is empty is intolerable, and there's no way I can get
around using system() or ``.

Any help on finding/fixing the problem is appreciated, please reply-to
chrisday@bigfoot.com, I don't stop by USENET very often, and would like to
fix this problem ASAP.


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

Date: Thu, 17 Sep 1998 07:01:13 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: Tie STDOUT
Message-Id: <slrn701ctn.aoj.adelton@aisa.fi.muni.cz>

On Wed, 16 Sep 1998 23:22:29 -0400, Jay Guerette <JayGuerette@pobox.com> wrote:
> This code is intended to capture output to STDOUT and redirect it elsewhere.
> I have 2 questions about the following snippet:
> 
> 1. Why doesn't PRINTF work?

What does it mean, doesn't work. Does it like print "krtek" instead of
that "hello world"? The following piece of code behaves quite happily
for me:

	package Tie::StdOut;
	sub TIEHANDLE {
		my $class = shift;
		bless {}, $class;
		}
	sub PRINT {
		my $self = shift;
		print STDERR 'Tie::StdOut::PRINT: ', @_;
		}
	sub PRINTF {
		my $self = shift;
		print STDERR 'Tie::StdOut::PRINTF: ';
		printf STDERR @_;
		}
	package main;
	tie *STDOUT, Tie::StdOut;
	print "hello world<br>\n";
	$greeting = "hello again";
	printf "%s<br>\n", $greeting;
	__END__

This is perl, version 5.004_04.

-- 
------------------------------------------------------------------------
 Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
                   I can take or leave it if I please
------------------------------------------------------------------------


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

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


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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

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