[17163] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4575 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 10 21:05:54 2000

Date: Tue, 10 Oct 2000 18:05:14 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <971226314-v9-i4575@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 10 Oct 2000     Volume: 9 Number: 4575

Today's topics:
        ActivePerl vs. IndigoPerl <fschmuck@chartertn.net>
    Re: CGI::Push <jeff@vpservices.com>
    Re: Counter Problems <vf1@smarts.com>
    Re: database accessing <lr@hpl.hp.com>
    Re: Deleting named files? (Mark-Jason Dominus)
    Re: Deleting named files? <longusername@NOSPAMhotmail.com>
    Re: Deleting named files? <tony_curtis32@yahoo.com>
    Re: Deleting named files? <longusername@NOSPAMhotmail.com>
    Re: factorial function problem (Mark-Jason Dominus)
        Help: system() returns odd values after normal >>= 8 <haertig@avaya.com>
        included files: really confused, and perldoc doesn't he <mcdonabNO@SPAMyahoo.com>
        Keeping data structures private. 13_hellfish@my-deja.com
    Re: Keeping data structures private. (Chris Fedde)
        Newbie LWP question:  what's wrong with this POST line? <davesisk@ipass.net>
    Re: Newbie LWP question:  what's wrong with this POST l <jeffp@crusoe.net>
    Re: Number of matches <lr@hpl.hp.com>
        pattern matching help ( ~s/// ) <kf4dmb@net-magic.net>
    Re: pattern matching help ( ~s/// ) <jeffp@crusoe.net>
    Re: pattern matching help ( ~s/// ) <juex@deja.com>
    Re: pattern matching help ( ~s/// ) <jeff@vpservices.com>
    Re: Perl Books! (Ilya Zakharevich)
    Re: perl resource (Martien Verbruggen)
    Re: Printing HTML form using CGI.pl <flavell@mail.cern.ch>
    Re: processing a file several times <lr@hpl.hp.com>
    Re: processing a file several times <brondsem@my-deja.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Tue, 10 Oct 2000 20:27:30 -0400
From: "Frank J. Schmuck" <fschmuck@chartertn.net>
Subject: ActivePerl vs. IndigoPerl
Message-Id: <39e3b38e_1@news.chartertn.net>

In the W2k environment which is "better" as a learning environment?  How
much of a bonus is the integration of Apache?  I thought Apache was a Linux
app?

Thanks
Frank




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

Date: Tue, 10 Oct 2000 15:11:38 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: CGI::Push
Message-Id: <39E3941A.F767C724@vpservices.com>

Troy Rasiah wrote:
> 
> > Internet Explorer does not support Push.
> >
> 
> dang..thats what i thought! hehe
> anyone know if they plan on supporting it in the near future?

I think it is the next project on their list after they complete the
construction of www.hellfreezesover.com.

-- 
Jeff


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

Date: Tue, 10 Oct 2000 18:06:19 -0400
From: "Victor Felix" <vf1@smarts.com>
Subject: Re: Counter Problems
Message-Id: <8s03sq$4f0$1@versa.smarts.com>


"Surani, Alykhan" <asurani@nortelnetworks.com> wrote in message
news:8rvt2o$mao$1@bcrkh13.ca.nortel.com...
> Hello,
>
> I am trying to install a cgi/perl counter on my page but I'm having some
> trouble.
> I uploaded the script to my cgi-bin and on the page I put the following:
>
> <!--#exec cgi="/mtx-cgi/asurani/mcount.cgi" -- >
>
> Does anyone know why this may not be working?
>
> Thanks in advance,
> Aly
>
>

This is an example of a server-side include (SSI). Is your web server
configured correctly to interpret the file? It would be helpful if you could
provide some more information and symptoms. What is it that you see when you
attempt to load the page?

-Victor




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

Date: Tue, 10 Oct 2000 15:02:27 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: database accessing
Message-Id: <MPG.144d31c92dd73a398ae1b@nntp.hpl.hp.com>

In article <39E092F0.4691E742@his.com> on Sun, 08 Oct 2000 11:29:52 -
0400, Steve Palincsar <palincss@his.com> says...
> Larry Rosler wrote:
> > 
> > In article <39D501D8.64B7@courrier.usherb.ca> on Fri, 29 Sep 2000
> > 16:55:53 -0400, jtjohnston <jtjohnston@courrier.usherb.ca> says...
> > 
> > ...
> > 
> > > I have a database file that looks like:
> > >
> > >         --- Snip -----
> > >         John:5:
> > >         Gail:3:
> > >         Dave:3:
> > >         --- Snip -----
> 
> > Just hope your system doesn't crash during the subsequent write, or bye-
> > bye, data!  The proper way to update a file is described in perlfaq5.
> > In a high-volume environment, you would also need to worry about file
> > locking to prevent simultaneous-access disasters.
> 
> Of course, a "database" like this has no place in a high-volume
> environment in the first place, does it?  I would think this would be
> much better implemented either as a DBM file or as a table in an RDBMS.

Why do you think that?

As the second half of my last sentence shows, 'high-volume' refers to 
the number of accesses, not to the size of the data file.  Reading and 
rewriting a 'smallish' flat file is far more efficient than using a DBM 
file or an RDBMS.

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


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

Date: Tue, 10 Oct 2000 22:07:21 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Deleting named files?
Message-Id: <39e39319.9eb$1d6@news.op.net>
Keywords: Delaney, daisy, subvert, threshold


In article <8rvp1f$it7vq$1@ID-34145.news.cis.dfn.de>,
CrinkleFish <longusername@NOSPAMhotmail.com> wrote:
>Whenever I do
>    unlink "test";
>it deletes the file.
>
>Whenever I do
>    $file = "test";
>    unlink $file;
>nothing happens.

I have a very strong sense that this is not actually the code that you
are having a problem with, but instead some other code that you made
up.  Unless you show the real code, there isn't a chance that anyone
will be able to help you.


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

Date: Wed, 11 Oct 2000 00:26:18 +0100
From: "CrinkleFish" <longusername@NOSPAMhotmail.com>
Subject: Re: Deleting named files?
Message-Id: <8s08e7$j4ugl$1@ID-34145.news.cis.dfn.de>


Mark-Jason Dominus <mjd@plover.com> wrote in message news:39e39319.9eb$1d6@news.op.net...
>
> In article <8rvp1f$it7vq$1@ID-34145.news.cis.dfn.de>,
> CrinkleFish <longusername@NOSPAMhotmail.com> wrote:
> >Whenever I do
> >    unlink "test";
> >it deletes the file.
> >
> >Whenever I do
> >    $file = "test";
> >    unlink $file;
> >nothing happens.
>
> I have a very strong sense that this is not actually the code that you
> are having a problem with, but instead some other code that you made
> up.  Unless you show the real code, there isn't a chance that anyone
> will be able to help you.

OK, fair point.
Here it is.
I run the program, I key in the word test, I get out the words just unlinked test.
The file named test remains in existence.
No comprende. A large tumescence is developing on my head.

#!/usr/local/bin/perl
#gcsepe.css
foreach (<STDIN>) {
#open (FILE, $_);
#open (OFILE, ">ofile.$_");
#foreach (<FILE>) {
#    s/gcsepe.css/GCSEPE.css/;
#    print OFILE;
#}
#close OFILE;
$file = $_;
#$nfile = "ofile.$_";
unlink $file;
print "just unlinked $file";
#rename $nfile, $file;
#print $nfile;
#print $file;
}





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

Date: 10 Oct 2000 18:29:15 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Deleting named files?
Message-Id: <878zrw46no.fsf@limey.hpcc.uh.edu>

>> On Wed, 11 Oct 2000 00:26:18 +0100,
>> "CrinkleFish" <longusername@NOSPAMhotmail.com> said:

> OK, fair point.  Here it is.  I run the program, I key
> in the word test, I get out the words just unlinked
> test.  The file named test remains in existence.  No
> comprende. A large tumescence is developing on my head.

> #!/usr/local/bin/perl

 .../perl -w
use strict;

> foreach (<STDIN>) {
> $file = $_;

Ahh, oiies kloa.

Try putting the line

    print "FILE IS <$file>\n";

at this point.  Note the position of ">", then

    perldoc -f chomp

hth
t
-- 
Namaste!
And an "oogabooga" to you too!
                                         -- Homer Simpson


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

Date: Wed, 11 Oct 2000 01:09:22 +0100
From: "CrinkleFish" <longusername@NOSPAMhotmail.com>
Subject: Re: Deleting named files?
Message-Id: <8s0auv$it0b3$1@ID-34145.news.cis.dfn.de>

Thank you Tony. Are you that famous actor guy. Chomp , chomp.

--
Your most humble servant,

CrinkleFish




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

Date: Wed, 11 Oct 2000 00:09:10 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: factorial function problem
Message-Id: <39e3afa5.de8$b5@news.op.net>

In article <8FC99ABB8indigodimcom@166.93.207.145>,
Tim <SPAM+indigo@dimensional.com> wrote:
>My take is the books are trying to teach recursion to an
>audience who isn't ready for a real recursion problem.

Could be.


>Wait until you get into tree structures before you throw recursion
>out there.

Fibonacci numbers are a reasonable and very simple application of recursion:

        sub fib {
          my $n = shift;
          return $n if $n < 2;
          fib($n-1) + fib($n-2);
        }

The Towers of Hanoi puzzle is also a good example.

You can solve both of these without recursion, of course.  But it
requires ingenuity, whereas the recursive solutions are trivial.



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

Date: Tue, 10 Oct 2000 16:00:40 -0600
From: David Haertig <haertig@avaya.com>
Subject: Help: system() returns odd values after normal >>= 8
Message-Id: <39E39188.3E814118@avaya.com>

Hi -

The problem:

$ret = 0xffff & system("echo hello");
$ret >>= 8;
print "Return value = $ret\n";

 ... outputs "Return value = 255" in a program we are trying to debug.

Modifying the system call to "echo hello >/tmp/output" shows
that the echo command is indeed working, but still returns
that unusual exit value.  Furthermore, modifying the system
call to "echo hello; echo $? >/tmp/moreoutput" puts a -1
in the "moreoutput" file.  So it's not just PERL that thinks
the exit value is funky.

Every attempt to recreate this problem outside of the program
it is actually failing in has resulting in normal behavior,
i.e., the exit value is 0.  It's only in that one program
that it fails.  We've tried emulating the environment of
the one failing program 100% as far as we can tell (invoking
it via cron, in the background, etc.)  But all of our test
programs work exactly as we expect them to and do not recreate
the problem.  Of course this is a large complex system written
by somebody else who is unavailable.  That large program is
not really trying to "echo hello" (obviously) ... we just patched
that in to simplify the testing.  No matter what command is executed,
we invariably get a 255 return value.  This also holds true
for backticks, qx, etc.  Even when we enclose the system
command in parenthesis (to hopefully force a subshell) we still
get 255 (I would expect to be getting the return value from
the shell, not the command, in that case).

Am I being totally brain-dead here?  Or does this behavior seem
weird to anybody else?  Does anybody have a clue where we should
start looking (that would include a trip to the neurosurgeon, if
the masses diagnose us as brain-dead bozos).

Thanks,
--
Dave Haertig
haertig@avaya.com


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

Date: Tue, 10 Oct 2000 17:10:55 -0700
From: "Brian McDonald" <mcdonabNO@SPAMyahoo.com>
Subject: included files: really confused, and perldoc doesn't help
Message-Id: <ZeOE5.4877$Wq1.1787558@nnrp5-w.sbc.net>


Hi.

I am very confused about how to include a file that contains variable defs
and data structures in a Perl script. I realize that this is a question that
often draws a RTFM response... but I've read the (ActiveState) docs and
still don't understand what to do.

First of all, I don't want to invoke Perl with the -P option so that I can
use a C-style #include statement.

Also, I suspect that using a Perl module is overkill for my objective... but
can't really discern that. Does one create a Perl module in order to include
variable declarations and initializations in a script?

I would really appreciate not getting flamed on this one. I am genuinely
confused on how to proceed with this simple matter.

Brian




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

Date: Tue, 10 Oct 2000 22:22:46 GMT
From: 13_hellfish@my-deja.com
Subject: Keeping data structures private.
Message-Id: <8s04rf$te1$1@nnrp1.deja.com>

How do I keep a data structure private?  I need to access both a hash
and an array in a subroutine.  So, I'm passing references to the
subroutine via \.

Now in the subroute, It's easy to to get at the data, with @$, but I
would like this data read only.  I'm not yet so great of a coder and
would like this extra protection.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 10 Oct 2000 23:38:37 GMT
From: cfedde@u.i.sl3d.com (Chris Fedde)
Subject: Re: Keeping data structures private.
Message-Id: <1MNE5.73$7J6.170610688@news.frii.net>

In article <8s04rf$te1$1@nnrp1.deja.com>,  <13_hellfish@my-deja.com> wrote:
>How do I keep a data structure private?  I need to access both a hash
>and an array in a subroutine.  So, I'm passing references to the
>subroutine via \.
>
>Now in the subroute, It's easy to to get at the data, with @$, but I
>would like this data read only.  I'm not yet so great of a coder and
>would like this extra protection.
>

One way to hide data from the rest of the program is to use the
flyweight pattern.  Put instance hashes into a lexically scoped
array and return blessed scalar refs containing an index into that
array.

    #!/usr/bin/perl

    package fly;
    use warnings;
    use strict;

    our $AUTOLOAD;

    {
	my @instance = ();

	sub new
	{
	    my $i = {};
	    push @instance, $i;
	    my $s = $#instance;
	    return bless \$s, $_[0];
	}

	sub AUTOLOAD
	{
	    my $self = $instance[${$_[0]}];

	    my $name = $AUTOLOAD;
	    $name =~ s/.*://;
	    if (defined $_[1])
	    {
		$self->{$name} = $_[1];
	    }
	    else
	    {
		return $self->{$name};
	    }
	}
    }

    package main;

    my $a = fly->new();
    $a->foo("splat");
    print $a->foo . "\n";

__END__

chris
-- 
    This space intentionally left blank


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

Date: Tue, 10 Oct 2000 23:56:55 GMT
From: "David Sisk" <davesisk@ipass.net>
Subject: Newbie LWP question:  what's wrong with this POST line?
Message-Id: <b1OE5.12747$QB1.2525053@typhoon.southeast.rr.com>

This works:

     my $req = POST 'http://quote.cboe.com/QuoteTable.dat',
                [ TICKER => 'csco', errors => 0 ];


This does not:

    $ticker = em(param('ticker'));
    my $req = POST 'http://quote.cboe.com/QuoteTable.dat',
               [ TICKER => $ticker, errors => 0 ];

What the heck am I doing wrong?  QuoteTable.dat is actually a CGI script
that expects one parameter, TICKER...

Any help appreciated!  Please post or email....

Regards,
Dave





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

Date: Tue, 10 Oct 2000 20:22:39 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Newbie LWP question:  what's wrong with this POST line?
Message-Id: <Pine.GSO.4.21.0010102021220.14163-100000@crusoe.crusoe.net>

[posted & mailed]

On Oct 10, David Sisk said:

>     my $req = POST 'http://quote.cboe.com/QuoteTable.dat',
>                [ TICKER => 'csco', errors => 0 ];
>
>    $ticker = em(param('ticker'));
>    my $req = POST 'http://quote.cboe.com/QuoteTable.dat',
>               [ TICKER => $ticker, errors => 0 ];

You are surrounding the text returned by param('ticker') with <EM> and
</EM> tags (this is assuming you're using CGI.pm's function-oriented
interface).

  $ticker = param('ticker');

should be sufficient.

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/





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

Date: Tue, 10 Oct 2000 16:37:29 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Number of matches
Message-Id: <MPG.144d48177952cb4998ae1c@nntp.hpl.hp.com>

In article <971063245.847539@pizza.crosslink.net> on Sun, 8 Oct 2000 
23:47:03 -0400, Collin Borrlewyn <collin@crosslink.net> says...
> What I'm trying to do is determine how many times a particlar pattern was
> matched in a scalar. ...

> ... I've looked at every bit of
> documentation I can think of, but nothing seems to mention it.

The FAQ is part of the documentation.

perlfaq4: "How can I count the number of occurrences of a substring 
within a string?"

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


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

Date: Tue, 10 Oct 2000 20:38:51 -0400
From: "jim and lois" <kf4dmb@net-magic.net>
Subject: pattern matching help ( ~s/// )
Message-Id: <39e3b80f.0@206.30.194.5>

I would like to replace this sting with this

orginal string    "  t:\test/one/jim.txt "

with                "  t:\test\one\jim.txt "

$string  =  " t:\test/one/jim.txt";
$string  = ~s ///\/ ;

I get errors . what am I doing wrong ?




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

Date: Tue, 10 Oct 2000 20:46:39 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: pattern matching help ( ~s/// )
Message-Id: <Pine.GSO.4.21.0010102042060.14163-100000@crusoe.crusoe.net>

[posted & mailed]

On Oct 10, jim and lois said:

>orginal string    "  t:\test/one/jim.txt "
>
>with                "  t:\test\one\jim.txt "

You'd want one of the following:

  s/\//\\/g;  # EWW MESSY -- lots of slashes...
  s!/!\\!g;   # more bareable
  tr/\//\\/;  # slashing again, ick
  tr!/!\\!;   # nicer, and faster than example #2

>$string  =  " t:\test/one/jim.txt";

In a double-quoted string, "\t" is a tab.  Perhaps you meant:

  $string = 't:\test/one/jim.txt';

>$string  = ~s ///\/ ;

Well, you have to \ the the / in the left-hand side of s///, and you need
to \ the \ in the right-hand side, to make it look like

  s/\//\\/g;

And you need that 'g' at the end to signify global substitutions.  But
even if you do that, you're mis-using the =~ operator.  =~ is ONE "unit",
so to speak.  The two statements that follow have ENTIRELY different
meanings:

  $string =~ s/foo/bar/;
  $string = ~ s/foo/bar/;

The first will change the first occurrence of 'foo' to 'bar' in $string.
The second will set $string equal to the 1's complement of whether or not
s/foo/bar/ was successful.  It's like saying:

  $flip = ($_ =~ s/foo/bar/);
  $string = ~$flip;

That's not what you want.  I suggest you read up on 'perlre' and
'perlretut', standard Perl documentation on regular expressions.

  perldoc perlre
  perldoc perlretut

Look for them online if you don't already have them.

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/





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

Date: Tue, 10 Oct 2000 17:53:40 -0700
From: "Jürgen Exner" <juex@deja.com>
Subject: Re: pattern matching help ( ~s/// )
Message-Id: <39e3ba15@news.microsoft.com>

"jim and lois" <kf4dmb@net-magic.net> wrote in message
news:39e3b80f.0@206.30.194.5...
> $string  =  " t:\test/one/jim.txt";
> $string  = ~s ///\/ ;

Well, let's see:
You are replacing the empty string (as indicated by the two first slashes
"//") with the empty string (as indicated by the second and third slash
"//") and then you have some additional garbage characters (a backslash and
another slash "\/") at the end.
This may not be what you meant to write, but it is what the Perl parser will
see.

1: use a different string separator (not the slash), e.g. a "+". Then you
don't have to escape the actual slash
2: if you want a literal backslash you have to escape it using ..... a
backslash

$string =~ s+/+\\+;

jue




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

Date: Tue, 10 Oct 2000 18:00:24 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: pattern matching help ( ~s/// )
Message-Id: <39E3BBA8.C014CD75@vpservices.com>

jim and lois wrote:
> 
> I would like to replace this sting with this
> 
> orginal string    "  t:\test/one/jim.txt "
> 
> with                "  t:\test\one\jim.txt "
> 
> $string  =  " t:\test/one/jim.txt";
> $string  = ~s ///\/ ;
> 
> I get errors . what am I doing wrong ?

1. There is a problem with *forward* slashes in a regex: is is very hard
to see what is going on because the forward slash is also the character
used to delimit the parts of the regex.  So when a forward slash is part
of the pattern it is better to use alternate delimiters (e.g. an
apostrophe) so you can see what is going on.  These two are exactly the
same (try it and see):

     s/a/b/;   s'a'b';

2. There is a problem with *backward* slashes in a regex: it is used to
escape characters, including itself.  So if you want to print a
backslash you actually have to use two of them.  This prints a single
backslash (try it and see):

    print '\\';

3. If you want something replaced more than once you need to use the 'g'
operator

So let's use apostrophes instead of slashes as delimiters in your
example and put in a double backslash everytime you mean a single
backslash and add a 'g' at the end:

   $string  = ' t:\test/one/jim.txt';
   $string  =~ s'/'\\'g ;

Which, in English, reads: replace each occurrence of a forward slash
with a backward slash.

Clear as mud?

-- 
Jeff


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

Date: 10 Oct 2000 22:17:23 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Perl Books!
Message-Id: <8s04hj$qv2$1@charm.magnus.acs.ohio-state.edu>

[A complimentary Cc of this posting was sent to Mark-Jason Dominus
<mjd@plover.com>],
who wrote in article <39e31663.6998$2e6@news.op.net>:
> >C'mon, and a lot of software packages are marked as "if you open this,
> >you agree to ...".  Whatever the publisher puts after the title page
> >is not binding.
> 
> The federal copyright statutes, however, are binding on people in the
> United States, and other countries have similar laws that apply there.

The purpose of the federal copyright statutes is not to *restrict* the
rights of the readers, it is to *extend* the right of the readers.
The whole point of the Fair Use clause is to make legal what is (was
considered at the time?) moral.

> >You know quite well that in a lot of situations "scanning in text from
> >a book without permission from the publisher" it not only legal, it is
> >moral too.  
> 
> This, however, is clearly not one of those cases.

What is "this"?  I was not discussing the lunacy which started this
thread, but the lunacy that *any* kind of scanning is immoral and illegal.

> >It is not that far from putting it on Internet...
> 
> It is completely different.  In one case you are distributing *copies*
> to everyone in the world.  In the other case you are displaying a
> *single* instance.

> I am amazed that you cannot tell the difference.

I'm amazed that you miss the point that what somebody puts on Internet
is *a single* copy.  All the other copies are created by those who
view them, not by the guy who put it.

It is quite similar to putting an instruction how to blow up the White
House on Internet.  This may be legal.  (Even reading it may be
legal.  ;-)  Implementing this instruction is not legal...

By the nature of US laws, of course it is a judge who decides which
analogy actually holds!  But consider this example:

  Click on the link below to read an online copy of PP III.
  By clicking on this button you agree that you own a legal copy of PP III.

  "I agree"    "I do not agree"

Ilya


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

Date: Tue, 10 Oct 2000 22:16:58 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: perl resource
Message-Id: <slrn8u75ah.8nu.mgjv@verbruggen.comdyn.com.au>

On Tue, 10 Oct 2000 12:13:25 -0400,
	JS/PL <admin@news.dynip.com> wrote:
> Hello,
> I realize this may be pure begging. I have a list of city names which is
> composed of one city per line in a plain text file. There are 42,000 lines
> but many duplicate city names (eg. Waco is entered 22 times on 22 lines
> between Wacissa and Waconia) I know perl is probably a great tool to remove
> all the duplicate names but leaving one name, what I don't have is a script
> to do it. I have almost no knowlege of writing scripts (actually none),
> could someone show me the way to a resource for finding such a script? Thank
> You

Assuming that your file is already sorted, which you seem to indicate,
you can just use uniq, if you're on a *nix system (as others have
suggested. Yet others have suggested that you may not be on a unix
system. I do know you have perl, so a poor man's version of uniq could
be:

# cat uniq.pl
#!/usr/local/bin/perl -n
print unless $o eq $_; 
$o = $_;
# ./uniq.pl data > data.uniq

If your file isn't sorted yet, you should sort it. Even win platforms
have a sort program that will work much better for large files than
perl's internal sort.

For a more elaborate version of uniq, and perl implementations of
other standard Unix tools, see http://language.perl.com/ppt/

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | For heaven's sake, don't TRY to be
Commercial Dynamics Pty. Ltd.   | cynical. It's perfectly easy to be
NSW, Australia                  | cynical.


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

Date: Wed, 11 Oct 2000 00:17:57 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Printing HTML form using CGI.pl
Message-Id: <Pine.GHP.4.21.0010110015110.12746-100000@hpplus03.cern.ch>

On Tue, 10 Oct 2000, Jeff Zucker wrote:

> _Official Guide to Programming with CGI.pm_, page 264:
> 
> "You can even add new HTML tags just by importing them in the use
> statement."

OK, so I should've read the book in addition to searching the
documentation.  c'est la vie.

Anyhow, if this was what our friend was asking, then he has at least
two working answers ;-)

cheers




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

Date: Tue, 10 Oct 2000 16:46:51 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: processing a file several times
Message-Id: <MPG.144d4a497111bbcb98ae1e@nntp.hpl.hp.com>

In article <slrn8u3dp8.jk8.clay@panix3.panix.com> on 9 Oct 2000 12:16:40 

GMT, Clay Irving <clay@panix.com> says...
+ On Mon, 09 Oct 2000 13:33:45 +0200, P.Eftevik <haf@autra.noXX> wrote:
+ >I'm processing a file with
+ >
+ >open myfile;
+ >while (< myfile >)  {}
+ >
+ >If I want to process the file once more from the start:  How do  I
+ >"rewind" the file pointer ?  ( I know that another 'open' statement
+ > will work, but guess it's slow ..... (?)  ).
+ 
+ Do you want to loop?
+ 
+   open MYFILE, "myfile" or die "Can not open myfile: $!\n:
+   $count = 0;
+   
+   until ($count == 2) {
+       while (<MYFILE>) {
+           print "processing myfile...\n";
+       }
+       $count++;
+   }

I doubt that you tried that before posting it.

The first time through, the 'while' loop reads from MYFILE until end of 
file.  The second time through, it falls out immediately on the same end 
of file.

The other responder (Denis Joiret) had almost the right answer (seek 
MYFILE, 0, 0), but forgot the error checking required on a request for 
an OS service.

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


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

Date: Wed, 11 Oct 2000 00:16:24 GMT
From: Dave Brondsema <brondsem@my-deja.com>
Subject: Re: processing a file several times
Message-Id: <8s0bgj$32h$1@nnrp1.deja.com>

In article <39E1AD18.4771529B@autra.noXX>,
  "P.Eftevik" <haf@autra.noXX> wrote:
> I'm processing a file with
>
> open myfile;
> while (< myfile >)  {}
>
> If I want to process the file once more from the start:  How do  I
> "rewind"
> the file pointer ?  ( I know that another 'open' statement will work,
> but guess
> it's slow ..... (?)  ).
>

open myfile;
@myarray = <myfile>
close myfile;

loop through the array as much as you want.

--
Dave Brondsema


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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.

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 V9 Issue 4575
**************************************


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