[25545] in Perl-Users-Digest
Perl-Users Digest, Issue: 7789 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 16 14:05:44 2005
Date: Wed, 16 Feb 2005 11:05:23 -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, 16 Feb 2005 Volume: 10 Number: 7789
Today's topics:
A hopefully simple question <harold@uga.edu>
Re: A wide open niche in Perl publishing... <please_post@nomail.edu>
Re: Accessing Hash of hash of arrays <ebohlman@omsdev.com>
Re: Accessing Hash of hash of arrays <lynn.watts@ugs.com>
Re: Accessing Hash of hash of arrays <flavell@ph.gla.ac.uk>
Re: Compare 2 files and put the matching part in a 3rd (colin_lyse)
Re: forms, cgi - beginner question (hymie!)
hash map <ax178@wp.pl>
Re: hash map <phaylon@dunkelheit.at>
Re: hash map <nobull@mail.com>
Re: hash map drleeds@gmail.com
Re: hash map <nobull@mail.com>
Re: hash map <ax178@wp.pl>
Re: hash map <phaylon@dunkelheit.at>
Re: Problem with IO::Socket <news@chaos-net.de>
Re: Problem with IO::Socket <phaylon@dunkelheit.at>
Re: Problem with IO::Socket chris-usenet@roaima.co.uk
Re: Problem with IO::Socket <news@chaos-net.de>
Re: Problem with IO::Socket <phaylon@dunkelheit.at>
Re: SET Operations in Perl <1usa@llenroc.ude.invalid>
Re: SET Operations in Perl <matternc@comcast.net>
Re: SET Operations in Perl <georgekinley@hotmail.com>
Re: SET Operations in Perl <lambik@kieffer.nl>
Re: SET Operations in Perl <1usa@llenroc.ude.invalid>
Re: SET Operations in Perl <nospam@bigpond.com>
Re: SET Operations in Perl <nobull@mail.com>
Re: The Problem with Perl <rhugga@yahoo.com>
Re: The Problem with Perl <do-not-use@invalid.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 16 Feb 2005 14:00:09 -0500
From: Harold Pritchett <harold@uga.edu>
Subject: A hopefully simple question
Message-Id: <42139839.3050507@uga.edu>
I am modifying a perl script which I did not write.
I am at best a beginning perl programmer, but have been
writing code in other languages for over 30 years.
My question is the difference in the following two
statements:
print FILE "$_";
print FILE ">$_";
The file is the same, and is opened with the statement:
&lopen($FH, ">>", "$opt_f$suffix") ||
die("Can't append to $opt_f$suffix: $!");
$is_open = 1;
This is done in a subroutine and the file handle FILE is
passed into the subroutine as FH. The file name obviously
is passed in two pieces, $opt_f and $suffix.
I've tried to find this on the web, but have failed
miserably.
Thanks
Harold
------------------------------
Date: Wed, 16 Feb 2005 16:46:24 +0000 (UTC)
From: bill <please_post@nomail.edu>
Subject: Re: A wide open niche in Perl publishing...
Message-Id: <cuvtd0$el2$1@reader2.panix.com>
In <cuuja1$sjs$1@reader2.panix.com> J Krugman <jkrugman345@yahbitoo.com> writes:
>(I sure hope that someone at O'Reilly, or Manning, or New Riders,
>or Apress, etc. is reading this.)
Pardon my cynical take, and since you bring up publishing
and realism, vague pseudo-code books have a much broader
potential market than brass-tacks, language-specific
books. Maybe that's why "Design Patterns"'s Amazon.com
sales rank is 853, while "The Perl Cookbook"'s is 1843.
Maybe Joel Spolsky (who coined the term "architecture
astronautics") is right in his claim that programming is
something that most people can only learn through
apprenticeship, not in school (and even less from books).
The implication from this is that real-world programming
is an activity dominated by issues that are too varied,
too contingent, and too specific to be suitable for
teaching grand theories in a university class (or for
writing best-selling books about).
bill
------------------------------
Date: 16 Feb 2005 17:23:35 GMT
From: Eric Bohlman <ebohlman@omsdev.com>
Subject: Re: Accessing Hash of hash of arrays
Message-Id: <Xns95FF753394D88ebohlmanomsdevcom@130.133.1.4>
"Lynn" <lynn.watts@ugs.com> wrote in news:4210dff3$1@usenet.ugs.com:
> Thanks for all of your help :-) It's nice to know that people like you
> spend your time
> helping out new perl programmers. I have found that the regulares here
> at CLPM are always very helpful.
I think it would be very instructive to point out *why* you had such a
good experience while many other Perl newbies seem to perceive this group
as hostile. Your initial post was practically a textbook example of how
to ask a "newbie" question the *right* way.
1) You put the subject of your post in the Subject of your post :)
Anyone just skimming the headers (which, in a high-volume group like
this, is just about everyone) could immediately tell exactly what your
post was about. You described the issue using the fewest possible words
(making every word count) that could adequately describe it, with no
superfluous verbiage like "newbie" or "help."
2) Your first paragraph succinctly described what you were trying to do.
You included a tiny bit of irrelevant information, but you didn't get all
defensive when someone pointed out that it was irrelevant.
3) Then you provided a code example that anyone could cut-and-paste and
run.
3.1) You asked your machine for all the help it could give you (using
strict and warnings).
3.2) The code example was free of typos, suggesting that you cut-and-
pasted it rather than retyping it.
3.3) The code example contained its own data.
4) You described what results you wanted. It's amazing how many posts
leave the reader guessing at that.
5) You included the *exact* error message that you got, not "something
like..."
6) You went to the manual and looked up the problem. You found the
explanation a little beyond you, but that's not a problem. You asked us
to clarify what the manual said rather than asking us to read it to you.
With your permission, I think it would be helpful if the posting
guidelines regularly posted here contained a citation (via the Google
archive or someone mirroring it on their Web site) to your post as an
example of a post that follows the guidelines.
------------------------------
Date: Wed, 16 Feb 2005 10:47:06 -0800
From: "Lynn" <lynn.watts@ugs.com>
Subject: Re: Accessing Hash of hash of arrays
Message-Id: <42139482$1@usenet.ugs.com>
Hi Eric,
"Eric Bohlman" <ebohlman@omsdev.com> wrote in message
news:Xns95FF753394D88ebohlmanomsdevcom@130.133.1.4...
>
> I think it would be very instructive to point out *why* you had such a
> good experience while many other Perl newbies seem to perceive this group
> as hostile.
Yes, unfortuntaly many do find this group hostile.
> Your initial post was practically a textbook example of how
> to ask a "newbie" question the *right* way.
Before I posted my message I was browsing this newsgroup and I was
astounded by the number of responses pointing to the guidelines. So
what I did was to printout the guidelines and follow them. Once I did
this I was very suprised as to how applying the guidelines has helped me
with my script. For example, orginally I was not going to ask a question
about a Hash of hashes of arrays I had a different problem that promped me
to start
a post to this newsgroup (and get the guidelines and use them)
In using the guidelines I was able to fix about 5 or 6 problems without
asking any
questions.
I think one of the misunderstandings new perl programmers have is that
they think the guidelines are strict rules on posting to CLPM when in fact
they are guidelines for helping you (the programmer) fix the actual perl
script.
(snipped)
> With your permission, I think it would be helpful if the posting
> guidelines regularly posted here contained a citation (via the Google
> archive or someone mirroring it on their Web site) to your post as an
> example of a post that follows the guidelines.
That's OK with me :-)
Thanks
Lynn
------------------------------
Date: Wed, 16 Feb 2005 18:59:52 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: Accessing Hash of hash of arrays
Message-Id: <Pine.LNX.4.61.0502161852120.9077@ppepc56.ph.gla.ac.uk>
On Wed, 16 Feb 2005, Lynn wrote:
> Before I posted my message I was browsing this newsgroup and I was
> astounded by the number of responses pointing to the guidelines. So
> what I did was to printout the guidelines and follow them. Once I
> did this I was very suprised as to how applying the guidelines has
> helped me with my script. For example, orginally I was not going to
> ask a question about a Hash of hashes of arrays I had a different
> problem that promped me to start a post to this newsgroup (and get
> the guidelines and use them) In using the guidelines I was able to
> fix about 5 or 6 problems without asking any questions.
That's beautiful.
> I think one of the misunderstandings new perl programmers have is
> that they think the guidelines are strict rules on posting to CLPM
> when in fact they are guidelines for helping you (the programmer)
> fix the actual perl script.
Just so. The guidelines are meant to 1. help folks to help
themselves, and 2. when that's not enough, to help anyone who has
appropriate expertise, to get to the root of the problem in an
effective way. When that happens, it makes everybody happy: the
questioner, because they get a solution: the respondent, because they
can see that their solution was understood and was useful; and the
bystanders, because they learnt something from seeing it done.
Usenet perfection.
Thanks for sharing!
------------------------------
Date: 16 Feb 2005 09:35:08 -0600
From: colin_lyse@98fgfgs.com (colin_lyse)
Subject: Re: Compare 2 files and put the matching part in a 3rd file
Message-Id: <42136791$0$58070$45beb828@newscene.com>
In article <mn.abb67d519ce75a90.18030@aol.com>, BerNaC <bernac001@aol.com> wrote:
>Hi all,
>
>I need to compare two text files and put the maching result in another
>file. Does anybody have an idea?
>
>file1 file2 comprare and match=
> file3
>------ -----------
> -----------
>1 3
> 3
>2 4
> 4
>3 5
> 5
>4 6
>5 7
>
>
>Thank you
>
{
my %t;
$t{$_} .= "1" for @file1;
$t{$_} .= "2" for @file2;
@matching = grep $t{$_} eq "12", keys %t;
}
no need to sort files first. VERY fast.
------------------------------
Date: Wed, 16 Feb 2005 15:36:02 -0000
From: hymie@lactose.smart.net (hymie!)
Subject: Re: forms, cgi - beginner question
Message-Id: <1116q32fmq05d42@corp.supernews.com>
In our last episode, the evil Dr. Lacto had captured our hero,
"John" <jfcampbell@aol.com>, who said:
>I am working from a book, "CGI Manual of Style," a Ziff-Davis number by
>Robert McDaniel.
>
>Page 8 says:
>"...when a Web server receives a request for a file contained in in the
>subdirectory cgi-bin, it knows that the file is a cgi script and will
>run it and return only output from the script.
Only if the web server is configured to recognize the cgi-bin
subdirectory as a place for CGI scripts. The directory can be named
anything. Or a web server can be configured without a cgi-bin directory.
There is nothing magic about the name "cgi-bin".
hymie! http://www.smart.net/~hymowitz hymie@lactose.smart.net
===============================================================================
------------------------------
Date: Wed, 16 Feb 2005 19:14:49 +0100
From: vertigo <ax178@wp.pl>
Subject: hash map
Message-Id: <cv02qf$133$1@nemesis.news.tpi.pl>
Hello
I display values from my map:
while(my ($key,$val) = each %$map){
printf $key."=".$val;
}
but how can i read value from map for specified key ?
I tried:
my $value = map{"USER"};
but i receive errors. Could anybody help ?
Thanx
Michal
------------------------------
Date: Wed, 16 Feb 2005 19:14:33 +0100
From: phaylon <phaylon@dunkelheit.at>
Subject: Re: hash map
Message-Id: <pan.2005.02.16.18.14.32.825144@dunkelheit.at>
vertigo wrote:
> I display values from my map:
> while(my ($key,$val) = each %$map){
^^^^^
What is map? Could you include the code that creates ($|%)map?
> printf $key."=".$val;
Hm, why printf without format? Why not just print "$key=$val\n";?
> but how can i read value from map for specified key ? I tried:
>
> my $value = map{"USER"};
>
> but i receive errors. Could anybody help ?
Yep, perldoc perldata. A bit more of code (like the generation of $map)
would also be nicer than guessing what you are about to try.
--
http://www.dunkelheit.at/
The mind is its own place, and in itself
Can make a heaven of hell, a hell of heaven. -- Milton, »Paradise Lost«
------------------------------
Date: Wed, 16 Feb 2005 18:25:03 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: hash map
Message-Id: <cv02s5$bgr$1@sun3.bham.ac.uk>
vertigo wrote:
> I display values from my map:
> while(my ($key,$val) = each %$map){
> printf $key."=".$val;
> }
>
> but how can i read value from map for specified key ?
> I tried:
>
> my $value = map{"USER"};
You can't just make stuff up and expect the computer to understand it.
$map is a hash reference so...
my $value = $$map{"USER"};
...or...
my $value = $map->{"USER"};
For an explainarion and more an information about references in Perl see:
perldoc perlref
perldoc perlreftut
Note: the "" are optional in both cases as USER is a word.
> but i receive errors.
That's a red-flag phrase. In this particular case it didn't matter but
you as the person asking for help were not in a position to know that.
You should never just say "errors" you should actually show us the
actual errors.
------------------------------
Date: 16 Feb 2005 10:30:57 -0800
From: drleeds@gmail.com
Subject: Re: hash map
Message-Id: <1108578657.367489.44800@o13g2000cwo.googlegroups.com>
your variable $map is a hash reference, so try:
my $value = ${$map}{"USER"};
or
my $value = ${$map}{'USER'};
or
my $value = ${$map}{USER};
This is instead of %{$map} because you are accessing an individual
element, not the hash as a whole. A hash in Perl is like a map in
other languages, but it is built in, you don't load it from a library.
------------------------------
Date: Wed, 16 Feb 2005 18:27:52 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: hash map
Message-Id: <cv031e$bgr$2@sun3.bham.ac.uk>
[ see answer in other response ]
vertigo wrote:
> Subject: hash map
Please put the subject of your post in the Subject of your post.
The word 'map' is just the name you happen to have used for a variable
in your example code so contains no information.
As such your subject line is in effect only one word: 'hash'
------------------------------
Date: Wed, 16 Feb 2005 19:43:55 +0100
From: vertigo <ax178@wp.pl>
Subject: Re: hash map
Message-Id: <cv04a2$dhk$1@atlantis.news.tpi.pl>
sorry , i had error in other part of code.
------------------------------
Date: Wed, 16 Feb 2005 19:40:07 +0100
From: phaylon <phaylon@dunkelheit.at>
Subject: Re: hash map
Message-Id: <pan.2005.02.16.18.40.07.588899@dunkelheit.at>
vertigo wrote:
> sorry , i had error in other part of code.
Yeah, but in this one too. Please read the posting guidelines and consult
faq and documentation before your next post.
--
http://www.dunkelheit.at/
Thru the darkness of futures past, the magician longs to see.
One chants out between two worlds: Fire, walk with me.
-- Twin Peaks, »Bob«
------------------------------
Date: Wed, 16 Feb 2005 16:35:01 +0100
From: Martin Kissner <news@chaos-net.de>
Subject: Re: Problem with IO::Socket
Message-Id: <slrnd16q15.16p.news@maki.homeunix.net>
A. Sinan Unur wrote :
> Martin Kissner <news@chaos-net.de> wrote in
> news:slrnd15upm.srt.news@maki.homeunix.net:
>
>
> FWIW, the services you are trying
>
> 1) May not be enabled on the computers you have tried
> 2) May be behind a firewall
> 3) May require prior authentication
Thank you for your response, Sinan.
After I had written my answer (pointing out what I have tried to exclude
the reasons you mentioned) I tried using the port numbers instead of the
service name.
This finally worked and leads me to the next question:
Why doesn't the script (or the Perl interpreter) look up the portnumber
in /etc/services. Telnet works properly with given servicenames.
Regards
Martin
--
perl -e 'print 7.74.117.115.116.11.32.13.97.110.111.116.104.101.114.11
.32.13.112.101.114.108.11.32.13.104.97.99.107.101.114.10.7'
------------------------------
Date: Wed, 16 Feb 2005 16:36:37 +0100
From: phaylon <phaylon@dunkelheit.at>
Subject: Re: Problem with IO::Socket
Message-Id: <pan.2005.02.16.15.36.37.349215@dunkelheit.at>
Martin Kissner wrote:
> Why doesn't the script (or the Perl interpreter) look up the portnumber in
> /etc/services. Telnet works properly with given servicenames.
- perl (lc) is not only for *ixoid systems.
- telnet is programmed to do so.
- perl can be programmed to do so.
- You can program perl to do so.
--
http://www.dunkelheit.at/
That is not dead, which can eternal lie,
and with strange aeons even death may die.
-- H.P. Lovecraft
------------------------------
Date: Wed, 16 Feb 2005 16:15:00 +0000
From: chris-usenet@roaima.co.uk
Subject: Re: Problem with IO::Socket
Message-Id: <458ce2-nac.ln1@moldev.cmagroup.co.uk>
Martin Kissner <news@chaos-net.de> wrote:
> Why doesn't the script (or the Perl interpreter) look up the portnumber
> in /etc/services. Telnet works properly with given servicenames.
perldoc -f getservbyname
perl -e 'print join(", ", getservbyname ("telnet", "tcp")), ".\n"'
Chris
------------------------------
Date: Wed, 16 Feb 2005 17:27:28 +0100
From: Martin Kissner <news@chaos-net.de>
Subject: Re: Problem with IO::Socket
Message-Id: <slrnd16t3g.16p.news@maki.homeunix.net>
phaylon wrote :
> Martin Kissner wrote:
>
>> Why doesn't the script (or the Perl interpreter) look up the portnumber in
>> /etc/services. Telnet works properly with given servicenames.
>
> - perl (lc) is not only for *ixoid systems.
> - telnet is programmed to do so.
> - perl can be programmed to do so.
> - You can program perl to do so.
Well, to be honest, I am just beginning with networkprogramming with
Perl.
That's why I am reading the book and at this point the above does not
really help.
It is the second example in the book (the first one reads one line
from a file) and is supposed to work without any preparations and also
on windows and classic Mac OS.
Maybe perl can be programmed to do so (I am sure it can), but at this
point, I do not want to work out my own humble solution.
I would rather be interested if anyone out there could run the script
successfully without any changes and with servicenames instead of
portnumbers as it is suggested in the book.
Regrads
Martin
--
perl -e 'print 7.74.117.115.116.11.32.13.97.110.111.116.104.101.114.11
.32.13.112.101.114.108.11.32.13.104.97.99.107.101.114.10.7'
------------------------------
Date: Wed, 16 Feb 2005 17:41:23 +0100
From: phaylon <phaylon@dunkelheit.at>
Subject: Re: Problem with IO::Socket
Message-Id: <pan.2005.02.16.16.41.23.8933@dunkelheit.at>
Martin Kissner wrote:
> I would rather be interested if anyone out there could run the script
> successfully without any changes and with servicenames instead of
> portnumbers as it is suggested in the book.
A better way is to use the docs. For IO::Socket::INET it is documented,
that
| If the constructor is only passed a single argument, it is assumed to be
| a PeerAddr specification.
A few lines up, we see
| The PeerAddr can be a hostname or the IP-address on the "xx.xx.xx.xx"
| form. The PeerPort can be a number or a symbolic service name. The
| service name might be followed by a number in parenthesis which is used
| if the service is not known by the system. The PeerPort specification
| can also be embedded in the PeerAddr by preceding it with a ":".
--
http://www.dunkelheit.at/
»Better to reign in hell than to serve in heaven«
-- John Milton, »Paradise Lost«
------------------------------
Date: 16 Feb 2005 14:05:09 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: SET Operations in Perl
Message-Id: <Xns95FF5C6D6FAFasu1cornelledu@132.236.56.8>
"George" <georgekinley@hotmail.com> wrote in news:xn0dykr5d1hkhz4001
@news.europe.nokia.com:
> Bernard El-Hagin wrote:
>
>> "George" <georgekinley@hotmail.com> wrote:
>>
>> > Hi,
>> > how can we do SET Operations in perl using two hashes or arrays
>> > in case it is too easy , please redirect me to some link
>>
>>
>> www.whatthehellareyoutalkingabout.com
>
> what was that you could not understand,
> dude
Well, you used SET, suggesting it might be an acronym or something. Since
you do not give an indication of what SET means to you, I am going to
assume that the following FAQ is related to your question:
perldoc -q intersection
As always, I'll remind you that you are supposed to browse through the
complete FAQ list before posting here. If the answer in the FAQ does not
answer your question, please feel free to post a message that contains a
comprehensible description of your question. Before doing so, however, I
sincerely recommend to you to please read the posting guidelines for this
group.
Sinan
------------------------------
Date: Wed, 16 Feb 2005 09:05:28 -0500
From: Chris Mattern <matternc@comcast.net>
Subject: Re: SET Operations in Perl
Message-Id: <7--dndKqLZ61zo7fRVn-rQ@comcast.com>
George wrote:
> Bernard El-Hagin wrote:
>
>> "George" <georgekinley@hotmail.com> wrote:
>>
>> > Hi,
>> > how can we do SET Operations in perl using two hashes or arrays
>> > in case it is too easy , please redirect me to some link
>>
>>
>> www.whatthehellareyoutalkingabout.com
>
> what was that you could not understand,
> dude
He can't understand why you think he's telepathic. Not enough
information to have any idea what you're talking about.
Dude.
--
Christopher Mattern
"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
------------------------------
Date: Wed, 16 Feb 2005 14:09:45 GMT
From: "George" <georgekinley@hotmail.com>
Subject: Re: SET Operations in Perl
Message-Id: <xn0dyks8z1j0lu2002@news.europe.nokia.com>
A. Sinan Unur wrote:
> "George" <georgekinley@hotmail.com> wrote in news:xn0dykr5d1hkhz4001
> @news.europe.nokia.com:
>
> > Bernard El-Hagin wrote:
> >
> >> "George" <georgekinley@hotmail.com> wrote:
> >>
> >> > Hi,
> >> > how can we do SET Operations in perl using two hashes or arrays
> >> > in case it is too easy , please redirect me to some link
> >>
> >>
> >> www.whatthehellareyoutalkingabout.com
> >
> > what was that you could not understand,
> > dude
>
> Well, you used SET, suggesting it might be an acronym or something.
> Since you do not give an indication of what SET means to you, I am
> going to assume that the following FAQ is related to your question:
>
> perldoc -q intersection
>
> As always, I'll remind you that you are supposed to browse through
> the complete FAQ list before posting here. If the answer in the FAQ
> does not answer your question, please feel free to post a message
> that contains a comprehensible description of your question. Before
> doing so, however, I sincerely recommend to you to please read the
> posting guidelines for this group.
>
> Sinan
Thanks and Sorry I should have looked harder my mistake
------------------------------
Date: Wed, 16 Feb 2005 15:23:31 +0100
From: Lambik <lambik@kieffer.nl>
Subject: Re: SET Operations in Perl
Message-Id: <37h35jF5e6t5jU1@individual.net>
Tore Aursand wrote:
> Bernard El-Hagin wrote:
> >>how can we do SET Operations in perl using two hashes or arrays
> >>in case it is too easy , please redirect me to some link
>
> > www.whatthehellareyoutalkingabout.com
>
> I think he is talking about this:
>
> <http://www.google.no/search?&q=%22SET+operations%22+programming>
>
Let's start a Poll. I think he want to change an environment variable:
Found in D:\perl5.8\lib\pod\perlfaq8.pod
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?
Unix
In the strictest sense, it can't be done--the script
executes as a different process from the shell it was
started from. Changes to a process are not reflected in
its parent--only in any children created after the
change. There is shell magic that may allow you to fake
it by eval()ing the script's output in your shell; check
out the comp.unix.questions FAQ for details.
------------------------------
Date: 16 Feb 2005 14:22:49 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: SET Operations in Perl
Message-Id: <Xns95FF5F6BDCEAFasu1cornelledu@132.236.56.8>
Lambik <lambik@kieffer.nl> wrote in news:37h35jF5e6t5jU1@individual.net:
> Let's start a Poll.
Let's not, please.
Sinan
------------------------------
Date: Thu, 17 Feb 2005 02:17:15 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: SET Operations in Perl
Message-Id: <37ha0cF5b4hr8U1@individual.net>
George wrote:
> Hi,
> how can we do SET Operations in perl using two hashes or arrays
> in case it is too easy , please redirect me to some link
> thanks
http://www.gregorytoomey.com/index.php?option=content&task=view&id=9&Itemid=28
gtoomey
------------------------------
Date: Wed, 16 Feb 2005 17:55:18 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: SET Operations in Perl
Message-Id: <cv0147$ahk$1@sun3.bham.ac.uk>
Gregory Toomey wrote:
> George wrote:
>
>
>>Hi,
>>how can we do SET Operations in perl using two hashes or arrays
>>in case it is too easy , please redirect me to some link
>>thanks
>
>
> http://www.gregorytoomey.com/index.php?option=content&task=view&id=9&Itemid=28
Those are good if you have sets in arrays.
But if you have to store sets in Perl then arrays are not the natural type.
The natural type in Perl is the valueless hash (i.e. one with only keys).
Some what one usually thinks of as the primative set operations are not
primative in this implementation but the primatives you do have are
sufficient.
The primatives you get are:
Add a list of elements to set:
@set{'element1','emement2'} = ();
Remove a list of elements from set:
delete @set{'element1','emement2'};
Enumerate elements of set:
my @elements = keys %set;
Test if one element is in a set:
exists $set{$element};
Reduce a list to those elements in a set (also test if ant of a list is
in the set in a scalar context):
grep { exists $set{$_} } LIST;
(Note for large data there is an unpleasant overhead for using grep in a
scalar context so for large data don't - roll your own loop).
Union is not as often wanted as you may think - most of the time people
think they want union they can really make do with "add a list elements
to a set".
my %union = ( %set1, %set2 );
Intersection is non-primative but is not as often wanted as you may
think - most of the time people think they want intersection they can
really make do with "reduce a list to those elements in a set".
my %intersection;
@intersection{ grep { exists $set1{$_} keys %set2 }} = ();
------------------------------
Date: 16 Feb 2005 06:22:07 -0800
From: "Rhugga" <rhugga@yahoo.com>
Subject: Re: The Problem with Perl
Message-Id: <1108563727.663335.167690@c13g2000cwb.googlegroups.com>
??? They are the same?
int foo(int x) {
return (x*2);
}
char foo() {
return "A";
}
float foo() {
return 100.99;
}
All completely different functions in C. The name 'foo' may be the same
but as far as the compiler is concerned, they are different functions.
Are you saying these three functions above are the same? I believe you
are suffering from learning an interpreted language before learning a
true language like C or C++.
------------------------------
Date: 16 Feb 2005 16:06:40 +0100
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: The Problem with Perl
Message-Id: <yzdoeek1r3z.fsf@invalid.net>
"Rhugga" <rhugga@yahoo.com> writes:
> ??? They are the same?
>
> int foo(int x) {
> return (x*2);
> }
>
> char foo() {
> return "A";
> }
>
> float foo() {
> return 100.99;
> }
>
> All completely different functions in C. The name 'foo' may be the same
> but as far as the compiler is concerned, they are different functions.
> Are you saying these three functions above are the same? I believe you
> are suffering from learning an interpreted language before learning a
> true language like C or C++.
Since someone might actually believe this lie... Here is what two C
compilers have to say about your code above:
t1.c:5: conflicting types for `foo'
t1.c:1: previous declaration of `foo'
t1.c: In function `foo':
t1.c:6: warning: return makes integer from pointer without a cast
t1.c: At top level:
t1.c:9: conflicting types for `foo'
t1.c:5: previous declaration of `foo'
cc: "t1.c", line 5: error 1584: Inconsistent type declaration: "foo".
cc: "t1.c", line 5: error 1711: Inconsistent parameter list declaration for "foo".
cc: "t1.c", line 6: warning 526: Pointer implicitly converted to integral value in assignment.
cc: "t1.c", line 9: error 1584: Inconsistent type declaration: "foo".
cc: "t1.c", line 9: error 1711: Inconsistent parameter list declaration for "foo".
It may be C++, but it's not C.
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 7789
***************************************