[18333] in Perl-Users-Digest
Perl-Users Digest, Issue: 501 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 16 09:05:39 2001
Date: Fri, 16 Mar 2001 06:05:16 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <984751516-v10-i501@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 16 Mar 2001 Volume: 10 Number: 501
Today's topics:
ANNOUNCE: Math::MatrixReal::Ext1 msouth@fulcrum.org
array/hash to file to array/hash <varghese@dstmail.itg.ti.com>
Re: array/hash to file to array/hash <postmaster@castleamber.co.nz>
Re: array/hash to file to array/hash (Abigail)
Re: better way for if structure ... <jens@irs-net.com>
Re: binary files <bart.lateur@skynet.be>
Re: Cant call subs (Eric Bohlman)
Re: Copy/Paste using Perl? <bart.lateur@skynet.be>
Create .tar.gz with Perl? <meisl@amvt.tu-graz.ac.at>
Re: Create .tar.gz with Perl? nobull@mail.com
Re: Create .tar.gz with Perl? <bart.lateur@skynet.be>
Re: Does Perl have an un-getc <bart.lateur@skynet.be>
Excute Script 2 <milliwave@rfengineering.freeserve.co.uk>
Re: Excute Script 2 <krahnj@acm.org>
Re: FAQ 7.16: What's the difference between dynamic a (Rafael Garcia-Suarez)
Re: Grokking map and grep <bart.lateur@skynet.be>
Re: Help in understood Perl some slides (Taming of Came nobull@mail.com
Re: Help to Install Perl <uri@sysarch.com>
Re: How to do this? <uri@sysarch.com>
Re: How to gret rid of Warning message? "Value of <HAND (Csaba Raduly)
Re: How to gret rid of Warning message? "Value of <HAND (Anno Siegel)
Re: module for national holidays <yeah.yeah@gmx.net>
Re: Most efficient way to extract unique array elements (Anno Siegel)
Re: Most efficient way to extract unique array elements (Abigail)
Need help with an expression <kalle@tvettsvamp.a.se>
Re: Need help with an expression (Philip Lees)
Re: Need help with an expression <krahnj@acm.org>
Re: Need help with an expression merrill@missioncriticallinux.com
new user <anders.goransson@chello.se>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 16 Mar 2001 09:05:38 GMT
From: msouth@fulcrum.org
Subject: ANNOUNCE: Math::MatrixReal::Ext1
Message-Id: <98sl12$nn9$1@inxs.ncren.net>
Hi,
My name is Mike South, I would like to contribute an extension to
Math::MatrixReal, which I am proposing to call Math::MatrixReal::Ext1.
I think it would be better inside Math::MatrixReal, but I have not been
able to get the authors to respond to the email listed in the
README or on 00whois.html (that one bounces, in fact). It seems to
me that a reasonable alternative is to just put this in a separate
file and then, when we get in contact with the author, we can
open the discussion on absorbing it. That allows this extension
to get out there, and provides a nice way of merging the two,
since we can just replace the Ext1.pm file with an empty subclass
if they are one day integrated.
the tgz is here:
http://fulcrum.org/personal/msouth/code/Math-MatrixReal-Ext1-0.3.tgz
the pod is here:
http://fulcrum.org/personal/msouth/code/Math-MatrixReal-Ext1-0.3.html
here is the information requested in the instructions on the contribution
instructions on the CPAN web site, followed by some of the pod so you
can see what it looks like:
======================================
Mike South
msouth@fulcrum.org
http://www.fulcrum.org/personal/msouth
MSOUTH
an extension for Math::MatrixReal that lets you create a matrix from
rows or colums, passed in as perl arrays rather than in the string format
which is currently required by Math::MatrixReal. The new methods are
new_from_cols() and new_from_rows(), complementing the existing
new_from_string() method. This makes the module a little more
"perlish", and, in particular, make it easier to create a matrix
from a program.
DLSI Descripttion
RdpO Convenience extensions for Math::MatrixReal
I think this would be better off inside Math::MatrixReal, but
I have had no luck contacting the authors.
==========================================
NAME
Math::MatrixReal::Ext1 - Minor extensions to Math::MatrixReal
SYNOPSIS
use Math::MatrixReal::Ext1;
$ident3x3 = Math::MatrixReal::Ext1->new_from_cols([1,0,0],[0,1,0],[0,0,1]);
$upper_tri = Math::MatrixReal::Ext1->new_from_rows([1,1,1],[0,1,1],[0,0,1]);
$col1 = Math::MatrixReal->new_from_string("[ 1 ]\n[ 3 ]\n[ 5 ]\n");
$col2 = Math::MatrixReal->new_from_string("[ 2 ]\n[ 4 ]\n[ 6 ]\n");
$mat = Math::MatrixReal::Ext1->new_from_cols( $col1, $col2 );
Lastly, I realize I need to mail to the modules list to become
registered, etc, but I wanted to put this out for public
discussion first.
--
Michael South | http://fulcrum.org
Head Mathophile, | 101 Canyon Run
fulcrum.org | Cary NC 27513 USA
(msouth@fulcrum.org) | (919) 465-9074
------------------------------
Date: Fri, 16 Mar 2001 06:27:29 -0600
From: Regy <varghese@dstmail.itg.ti.com>
Subject: array/hash to file to array/hash
Message-Id: <3AB206B1.D537416F@dstmail.itg.ti.com>
Is there an easy way of writing the contents of an array/hash to a file
and reading the same file later and regenerating that array? Thanks for
any help.
------------------------------
Date: Sat, 17 Mar 2001 01:47:28 +1300
From: "John Bokma" <postmaster@castleamber.co.nz>
Subject: Re: array/hash to file to array/hash
Message-Id: <98t23q$rdu$1@lust.ihug.co.nz>
Regy wrote in message <3AB206B1.D537416F@dstmail.itg.ti.com>...
>Is there an easy way of writing the contents of an array/hash to a file
>and reading the same file later and regenerating that array? Thanks for
>any help.
see Data::Dumper, Storable and FreezeThaw
John
--
Castle Amber - Software Development
Perl / Java / C / C++ developer *available*
email john@castleamber.co.nz for more info
or visit http://castleamber.co.nz/
------------------------------
Date: 16 Mar 2001 13:48:28 GMT
From: abigail@foad.org (Abigail)
Subject: Re: array/hash to file to array/hash
Message-Id: <slrn9b46dc.863.abigail@tsathoggua.rlyeh.net>
Regy (varghese@dstmail.itg.ti.com) wrote on MMDCCLIV September MCMXCIII
in <URL:news:3AB206B1.D537416F@dstmail.itg.ti.com>:
'' Is there an easy way of writing the contents of an array/hash to a file
'' and reading the same file later and regenerating that array? Thanks for
'' any help.
For a hash, you could tie it to a DBM file.
And in general, you could use Data::Dumper.
Abigail
------------------------------
Date: Fri, 16 Mar 2001 09:27:23 +0100
From: "Jens Luedicke" <jens@irs-net.com>
Subject: Re: better way for if structure ...
Message-Id: <20010316.092720.1346811305.28629@irs-net.com>
Hi ...
I embedded it into my program to replace the @head, @headings, @messages
arrays. Works great. The idea with the 3 different arrays wasn't mine,
because the core of my mail program wasn't written by me.
In article <0ej1btgm0lfrme54qlilkm8824ettv7jp3@4ax.com>, "Bart Lateur"
<bart.lateur@skynet.be> wrote:
> Perhaps you're just doing this the wrong way. You seem to have an array
> of "records", but each record is spread over 3 variables: @head, each
> item an anonymous array of 4 (5?) headers; @headings, the rest; and
> @messages, the bodies.
> Why don't you turn this around, and create ONE array of anonymous hashes
> instead? Each item could be
>
> for (0 .. $#message) {
> $records[$_] = { "From" => $head[$_][0], "To" => $head[$_][1],
> "Subject" => $head[$_][2], "Cc" => $head[$_][4], "Header" =>
> $headings[$_], "Body" => $messages[$_] };
> }
> and your test:
>
> $records[$_]{$i->{type}} =~ /$i->{pattern}/
> Yes, sometimes it's extremely nice that a "record" in Perl is just an
> associative array. JavaScript shares this idea. BTW, a lot of JavaScript
> appears to be at least inspired by Perl. (an Object in Javascript is a
> hash, and an Array is one-dimensional, and can grow on demand. Does that
> seem familiar?)
>
--
with friendly regards....
jens luedicke <jens@irs-net.com>
PMC - Perl Mail Client
http://www.irs-net.com/
perl -le 'use Inline C=>("bool debcheck(){\n#ifdef DEBIAN\n
return TRUE;\n#endif\n}");&debcheck==0||print"This is a Debian System!"'
------------------------------
Date: Fri, 16 Mar 2001 10:06:27 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: binary files
Message-Id: <5dp3bt4dpsiu26nqorgsvdg4fvk0u29ekn@4ax.com>
Uri Guttman wrote:
>many mainframes and vaxes support decimal math in hardware but that is
>BCD.
...
>then we wouldn't have to hear about all
>the rounding issues from float newbies. :)
Only if those machines use BigFloats instead of real floats. "BCD" is
not a magical solution.
--
Bart.
------------------------------
Date: 16 Mar 2001 13:34:01 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Cant call subs
Message-Id: <98t4o9$b1l$1@bob.news.rcn.net>
nobull@mail.com wrote:
> "moneybyus" <webmaster@moneybyus.net> writes:
>> Could someone please help me out on this and tell me what im doing
>> wrong.
> You are posing your program UU encoded.
> You don't use strict.
> You don't enable warnings.
...
> You rolled your own implementation of the CGI API rather than using
> the standard libraries.
> You put a \ infront of an @ in a single quoted string.
> You don't check return values from open().
> You don't show us the exact error you are getting.
> You did not cut-down you script to the minimal for that still produces
> the effect in question before posting.
> You open a file in overwrite mode when you clearly meant to open it in
> append mode.
And there are two dead pigeons in the water tank.
------------------------------
Date: Fri, 16 Mar 2001 09:55:27 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Copy/Paste using Perl?
Message-Id: <fon3btk3l9ah05k6h3stslm6s0vm77n8b2@4ax.com>
LK wrote:
>open (FILE, $file);
>@records = <FILE>;
>close(FILE);
>
>$newfile = $file."\.txt";
>open (FIEL, ">>$newfile");
>foreach $i(@records){
> print FIEL "$i\n";
>}
Why are you adding a newline to every line? The newline is still there.
So now there will be two.
Uh... this is a binary file? Ouch! Most definitely use binmode on both
input and output file handles! This at least will give an exact copy:
open (FILE, $file);
binmode FILE;
@records = <FILE>;
close(FILE);
$newfile = $file."\.txt";
open (FIEL, ">>$newfile");
binmode FIEL;
foreach (@records){
print FIEL;
}
But no, that's not even what you want. You want to PARSE the WordPerfect
file, and extract the text from it, and then print out the plain text.
But CPAN doesn't have any modules referencing "Word PErfect" or
"Wordperfect". Tough luck.
So, automation is the only way to go: control WordPerfect to open the
file for you, maybe even make it save as text. Best bet: see what
Win32::OLE can do for you. At worst, make it copy the text. Using
Win32::API it must be possible to retrieve the text from the clipboard
into a scalar (OpenClipboard(), GetClipboardData(CF_TEXT), GLobalLock(),
RtlMoveMemory(), GLobalUnlock(), CloseCLipboard()).
Then you can just save the scalar. I assume it already contains CR
characters, so binmode again is necessary. To notepad, CR+CR+LF is a
softwrap marker, make one edit with notepad and you'll loose all of your
returns. You might have seen this happen with HTML files doawnloaded
from internet.
--
Bart.
------------------------------
Date: 16 Mar 2001 09:09:00 +0100
From: Christian Meisl <meisl@amvt.tu-graz.ac.at>
Subject: Create .tar.gz with Perl?
Message-Id: <m366harv8j.fsf@famvtpc59.tu-graz.ac.at>
I want to write a small backup script that generates backup.tar.gz
archives from my data. Therefore I was looking for tar- and
gzip-modules on CPAN. I found Tar that allows to create tar archives,
but I could not find a gzip module (only PerlIO::Gzip, and that does
not work with Perl 5.6.0).
Can anyone give me some hints on creating .tar.gz archives with Perl?
Can this be done without backticks or system calls?
Regards,
Christian
--
Christian Meisl <meisl@amvt.tu-graz.ac.at> www.amft.tu-graz.ac.at
Inst. f. Apparatebau, Mech. Verfahrenstechnik und Feuerungstechnik
---------------------- while (!asleep()) sheep++; ----------------------
PGP fingerprint: DF48 2503 0411 F0EF 149C 851B 1EF0 72B9 78B6 034A
------------------------------
Date: 16 Mar 2001 08:46:50 +0000
From: nobull@mail.com
Subject: Re: Create .tar.gz with Perl?
Message-Id: <u9lmq6dngg.fsf@wcl-l.bham.ac.uk>
Christian Meisl <meisl@amvt.tu-graz.ac.at> writes:
> I want to write a small backup script that generates backup.tar.gz
> archives from my data. Therefore I was looking for tar- and
> gzip-modules on CPAN.
AFAIK the Compress::Zlib module as described in the Archive::Tar
manpage is on CPAN (and indeed is used by CPAN.pm) but for some reason
is not listed in the main module list.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 16 Mar 2001 10:39:05 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Create .tar.gz with Perl?
Message-Id: <u6r3bt80dnl856brva04bonu4cr3mtike6@4ax.com>
Christian Meisl wrote:
>I want to write a small backup script that generates backup.tar.gz
>archives from my data. Therefore I was looking for tar- and
>gzip-modules on CPAN. I found Tar that allows to create tar archives,
>but I could not find a gzip module (only PerlIO::Gzip, and that does
>not work with Perl 5.6.0).
Nonono. Archive::Tar has built-in support for gzip. It depends on the
presence of another module, Compress::Zlib I think. You can simply
create a .tar.gz file directly, by specifying a true value for write()
for the second paramater; the first being the file name.
--
Bart.
------------------------------
Date: Fri, 16 Mar 2001 10:47:04 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Does Perl have an un-getc
Message-Id: <mnr3bt0kgb3leee2fdkqbj9d401lqb7oet@4ax.com>
Tim Tracy wrote:
>Your suggestion worked great. I used the seek function to achieve the
>desired "un-getc" functionality and it worked great.
Note that to really get the effect of ungetc(), you should seek back by
-1, not -2. The latter backs up two characters, which was needed for
this particular application.
seek IN, -1, SEEK_CUR;
--
Bart.
------------------------------
Date: Thu, 15 Mar 2001 23:28:27 -0000
From: "Milliwave" <milliwave@rfengineering.freeserve.co.uk>
Subject: Excute Script 2
Message-Id: <98rj4f$h40$1@newsg4.svr.pol.co.uk>
Hello I have two separate scripts
script 1 and script 2.
Script 2 needs information from script 1, and hence can only be executed
once script 1 has completed running. Is there any sought of command which I
can use within script 1 to execute script 2, once script
one has completed executing? Basically a command which could fire-off script
2?
Cheers
Kev
------------------------------
Date: Fri, 16 Mar 2001 12:07:51 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Excute Script 2
Message-Id: <3AB2038A.659A0D20@acm.org>
Milliwave wrote:
>
> Hello I have two separate scripts
>
> script 1 and script 2.
>
> Script 2 needs information from script 1, and hence can only be executed
> once script 1 has completed running. Is there any sought of command which I
> can use within script 1 to execute script 2, once script
> one has completed executing? Basically a command which could fire-off script
> 2?
perldoc -f eval
perldoc -f exec
perldoc -f system
perldoc -f do
John
--
use Perl;
program
fulfillment
------------------------------
Date: Fri, 16 Mar 2001 08:17:00 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: FAQ 7.16: What's the difference between dynamic and lexical (static) scoping? Between local() and my()?
Message-Id: <slrn9b3ivq.i5o.rgarciasuarez@rafael.kazibao.net>
PerlFAQ Server wrote in comp.lang.perl.misc:
>
> What's the difference between dynamic and lexical (static) scoping? Between local() and my()?
It would be probably useful to add a word about our() in this FAQ.
------------------------------
Date: Fri, 16 Mar 2001 10:35:15 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Grokking map and grep
Message-Id: <n3r3btcbaqigqta3ndf21d02f1lia6hufs@4ax.com>
Matthew O. Persico wrote:
>{
> local $^W = 0;
... # some test which can generate warnings
>}
There's no need to explicitely set $^W to zero. Just
local $^W;
will do.
--
Bart.
------------------------------
Date: 16 Mar 2001 12:35:25 +0000
From: nobull@mail.com
To: Mirek Rewak <cave@pertus.com.pl>
Subject: Re: Help in understood Perl some slides (Taming of Camel)
Message-Id: <u9ae6lesl9.fsf@wcl-l.bham.ac.uk>
Mirek Rewak <cave@pertus.com.pl> writes:
> PS Sound file to slides (that was mentioned by nobull) would be also
> great.
The sound file I was talking about is a recording of Larry's "Camel
Lot #6" Keynote speach at Atlanta Linux Showcase and Conference
[2000-10-16] which reused the "Taming of Camel" slides you refer to.
I cannot recall where I got it but a Google search for "Camel Lot 6" finds
http://technetcast.com/tnc_play_stream.html?stream_id=375
where you can get the slides, the audio and the transcript.
Way back in the dawn of time, this is what Unix looked like. Either
you programmed in C, or you programmed in shell. Of course, those
were two different realms, and it was sort of one or the other. We
had this dichotomy of our thinking, that you had to do one or the
other.
How it really was back then, one day it opened up to me, these were
not opposites but think of an oyster shell opening up here. Instead
of opposites, they were two different dimensions in space that you
could graph things like this. You could consider sed and awk to be
sort of warts on the shell.
For those of you at the back who can't read this, the left hand axis
(what C is good at) is called "manipulexity" and the horizontal
attitude is called "whipuptitude".
With that realization I realized that there was a big gray area out
there. In biological terms, that's an ecological niche. So I decided
to fill it.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 16 Mar 2001 09:05:21 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Help to Install Perl
Message-Id: <x7u24u6q3z.fsf@home.sysarch.com>
>>>>> "SRG" == Scott R Godin <webmaster@webdragon.munge.net> writes:
SRG> | for(reverse (0..99)){($a,$b,$c)=(' bottles of beer',' on the
SRG> wall', | 'Take one down, pass it around');$a=~s/s//
SRG> if/1/;print"$_$a$b\n\n" |
SRG> unless/99/;print"$_$a$b\n$_$a\n$c\n"unless/0/;}print"*hic*\n"
SRG> ROFL, and the sig was SO apropos too :D
about 2 years ago, we had a golf thread on printing out that song. there
is a web site devoted to ways of printing that song in as many computer
languages as possible. the perl entry stunk so we worked at making it
much better/shorter.
here was one. i don't have the author's name.
$_=shift||99;$b='"$_ bottle$s[$_==1] of beer"';$w=' on the wall';@s='s';print
eval$b,"$w, ",eval$b,"!\nTake one down, pass it around,\n",eval'$_--;'.$b,$w,
"!\n\n"while$_
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Fri, 16 Mar 2001 08:58:21 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: How to do this?
Message-Id: <x7wv9q6qfm.fsf@home.sysarch.com>
>>>>> "CKC" == Charles K Clarkson <c_clarkson@hotmail.com> writes:
CKC> Wouldn't you want to increment $col_num somewhere in there?
sure. why not.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Fri, 16 Mar 2001 10:54:00 +0000 (UTC)
From: real.email@signature.this.is.invalid (Csaba Raduly)
Subject: Re: How to gret rid of Warning message? "Value of <HANDLE>"
Message-Id: <Xns9066673DBquuxi@194.203.134.135>
And so it came to pass that yf110@vtn1.victoria.tc.ca (Malcolm
Dew-Jones) on 08 Mar 2001 wrote <3aa7e576@news.victoria.tc.ca>:
>Thanh Q Lam (thanh.q.lam@alcatel.com) wrote:
>: I keep getting this warning message when I run listChg.pl script
>
>: Value of <HANDLE> construct can be "0"; test with defined() at
>: ./listChg.pl line 65535.
>
>see below, the line should be
>
> while (defined($rmstodo = <RMSTODO>))
> ^^^^^^^^ ^
>
>: I don't even have that many lines in my code. the listChg.pl is
>: very
>
>On some occasions the line number is all wrong.
>
[snip]
Ain't that a bug (in Perl) ?
--
Csaba Raduly, Software Developer , Sophos Anti-Virus
email:csaba.raduly@sophos.com http://www.sophos.com/
US Support +1 888 SOPHOS 9 UK Support +44 1235 559933
In case of water landing, YOU may be used as a flotation device!
------------------------------
Date: 16 Mar 2001 12:22:30 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: How to gret rid of Warning message? "Value of <HANDLE>"
Message-Id: <98t0i6$1o$1@mamenchi.zrz.TU-Berlin.DE>
According to Csaba Raduly <real.email@signature.this.is.invalid>:
> >Thanh Q Lam (thanh.q.lam@alcatel.com) wrote:
[...]
> >: ./listChg.pl line 65535.
[...]
> Ain't that a bug (in Perl) ?
Yes, a well known and loved one. I'd miss it.
Anno
------------------------------
Date: Fri, 16 Mar 2001 14:16:57 +0100
From: Markus Weihrauch <yeah.yeah@gmx.net>
Subject: Re: module for national holidays
Message-Id: <98t78p.1gs.1@ID-35539.user.dfncis.de>
On Fri, 16 Mar 2001 02:10:06 GMT, Gordon Tisher <gordon@balafon.net>
wrote:
> Is there a perl module that knows about national holidays (I'm
> particularly interested in Canadian holidays)?
We have used PCalc as a basis, available here:
http://catcode.com/date/pcalc.html
http://www.engelschall.com/u/sb/download/
http://www.perl.com/CPAN/authors/id/STBEY/
There is also a package called "Date-Calc", e.g. version 5. It is a C
module and some Perl to access it from Perl. Same URL.
Markus
--
"We're all capable of mistakes, but I do not care to enlighten you on the
mistakes we may or may not have made."
Governor George W. Bush, Jr.
------------------------------
Date: 16 Mar 2001 11:22:55 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Most efficient way to extract unique array elements?
Message-Id: <98st2f$pn5$1@mamenchi.zrz.TU-Berlin.DE>
According to John Bokma <john@castleamber.co.nz>:
[...]
> Use a hash. A long example:
>
> my %hash;
> foreach my $item (@array1)
> {
> $hash{$item} = 1;
> }
>
> keys %hash now contain the unique elements
>
> shorter way:
>
> my %hash;
> @hash{@array1} = (1) x @array1;
Still shorter:
@hash{ @array1} = ();
If all you want is the keys, undefined values are fine.
Anno
------------------------------
Date: 16 Mar 2001 12:57:49 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Most efficient way to extract unique array elements?
Message-Id: <slrn9b43ed.863.abigail@tsathoggua.rlyeh.net>
Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMDCCLIV
September MCMXCIII in <URL:news:98st2f$pn5$1@mamenchi.zrz.TU-Berlin.DE>:
.. According to John Bokma <john@castleamber.co.nz>:
..
.. [...]
..
.. > Use a hash. A long example:
.. >
.. > my %hash;
.. > foreach my $item (@array1)
.. > {
.. > $hash{$item} = 1;
.. > }
.. >
.. > keys %hash now contain the unique elements
.. >
.. > shorter way:
.. >
.. > my %hash;
.. > @hash{@array1} = (1) x @array1;
..
.. Still shorter:
..
.. @hash{ @array1} = ();
And as one line:
my %hash = map {$_ => 1} @array1;
Abigail
--
use lib sub {($\) = split /\./ => pop; print $"};
eval "use Just" || eval "use another" || eval "use Perl" || eval "use Hacker";
------------------------------
Date: Fri, 16 Mar 2001 11:45:06 GMT
From: "Kalle Anka" <kalle@tvettsvamp.a.se>
Subject: Need help with an expression
Message-Id: <61ns6.148$4N4.44681@newsc.telia.net>
If ($textfile contain a perfect match with $input) # How do I express
this?
{{
print "OK"
}
else
{
print "NO"
}}
# Example: If the line i the textfile is somone@someone.com and the input is
someone@somewere or @ or com its NO.
If the input is exactly the same, someone@somewere.com, its OK.
Regards
Kalle
------------------------------
Date: Fri, 16 Mar 2001 12:07:31 GMT
From: pjlees@ics.forthcomingevents.gr (Philip Lees)
Subject: Re: Need help with an expression
Message-Id: <3ab2007a.17310421@news.grnet.gr>
On Fri, 16 Mar 2001 11:45:06 GMT, "Kalle Anka" <kalle@tvettsvamp.a.se>
wrote:
>If ($textfile contain a perfect match with $input) # How do I express
>this?
Er ...
if ( $textfile eq $input ){
print "Yes\n";
}else{
print "No\n";
}
You can find out more by looking under Relational Operators and
Equality Operators in the perlop section of the Perl documentation on
your hard disk.
If you intend to ask more questions here you might think about using a
Subject line that describes your problem more clearly.
Phil
--
@x=split//,'Just another Perl decoder,';split//,'*'x@x;%i=split/=/,
'AA=a=aa= =1=,';for$i(0..$#x){$_[$i]=chr($=+5);while($_[$i]ne$x[$i])
{$_[$i]=$i{$_[$i]}if$i{++$_[$i]};print@_,"\r";while(rand!=rand){}}}
Ignore coming events if you wish to send me e-mail
------------------------------
Date: Fri, 16 Mar 2001 12:03:08 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Need help with an expression
Message-Id: <3AB2026F.48870C77@acm.org>
Kalle Anka wrote:
>
> If ($textfile contain a perfect match with $input) # How do I express
> this?
> {{
> print "OK"
> }
> else
> {
> print "NO"
> }}
>
> # Example: If the line i the textfile is somone@someone.com and the input is
> someone@somewere or @ or com its NO.
> If the input is exactly the same, someone@somewere.com, its OK.
if ( $textfile eq $input ) {
print "OK";
}
else {
print "NO";
}
John
--
use Perl;
program
fulfillment
------------------------------
Date: 16 Mar 2001 12:46:28 GMT
From: merrill@missioncriticallinux.com
Subject: Re: Need help with an expression
Message-Id: <98t1v4$6cm$1@news.netmar.com>
In article <61ns6.148$4N4.44681@newsc.telia.net>, Kalle Anka
<kalle@tvettsvamp.a.se> writes:
>If ($textfile contain a perfect match with $input) # How do I express
>this?
You would say:
open(FH, "<filename_to_read") || die "Couldn't open input file";
while (<FH>) {
if ($_ =~ /someone\@somewhere.com/) {
print "It *IS* a match\n";
}
else {
print "It is *NOT* a match\n";
}
}
The "=~" will match a regular expression. If you want to match
exactly, then you could also use this if:
if ($_ eq "someone@somewhere.com") {
You'll have to test these solutions to see if you need to escape
the at-sign and the dot before the "com".
Hope this helps.
Hardy Merrill
Mission Critical Linux, Inc.
http://www.missioncriticallinux.com
>{{
>print "OK"
>}
>else
>{
>print "NO"
>}}
>
>
># Example: If the line i the textfile is somone@someone.com and the input is
>someone@somewere or @ or com its NO.
>If the input is exactly the same, someone@somewere.com, its OK.
>
>
>
>Regards
>Kalle
>
>
----- Posted via NewsOne.Net: Free (anonymous) Usenet News via the Web -----
http://newsone.net/ -- Free reading and anonymous posting to 60,000+ groups
NewsOne.Net prohibits users from posting spam. If this or other posts
made through NewsOne.Net violate posting guidelines, email abuse@newsone.net
------------------------------
Date: Fri, 16 Mar 2001 11:02:53 GMT
From: Anders Goeransson <anders.goransson@chello.se>
Subject: new user
Message-Id: <2gs3btg123nhje483rjsqnhkr6kribl16i@4ax.com>
Hi!
I just downloaded perl
---------------------------
This is perl, v5.6.0 built for MSWin32-x86-multi-thread
(with 1 registered patch, see perl -V for more detail)
Copyright 1987-2000, Larry Wall
Binary build 623 provided by ActiveState Tool Corp.
http://www.ActiveState.com
Built 16:27:07 Dec 15 2000
--------------------------
I now try to run a little script (which I've gotten from a friend) and
it works fine on a machine using MKS tools. On the above perl I get
the following messages:
Global symbol "$dir" requires explicit package name at
C:\Perl\eg\example.pl lin
e 2.
Global symbol "$dir" requires explicit package name at
C:\Perl\eg\example.pl lin
e 4.
Global symbol "$newdir" requires explicit package name at
C:\Perl\eg\example.pl
line 5.
Global symbol "$dir" requires explicit package name at
C:\Perl\eg\example.pl lin
e 5.
Global symbol "$newdir" requires explicit package name at
C:\Perl\eg\example.pl
line 6.
Global symbol "$file" requires explicit package name at
C:\Perl\eg\example.pl li
ne 7.
Global symbol "$in" requires explicit package name at
C:\Perl\eg\example.pl line
10.
Global symbol "$dir" requires explicit package name at
C:\Perl\eg\example.pl lin
e 10.
Global symbol "$file" requires explicit package name at
C:\Perl\eg\example.pl li
ne 10.
Global symbol "$in" requires explicit package name at
C:\Perl\eg\example.pl line
12.
Global symbol "$in" requires explicit package name at
C:\Perl\eg\example.pl line
14.
Global symbol "$newdir" requires explicit package name at
C:\Perl\eg\example.pl
line 16.
Global symbol "$newdir" requires explicit package name at
C:\Perl\eg\example.pl
line 16.
Global symbol "$newdir" requires explicit package name at
C:\Perl\eg\example.pl
line 18.
Global symbol "$file" requires explicit package name at
C:\Perl\eg\example.pl li
ne 18.
Global symbol "$in" requires explicit package name at
C:\Perl\eg\example.pl line
20.
Execution of C:\Perl\eg\example.pl aborted due to compilation errors.
----------------
How do I get all these explicit packages names.
regards Anders
------------------------------
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 V10 Issue 501
**************************************