[9603] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3197 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jul 19 10:08:05 1998

Date: Sun, 19 Jul 98 07:00:42 -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           Sun, 19 Jul 1998     Volume: 8 Number: 3197

Today's topics:
    Re: Can a Crontab run perl script <avir@compugen.co.il>
        Counting Number of Strings <hannum@oak.cat.ohiou.edu>
    Re: Editing files in Perl <tchrist@mox.perl.com>
        File Sizes <minich@globalnet.co.uk>
    Re: File Sizes (Tad McClellan)
        grep for lists <david@quixell.com>
        if ($line =~ /$in{'word'}/i) <elssa09@nospam.callisto.si.usherb.ca>
    Re: if ($line =~ /$in{'word'}/i) (Tad McClellan)
    Re: multiple forks??? (Neil Briscoe)
        NEWBIE Question on Text replacement (Randy Owens)
        OOP : Object Oriented PROBLEMS! <*clinton@consol.co.uk>
    Re: OOP : Object Oriented PROBLEMS! <zenin@bawdycaste.org>
    Re: Perl Beautifier Home Page <zenin@bawdycaste.org>
    Re: Perl Beautifier Home Page <rra@stanford.edu>
        Scrpt that will dump unwamted users (Jim)
        using get quicker <joe@rhein.to>
    Re: WARNING: Newbie Inquiry - PERL Architecture <zenin@bawdycaste.org>
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Sun, 19 Jul 1998 10:51:08 +0300
From: Avi Rosenberg <avir@compugen.co.il>
Subject: Re: Can a Crontab run perl script
Message-Id: <35B1A56C.85E14798@compugen.co.il>

> 
> Wali Haidri <whaidri@ford.com> Said this:
> 
> >I wrote a perl (actually an oraperl) program. It runs as expected when
> >submitted from the command line. But when I run it from a crontab, it
> >does not work.
> >
> >Thanks.
> 
> Anywhere in the script where you use "relative" paths, you will need
> to make them full paths.....
>

Also remember that when you run a script from cron, it might be
executing
with a different uid than your interactive checks... 


-- 
***********************************************************************
 Avi Yeshah Rosenberg                   "GCCGTAATCCGG"
 Compugen Ltd.                          Tel: +972-3-9348482
 17 Hamacabim St.                       Fax: +972-3-9348489
 Petach-Tikva, 49220                    E-mail: avir@compugen.co.il
 Israel                                 WWW: http://www.cgen.com
**********************************************************************


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

Date: Thu, 16 Jul 1998 14:49:12 GMT
From: "Dave" <hannum@oak.cat.ohiou.edu>
Subject: Counting Number of Strings
Message-Id: <Ew6wyD.4yv@boss.cs.ohiou.edu>

Hello all.

I'm parsing the options selected from a dropdown list (multiple options) and
inserting them into columns in a database.  How can I count the number of
options selected?  I want to return an error message to the user if more
than 5 are selected.  Following is my code for parsing them out.

Thanks,
Dave


for (my $i=0; $i<=4; $i++) {
 unless(defined($specific_1[$i]))
  {
   $specific_1[$i]="";
  }
 };

Then I put them in a bind statement for inserting.




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

Date: 19 Jul 1998 06:29:07 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Editing files in Perl
Message-Id: <6os3nj$ngf$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    tim221175@my-dejanews.com writes:
:What I want is to add a line of text in the middle of a file. 

man perlfaq5, seek out the second question.

--tom
-- 
    echo "I can't find the O_* constant definitions!  You got problems."
            --The Configure script from the v5.0 perl distribution


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

Date: Sun, 19 Jul 1998 13:31:00 +0100
From: "Martin" <minich@globalnet.co.uk>
Subject: File Sizes
Message-Id: <6osoro$gfb$1@heliodor.xara.net>

Does anyone know how to get the size of a file given its file
handle without having to read all of the file into an array and
get its length?

Martin




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

Date: Sun, 19 Jul 1998 08:47:43 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: File Sizes
Message-Id: <vdtso6.9nl.ln@localhost>

Martin (minich@globalnet.co.uk) wrote:
: Does anyone know how to get the size of a file given its file
: handle without having to read all of the file into an array and
: get its length?


   $size = -s FILE;    # see the '-X' section in the 'perlfunc' man page

   
--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Sun, 19 Jul 1998 14:11:29 +0100
From: David Turner <david@quixell.com>
Subject: grep for lists
Message-Id: <35B1F081.2F957C6D@quixell.com>

Hi, I hope this is the right place to be asking... I've got a simple
problem but I'm new to Perl so, to me, it seems like a mammoth task!

What I want to do is take two lists A and B and produce a third list C
which contains all the elements in A that are NOT in B. (By lists I mean
two files with one text string on each line). ie A - (AnB)

Here's what I thought of myself...

--8<---------------------

#!/usr/bin/perl

open (FILEA, "<./fileA");
open (FILEB, "<./fileB");

@lista = <FILEA>;
@listb = <FILEB>;

sub valid {
  ($element) = @_;
  if (grep /$element/, @listb) {
    return;
  }
  else {
    return $element;
  }
}

@listc = map {valid} @lista; 
print @listc;

close FILEA;
close FILEB;

--8<---------------------

The thinking is that for each element in list A return add the output to
list C iff the element doesn't exist in list B. Naturally, as this is my
first Perl program, it doesn't work and I can't for the life of my work
out why!

Thanks in advance, I'm sure it should only take about 30 seconds to spot
the mistake.

David


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

Date: Sun, 19 Jul 1998 07:16:44 GMT
From: "Nathalie M." <elssa09@nospam.callisto.si.usherb.ca>
Subject: if ($line =~ /$in{'word'}/i)
Message-Id: <35B19CC3.4D31@nospam.callisto.si.usherb.ca>

I know there's an error somewhere in this line:

	if ($line =~ /$in{'word'}/i)

I'm opening a text file. Using an input from a *.html page, I use the
code below to search for instances of a word ($in{'word'}) in each line
of text ($line):

I want to output to the screen each line in the text file that contains
the word I input: $in{'word'}.

-----------------------------------------------------------------
	open(HTMLFILE,"<$corpus");
	@inputData=<HTMLFILE>;
	close(HTMLFILE);

$word = $in{'word'};

foreach $line (@inputData) {

	if ($line =~ /$in{'word'}/i)
#	if ($line =~ /$word/i)
#	if ($line =~ /cold/)
#	if ($line = $word)
	{
	print "success $line<BR>\n";
	}
	else
	{
	print "Not in this line.<BR>\n";
	}
}
-------------------------------------------------------

If I simply type the word in the code:

	if ($line =~ /cold/)

It works. It outputs to the screen ONLY those lines that contain the
word 'cold'.

My other experimentations don't:

	if ($line =~ /$in{'word'}/i)
	if ($line =~ /$word/i)
	if ($line = $word)

All screw up and output to the screen every line of text.
I want to output to the screen each line in the text file that contains
the word I input: $in{'word'}.

I know my syntax and experimentation are shakey. Where is the syntax
error in this line?

	if ($line =~ /$in{'word'}/i)


Please reply:

mailto:elssa09@nospam.callisto.si.usherb.ca

delete "nospam."

Thanks!

:-)

Nathalie


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

Date: Sun, 19 Jul 1998 08:42:44 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: if ($line =~ /$in{'word'}/i)
Message-Id: <k4tso6.9nl.ln@localhost>

Nathalie M. (elssa09@nospam.callisto.si.usherb.ca) wrote:
: I know there's an error somewhere in this line:

: 	if ($line =~ /$in{'word'}/i)


   I don't know that there's an error somewhere in that line  ;-)

   (it looks fine to me)


: I want to output to the screen each line in the text file that contains
: the word I input: $in{'word'}.

: -----------------------------------------------------------------
: 	open(HTMLFILE,"<$corpus");


   You should always, yes always, check the return value from open():

      open(HTMLFILE, $corpus) || die "could not open '$corpus'  $!";

   (don't need the double quotes either)


: 	@inputData=<HTMLFILE>;
: 	close(HTMLFILE);

: $word = $in{'word'};


   I wonder what the value stored in $in{'word'} is?

   Can't really help you without that...

   Try setting it explicitly in your code and see if that works (it should):

      $in{'word'} = 'cold';


: 	if ($line =~ /$in{'word'}/i)
: 	if ($line =~ /$word/i)
: 	if ($line = $word)

: All screw up and output to the screen every line of text.

   That would happen if $in{'word'} is undefined, or is equal to
   an empty string. But we don't know what the value of $in{'word'} is...

   You are, of course, using the -w switch, and then checking for
   output in your server error logs, right?


: I want to output to the screen each line in the text file that contains
: the word I input: $in{'word'}.

: I know my syntax and experimentation are shakey. Where is the syntax
: error in this line?

: 	if ($line =~ /$in{'word'}/i)


   There is *no* syntax error in that line.

   If perl is not complaining, then there is no syntax error.

   Syntax errors are uninteresting and easy to fix (not interesting
   because a machine, the perl interpreter, can find those kinds
   of errors).

   The interesting type of errors are _semantic_ (meaning) or logic
   errors...



   Looks to me like what you have should work fine. Are you certain
   that $in{'word'} is getting set correctly?



: Please reply:
: mailto:elssa09@nospam.callisto.si.usherb.ca
: delete "nospam."

   You're kidding, right?


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Sun, 19 Jul 1998 14:03 +0100 (BST)
From: neilb@zetnet.co.uk (Neil Briscoe)
Subject: Re: multiple forks???
Message-Id: <memo.19980719140353.20311A@skep.compulink.co.uk.cix.co.uk>

In article <6orlcu$4b4$1@msunews.cl.msu.edu>, spence79@pilot.msu.edu (AJS) 
wrote:

> Hey All:
> 
> I am wondering how I can spawn multiple children from 1 parent?  I am
> comfortable with one child process, but multiple is giving me problems. 
>  I
> want to run a synchronous row/column sort on a matrix.  Any basic 
> multiple
> process pointers would be great.
> 

Here is an approach which may work.  I havn't tested it.

FORK1: {
	my $pid = fork();
	
	if ($pid == 0) { # Child
		# Child code goes here.  Either exec other code,
		# or use last FORK1 as the last statement
	}
	
	if (defined $pid) { # Parent
		push(@pids, $pid);
		last FORK1;
	}
	
	warn "Unable to fork - retrying.....\n";
	sleep 2;
	redo FORK1;
}

Now repeat the above with labels FORK2, FORK3 ... FORKn as required.

The reason for pushing the $pid into an array - which is global, or at 
least, has a wider lexical scope than these labels, is so that you can 
reap the processes properly at the end of the concurrency.

Regards
Neil



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

Date: Sun, 19 Jul 1998 13:13:23 GMT
From: randyo@mindspring.com (Randy Owens)
Subject: NEWBIE Question on Text replacement
Message-Id: <35b1f033.1203964@news.mindspring.com>

I am trying to figure out how to search an ascii output file, locate
all occurences of CNTL L (^L), which is being used as a form feed, and
replace them with a Carriage return (^M) and a line feed (^J).  I may
need to advance about 50 bytes down the line before doing the
replacement.  

Is this something relatively simple with Perl?  All help is greatly
appreciated!



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

Date: Sun, 19 Jul 1998 10:16:06 +0100
From: "Clinton Gormley" <*clinton@consol.co.uk>
Subject: OOP : Object Oriented PROBLEMS!
Message-Id: <6ose21$2j6$1@taliesin.netcom.net.uk>

I've been trying my hand at some object oriented programming and have run
into difficulties which I could probably overcome by going back to function
calls, but my ego dictates...

So : I'm trying to build methods that allow me to save hashes in an
SDBM_File database.  My TIEHASH method creates a new SDBM_File and stores
the object in Info (the name of my package).  FETCH and STORE convert
between hashes and strings and either save or fetch the data.  All well and
good.  (See code below)

My problem is that various methods which work for straight SDBM_File objects
disappear when I use my object Info.  For instance, delete ($hash{$key})
works for and SDBM_File Object, but I can't call the SDBM Delete method from
Info.  Likewise I can't use keys %hash, as their isn't a FIRSTKEY method.

I've tried to debug the process that SDBM goes through, but for my newbie
brain it's a little complicated (all of that Dynaloader stuff!!)

Does anybody have any suggestions, or sobriques? And that doesn't include
switching to Berkley DB as I don't have that option open to me at the moment
(running NT etc)

Thanks

Clint

Source :
package Access; #used to save hashes with SDBM;
use SDBM_File;
use Tie::Hash;
@ISA = qw( Tie::Hash );
sub TIEHASH         #Initialise with $access=tie
%hash,'Access',"dfilename",O_RDWR|O_CREAT,0640
 {my $type=shift;
  my (@list)=@_;
  my ($self)={};
  $self->{dbm}=SDBM_File->new(@list);
  $self->{dbfile}=$list[0];
  bless $self,$type;
 }
sub FETCH     #Shouldn't need to access this from outside
 {my ($self)=shift;
  my ($reg)=shift;
  my ($temp)='';
   my ($dbm)=$self->{dbm};
 # open (dbf,$self->{dbfile});
 # flock (dbf,LOCK_SH);
  $temp=$dbm->FETCH($reg);
 # close (dbf);
 # flock (dbf,LOCK_EX);
  return split (/\|/,$temp);
 }
sub STORE    #Shouldn't need to access this from outside
 {my ($self)=shift;
  my ($reg)=shift;
  my ($hashref)=shift;
  my ($temp)=join ('|',%$hashref);
  $temp=~s/\w+\|\|//g;
  my ($dbm)=$self->{dbm};
 # open (dbf,'+>'.$self->{dbfile});
 # flock (dbf,LOCK_EX);
  $dbm->STORE ($reg,$temp);
 # close (dbf);
 # flock (dbf,LOCK_UN);
  return 1;
 }
sub DELETE   #Use to delete records : delete $hash{$record};
 {my $self=shift;
  my $reg=shift;
  my $dbm=$self->{dbm};
 # open (dbf,'+>'.$self->{dbfile});
 # flock (dbf,LOCK_EX);
  $dbm->STORE ($reg,'');
 # close (dbf);
 # flock (dbf,LOCK_UN);
  return 1;
 }
sub update    #Use to update records : $access->update($record,\%hash);
 {my ($self)=shift;
  my $reg=shift;
  my $hash=shift;
  my $key='';
  my %temp=$self->FETCH($reg);
  foreach $key (keys %$hash)
  {$temp{$key}=$$hash{$key};}
  $self->STORE ($reg,\%temp);
 }
sub populate    #Use to add values to keys :
$access->populate($record,\%hash);
 {my $self=shift;
  my $reg=shift;
  my $hash=shift;
  my $key='';
  my %temp=$self->FETCH($reg);
  foreach $key (keys %$hash)
  {if (exists $temp{$key})
   {$$hash{$key}=$temp{$key};}
   else
   {$$hash{$key}='';}
  }
 }
1




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

Date: 19 Jul 1998 13:33:01 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: OOP : Object Oriented PROBLEMS!
Message-Id: <900855758.906569@thrush.omix.com>

Clinton Gormley <*clinton@consol.co.uk> wrote:
	>snip<
: Does anybody have any suggestions, or sobriques? And that doesn't include
: switching to Berkley DB as I don't have that option open to me at the moment
: (running NT etc)

	I like to help, but it's 6:39am and I'm out of brain cells... :-(

	However, I thought you might like to know there is a binary
	distribution of Berkley DB for Win32 available:

	ftp://www.cdrom.com/pub/perl/CPAN/authors/id/GSAR/DB_File-1.54-bin-v3-x86-mswin32-bc.zip

-- 
-Zenin (zenin@archive.rhps.org)           From The Blue Camel we learn:
BSD:  A psychoactive drug, popular in the 80s, probably developed at UC
Berkeley or thereabouts.  Similar in many ways to the prescription-only
medication called "System V", but infinitely more useful. (Or, at least,
more fun.)  The full chemical name is "Berkeley Standard Distribution".


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

Date: 19 Jul 1998 06:24:20 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: Perl Beautifier Home Page
Message-Id: <900830038.186148@thrush.omix.com>

Russ Allbery <rra@stanford.edu> wrote:
	>snip<
: That's unnecessarily long for most people's version numbers.  Try this
: instead.  :)
: ($VERSION = (split (' ', q$Revision: 1.2 $ ))[1]) =~ s/\.(\d)$/.0$1/;

	Try that with 1.2.1 or 1.100 and you'll get burned hard.

-- 
-Zenin (zenin@archive.rhps.org)           From The Blue Camel we learn:
BSD:  A psychoactive drug, popular in the 80s, probably developed at UC
Berkeley or thereabouts.  Similar in many ways to the prescription-only
medication called "System V", but infinitely more useful. (Or, at least,
more fun.)  The full chemical name is "Berkeley Standard Distribution".


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

Date: 19 Jul 1998 00:04:23 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Perl Beautifier Home Page
Message-Id: <m33eby724o.fsf@windlord.Stanford.EDU>

Zenin <zenin@bawdycaste.org> writes:
> Russ Allbery <rra@stanford.edu> wrote:

>> That's unnecessarily long for most people's version numbers.  Try this
>> instead.  :)
>> ($VERSION = (split (' ', q$Revision: 1.2 $ ))[1]) =~ s/\.(\d)$/.0$1/;

> 	Try that with 1.2.1 or 1.100 and you'll get burned hard.

Yup.  And when I have something with a version number like that, I'll
worry about it.  :)  (Actually, it works fine for 1.100, as well as it
can, but that type of version number cannot be easily converted into
something that MakeMaker is going to like pretty much no matter what you
do.)

I have variations that can handle three digits.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: Sun, 19 Jul 1998 08:59:36 -0400
From: stuffit@NOSPAM--usa.net (Jim)
Subject: Scrpt that will dump unwamted users
Message-Id: <MPG.101bb7c5f0ca3dcf989698@news.erols.com>

Hello,

I have no idea how to program in perl. My question is: Can I find a 
script that will filter out and bounce unwanted guest from my site either 
by visitor or entire ISP's? I run a Multiple Sclerosis Chat Room, and I 
get complaints that spammers are getting in and causing trouble.


Thanks,
Jim

Remove NOSPAM from address


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

Date: Sun, 19 Jul 1998 14:46:24 +0200
From: "joe" <joe@rhein.to>
Subject: using get quicker
Message-Id: <6ospu4$rp7$1@usenet41.supernews.com>

Hey Guys (and just to be diplomatically correct - Hey Gals - even if the
plural is always masculine) ;-)

Currently I need to "get" (as in the method GET) aprox. 1500 URLs per hour.
My server doesnt like this to much, because its performance goes down
drastically. (it is a RedHat Linux P II 400 Mhz with eight 155 megabit
connections to major backbones in the US)
I am using the

$ok = get($geturl);

feature of

LWP::Simple

The question is does anyone know of a way for me to "get" these urls in a
shorter amount of time and how to "get" them in such a fashion, that one
doesnt notice anything when one trys to access the sites on my server.

Thanks a lot

Joe






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

Date: 19 Jul 1998 06:29:28 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: WARNING: Newbie Inquiry - PERL Architecture
Message-Id: <900830346.804346@thrush.omix.com>

Dan Baker <dtbaker_@flash.net> wrote:
: well, I may get corrected on this one, but I would assume that since
: Perl is an interpreted language, it just depends if you want to chew up
: the time and memory all up front if everything is in one file, or in
: pieces if it is in subs.

	If you're worrying about how it affects startup time, you're
	probably better off finding a different code design or algorithm.

	The reason to break up subs into there own files or group them
	all into one is much more related to scoping issues, reuse, and
	error control then to differences in efficiency for most people.
-- 
-Zenin (zenin@archive.rhps.org)           From The Blue Camel we learn:
BSD:  A psychoactive drug, popular in the 80s, probably developed at UC
Berkeley or thereabouts.  Similar in many ways to the prescription-only
medication called "System V", but infinitely more useful. (Or, at least,
more fun.)  The full chemical name is "Berkeley Standard Distribution".


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

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

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