[25561] in Perl-Users-Digest
Perl-Users Digest, Issue: 7805 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 21 06:05:50 2005
Date: Mon, 21 Feb 2005 03: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 Mon, 21 Feb 2005 Volume: 10 Number: 7805
Today's topics:
Any Perl Modules to gzip and gunzip <urgearun@gmail.com>
Re: Any Perl Modules to gzip and gunzip <noeltd@hotmail.com>
Re: Any Perl Modules to gzip and gunzip <noreply@gunnar.cc>
Re: Archive::Zip - _isSeekable a bit bodgy <not@invalid.invalid>
Re: Can't get regex right <tadmc@augustmail.com>
Re: Can't get regex right <noreply@gunnar.cc>
Re: Can't get regex right <abigail@abigail.nl>
Re: compacting '..' path segments using File::Spec <mgjv@tradingpost.com.au>
Re: compacting '..' path segments using File::Spec ofer@netapt.com
Re: cperl-mode and emacs-21.4 brocken? <nospam-abuse@ilyaz.org>
Re: cubic root subroutine (John M. Gamble)
Re: cubic root subroutine <do-not-use@invalid.net>
Re: emacs AAAAAAAAAAAAAHHH!!! babydoe@mailinator.com
Re: emacs AAAAAAAAAAAAAHHH!!! <anomousty@webwonders.org>
Re: emacs AAAAAAAAAAAAAHHH!!! <constantin.wiemer@infineon.com>
Re: emacs AAAAAAAAAAAAAHHH!!! <do-not-use@invalid.net>
How to test for existance ? <uce@ftc.gov>
Re: How to test for existance ? <1usa@llenroc.ude.invalid>
Re: Importing records with both space and quoted text q <joe@inwap.com>
Re: Need a module for grabbing text from a web page <joe@inwap.com>
Re: Need a module for grabbing text from a web page <phaylon@dunkelheit.at>
Parsing a text file..... clearguy02@yahoo.com
Re: Parsing a text file..... <do-not-use@invalid.net>
Re: Problem with IO::Socket [... on Mac OS X] (Anno Siegel)
Re: The Problem with Perl <goedicke@brandeis.edu>
Re: user login <lv@aol.com>
Re: user login <tadmc@augustmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 21 Feb 2005 00:14:48 -0800
From: "arun" <urgearun@gmail.com>
Subject: Any Perl Modules to gzip and gunzip
Message-Id: <1108973688.695303.61830@o13g2000cwo.googlegroups.com>
Hi ,
Is there any perl modules to compress and uncompress files, folders.
Thanks
With Regards
Arun
------------------------------
Date: Mon, 21 Feb 2005 08:45:26 GMT
From: "Atlantis" <noeltd@hotmail.com>
Subject: Re: Any Perl Modules to gzip and gunzip
Message-Id: <GchSd.129$r53.56@newsfe5-gui.ntli.net>
"arun" <urgearun@gmail.com> wrote in message
news:1108973688.695303.61830@o13g2000cwo.googlegroups.com...
> Hi ,
> Is there any perl modules to compress and uncompress files, folders.
>
> Thanks
> With Regards
> Arun
>
Archive::Zip
------------------------------
Date: Mon, 21 Feb 2005 11:00:02 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Any Perl Modules to gzip and gunzip
Message-Id: <37tplfF5epdcfU1@individual.net>
arun wrote:
> Is there any perl modules to compress and uncompress files, folders.
http://search.cpan.org/search?query=compress
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 21 Feb 2005 14:08:23 +1000
From: Matthew Braid <not@invalid.invalid>
Subject: Re: Archive::Zip - _isSeekable a bit bodgy
Message-Id: <cvbmrn$o7c$1@bunyip2.cc.uq.edu.au>
Anno Siegel wrote:
> It is true that ->can has problems (in particular in combination with
> AUTOLOAD), but in this case it's right. tempfile() returns an unblessed
> globref, which indeed doesn't have a ->stat method. That the Perl function
> stat() knows how to deal with it is outside ->can's responsibility.
I humbly apologise to UNIVERSAL and its ->can :)
> The bug is in Archive::Zip. It should probably add a test "ref( $fh) eq
> 'GLOB'" in _is_seekable to catch this.
I find it a little odd that it checks at all - the doco says the input
file handle must be seekable, so assuming it is and letting the seek die
would have been the appropriate thing to do IMHO.
> For a quick fix try blessing the temp fh into IO::File before using it.
> That should repair the behavior of Archive::Zip without hurting the file
> handle as such. Untested.
This seems to work. It may screw up some kind of filehandle arcanum, but
I'm only doing simple reads/writes/seeks so it should be OK. Ta :)
MB
------------------------------
Date: Sun, 20 Feb 2005 21:34:37 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Can't get regex right
Message-Id: <slrnd1ilmd.mat.tadmc@magna.augustmail.com>
Jazeker <jazeker_b_nospamlalala@yahoo.co.uk> wrote:
> Gunnar Hjalmarsson wrote:
>> Jazeker wrote:
>>
>>> Gunnar Hjalmarsson wrote:
>>>
>>>> You probably need the /s modifier.
>>>
>>>
>>> Thank you so much ! I wonder then why ([\n.]*) did not do the trick...
>>
>>
>> Because the . character is not special within a character class. [\n.]
>> represents only a newline or a literal dot.
>>
>:-|
>
> *starts beating himself very hard*
To avoid that in the future, let's review the only four characters
that are meta in a character class:
] ends the class, unless it is first
^ negates the class if it is first
- forms a range unless it is first or last
\ removes the meta-ness of any of the meta chars
That's it. Anything else is literal.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 21 Feb 2005 04:56:44 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Can't get regex right
Message-Id: <37t4gvF50tqciU1@individual.net>
Tad McClellan wrote:
> let's review the only four characters that are meta in a character
> class:
>
> ] ends the class, unless it is first
>
> ^ negates the class if it is first
>
> - forms a range unless it is first or last
>
> \ removes the meta-ness of any of the meta chars
>
>
> That's it. Anything else is literal.
It's not quite that easy, is it? E.g. \n and \t, as well as the \w and
\s character classes, retain their special meaning in a bracket
delimited character class.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 21 Feb 2005 08:09:37 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Can't get regex right
Message-Id: <slrnd1j5q1.p92.abigail@alexandra.abigail.nl>
Gunnar Hjalmarsson (noreply@gunnar.cc) wrote on MMMMCXCII September
MCMXCIII in <URL:news:37t4gvF50tqciU1@individual.net>:
** Tad McClellan wrote:
** > let's review the only four characters that are meta in a character
** > class:
** >
** > ] ends the class, unless it is first
** >
** > ^ negates the class if it is first
** >
** > - forms a range unless it is first or last
** >
** > \ removes the meta-ness of any of the meta chars
** >
** >
** > That's it. Anything else is literal.
**
** It's not quite that easy, is it? E.g. \n and \t, as well as the \w and
** \s character classes, retain their special meaning in a bracket
** delimited character class.
Not to mention that - doesn't form a range if it's the second character,
and ^ is the first. And that [ can also be special, but only if followed
by the right syntax.
Abigail
--
#!/opt/perl/bin/perl -w
$\ = $"; $SIG {TERM} = sub {print and exit};
kill 15 => fork for qw /Just another Perl Hacker/;
------------------------------
Date: 21 Feb 2005 02:33:06 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: compacting '..' path segments using File::Spec
Message-Id: <slrnd1ii38.c6f.mgjv@verbruggen.comdyn.com.au>
On 20 Feb 2005 13:57:05 -0800,
ofer@netapt.com <ofer@netapt.com> wrote:
>> You'll note that I mentioned this in my response dated 2005-02-01.
>
> Yes, you did. I didn't respond to that post because it didn't contain
> anything resembling a solution, but you deserve credit for informing us
> about that trap (and it is a nasty one).
It did have the same solution that you posted in your own followup. To
quote from Brian's post:
> Cwd::abspath, on the other hand will give you the canonical
> absolute path with no symbolic references.
Martien
--
|
Martien Verbruggen | Blessed are the Fundamentalists, for they
| shall inhibit the earth.
|
------------------------------
Date: 20 Feb 2005 22:46:09 -0800
From: ofer@netapt.com
Subject: Re: compacting '..' path segments using File::Spec
Message-Id: <1108968369.639812.260720@g14g2000cwa.googlegroups.com>
(blink) (blink)
How the heck did I miss that...
Maybe I should just shut up now.
-ofer
------------------------------
Date: Sun, 20 Feb 2005 23:41:27 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: cperl-mode and emacs-21.4 brocken?
Message-Id: <cvb777$2h72$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Mike Dowling
<fake@tu-bs.de>], who wrote in article <slrnd1gs93.p0.mike53@moocow.localhost>:
> On Sat, 19 Feb 2005 22:28:08 +0000 (UTC), Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:
> > What do people think: is the presense of two versions hurting more
> > than availability of a version "which just works" no matter what
> > version of Emacs you are using (I use 19.33 ;-)?
>
> Well, it hurts a bit. Obviously the version with emacs 21.4 is broken,
> and that hurts.
>
> As for the version, I always need the latest version of all useful Linux
> software.
The "mine" and "their" versions have the same "version number"; *this*
is the problem I had in mind. (*If* "their" version has any version
number at all - they have some opposition to RCS strings in .el files...)
Yours,
Ilya
------------------------------
Date: Sun, 20 Feb 2005 23:15:00 +0000 (UTC)
From: jgamble@ripco.com (John M. Gamble)
Subject: Re: cubic root subroutine
Message-Id: <cvb5lk$d4p$2@e250.ripco.com>
In article <bkORd.17729$d5.140845@newsb.telia.net>,
Dan van Ginhoven <danfan46@hotmail.com> wrote:
>Hi.
>
>I needed a cubic root subroutine but didn´t find one at a quick search.
>So I wrote a simple one.
>It seems pretty fast and accurate enough.
>Any ideas how to improve it,
>or point me to better solutions.
>
perldoc Math::Complex
Page down until you come to "The following extra operations are
supported on both real and complex numbers:"
Look in particular for cbrt() and root().
Very useful functions.
--
-john
February 28 1997: Last day libraries could order catalogue cards
from the Library of Congress.
------------------------------
Date: 21 Feb 2005 09:55:46 +0100
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: cubic root subroutine
Message-Id: <yzd7jl21ect.fsf@invalid.net>
"Jürgen Exner" <jurgenex@hotmail.com> writes:
> Dan van Ginhoven wrote:
> > I needed a cubic root subroutine but didn´t find one at a quick
> > search. So I wrote a simple one.
> > It seems pretty fast and accurate enough.
> > Any ideas how to improve it,
> > or point me to better solutions.
>
> Is there anything wrong with just using the exponentiation operator?
>
> $cubicroot = $foo ** (1/3);
You may want to handle the sign separately, since letting $foo be
negative results in NaN ("Not a number"), at least here, on
Solaris 2.8 x86.
Also, it may be worth making sure that the cube of an integer always
comes back as an integer, and not with a little rounding-error, if
that is important for the application. The IEEE floating-point
specification doesn't guarantee that, or does it?
------------------------------
Date: 20 Feb 2005 16:10:23 -0800
From: babydoe@mailinator.com
Subject: Re: emacs AAAAAAAAAAAAAHHH!!!
Message-Id: <1108944623.315952.282010@f14g2000cwb.googlegroups.com>
What a lovely reply Wana, thankyou.
If you'd like to dive into programming in Lisp, it may be worthwhile
browsing the greatest programming book ever written :
http://mitpress.mit.edu/sicp/full-text/book/book.html
------------------------------
Date: Sun, 20 Feb 2005 18:23:07 -0600
From: m <anomousty@webwonders.org>
Subject: Re: emacs AAAAAAAAAAAAAHHH!!!
Message-Id: <cvb9ml$b7p$1@nntp.msstate.edu>
ioneabu@yahoo.com wrote:
>
> I have now used emacs on OS X and Win XP. I have gone through the
> tutorial and learned to navigate around and do the basics. I also
> learned to invoke cperl-mode and even how to cut & paste some lisp code
> into an .emacs file to supposedly start up with cperl-mode configured
> in various ways.
>
> Is it worth continuing or am I just as well off without it? I like vi
>
> Thanks for any advice
>
> wana
>
try eclipse. i use it always and its grt even in windows.will help in
all your other languages also.
------------------------------
Date: Mon, 21 Feb 2005 08:17:26 +0100
From: Constantin Wiemer <constantin.wiemer@infineon.com>
Subject: Re: emacs AAAAAAAAAAAAAHHH!!!
Message-Id: <cvc1u6$68k$1@athen03.muc.infineon.com>
ioneabu@yahoo.com wrote:
> Sorry for the annoying subject, but I cannot express my frustration any
> better here. I am willing to take on learning anything new that will
> help me to program better and more efficiently.
>
> I have now used emacs on OS X and Win XP. I have gone through the
> tutorial and learned to navigate around and do the basics. I also
> learned to invoke cperl-mode and even how to cut & paste some lisp code
> into an .emacs file to supposedly start up with cperl-mode configured
> in various ways.
>
> All I really wanted up front was to see my Perl syntax color coded and
> to compile and run my Perl program from within emacs, just to see it
> work.
>
> I did see it expand things for me, like:
>
> while (()) {
> }
>
> which was pretty neat. It also persistantly gave me an explanation of
> what #!/usr/bin/perl was for. Occasionally, it gave unhelpful advice
> about unclosed {} on certain lines, which I am certain it was not
> correct.
>
> I have wasted a day and a half that could have been dedicated to
> learning a new module or two or learning more core Perl or whatever.
>
> I see that many people use and love emacs and think it is the greatest
> for programming and everything else. I cannot find a decent online
> tutorial for using emacs to write Perl. Everyplace I look just gives
> the same few lines for the .emacs file and little else. I don't even
> see a Perl/emacs book on amazon.com.
>
> Is it worth continuing or am I just as well off without it? I like vi
> and I also use a simple editor I wrote for Windows which has an ever
> present directory and file list box at the left of the screen which
> makes it really easy to fly through directories and files quickly.
> Sometimes I just like to grab the mouse and grab a bunch of text for
> copying, cutting etc... instead of thinking, 'let me mark here and mark
> there, yank, jump over here now, delete, aaaaah! I just erased the
> stuff in my buffer!' I grew up with Windows/Mac type editors and am
> learning Unix type editing later in life.
>
> Thanks for any advice
>
> wana
>
If you prefer a more Windows/Mac-like but still powerful editor, you may
want to give NEdit (http://www.nedit.org) a try. It allows GUI-based
editing but has a lot of features and is also programmable.
Hope this helps,
Constantin Wiemer
------------------------------
Date: 21 Feb 2005 09:45:44 +0100
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: emacs AAAAAAAAAAAAAHHH!!!
Message-Id: <yzdbrae1etj.fsf@invalid.net>
ioneabu@yahoo.com writes:
> Sorry for the annoying subject, but I cannot express my frustration any
> better here. I am willing to take on learning anything new that will
> help me to program better and more efficiently.
Some commands in Emacs I find very helpful when writing/reading code in
programming languages that use matching brackets of varying kinds
(that is, virtually all) are C-M-f, C-M-b and C-M-k, for jumping over
one "expression" forwards, backwards, and deleting it forwards, respectively.
An expression here is anything between balanced brackets (this is sometimes
useful even for ordinary text).
The "mark" concept is also one I use heavily. You can set a mark with
C-space, and later jump back to that place in the buffer with C-x
C-x. Sometimes marks get set automatically, like when you finish a
search. Marks are saved in a stack (or ring - they go back to the end
when the "stack" is popped), so if I know I had an interesting
position marked and want to get back to it, I use C-U C-space a few
times.
A third thing that helps when writing code is automatic indenting (not
so automatic that it does it as soon I press anything at all - I don't
like "electric" indenting). If I press Tab on a line, it gets indented
appropriately considering what is above. Often an unexpected result from
this helps me see an earlier syntax error. (Sometimes it fails - I can't
vouch for how well it works in Perl mode, since I haven't programmed
much Perl yet - this depends on how many peculiar ways there are in the
language of using brackets that don't match.)
------------------------------
Date: Mon, 21 Feb 2005 04:42:58 GMT
From: no spam <uce@ftc.gov>
Subject: How to test for existance ?
Message-Id: <mFdSd.447549$6l.334107@pd7tw2no>
Here's a small script to show what I am trying to do:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/usr/bin/perl -w
sub print_yep
{
print "yep...\n";
}
$function1 = "print_yep";
$function2 = "rubbish";
$vector->{ACTION1} = \&$function1;
$vector->{ACTION2} = \&$function2;
print "something's fishy !\n" if (! exists $vector->{ACTION2});
$vector->{ACTION1}();
$vector->{ACTION2}();
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
How can I test if a function exist or not ?
Shouldn't this print "something's fishy" ??
I've tried to use defined, to deference in different ways, but I can't get
it working.
Thanks,
Yves.
----
Yves Dorfsman
http://www.cuug.ab.ca/dorfsmay
http://www.SollerS.ca
------------------------------
Date: 21 Feb 2005 05:45:02 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: How to test for existance ?
Message-Id: <Xns96047F193EF5asu1cornelledu@132.236.56.8>
no spam <uce@ftc.gov> wrote in news:mFdSd.447549$6l.334107@pd7tw2no:
> Here's a small script to show what I am trying to do:
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> #!/usr/bin/perl -w
use warnings;
is preferable because it allows you to switch specific types of warnings
on/off of various scopes.
Also, you are missing:
use strict;
> sub print_yep
> {
> print "yep...\n";
> }
>
>
> $function1 = "print_yep";
> $function2 = "rubbish";
>
> $vector->{ACTION1} = \&$function1;
> $vector->{ACTION2} = \&$function2;
At this point, it would be instructive to use Data::Dumper to print what
$vector actually contains. Because of auto-vivification, exists will not
tell you anything useful. You should also have checked for the
documentation for defined to see:
defined EXPR
defined Returns a Boolean value telling whether EXPR has a value other
than the undefined value "undef".
that it would have been less than useful in this case.
> print "something's fishy !\n" if (! exists $vector->{ACTION2});
>
> $vector->{ACTION1}();
> $vector->{ACTION2}();
I am sure others who know more about this stuff than I do will show a way
of doing this by checking the symbol table, but my first inclination would
have been to wrap the call in an eval.
> Shouldn't this print "something's fishy" ??
No.
> I've tried to use defined, to deference in different ways,
ITYM 'dereference'.
use strict;
use warnings;
use Carp;
sub print_yep {
print "yep...\n";
}
my $vector = {
ACTION1 => 'print_yep',
ACTION2 => 'rubbish',
};
sub dispatch {
my $table = shift;
my $action = shift;
my $dispatch_to = \&{$table->{$action}};
my @r = eval {
$dispatch_to->(@_);
};
if( $@ ) {
carp 'Something is fishy';
@r = ();
}
return wantarray ? @r : $r[0];
}
dispatch($vector, 'ACTION1');
dispatch($vector, 'ACTION2');
__END__
------------------------------
Date: Sun, 20 Feb 2005 23:18:21 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: Importing records with both space and quoted text qualifiers...
Message-Id: <ltydnaw0cpHdFoTfRVn-3Q@comcast.com>
L. D. James wrote:
> I'm writing a script to analyze a web access log output.
If the quotes are always around only certain fields, then split()
is not the right tool to use. Use a capturing regex that explicitly
matches the quotes you are expecting to see.
@f = /(\S+) (\S+) (\S+) \[(.*?)\] "(.*?)" (\d+) (\d+) "(.*?)" "(.*)"$/;
Or use an existing module for that.
http://search.cpan.org/~dtiberio/Logfile-Access-1.30/Access.pm
-Joe
------------------------------
Date: Sun, 20 Feb 2005 23:29:04 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: Need a module for grabbing text from a web page
Message-Id: <pZWdnQQ20qNeEITfRVn-oQ@comcast.com>
A. Sinan Unur wrote:
> emelio garcia <EmelioGarcia@wazoo.com> wrote in
> news:2orc11l01cpq6do60dgrjfb45on354i7cf@4ax.com:
>
>
>>Subject: Need a module for grabbing text from a web page
>>Not just the text, but the urls for the images on that page as well.
>
> What on God's red planet do you mean by this?
The OP undoubtably has not investigated
http://search.cpan.org/search?query=LinkExtractor
or a general-purpose HTML parser.
-Joe
------------------------------
Date: Mon, 21 Feb 2005 11:26:01 +0100
From: phaylon <phaylon@dunkelheit.at>
Subject: Re: Need a module for grabbing text from a web page
Message-Id: <pan.2005.02.21.10.26.01.92644@dunkelheit.at>
emelio garcia wrote:
> Not just the text, but the urls for the images on that page as well.
I would use WWW::Mechanize.
--
http://www.dunkelheit.at/
codito, ergo sum.
------------------------------
Date: 21 Feb 2005 00:47:09 -0800
From: clearguy02@yahoo.com
Subject: Parsing a text file.....
Message-Id: <1108975629.015272.64290@c13g2000cwb.googlegroups.com>
Hi all,
Below is the scenario:
I have a file (c:\test.txt) with the below lines:
===============================
JSMITH 2002.05.00
JSMITH 2003.06.10
BBRAND 2002.05.00
JCARTER 2002.05.00
JCARTER 4.2
MSUBBA 2003.06.10
SSUSAN 2002.05.00
SSUSAN 2003.06.10
JPORTER 2003.06.10
================================
The logic is that if the same name has two or more different numeric
values (example: JSMITH has 2002.05.00 and 2003.06.10), you need to
skip those lines.
So, output file should be as follows:
==================================
BBRAND 2002.05.00
MSUBBA 2003.06.10
JPORTER 2003.06.10
=================================
So, how can I get the above output from the above input file?
Below is my stupid piece of code which doesn't work:
====================================
while (<DATA>)
{
($name, $version) = split (/\s+/, $_);
next if (($name =~ /$version/) && ($name !~ /$version/));
print $_;
}
__DATA__
JSMITH 2002.05.00
JSMITH 2003.06.10
BBRAND 2002.05.00
JCARTER 2002.05.00
JCARTER 4.2
MSUBBA 2003.06.10
SSUSAN 2002.05.00
SSUSAN 2003.06.10
JPORTER 2003.06.10
===================================
I guess using hashes is a way to go. Can some one suggest me how I can
use hashes in this case?
Thanks,
Rider.
------------------------------
Date: 21 Feb 2005 10:35:25 +0100
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: Parsing a text file.....
Message-Id: <yzd3bvq1ciq.fsf@invalid.net>
clearguy02@yahoo.com writes:
>
> I have a file (c:\test.txt) with the below lines:
>
> ===============================
> JSMITH 2002.05.00
> JSMITH 2003.06.10
> BBRAND 2002.05.00
> JCARTER 2002.05.00
> JCARTER 4.2
> MSUBBA 2003.06.10
> SSUSAN 2002.05.00
> SSUSAN 2003.06.10
> JPORTER 2003.06.10
> ================================
> The logic is that if the same name has two or more different numeric
> values (example: JSMITH has 2002.05.00 and 2003.06.10), you need to
> skip those lines.
>
> So, output file should be as follows:
> ==================================
> BBRAND 2002.05.00
> MSUBBA 2003.06.10
> JPORTER 2003.06.10
> =================================
>
> So, how can I get the above output from the above input file?
>
> Below is my stupid piece of code which doesn't work:
> ====================================
> while (<DATA>)
> {
> ($name, $version) = split (/\s+/, $_);
> next if (($name =~ /$version/) && ($name !~ /$version/));
> print $_;
>
> }
Your code seems to say "print the line if $name both matches and does
not match $version".
> I guess using hashes is a way to go. Can some one suggest me how I can
> use hashes in this case?
Here is my attempt. You may want to add error handling when the input
lines don't conform to your specification.
#! /usr/local/bin/perl
use warnings;
use strict;
my %count;
my %values;
while (<DATA>) {
my ($name, $value) = split;
$count{$name}++;
$values{$name} = $_;
}
for my $name (sort keys %count) {
if ($count{$name} == 1) {
print "$values{$name}";
}
}
__DATA__
JSMITH 2002.05.00
JSMITH 2003.06.10
BBRAND 2002.05.00
JCARTER 2002.05.00
JCARTER 4.2
MSUBBA 2003.06.10
SSUSAN 2002.05.00
SSUSAN 2003.06.10
JPORTER 2003.06.10
------------------------------
Date: 21 Feb 2005 10:14:55 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Problem with IO::Socket [... on Mac OS X]
Message-Id: <cvccav$q9s$1@mamenchi.zrz.TU-Berlin.DE>
Martin Kissner <news@chaos-net.de> wrote in comp.lang.perl.misc:
> Anno Siegel wrote :
>
> > Something is fishy on Darwin. I also see it hang when the service is
> > given by name and reply as expected when given by port number. However,
[...]
> After all I tried the script once again without making any changes and
> to my very great surprise it ran flawlessly with servicenames and with
> portnumbers.
> If Anno had not seen it hang when servicenames were given, I'd probably
> doubted my mental health ;-).
I've seen that too. It wasn't reproducible, so I dismissed it for
the time being.
Anno
------------------------------
Date: Mon, 21 Feb 2005 00:09:25 -0500
From: William Goedicke <goedicke@brandeis.edu>
Subject: Re: The Problem with Perl
Message-Id: <m34qg6fqii.fsf@goedsole.com>
Dear Wes -
>>>>> "Wes" == Wes Groleau <groleau+news@freeshell.org> writes:
Wes> William Goedicke wrote:
>> the problem is that Perl is "context sensitive".
Wes> C is _not_ a strongly typed language. Sure, a newbie might
Wes> be surprised by @LIST being a list sometimes and the size of
Wes> the list other times. But C programmers--even experts--are
Wes> often surprised by the results of C's implicit automatic
Wes> casts, or it's ability to add two positive numbers and get a
Wes> negative without complaint.
I often found myself surprised as a newbie C programmer. Regularly it
resulted from my poor use of (loosely typed) pointers in C; my bad as
a programmer.
One difference I've noticed between Perl and C (my two most used
languages) is that one had typing in the scalars and the other has typing
in the pointers. (Sorry for the C terminology. One types locations in
memory and the other types in (ummm) scalars.)
I find that distinction interesting.
- Billy
============================================================
William Goedicke goedicke@brandeis.edu
Cell 617-510-7244 Office 781-736-4657
AIM goedsole
============================================================
Lest we forget:
"ff0000" (html for bright red) turns out to be as good
an indicator of spam as any pornographic term.
- Paul Graham
------------------------------
Date: Sun, 20 Feb 2005 18:58:39 -0600
From: l v <lv@aol.com>
Subject: Re: user login
Message-Id: <421932dc$1_2@127.0.0.1>
cljlk@hotmail.com wrote:
> We have Windows 2000 in computer room, and we need to track user login
> and save the user in a log file.
> Would anyone provide perl scripts program.
>
> Thanks
>
Should already be logged in the Security Event Log, look at
Win32::EventLog if you want to mechanically export the log.
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
------------------------------
Date: Sun, 20 Feb 2005 21:39:08 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: user login
Message-Id: <slrnd1ilus.mat.tadmc@magna.augustmail.com>
cljlk@hotmail.com <cljlk@hotmail.com> wrote:
> Would anyone provide perl scripts program.
Yes. The type of people that do that sort of thing are often
called "contract programmers". Consider hiring one.
If you want to *write* a Perl program, then this would be the
place to discuss any problems you are having with it.
Are you having problems writing the program that you need?
--
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.
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 7805
***************************************