[21966] in Perl-Users-Digest
Perl-Users Digest, Issue: 4188 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 27 11:06:14 2002
Date: Wed, 27 Nov 2002 08:05:15 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 27 Nov 2002 Volume: 10 Number: 4188
Today's topics:
ANNOUNCE CGI::Widget::Tabs v1.04 (Koos Pol)
Re: Apache/MySQL/DBI problem <cpryce@pryce.net>
Counting the number of records in @rows <rubberducky703@hotmail.com>
Re: Counting the number of records in @rows <twhu@lucent.com>
Re: Counting the number of records in @rows <bernard.el-hagin@DODGE_THISlido-tech.net>
Re: Counting the number of records in @rows <dave@dave.org.uk>
Re: Counting the number of records in @rows <clay@panix.com>
Re: Getopt::Std <bart.lateur@pandora.be>
Re: Getopt::Std (Jay Tilton)
Re: Help writing a script simulating CSS word-break of <ubl@schaffhausen.de>
Re: help: multi-dimensional hash from flat array <usenet@tinita.de>
Re: help: multi-dimensional hash from flat array <usenet@tinita.de>
Re: how to call an external script and using the env-de <nobull@mail.com>
Re: how to call an external script and using the env-de (Tad McClellan)
Re: how to test for empty nonexistent array??? (Bruno Boettcher)
Is this a safe way to test for an empty hash? (Ronald Fischer)
Re: Is this a safe way to test for an empty hash? <usenet@tinita.de>
Re: Is this a safe way to test for an empty hash? <ubl@schaffhausen.de>
Re: Is this a safe way to test for an empty hash? <rick.delaney@rogers.com>
Re: Is this a safe way to test for an empty hash? <usenet@tinita.de>
Re: Is this a safe way to test for an empty hash? <josef.moellers@fujitsu-siemens.com>
Keep duplicates in a file (Jen Kelly)
Re: Keep duplicates in a file (Helgi Briem)
Re: Keep duplicates in a file ctcgag@hotmail.com
MailX - HTML Email problem (Elie)
Re: Perl/Tk <simon.andrews@bbsrc.ac.uk>
regexp (multiple lines) substitution <peter_news@web.de>
Re: regexp (multiple lines) substitution (Tad McClellan)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 24 Nov 2002 02:23:52 -0800
From: koos_pol@hotmail.com (Koos Pol)
Subject: ANNOUNCE CGI::Widget::Tabs v1.04
Message-Id: <3de4b60d$1_3@news.teranews.com>
Announcement for CGI::Widget::Tabs, version 1.04
The changes for this version are:
- Added CSS example style sheets to the demo script.
You can now choose a different style with just
one mouse lick.
Enclosed is the README for reference.
Best regards,
Koos Pol
CGI::Widget::Tabs
=================
DESCRIPTION
CGI::Widget::Tabs lets you simulate tab widgets in HTML. You
could benefit from a tab widget if you want to serve only one
page. Depending on the tab selected you fetch and display the
underlying data. There are two main reasons for taking this
approach:
1. For the end user not to be directed to YAL or YAP (yet another
link / yet another page), but keep it all together: The single
point of entry paradigm.
2. For the Perl hacker to generate and display multiple data
sources within the same script environment.
As an example the following tabs could be used on a web page for
someone's spotting hobby:
________ ________ _____________
/ Planes \ / Trains \ / Automobiles \
-----------------------------------------------------
The nice thing about CGI::Widget::Tabs is that the tabs know
their internal state. So you can ask a tab for instance which tab
heading has been clicked by the user. This way you get instant
feedback.
DOCUMENTATION
The documentation is included in the module. You can read it's
manpage after installation with `perldoc CGI::Widget::Tabs'. If
you prefer you can read the documentation before installation
with `perldoc ./Tabs.pm'
DEPENDENCIES
- CGI, CGI::Minimal or another CGI "object broker"
with the param() method and with similar behaviour
- HTML::Entities
- URI
- A CSS style sheet for the tabs markup
INSTALLATION
To install this module type the following:
perl Makefile.PL
make
make test
make install
DOWNLOAD
The latest version of CGI::Widget::Tabs is always available from
the CGI::Widget::Tabs homepage at:
http://users.raketnet.nl/koos_pol/en/Tabs/index.html
COPYRIGHT AND LICENCE
Copyright (c) 2002 Koos Pol. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
CHANGES
These changes are against the previous version. For a complete
history log, see the file 'CHANGES' in the distribution.
1.04 (2002-11-23)
--------------------
- Added CSS example style sheets to the demo script.
--
KP
koos _ pol @ raketnet nl
------------------------------
Date: Wed, 27 Nov 2002 09:11:06 -0600
From: cp <cpryce@pryce.net>
Subject: Re: Apache/MySQL/DBI problem
Message-Id: <BA0A3CAA.127DC%cpryce@pryce.net>
in article 64fe533f.0211261502.3c5eca9e@posting.google.com, Lord V at
lordvee@tin.it wrote on 11/26/02 5:02 PM:
> I have a script that connects to MySQL and checks for login and pw.
> the thing is that when i try to log in with a name that's not in the
> database row i get a:
> "Premature end of script headers: /usr/lib/cgi-bin/reg.cgi"
> I read somewhere that the above is a compile time error, so i'm trying
> to get the picture clear about what could be wrong. Any quick clue?
Where did you read that? Premature end of script headers means that your Web
browser expected a full HTTP header, and didn't get one. So it assumed an
error on the server and refused to accept any more data. Any error that your
code generates before sending headers to a Web browser will cause this error
to happen. Using warnings (use warnings or #!/path/to/perl -w) will print
those warnings to STDOUT. STDOUT for a script invoked from the server is the
Web server's error log. Those warnings are an enormous help to debugging.
They come free with Perl. Why not use them?
> using perl -wT doesn't give out any new info, while using "use
> strict;" makes a infinite serie of warnings...
> If the login name exists, the script keeps on running the way it's
> supposed to.
Using strictures and warnings should be part of any script. Adding them
after a script generates errors is a bit like closing the barn door after
the horse has escaped.
>
> Any hint would be greatly apreciated :)))
Complete code generates complete hints. Otherwise we're guessing here.
>
> This is the relevant part of it:
>
> --
> elsif ($in{'loginscript'} ne "") {
> my $dbh = DBI->connect("DBI:mysql:utenti_registrati", $user,
> $pwd) or print "Impossibile connettersi al database: " . DBI->errstr;
Yes. I'm guessing here, but you probably haven't sent the HTTP header to the
browser yet. Invoked from the Web server, print without a handle is printing
to STDOUT. STDOUT in this case is the Web browser. A Web browser expects a
full HTTP header first; when a full header isn't sent first, any data is an
error. A premature end of script error.
Again, it's a guess, but if the connect succeeds, no print message is
generated, so the script executes normally and eventually prints the headers
before sending data...
cp
------------------------------
Date: Wed, 27 Nov 2002 14:57:39 -0000
From: "Rubber Duck" <rubberducky703@hotmail.com>
Subject: Counting the number of records in @rows
Message-Id: <as2me3$nd9kv$1@ID-116287.news.dfncis.de>
All, i'm an intermediate perl programmer.
I have a CSV file which i split using:
my @rows = split /\r/, $_;
chomp(@rows); # for good measure
foreach my $line (@rows)
{
my @cols = split /,/, $line; #split on commas
my $cols = @cols; # this gives me the number of columns
....
}
How can i tell how many rows (i.e. records that there are in @rows??
I tried my $numberofrecords = @rows but it always gives me 1.
Your thoughts?
RD
------------------------------
Date: Wed, 27 Nov 2002 09:59:03 -0500
From: "Tulan W. Hu" <twhu@lucent.com>
Subject: Re: Counting the number of records in @rows
Message-Id: <as2mjp$4a5@netnews.proxy.lucent.com>
"Rubber Duck" <rubberducky703@hotmail.com> wrote in...
> How can i tell how many rows (i.e. records that there are in @rows??
> I tried my $numberofrecords = @rows but it always gives me 1.
my $numberofrecords = $#rows + 1;
------------------------------
Date: Wed, 27 Nov 2002 15:02:37 +0000 (UTC)
From: Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: Counting the number of records in @rows
Message-Id: <as2mqc$oek$1@korweta.task.gda.pl>
In article <as2me3$nd9kv$1@ID-116287.news.dfncis.de>, Rubber Duck
wrote:
> All, i'm an intermediate perl programmer.
>
> I have a CSV file which i split using:
>
> my @rows = split /\r/, $_;
I have a strong suspicion you want /\n/ instead of /\r/, although I
may be wrong.
> chomp(@rows); # for good measure
>
> foreach my $line (@rows)
> {
> my @cols = split /,/, $line; #split on commas
> my $cols = @cols; # this gives me the number of columns
> ....
> }
>
> How can i tell how many rows (i.e. records that there are in @rows??
>
> I tried my $numberofrecords = @rows but it always gives me 1.
>
> Your thoughts?
What's in $_ when you do the split into @rows?
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'
------------------------------
Date: Wed, 27 Nov 2002 15:44:52 +0000
From: "Dave Cross" <dave@dave.org.uk>
Subject: Re: Counting the number of records in @rows
Message-Id: <pan.2002.11.27.15.44.51.1814@dave.org.uk>
On Wed, 27 Nov 2002 09:59:03 +0000, Tulan W. Hu wrote:
> "Rubber Duck" <rubberducky703@hotmail.com> wrote in...
>> How can i tell how many rows (i.e. records that there are in @rows??
>
>> I tried my $numberofrecords = @rows but it always gives me 1.
> my $numberofrecords = $#rows + 1;
In the vast majority of cases (i.e. unless you've changed the value of $[
- and DON'T DO THAT!) the two pieces of code
my $numberofrecords = @rows
and
my $numberofrecords = $#rows + 1;
are exactly equivalent. If one of them isn't working then the other won't
either. So your suggestion will only confuse the original poster more. Why
did you think that it would give a different answer?
In this case it seems that the array does, in fact, contain only one
element. Therefore the problem is almost certainly that the call to
"split" is wrong.
hth,
Dave...
--
And crawling on the planet's face, some insects called the human race
Lost in time, and lost in space. And meaning.
------------------------------
Date: Wed, 27 Nov 2002 15:56:43 +0000 (UTC)
From: Clay Irving <clay@panix.com>
Subject: Re: Counting the number of records in @rows
Message-Id: <slrnau9qpr.ji9.clay@panix1.panix.com>
In article <as2mjp$4a5@netnews.proxy.lucent.com>, Tulan W. Hu wrote:
> "Rubber Duck" <rubberducky703@hotmail.com> wrote in...
>> How can i tell how many rows (i.e. records that there are in @rows??
>
>> I tried my $numberofrecords = @rows but it always gives me 1.
> my $numberofrecords = $#rows + 1;
I'm surprised no on mentioned:
print scalar(@rows), "\n";
--
Clay Irving <clay@panix.com>
s = (char*)(long)retval; /* ouch */
-- Larry Wall in doio.c from the perl source code
------------------------------
Date: Wed, 27 Nov 2002 11:29:58 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Getopt::Std
Message-Id: <83b9uuou5qph4nn4a55nn6fjj65fg9rjqi@4ax.com>
qanda wrote:
>I can handle
>
>prg
>prg -c
>prg -d
>prg -a arg -b arg -e arg
>
>then I can handle all invalid entries except
>
>prg -a arg -b arg -e arg extra_arg
>
>It's the extra_arg on the end I can't trap.
Eh, what? In the last case, the array @ARGV will contain
('extra_arg')
while in all other cases it will be empty. So I fail to see how you
can't trap that.
--
Bart.
------------------------------
Date: Wed, 27 Nov 2002 11:35:40 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Getopt::Std
Message-Id: <3de4a73b.233787650@news.erols.com>
fumail@freeuk.com (qanda) wrote:
: I've just started with perl and am having trouble. I want to use
: Getopt::Std calling getopts so I can use something like 'a:b:cde:' for
: options;
[explanation of how the options influence the program's behavior elided]
: The actual problem is having
: some condition to tell me when there are extra arguemnts. For example
: I can handle
:
: prg
: prg -c
: prg -d
: prg -a arg -b arg -e arg
:
: then I can handle all invalid entries except
:
: prg -a arg -b arg -e arg extra_arg
:
: It's the extra_arg on the end I can't trap. That is, I don't know how
: to check for extra arguments, extra options are picked up by getopts
: but I'm totally confused with the extra argument, I can't use @ARGV
: for range checking as we can specify options with operands without
: spaces so the equivalent argc count would be invalid.
The explanation of the problem is somewhat muddled. The way I'm reading
it is that you want to call the program like
prg -e arg extra_arg foo bar baz
and let the -e switch catch "arg" and "extra_arg", so @ARGV ends up
holding only "foo" "bar" and "baz".
The easiest way to get there would be to use some of the shell's
capabilities. Call it like
prg -e "arg extra_arg" foo bar baz
then whitespace-split the argument caught in the -e switch.
If I've missed the mark, a clarification of exactly where "extra_arg"
should end up would help.
------------------------------
Date: Wed, 27 Nov 2002 16:48:51 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: Help writing a script simulating CSS word-break of IE
Message-Id: <as2sqk$1kv$1@news.dtag.de>
Hyungjin Ahn wrote:
> a lot of text
Well, I guess you could approximate the width of a word by rendering it
on the server side using one of the graphic libraries with font support.
This, of course, cannot be very accurate because font rendering is
subject to many system dependent factors.
Anyway, this approach will be _very_ slow. Maybe, if the page is too
wide you might just want to buy a bigger monitor, preferably a wide
screen model :)
->malte
--
srand 108641088; print chr int rand 256 for qw<J A P H>
------------------------------
Date: 27 Nov 2002 12:59:55 GMT
From: Tina Mueller <usenet@tinita.de>
Subject: Re: help: multi-dimensional hash from flat array
Message-Id: <as2fkb$n1amk$1@fu-berlin.de>
Chef Tako <tako@luigios.com> wrote:
> i need to create an arbitrary multi-dimensional hash
> from a flat array. i don't understand why the simple
> $h{a}{b}{c}{d}{e}='x' ain't working.
> use strict;
use Data::Dumper;
> my $var = "a-b-c-d-e";
> my %h =();
my @j=split /-/,$s;
my $ref=\\%h;
for my $key (@j) {
$$ref->{$key}={};
$ref = \$$ref->{$key};
}
> ## let eval do the assignment
> my $r="%h->$m=823";
$$ref = 823;
print Dumper \%h;
hth, tina
--
http://www.tinita.de/ \ enter__| |__the___ _ _ ___
http://Movies.tinita.de/ \ / _` / _ \/ _ \ '_(_-< of
http://PerlQuotes.tinita.de/ \ \ _,_\ __/\ __/_| /__/ perception
------------------------------
Date: 27 Nov 2002 13:05:54 GMT
From: Tina Mueller <usenet@tinita.de>
Subject: Re: help: multi-dimensional hash from flat array
Message-Id: <as2fvi$n1amk$2@fu-berlin.de>
Tina Mueller <usenet@tinita.de> wrote:
> Chef Tako <tako@luigios.com> wrote:
>> i need to create an arbitrary multi-dimensional hash
>> from a flat array. i don't understand why the simple
>> $h{a}{b}{c}{d}{e}='x' ain't working.
> for my $key (@j) {
> $$ref->{$key}={};
this line isn't necessary at all, so:
for my $key (@j) {
$ref = \$$ref->{$key};
}
--
http://www.tinita.de/ \ enter__| |__the___ _ _ ___
http://Movies.tinita.de/ \ / _` / _ \/ _ \ '_(_-< of
http://PerlQuotes.tinita.de/ \ \ _,_\ __/\ __/_| /__/ perception
------------------------------
Date: 27 Nov 2002 13:36:47 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: how to call an external script and using the env-definitions?
Message-Id: <u9k7iz8780.fsf@wcl-l.bham.ac.uk>
Michael Kirchner <michael.kirchner@unibw-muenchen.de> writes:
> during the last days I thought about a special problem and I have no
> idea how to solve it.
What makes you think it's special?
> How can I call the start-script form perl without starting a
> child-shell, so that I can use the environment-definitions
> afterwards?
You cannot. This is a FAQ. It's really a Unix FAQ - nothing to do
with Perl. But it's asked in a Perl context sufficiently often that
it also appears in the Perl FAQ.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 27 Nov 2002 09:38:01 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: how to call an external script and using the env-definitions?
Message-Id: <slrnau9pmp.2la.tadmc@magna.augustmail.com>
Michael Kirchner <michael.kirchner@unibw-muenchen.de> wrote:
> during the last days I thought about a special problem and I have no
> idea how to solve it. Maybe you have...
Your problem is not so special, it is a Question that
is Asked Frequently.
[snip "processing" is a collection of programs, some in Perl]
> Before starting
> the processing it is necessary to execute a start-script which sets a
> lot of environment variables needed for the other programs.
^^^^^^^^^^^
perldoc -q environment
"I {changed directory, modified my environment} in a perl
script. How come the change disappeared when I exited the
script? How do I get my changes to be visible?"
> Now the problem:
> It is necessary to rewrite my script for automatic processing in perl
> but it is not possible to rewrite the start-script.
Can you replace the start-script with a Perl script?
If all it does is set env vars, then set env vars in Perl
before launching the further "processing".
You can manipulate the %ENV hash before invoking any child
processes, and they will inherit that environment from their
Perl parent.
> How can I call the
> start-script form perl without starting a child-shell,
You can't.
You need some other workaround, like doing in native Perl
what would otherwise be done in the shell script.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 27 Nov 2002 15:09:47 GMT
From: bboett@bboett.dyndns.org (Bruno Boettcher)
Subject: Re: how to test for empty nonexistent array???
Message-Id: <as2n7r$43c$1@news-reader11.wanadoo.fr>
In article <Xns92D2CA4B22959dkwwashere@63.240.76.16>,
David K. Wall <usenet@dwall.fastmail.fm> wrote:
>bboett@bboett.dyndns.org (Bruno Boettcher) wrote:
>Are you sure the array doesn't contain undef?
yup the array is simply not initialized...
> use strict;
> use warnings;
> my @ary;
> my $aref = \@ary;
> my $sc1 = join(' ', @ary ) if @ary;
> my $sc2 = join(' ', @$aref) if @$aref;
clashes on my system....
>then it produces the "Use of uninitialized value in join or
>string..." error, because even though the array contains one element
>(scalar(@ary) is 1), that element is undefined.
>
>You DO have warnings and strictures enabled, right?
self speakingly....
--
ciao bboett
==============================================================
bboett@adlp.org
http://inforezo.u-strasbg.fr/~bboett
------------------------------
Date: 27 Nov 2002 05:11:31 -0800
From: ronaldf@eml.cc (Ronald Fischer)
Subject: Is this a safe way to test for an empty hash?
Message-Id: <219750c.0211270511.7138b15@posting.google.com>
$hr is a reference to an empty hash. I would like to test if the hash
is empty. Is this a safe way to
do this?
print "is empty" unless %$hr;
The idea is this: Putting a hash into scalar context, yields either a
string of the form
'm/n'
where m is the number of entries, and n is the capacity, or
0
Of course, the latter indicates that the hash is empty, but I wonder
if Perl guarantees this.
In theory, an empty hash could also be represented by
'0/n'
which would evaluate to true. I have never encountered 0/n, but of
course this does not
mean if this is impossible.
So I have two questions: First, is my method safe? Second, is there a
better way to do it?
I am aware that there are various methods to test the emptiness of a
hash, but I did not
find one of similar elegance (which is, of course, a very subjective
term).
Ronald
------------------------------
Date: 27 Nov 2002 13:29:08 GMT
From: Tina Mueller <usenet@tinita.de>
Subject: Re: Is this a safe way to test for an empty hash?
Message-Id: <as2hb4$nemkv$1@fu-berlin.de>
Ronald Fischer <ronaldf@eml.cc> wrote:
> $hr is a reference to an empty hash. I would like to test if the hash
> is empty. Is this a safe way to
> do this?
> print "is empty" unless %$hr;
i'd do:
print "is empty" unless keys %$hr;
hth, tina
--
http://www.tinita.de/ \ enter__| |__the___ _ _ ___
http://Movies.tinita.de/ \ / _` / _ \/ _ \ '_(_-< of
http://PerlQuotes.tinita.de/ \ \ _,_\ __/\ __/_| /__/ perception
------------------------------
Date: Wed, 27 Nov 2002 15:12:55 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: Is this a safe way to test for an empty hash?
Message-Id: <as2n6o$a6k$1@news.dtag.de>
Tina Mueller wrote:
> Ronald Fischer <ronaldf@eml.cc> wrote:
>
>>$hr is a reference to an empty hash. I would like to test if the hash
>>is empty. Is this a safe way to
>>do this?
>
>
>> print "is empty" unless %$hr;
>
>
> i'd do:
> print "is empty" unless keys %$hr;
Why would that be better?
->malte
------------------------------
Date: Wed, 27 Nov 2002 14:29:19 GMT
From: Rick Delaney <rick.delaney@rogers.com>
Subject: Re: Is this a safe way to test for an empty hash?
Message-Id: <m3lm3frsqp.fsf@cs839290-a.mtth.phub.net.cable.rogers.com>
ronaldf@eml.cc (Ronald Fischer) writes:
> $hr is a reference to an empty hash. I would like to test if the hash
> is empty. Is this a safe way to
> do this?
>
> print "is empty" unless %$hr;
Yes.
--
Rick Delaney
rick.delaney@rogers.com
------------------------------
Date: 27 Nov 2002 14:37:21 GMT
From: Tina Mueller <usenet@tinita.de>
Subject: Re: Is this a safe way to test for an empty hash?
Message-Id: <as2lb1$na13j$1@fu-berlin.de>
Malte Ubl <ubl@schaffhausen.de> wrote:
> Tina Mueller wrote:
>> Ronald Fischer <ronaldf@eml.cc> wrote:
>>
>>>$hr is a reference to an empty hash. I would like to test if the hash
>>>is empty. Is this a safe way to
>>>do this?
>>
>>> print "is empty" unless %$hr;
>>
>> print "is empty" unless keys %$hr;
> Why would that be better?
good question. it's not *better*, but i would have coded
it like this because it tells me at the first glance what
it is doing. just a matter of taste, probably.
without keys() it is even more efficient, i'd guess.
regards, tina
--
http://www.tinita.de/ \ enter__| |__the___ _ _ ___
http://Movies.tinita.de/ \ / _` / _ \/ _ \ '_(_-< of
http://PerlQuotes.tinita.de/ \ \ _,_\ __/\ __/_| /__/ perception
------------------------------
Date: Wed, 27 Nov 2002 16:32:46 +0100
From: Josef =?iso-8859-1?Q?M=F6llers?= <josef.moellers@fujitsu-siemens.com>
Subject: Re: Is this a safe way to test for an empty hash?
Message-Id: <3DE4E59E.73081D10@fujitsu-siemens.com>
Rick Delaney wrote:
> =
> ronaldf@eml.cc (Ronald Fischer) writes:
> =
> > $hr is a reference to an empty hash. I would like to test if the hash=
> > is empty. Is this a safe way to
> > do this?
> >
> > print "is empty" unless %$hr;
> =
> Yes.
print "is empty";
is probably faster, given Ronald's question B-{)
-- =
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: 27 Nov 2002 05:29:16 -0800
From: jennykelly@hotmail.com (Jen Kelly)
Subject: Keep duplicates in a file
Message-Id: <a28674d8.0211270529.7b2e6f89@posting.google.com>
Can anyone think of a way to *keep* all the duplicates in a file, and
delete all the unique items?
Arrays are out of the question by the way because the file I am using
is huge.
Thanks,
Jenny
------------------------------
Date: Wed, 27 Nov 2002 13:35:45 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Keep duplicates in a file
Message-Id: <3de4c986.3666314671@news.cis.dfn.de>
On 27 Nov 2002 05:29:16 -0800, jennykelly@hotmail.com (Jen
Kelly) wrote:
>Can anyone think of a way to *keep* all the duplicates in a file, and
>delete all the unique items?
If the question is about Perl and the answer is not either
"use a hash" or "use a module that uses a hash", the
answer is probably wrong.
>Arrays are out of the question by the way because the file I am
>using s huge.
Is suggest using the Tie::File module that ties an array
to a file.
search.cpan.org/author/MJD/Tie-File-0.93/lib/Tie/File.pm
--
Regards, Helgi Briem
helgi AT decode DOT is
A: Top posting
Q: What is the most irritating thing on Usenet?
- "Gordon" on apihna
------------------------------
Date: 27 Nov 2002 15:53:26 GMT
From: ctcgag@hotmail.com
Subject: Re: Keep duplicates in a file
Message-Id: <20021127105326.572$rc@newsreader.com>
jennykelly@hotmail.com (Jen Kelly) wrote:
> Can anyone think of a way to *keep* all the duplicates in a file, and
> delete all the unique items?
Yes. But what is your perl question?
Do you mean exactly duplicated, or at least duplicated. i.e., do you wish
to keep triplicates, quadruplicates, etc, also?
sort file|uniq -d
On most unices will give you one occurence of each replicated line.
sort file|uniq -D
On some unices will give you n occurences of each n-plicated line.
> Arrays are out of the question by the way because the file I am using
> is huge.
That would depend on what you are using the arrays for, wouldn't it?
Hashes would be a good way to go in Perl, but if arrays are uniformally
unsuitable due to the size of the problem, hashes must be right out the
window as well, they aren't any more space efficient. But perhaps
you should have an open mind, maybe we can use arrays (and hashes) more
efficiently than you originally thought of.
How many lines are in the huge file? How many unique lines are in the
huge file?
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
------------------------------
Date: 27 Nov 2002 07:25:18 -0800
From: elie.goldberg@gs.com (Elie)
Subject: MailX - HTML Email problem
Message-Id: <fb3e04bc.0211270725.4062d9fe@posting.google.com>
I am using ths code
***************************************************
open(INF,"mail.dat");
@mail = <INF>;
close(INF);
print MAIL <<EOM;
The following recurring meeting is about to expire:
Content-type: text/html\n\n
<html>
<B><I>helleokwed</b></i>
</html>
Meeting Name : $MeetingName
Recurring Meeting Number : $BBNum
Type : $Frequency
Reserved For : $ReservedFor
Start Time : $StartTime
End Time : $EndTime
Start Date : $FirstDate
End Date : $EndDate
To extend your recurring meeting click on this link:
http://fwgsny07a.ny.fw.gs.com/realm/menupage.asp
EOM
close(MAIL);
******************************************************
But the email arrives as plain text, not html.
Any thoughts?
------------------------------
Date: Wed, 27 Nov 2002 13:32:03 +0000
From: Simon Andrews <simon.andrews@bbsrc.ac.uk>
Subject: Re: Perl/Tk
Message-Id: <3DE4C953.BCC9B020@bbsrc.ac.uk>
fafanie wrote:
>
> Hi,
>
> I want to build a graphical interface in Perl/Tk.
> Via this interface, I want to run a script perl from a button.
> For the moment, this script run via a console MS-Dos or a xterm unix.
>
> How to do?
> The command system("perl test.pl")
..will fail if perl.exe isn't in your path, or if test.pl isn't in the
current directory. Try a variation on...
chdir('c:/My Documents/Perl Scripts/') || die "Can't chdir: $!";
system('c:/perl/bin/perl test.pl') && die "Still doesn't work";
> or system("start perl test.pl") fails.
Shouldn't this be...
system("start test.pl")
..again assuming you've already chdir'd to the directory test.pl is in.
> Thus, my script writes some messages in STDOUT (console,xterm).
> How can I see theses outputs in my interface?
Others have already provided answers to this...
Hope this helps
Simon.
------------------------------
Date: Wed, 27 Nov 2002 13:50:47 +0100
From: Peter Schaffrath <peter_news@web.de>
Subject: regexp (multiple lines) substitution
Message-Id: <oof9uucvp77pkd2cmmvr0ak2utcd3bbul3@4ax.com>
Hello!
I try to substitute the th tag in
<th>
total:
</th>
with a td tag in some HTML files. $data contains the whole file and I
tried
$data =~ s|
<th> # start th tag
(\s*total:\s*) # "total:" on separate line
</th> # end th tag
|<td>$1</td> # replacement
|gxs;
I tried several different regular expressions, but none of them
substituted the tag correctly. What is weird, when I count the number
of substitutions with
$count = ($data =~ s|... |);
it says 4 occurences have been changed.
I'm sorry, this probably is a common problem, but somehow I can't
manage to get it right. I read the perlop man page again and used
google :-(.
Peter
------------------------------
Date: Wed, 27 Nov 2002 08:08:20 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: regexp (multiple lines) substitution
Message-Id: <slrnau9kek.2la.tadmc@magna.augustmail.com>
Peter Schaffrath <peter_news@web.de> wrote:
> I try to substitute the th tag in
><th>
> total:
></th>
>
> with a td tag in some HTML files.
You should use a module that understands HTML for processing HTML.
Using a regex to "parse" HTML is most often a really bad idea,
there are a thousand-and-one gotchas.
You can see some gotchas in the answer to this FAQ:
perldoc -q "remove HTML"
> $data contains the whole file and I
> tried
>
> $data =~ s|
> <th> # start th tag
> (\s*total:\s*) # "total:" on separate line
^^ ^^
^^ ^^
Here is where you match newline characters...
> </th> # end th tag
> |<td>$1</td> # replacement
^^
^^
... and here is where you put those newline characters right back in.
Don't capture the newlines if you don't want to put them back in:
\s*(total:)\s*
> |gxs;
You do not need the s///s option. It does not change anything
for the pattern you are using.
You do need the s///i option, HTML is case-insensitive.
> What is weird, when I count the number
> of substitutions with
> $count = ($data =~ s|... |);
> it says 4 occurences have been changed.
All your s/// does is change some of the "h" characters
it finds into "d" characters. :-)
You probably missed that the s/// had actually substituted something.
> I'm sorry, this probably is a common problem,
Processing HTML with regexes is the common problem part of your problem.
If you control the generation of this HTML that you are processing,
and/or don't mind if it doesn't work on 100% of all data, only
then might you consider pattern matching against HTML data
rather than doing it properly with a module.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.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 V10 Issue 4188
***************************************