[12115] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5715 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 18 16:07:12 1999

Date: Tue, 18 May 99 13:00:23 -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           Tue, 18 May 1999     Volume: 8 Number: 5715

Today's topics:
    Re: ->Folkert Meeuw: syntax error at 1.8.pl line 11, ne (Bart Lateur)
    Re: ->Folkert Meeuw: syntax error at 1.8.pl line 11, ne (Bart Lateur)
    Re: Anyone can help ?? (Thomas Wade Vaughan)
    Re: comp.lang.perl.* archive? (Cameron Laird)
        Creating FIle with a predeterminated Size <"Pep Mico"@hp.com>
    Re: Creating FIle with a predeterminated Size <dgris@moiraine.dimensional.com>
    Re: Creating FIle with a predeterminated Size (I R A Aggie)
    Re: Creating FIle with a predeterminated Size (John Stanley)
    Re: generated functions and caller (or better way?) (M.J.T. Guy)
        Help! cgi and system() failure <madigan@rohan.sdsu.edu>
    Re: How to create modules? <cassell@mail.cor.epa.gov>
    Re: How to create modules? <aqumsieh@matrox.com>
        How to get the infomation of a variable if it is scalar (Ryan Ngi)
    Re: How to move a directory? (Tad McClellan)
        How to override HTTP_USER_AGENT when using libwww-perl? <ginsburg@haas.berkeley.edu>
    Re: negative subscripts (Bart Lateur)
    Re: negative subscripts (Tom Vaughan)
    Re: negative subscripts (Tom Vaughan)
    Re: Perl "constructors" <garethr@cre.canon.co.uk>
    Re: PERLFUNC: opendir - open a directory <tchrist@mox.perl.com>
        Problem With Scope (Ryan Ngi)
    Re: Protecting perl source code <jbc@shell2.la.best.com>
    Re: Protecting perl source code (Bart Lateur)
    Re: Protecting perl source code <dgris@moiraine.dimensional.com>
    Re: Removing Data from the File <wassimk@iname.com>
    Re: Sorting is too slow for finding top N keys... - UPD (M.J.T. Guy)
    Re: Sorting is too slow for finding top N keys... - UPD (Bart Lateur)
    Re: Sorting is too slow for finding top N keys... - UPD <cassell@mail.cor.epa.gov>
        Tie Fighter <gbartels@xli.com>
    Re: what's wrong with my head(er)...? (Tad McClellan)
        Why does a perl cgi-script 'hang' <th.bossert@z.zgs.de>
        XML::XQL <nlymbo@mindspring.com>
    Re: Y2K.  localtime(time) <tchrist@mox.perl.com>
    Re: Y2K.  localtime(time) (I R A Aggie)
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Tue, 18 May 1999 18:46:24 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: ->Folkert Meeuw: syntax error at 1.8.pl line 11, near "$freund ("   Execution of 1.8.pl aborted due to compilation errors.
Message-Id: <3742b517.1022923@news.skynet.be>

Folkert Meeuw wrote:

>$frriends = <IN>;

Two errors:

A] Typo in the variable's name.

B] You're assigning to a scalar (single value). I'm pretty sure you
intended to assign to the array @friends -- the one you keep using
further down in your code.


	Bart.


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

Date: Tue, 18 May 1999 19:42:21 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: ->Folkert Meeuw: syntax error at 1.8.pl line 11, near "$freund ("   Execution of 1.8.pl aborted due to compilation errors.
Message-Id: <3744c227.2334037@news.skynet.be>

Folkert Meeuw wrote:

>Who knows ?

I ust noticed that your subject line is extremeluy long, and contains
more info.

>Subject: ->Folkert Meeuw: syntax error at 1.8.pl line 11, near "$freund ("
> 	Execution of 1.8.pl aborted due to compilation errors.

Hmmm... Are you sure you're running Perl 5?

	Bart.


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

Date: 18 May 1999 17:50:16 GMT
From: vaughan@well.com (Thomas Wade Vaughan)
Subject: Re: Anyone can help ??
Message-Id: <7hs98o$b4o$1@its.hooked.net>

Austin Ming (austin95002887@yahoo.com) wrote:

: #!/usr/bin/perl

: $myVar = 3;
: mySub($myVar);
: print $myVar;
: print youSub();

: sub mySub { $myVar = $myVar + 2 ; }

If you want to pass by value, then try this:

	sub mySub()
	{
		my $myvar = shift;
		$myvar+2;
	}

	If you want to change the passed parameter (call by reference):

	sub mySub()
	{
		$_[0]+=2;
	}
: sub youSub { $a=1 ; $b=2; $a; }

: I do not know if the above script is correct to use 
:  call by reference and call by value.

: Anyone can help ??



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

Date: 18 May 1999 13:46:34 -0500
From: claird@Starbase.NeoSoft.COM (Cameron Laird)
Subject: Re: comp.lang.perl.* archive?
Message-Id: <7hscia$9pm$1@Starbase.NeoSoft.COM>

In article <373bf31b@newsread3.dircon.co.uk>,
Jonathan Stowe  <gellyfish@gellyfish.com> wrote:
>Pavel Kotala <pkotala@logis.cz> wrote:
>> Exists any way to explore historical news? I am biginner in discussion
>> groups.
>> 
>
>Deja News at http://www.deja.com is the method most people use - except
>for those of use who keep our own news archive ....
			.
			.
			.
See also <URL:http://
starbase.neosoft.com/~claird/news.lists/compnewsgroup_archives.html#perl>.
-- 

Cameron Laird           http://starbase.neosoft.com/~claird/home.html
claird@NeoSoft.com      +1 281 996 8546 FAX


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

Date: Tue, 18 May 1999 20:09:56 +0200
From: Pep Mico <"Pep Mico"@hp.com>
Subject: Creating FIle with a predeterminated Size
Message-Id: <3741ACF4.ADBE04C5@hp.com>


Hello,

How can I create a file with a predeterminated file? or for example, how
Can I create a file with a size of 10Mbytes?

Thanks in advance
pep_mico@hp.com




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

Date: 18 May 1999 12:19:54 -0600
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: Creating FIle with a predeterminated Size
Message-Id: <m33e0ujl4l.fsf@moiraine.dimensional.com>

Pep Mico <"Pep Mico"@hp.com> writes:

> How can I create a file with a predeterminated file? or for example, how
> Can I create a file with a size of 10Mbytes?

% perl -le 'print q.x. x (1024 * 1024 * 10 - 1)' > my_new_file
%

Exactly 10 megs.

dgris
-- 
Daniel Grisinger          dgris@moiraine.dimensional.com
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print 
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'


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

Date: 18 May 1999 18:30:14 GMT
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Creating FIle with a predeterminated Size
Message-Id: <slrn7k3ciq.rn4.fl_aggie@thepentagon.com>

On Tue, 18 May 1999 20:09:56 +0200, Pep Mico <@hp.com>, in
<3741ACF4.ADBE04C5@hp.com> wrote:

+ How can I create a file with a predeterminated file? or for example, how
+ Can I create a file with a size of 10Mbytes?

Under unix you might:

dd if=/dev/zero of=output.file bs=1024 count=10240

So, if you wanted to do this in perl, you could try something
like:

open(IN,'/dev/zero') or die "Failed on /dev/zero? $!";
$bytes=read IN,$one_kb,1024;
close(IN);
if ($bytes==1024) {
    open(OUT,">output.file") or die "Failed opening output: $!";
    for($ikbytes=0;$ikbytes++;$ikbytes<10240) {
	print OUT $one_kb;
    }
    close(OUT);
} else {
    die "So sorry, unable to read 1024 bytes from /dev/zero, exiting!\n";
}

I didn't try to run it, tho I did run it past perl -c with no
problems...it may work, it may not, and there may be better
solutions...

James


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

Date: 18 May 1999 19:04:52 GMT
From: stanley@skyking.OCE.ORST.EDU (John Stanley)
Subject: Re: Creating FIle with a predeterminated Size
Message-Id: <7hsdkk$8tf$1@news.NERO.NET>

In article <3741ACF4.ADBE04C5@hp.com>, Pep Mico  <"Pep Mico"@hp.com> wrote:
>How can I create a file with a predeterminated file? or for example, how
>Can I create a file with a size of 10Mbytes?

mkfile 10m



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

Date: 18 May 1999 18:37:09 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: generated functions and caller (or better way?)
Message-Id: <7hsc0l$r6m$1@pegasus.csx.cam.ac.uk>

In article <7hpgm2$2pu$1@fcnews.fc.hp.com>, Andrew Allen <ada@fc.hp.com> wrote:
>Rand A. Bamberg (rand@qualityic.com) wrote:
>
>: AFAIK there are two ways to generate a function at
>: run-time: either assign an anonymous closure to a typeglob
>: as described in the Cookbook p358 (a little exotic), or
>: assemble the new function as a string and C<eval> it (ick).
>
>and AUTOLOAD.

AUTOLOAD doesn't generate functions itself.   It merely provides a
place where the function generating methods described by Rand can be
deployed.


Mike Guy


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

Date: Tue, 18 May 1999 11:27:16 -0700
From: Michael Madigan <madigan@rohan.sdsu.edu>
Subject: Help! cgi and system() failure
Message-Id: <3741B104.2F08@rohan.sdsu.edu>

If anyone has seen something similar to this please help me out.  

I am trying to make a call from a perl cgi script:
 	system("runscript"); 
to run a perl script on my server.  It runs fine from the command line
but not when invoked through a browser.  I have tried different quotes,
back quotes, exec().  All the permissions are 0777 for "runscript".  The
directory permissions are 0711 and the cgi permissions are 0755, these
are the system defaults.  My only guess is the browser is not allowed to
execute a script on the server through a system() call.

If anyone has any insight, it would be greatly appreciated.
Mike Madigan
madigan@rohan.sdsu.edu


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

Date: Tue, 18 May 1999 11:44:50 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: How to create modules?
Message-Id: <3741B522.F89D602A@mail.cor.epa.gov>

Ron Frazier wrote:
> 
> How do I create and use modules? Say I have a function called Test() that I
> want to put in another file (we'll call it subs.pm). Then I want to use the
> Test() function is testing.pl. How do I define everything (in both the
> subs.pm and the testing.pl files).

Jonathan already gave an informative response, making the 
assumption that you really meant `module'.  But your description
sounds more like you just want to be able to include some
external code.  You might want to look at the docs for 'do'
and see if that does what you want.. before you spend time
putting it in a module.
 
> Thanks to anyone who can help. If you dont mind, please email me your
> response.

I've decided to live by the immortal words of Bob Trieger:
"Sorry.  Post here, get mocked here."  :-)

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Tue, 18 May 1999 13:35:15 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: How to create modules?
Message-Id: <x3ywvy6uvqk.fsf@tigre.matrox.com>


"Ron Frazier" <ldkronos@umd.umich.edu> writes:

> How do I create and use modules? 

Start off by reading:

	- perlmod
	- perlmodlib

If you still have more questions, then post again.

HTH,
Ala



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

Date: Wed, 12 May 1999 09:22:48 GMT
From: ryanngi@hotmail.com (Ryan Ngi)
Subject: How to get the infomation of a variable if it is scalar or integer?
Message-Id: <35581412.16313042@news.inet.co.th>

How to get the infomation of a variable if it is scalar or integer? 



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

Date: Tue, 18 May 1999 10:30:01 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: How to move a directory?
Message-Id: <9htrh7.2da.ln@magna.metronet.com>

Jalil Feghhi (jalil@corp.home.net) wrote:
: Is there a function for moving directories in Perl?


   Yes. The same one that moves files.


      perldoc -f rename


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


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

Date: Tue, 18 May 1999 12:04:07 -0700
From: Mark Ginsburg <ginsburg@haas.berkeley.edu>
Subject: How to override HTTP_USER_AGENT when using libwww-perl?
Message-Id: <3741B9A7.3A403345@haas.berkeley.edu>


Hi,

how do I override the HTTP_USER_AGENT = AgentName/0.1
libwww-perl/5.33<BR>
entry when I use the libwww-perl package?

I would like to substitute arbitrary other values for HTTP_USER_AGENT as
I am
doing various experiments with ad-content analysis and filtering.

I find that when certain servers detect the libwww-perl/5.33
HTTP_USER_AGENT value,
they do not furnish me with all of their ads as they know they are
dealing with a "robot".

I tried just hardcoding this variable before the I did the method
request, but the package
still puts its own value there as I verify when I do a GET or a POST to
a script which dumps
out all the HTTP ENV Vars.

Thanks.


Mark

--
*******************************
Mark Ginsburg, Ph.D.  Fisher Center,
Haas School of Business,
UC Berkeley, F432 MC1930
Berkeley, CA 94720
Tel (510) 643-0625 Fax (510) 642-2826
Ginsburg@haas.berkeley.edu
********************************




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

Date: Tue, 18 May 1999 18:43:28 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: negative subscripts
Message-Id: <3741b47f.871055@news.skynet.be>

Jonathan Stowe wrote:

>Perhaps but the behaviour is only documented for values of 0 and 1 and
>fiddling with this is highly deprecated anyhow - therefore I dont think
>you are going to get much sympathy if it starts to behave in a peculiar
>manner.

In that case, the "nice thing" for Perl to do, would be to give a
warning whenever anybody sets $[ to a negative value.

This can be patched by tying $[ to some package, I assume?

	Bart.


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

Date: 18 May 1999 19:42:41 GMT
From: vaughan@itdc.edu (Tom Vaughan)
Subject: Re: negative subscripts
Message-Id: <7hsfrh$3fb$1@malgudi.oar.net>

Jonathan Stowe (gellyfish@gellyfish.com) wrote:
: Thomas Wade Vaughan <vaughan@well.com> wrote:
: > J|rgen Exner (juex@my-dejanews.com) wrote:
: > : Thomas Wade Vaughan <vaughan@well.com> wrote in message
: > : news:7hpojf$3v0$1@its.hooked.net...
: > : > A co-worker wanted to know if we could start the index of an array
: > : > with a negative value. Initially I said no, but later thought of
: > 
: > : Use a hash instead.
: > : A hash is functionally the same as an array, except that the domain is not
: > : fixed to a continous subset of the natural numbers starting at 0.
: > 
: > Doesn't the $[ variable change where the index begins? It seemed to until
: > I iterated with a for loop.
: > 

: Perhaps but the behaviour is only documented for values of 0 and 1 and
: fiddling with this is highly deprecated anyhow - therefore I dont think
: you are going to get much sympathy if it starts to behave in a peculiar
: manner.

I agree that it should not be used, but a coworker had a "need" to do it and
I suggested both the hash and the offset method to normalize a negative subscript
to a 0 based index. I was just curious because originally it seemed to work 
when I changed the $[ variable to a -5 value. I think I will return to my first
answer and say it can't be done without a hash or a way to normailize the index to
a zero based value.

Tom


: /J\
: -- 
: Jonathan Stowe <jns@gellyfish.com>



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

Date: 18 May 1999 19:44:37 GMT
From: vaughan@itdc.edu (Tom Vaughan)
Subject: Re: negative subscripts
Message-Id: <7hsfv5$3fb$2@malgudi.oar.net>

Bart Lateur (bart.lateur@skynet.be) wrote:
: Jonathan Stowe wrote:

: >Perhaps but the behaviour is only documented for values of 0 and 1 and
: >fiddling with this is highly deprecated anyhow - therefore I dont think
: >you are going to get much sympathy if it starts to behave in a peculiar
: >manner.

: In that case, the "nice thing" for Perl to do, would be to give a
: warning whenever anybody sets $[ to a negative value.

I agree that it should be bound to 0 or 1 only. Just thought it would be
interesting to see if anyone else had seen this before.

Tom


: This can be patched by tying $[ to some package, I assume?

: 	Bart.


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

Date: Tue, 18 May 1999 18:03:04 GMT
From: Gareth Rees <garethr@cre.canon.co.uk>
Subject: Re: Perl "constructors"
Message-Id: <si1zgefe7b.fsf@cre.canon.co.uk>

John Porter <jdporter@min.net> wrote:
> even if Perl did add support for overloading

Perl already has support for overloading.  Use the CPAN module
Class::Multimethods.

-- 
Gareth Rees


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

Date: 18 May 1999 12:10:08 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: PERLFUNC: opendir - open a directory
Message-Id: <3741ad00@cs.colorado.edu>

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

In comp.lang.perl.misc, ada@fc.hp.com (Andrew Allen) writes:
:Tom Christiansen (perlfaq-suggestions@perl.com) wrote:
:: DIRHANDLEs have their own namespace separate from
::     FILEHANDLEs.
:
:This sentence has always made me curious: how would I implement a
:class of variables in my own "namespace"? 

It just means that a sub name FOO is different from a file handle named
FOO which is different from a format named FOO which is different from
a directory handle named FOO, etc.  There are still only six type pointers
in the glob, though.  The IO bifurcates later.  

:Can it be done from pure
:perl? *myvar{FOO}=\$a; gives a syntax error.
:
:Also, is there a *myvar{THING} syntax to access dirhandles?

No.  It's a botched thing.  Sorry.

--tom
-- 
Travel important today; Internal Revenue men arrive tomorrow.


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

Date: Wed, 12 May 1999 11:28:54 GMT
From: ryanngi@hotmail.com (Ryan Ngi)
Subject: Problem With Scope
Message-Id: <355831e2.911704@news.inet.co.th>

$x = 5

sub{
	my($x)=3;
	$y= ..... # how to assign y to the global $x, not the my($x)
}

!?


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

Date: 18 May 1999 18:39:52 GMT
From: John Callender <jbc@shell2.la.best.com>
Subject: Re: Protecting perl source code
Message-Id: <3741b3f8$0$213@nntp1.ba.best.com>

It occurs to me that if someone just wrote an obfuscator that ROT13'd
all the user-defined variable and subroutine names, deleted all the
comments, and squashed all the whitespace outside of quoted strings,
you could just point these people to it and stop waging the eternal
battle of trying to convince people that they shouldn't hide their
code.

This would do very little to thwart a determined person, but it would
be sufficiently annoying, I would think, to satisfy many of these
folks.

This, I take it, is one of those areas where my lack of a proper
background in professional-type programming is blinding me to the
deeper issues involved. *sigh* Perhaps I'll understand some day.

-- 
John Callender
jbc@west.net
http://www.west.net/~jbc/


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

Date: Tue, 18 May 1999 18:48:48 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Protecting perl source code
Message-Id: <3743b5d4.1212194@news.skynet.be>

Doug Seay wrote:

>Tell your boss to fire your sysadmin and hire a good replacement.  He is
>obviously unqualified for his job since he didn't install the online
>docs that came with the distribution.  I'm assuming that if you had the
>docs, you would have read them.  This is a good assumption, isn't it?

Actually, I think that technically this is a good sysadmin, if he's
capable of installing Perl without the docs.

I think it's more likely they were deleted after the installation.

	Bart.


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

Date: 18 May 1999 13:34:54 -0600
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: Protecting perl source code
Message-Id: <m3wvy6i335.fsf@moiraine.dimensional.com>

John Callender <jbc@shell2.la.best.com> writes:

> It occurs to me that if someone just wrote an obfuscator that ROT13'd
> all the user-defined variable and subroutine names, deleted all the
> comments, and squashed all the whitespace outside of quoted strings,
> you could just point these people to it and stop waging the eternal
> battle of trying to convince people that they shouldn't hide their
> code.

This is one of those things that is very much easier said than
done.

First, stripping comments from a perl program is not a trivial
task.  You need to be able to deal with code like this-

  my @a;           # this is a comment
  $#a = 1 << 15;
  # more code, presumably populating @a

  for (my $i = 0; $i < $#a; $i++) {
    $a[$i] = s#^\s+##;     # lose leading white space
    $a[$i] = s|\s+$ (?#      no trailing whitespace
                             and this is still a comment)||x;
    $# = '%.5f';
    # this really is a comment :-)
  }

Second, munging names can have seriously deleterious effects
on your program.  Consider-

  sub AUTOLOAD {
    my $called_name = $::AUTOLOAD;
    $called_name =~ s/(.*)(?=::)/$lookup{$1}/;
    goto &$called_name;
  }

In this example you are explicitly dependent upon the
actual string that the function was called using.  Munging
a program that has this will break very badly unless you take
extreme care while doing so to make sure that the keys in the
lookup table get munged correctly.  Of course, you don't want
to do that because hash keys are merely (usually implicitly) 
quoted strings and you don't want to go changing the contents of 
your string constants.

We still haven't considered the possible effect of this on
programs that C<use fields;>, programs that rely on symbolic
references, or programs directly manipulating the various
symbol tables at runtime.

You'll need a full blown perl parser to do this, and thus far
the only perl parser available is in perl5.*\.tar\.gz (ignoring
flea bitten carcasses for the moment :-)

> This, I take it, is one of those areas where my lack of a proper
> background in professional-type programming is blinding me to the
> deeper issues involved. *sigh* Perhaps I'll understand some day.

The only thing you are misunderstanding is the inherent difficulty of
what you are suggesting.  The only ways I can think of to do what you
are suggesting reliably are-

  0)  Write some XS code that will let you get at the parser.  This
      would be for too difficult for the vast (say, 99.7%) majority
      of perl programmers.
  1)  Yank the lexer and parser out of perl and build a standalone app
      with the desired functionality.  This is probably a little
      bit easier up front than writing the XS code, but faces real
      problems as to how to target different versions of perl (with
      parsers that are subtly different).
  2)  Remimplement the perl lexer and parser, perhaps even in perl.
      This isn't any easier, but at least it has the benefit that
      most perl programmers would be able to read the code and
      figure out how it works.

The real problem is that the people who want this and
the people competent to implement it are disjoint groups.
When you want it you're not good enough to have it, when
you're good enough to have it you don't want it anymore.

dgris
-- 
Daniel Grisinger          dgris@moiraine.dimensional.com
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print 
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'


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

Date: Tue, 18 May 1999 13:20:29 -0500
From: "Wassim Metallaoui" <wassimk@iname.com>
Subject: Re: Removing Data from the File
Message-Id: <3741b035.0@wznews.webzone.net>

Thank you for your help I know understand how it is removed....
Also I cleaned the code up a little bit... Tell me if this looks any better:


sub unsubscribe {
if (&checkaddress($INPUT{'email'}) == 1)
 {
  open (EMAILS, "<$listdir/emails.txt"); #opens the file to read only
     if ($LOCK_EX)


        flock(EMAILS, $LOCK_EX);
  }

     @email_array = <EMAILS>;  #puts each line in the array
     close(EMAILS);


open (EMAILS, ">$listdir/emails.txt");  #opens the file for a complete
rewrite
    if ($LOCK_EX)


   flock(EMAILS, $LOCK_EX);
    }
    chomp($lines);

    foreach $lines (@email_array)


    $INPUT{'email'} =~ tr/A-Z/a-z/;
   $lines =~ tr/A-Z/a-z/;

   if ($lines eq $INPUT{'email'})


    $title = "Removed Successfully";
    $message = "You have been successfully removed from the $companyname
mailing list! If you are having trouble with this program then please <a
href=\"mailto:$youremail\" target=\"_top\">$yourname</a>, for some
support.";
    &success;
       $found = 1;

    open (MAIL, "|$mailprog -t") || print "Can't start mail program!";
     print MAIL "To: $INPUT{'email'}\n";
          print MAIL "From: $youremail\n";
     print MAIL "Subject: Removed Successfully!\n\n";

     print MAIL "This message is to confirm the removal of your\n";
        print MAIL "email address: $INPUT{'email'} from the $yourcompany\n";
        print MAIL "mailing list.\n";
     print MAIL "\n";
        print MAIL "If you feel you have received this notice an error,\n";
        print MAIL "please visit $yourcompany to add yourself again, \n";
        print MAIL "our URL is: $websiteurl\n";
     print MAIL "\n\n";
        print MAIL "Thank you,\n\n";
        print MAIL "$yourname\n";
     print MAIL "$yourcompany\n\n";

    close (MAIL);
    }

  else
   {
       print DAT "$lines\n";
    }
    }
close(EMAILS);

    #Now that we have stepped through the file, close the file and check
    #to see if the input email was found.
    unless($found) {
      $title = "Not Found";
      $message = "The address: $INPUT{'email'} is currently not listed in
our mailing list database! If you are having trouble with this program then
please <a href=\"mailto:$youremail\" target=\"_top\">$yourname</a>, for some
support.";
      &success;
        }
  }

    else       {
         $title = "Not Valid";
      $message = "Your e-mail: $INPUT{'email'} was not a valid e-mail
address.  If you are having trouble with this program then please <a
href=\"mailto:$youremail\" target=\"_top\">$yourname</a>, for some
support.";
      &success;
       }

exit;
}




Stephen Warren <swarren@www.wwwdotorg.org> wrote in message
news:7hru2r$1lp$1@owl.slip.net...
> Wassim Metallaoui <wassimk@iname.com> wrote in message
> news:3740e732.0@wznews.webzone.net...
> > Can someone please explain some of this too me.. . I am trying to remove
> the
>
> Re-indented for clarity. Comments moved to avoid wrapping...
>
> > sub unsubscribe {
> >
> > # routine that makes sure its an okay e-mail address to use.
> > # if its not okay then it will exit and tell me
> > &checkaddress;
> >
> > # opens the database file, each line is an e-mail address
> > open (DAT,"$listdir/emails.txt");
>
> Add: || die "Can't open '$listdir/emails.txt' for reading: $!" ;
>
> > # just locks the file
> > if ($LOCK_EX){ flock(DAT, $LOCK_EX); }
> > # puts everything into an array
> > @database_array = <DAT>;
> > close(DAT);  #closes the file
> >
> > #standard html header
> > print "Content-type: text/html\n\n";
> >
> > #opens the file again
> > open (DAT,"<$listdir/emails.txt");
> > # locks it
> > if ($LOCK_EX){ flock(DAT, $LOCK_EX); }
>
> One wonders why - you don't read from it again.
> If you do keep this, you should add the '|| die' part here too.
>
> > #defines the lines from the database array
> > foreach $lines(@database_array) {
> >    # chops off the end character on the lines
> >    chomp($lines);
>
> End of line characters!
>
> >    # e-mail inputted from the web
> >    $email = $INPUT{'email'};
>
> Why not do this outside the loop?
>
> >    # changes all of the lines contents from
> >    $lines =~ tr/A-Z/a-z/;
> >    uppercase to lowercase
>
> One might consider storing the email addresses in the file in lower case
so
> that this wasn't required each time.
>
> >    #  changes all of the e-mails contents from uppercase to lowercase
> >    $email =~ tr/A-Z/a-z/;
>
> Again, this should be done outside the loop.
>
> >    # if the database has the e-mail in it then tell me so and move on
> >    if ($lines eq $email)
>
> >       # tell me whats going on
> >       print "removed successfully";
> >       # close the data file
> >       close (DAT);
>
> Never used it!
>
> >       # opens file with write permissions
> >       open (DAT,">$listdir/emails.txt");
>
> More like opens file for writing *if* you have write permissions.
>
> Again, you need to add '|| die' part here. (Or some error checking)
>
> >       # locks it
> >       if ($LOCK_EX){ flock(DAT, $LOCK_EX); }
> >          # defines the lines in the array
> >          foreach $lines(@database_array) {
>
> *Reads* not defines the lines. You're using the same variable name as your
> outer loop which probably isn't a good idea.
>
> One might also name your variable as a non-plural name - $lines actual
> contains one line, not multiple lines.
>
> >             # chops of the ends of the lines
> >             chomp($lines);
> >
> >             # the e-mail from the we
> >             $email = $INPUT{'email'};
>
> You already have this.
>
> >             # converts uppercase to lower
> >             $lines =~ tr/A-Z/a-z/;
> >             # converts uppercase to lower
> >             $email =~ tr/A-Z/a-z/;
>
> You already did this.
>
> >             # if the email is not in the database then there is nothing
to
> remove
> >             if ($lines ne $email) {
> >                print DAT "$lines\n";   #so put everything back in
>
> The bit you're looking for is here. A line gets written back to the file
if
> it isn't (case-insensitive)-equal to the email from the form.
>
> >             }
> >          }
> >          # close the file
> >          close (DAT);
> >
> >          # exit the script
> >          exit;
> >       }
> >    }
> >    # tell me I am not in it...
> >    print "Your not in the database";
>
> You're
>
> >    # close something again..
> >    close (DAT);
> >    # exit the script
> >    exit;
> >
> > } #closes the sub
>
> I don't think the braces match unless I mis-interpreted your code...
>
> This seems an extremely convoluted way of doing things. A better way would
> be something more like:
>
> Open original for reading/writing
> Open temp file for writing
> foreach line in the file
> {
>    if the line doesn't match the email
>       write to output file
> }
> close writing file
> seek back to beginning of reading file
> open temp file for reading
> foreach line of temp file
>    write to original file
> close temp file
> close original file
>
> With the appropriate locking. This way you're guaranteed a backup copy in
> the event of a crash. It also separates out the algorithm from nested
loops.
>
> --
> Stephen Warren, Snr Systems Engineer, Technology House, San Francisco
> mailto:swarren@techhouse.com                http://www.techhouse.com/
> mailto:swarren@wwwdotorg.org                http://www.wwwdotorg.org/
>               MIME, S/MIME and HTML mail are acceptable
>
>
>




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

Date: 18 May 1999 18:51:10 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Sorting is too slow for finding top N keys... - UPDATE
Message-Id: <7hscqu$rt8$1@pegasus.csx.cam.ac.uk>

In article <37413c59.990407@news.skynet.be>,
Bart Lateur <bart.lateur@skynet.be> wrote:
>M.J.T. Guy wrote:
>
>>More careful implementations, such as Tom's, divide into three parts,
>>below, equal and above.    The equal values won't need to be processed
>>again, so cases like Michel's become *very* fast to sort as you can see.
>>
>>I strongly recommend having a look at Tom's code, which can be found
>>near the end of the pp_ctl.c file in the Perl distribution.    It's an
>>excellent demonstration of how quicksort should be coded, and also
>>(unlike most of the Perl source :-() an excellent demonstration of clear
>>commenting of C code.
>
>What are you saying? That there's a smarter quicksort (for the
>pathological case) part of Perl's source, but it's not used in the final
>binary?

Eh?  How did you read that into what I said?  I never mention binaries.

And I should point out that while improving performance in pathological
cases was a bonus, the real reason for overriding the platform qsort
was that they had a nasty habit of going SEGV if supplied with an
invalid comparison subroutine.


Mike Guy


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

Date: Tue, 18 May 1999 19:39:43 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Sorting is too slow for finding top N keys... - UPDATE
Message-Id: <3742c1c5.2236106@news.skynet.be>

M.J.T. Guy wrote:

>Eh?  How did you read that into what I said?

I understood what you wrote as: "Look at the source for Perl. It
contains a better version than what Perl currently uses."

	Bart.


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

Date: Tue, 18 May 1999 12:58:40 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Sorting is too slow for finding top N keys... - UPDATE
Message-Id: <3741C670.25CE1CA2@mail.cor.epa.gov>

Bart Lateur wrote:
> 
> M.J.T. Guy wrote:
> 
> >Eh?  How did you read that into what I said?
> 
> I understood what you wrote as: "Look at the source for Perl. It
> contains a better version than what Perl currently uses."

I understood what he wrote as:
                                  "Look at the source for Perl. It
  contains a better version than what [1]  currently uses."
where [1] is your OS, for some values of OS.

Bart, stop trying to confuse me!  :-)
 
David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Tue, 18 May 1999 15:46:19 -0400
From: Greg Bartels <gbartels@xli.com>
Subject: Tie Fighter
Message-Id: <3741C38B.10E8BBD9@xli.com>

I have a subroutine which ties a variable passed into it by using $_[0]
to access the actual variable for tying.

sub my_tie{  tie ($_[0], 'package_name');  }

using it looks like this:

my_tie(my $tied_var);

is there a way to do this so that instead of being an input parameter,
it
is a return value? like this:

my $tied_var = my_tie();

in other words, is there a way to directly access the variable that gets
the return value, similar to the way you can directly access the input
parameters?

If anyone could email the answer to me, I'd appreciate it greatly.
a network failure here at work has inadvertantly created a firewall, 
and the only thing that can get in is email. I had to borrow a machine
to post this message.

Thanks much.

gbartels@xli.com

"I dont know, fly casual"


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

Date: Tue, 18 May 1999 10:28:32 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: what's wrong with my head(er)...?
Message-Id: <getrh7.2da.ln@magna.metronet.com>

brent (simp@mail.utexas.edu) wrote:
: admitted newbie has following headache --

: When I debug it from
: the command line it keeps closing the <body> & <html> tags before putting
: any of my content in ... what up with that?


   Buffering.


: Any advice would be greatly appreciated ...


   Perl FAQ, part 5:

      "How do I flush/unbuffer an output filehandle?  Why must I do this?"


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


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

Date: 18 May 1999 19:29:35 GMT
From: "T. Bossert" <th.bossert@z.zgs.de>
Subject: Why does a perl cgi-script 'hang'
Message-Id: <3741BF92.AB728632@z.zgs.de>

Hi,

What's wrong, if a perl cgi-script only starts running after the
'stop'-button of the browser has been hit, the html-part however, if
started as whatever.html, works just fine ?

e.g.
the perl-script
 ---- snip
print "Content-Type: text/html\n\n";
print <<html_block;
<html>
<body>
<EMBED
                  ..... follows specs for a java-plugin-'embed-tag'
>
<NOEMBED></NOEMBED>
</EMBED>
</body>
</html>
html_block
exit(0);
 ---- snip
doesn't start until 'stop' has been hit - if the source is then checked
( browser ) everything looks fine ( and may be use as 'html-file' ).
the 'html_block' only - saved as html - works like a charm.
BTW: It doesn't make a difference if I 'print' every line or if I 'use
CGI' for the standard html-part.

Thomas




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

Date: Tue, 18 May 1999 15:58:24 -0400
From: Steve Farris <nlymbo@mindspring.com>
Subject: XML::XQL
Message-Id: <3741C660.258048D7@mindspring.com>

Does anyone have some code samples using the XML::XQL module. 
Having trouble building queries and accessing element contents.
Thanks!


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

Date: 18 May 1999 12:22:33 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Y2K.  localtime(time)
Message-Id: <3741afe9@cs.colorado.edu>

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

In comp.lang.perl.misc, 
    Eric Bohlman <ebohlman@netcom.com> writes:
:I'd really like to know *why* so many people have a mental block about 
:this.  

Because they can't fricking read, and even if they can, it never occrus
to them to try.  It's the Microsoft way.  The gulf between the classes
(those who read, those who don't) continues to broaden.  Just be glad
you're not in the post-literate majority.

--tom
-- 
"If Dennis Ritchie were the man who developed Modula-2 then C would be long forgotten."
    --Tarjei Jensen


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

Date: 18 May 1999 18:38:13 GMT
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Y2K.  localtime(time)
Message-Id: <slrn7k3d1q.rn4.fl_aggie@thepentagon.com>

On Tue, 18 May 1999 16:05:07 GMT, Eric Bohlman <ebohlman@netcom.com>, in
<ebohlmanFBxrCJ.BrF@netcom.com> wrote:

+ I'd really like to know *why* so many people have a mental block about 
+ this.

Because they think they know what they're doing, and run a test.
When it spits back 100 (and not 0 or 2000), they become alarmed
that it isn't behaving _as expected_, and that therefore there 
*must* be a hideous Y2K bug in perl...

+ The description in localtime()'s documentation leaves not the 
+ slightest room for interpretation, but for a lot of people it goes in one 
+ eye and out the other.

Probably because the doc set wasn't consulted, ever. Not only is it
documented in 'perldoc -f localtime', its also documented in 'man
localtime', which is the system library man page.

Perl's localtime gets its information from the underlying system. If
you really do have a Y2K problem in a perl script, the odds are very
good that you have a Y2K problem in your OS...

James - it remains unknown if there is any hideous Y2K bug in perl4...


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

Date: 12 Dec 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 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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

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