[22411] in Perl-Users-Digest
Perl-Users Digest, Issue: 4632 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 27 03:05:45 2003
Date: Thu, 27 Feb 2003 00:05:10 -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 Thu, 27 Feb 2003 Volume: 10 Number: 4632
Today's topics:
Re: FAQ proposal: Why can't I compare two strings using <jurgenex@hotmail.com>
Re: FAQ proposal: Why can't I compare two strings using <jurgenex@hotmail.com>
Re: FAQ proposal: Why can't I compare two strings using (Philip Lees)
Re: FAQ proposal: Why can't I compare two strings using (Philip Lees)
Re: FAQ proposal: Why can't I compare two strings using (Philip Lees)
Re: Feedback request: photobrowser <usenet_poster_a@tranzoa.com>
Re: Feedback request: photobrowser <tassilo.parseval@post.rwth-aachen.de>
Re: getting prmature end of script headers <REMOVEsdnCAPS@comcast.net>
Re: getting prmature end of script headers <urzaserra@home.com>
Re: How Do I Clone An Object <tassilo.parseval@post.rwth-aachen.de>
More help. <mail@annuna.com>
Re: More help. <bwalton@rochester.rr.com>
Re: More help. (Tad McClellan)
Re: More help. <jurgenex@hotmail.com>
Question about text processing <smiley@uvgotemail.com>
Re: Question about text processing <GPatnude@adelphia.net>
Re: Question about text processing <uri@stemsystems.com>
Re: Question about text processing <Jodyman@hotmail.com>
Re: Question <jurgenex@hotmail.com>
Re: Reading Multiple Input Files with <> <Jodyman@hotmail.com>
regexp to *not* match a certain character sequence (Bennett Haselton)
Re: regexp to *not* match a certain character sequence <bernard.el-hagin@DODGE_THISlido-tech.net>
Re: remove unwanted characters <jurgenex@hotmail.com>
Re: remove unwanted characters <eighner@io.com>
Re: sort, uniq -c <bwalton@rochester.rr.com>
Re: sort, uniq -c (Tad McClellan)
Re: splitting <tassilo.parseval@post.rwth-aachen.de>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 27 Feb 2003 03:21:20 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: FAQ proposal: Why can't I compare two strings using == ?
Message-Id: <Quf7a.32257$ep5.10502@nwrddc02.gnilink.net>
Tore Aursand wrote:
> On Wed, 26 Feb 2003 07:52:07 +0000, Philip Lees wrote:
>>>> How about: 'Why don't my equality tests work right?'
>
>>> I agree that this question should be answered in the FAQ, but I
>>> don't see this question as _one_ question.
>
>> You're right, of course, but as a long time lurker it seems to me
>> that when the question comes up here it almost _always_ refers to
>> something equivalent to:
>> [...]
>
> You are also right. After some thinking, I came up with the following
> questions:
>
> "Why doesn't my use of operator do what I excpect?"
>
> It's a problem with this one, though; a lot of people don't even
> _know_ what an operator is. :-/
Plus the average user wouldn't find this entry using "perldoc -q".
Typically you would search for "compare", "equal", maybe "string".
Therefore, although it is technically accurate I would prefer a less
accurate but more useful wording.
jue
------------------------------
Date: Thu, 27 Feb 2003 03:21:20 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: FAQ proposal: Why can't I compare two strings using == ?
Message-Id: <Quf7a.32258$ep5.16799@nwrddc02.gnilink.net>
Tore Aursand wrote:
> On Wed, 26 Feb 2003 07:52:07 +0000, Philip Lees wrote:
>>>> How about: 'Why don't my equality tests work right?'
>
>>> I agree that this question should be answered in the FAQ, but I
>>> don't see this question as _one_ question.
>
>> You're right, of course, but as a long time lurker it seems to me
>> that when the question comes up here it almost _always_ refers to
>> something equivalent to:
>> [...]
>
> You are also right. After some thinking, I came up with the following
> questions:
>
> "Why doesn't my use of operator do what I excpect?"
>
> It's a problem with this one, though; a lot of people don't even
> _know_ what an operator is. :-/
Plus the average user wouldn't find this entry using "perldoc -q".
Typically you would search for "compare", "equal", maybe "string".
Therefore, although it is technically accurate I would prefer a less
accurate but more useful wording.
jue
------------------------------
Date: Thu, 27 Feb 2003 07:37:42 GMT
From: pjlees@ics.forthcomingevents.gr (Philip Lees)
Subject: Re: FAQ proposal: Why can't I compare two strings using == ?
Message-Id: <3e5dbf97.63328218@news.grnet.gr>
On Wed, 26 Feb 2003 11:19:02 -0600, "Eric J. Roode"
<REMOVEsdnCAPS@comcast.net> wrote:
>pjlees@ics.forthcomingevents.gr (Philip Lees) wrote in
>news:3e5cc3d7.84597531@news.grnet.gr:
>
>> On Wed, 26 Feb 2003 05:54:00 -0600, tadmc@augustmail.com (Tad
>> McClellan) wrote:
>>
>>>Philip Lees <pjlees@ics.forthcomingevents.gr> wrote:
>>>
>>>> NOTE: If you use strictures and warnings (as you should) then Perl
>>>> will warn you about what's wrong.
>>>
>>>strictures have nothing to do with the warning.
>>>adding warnings alone will be enough to have perl tell you about it.
>>
>> I know that. I just thought it wouldn't hurt to mention the strictures
>> as well.
>
>Strictures are a good thing; however, we need not stoop to lying about them
>to make them look more useful than they are. ;-)
There's no lie there. Well, maybe a terminological inexactitude.
Okay, how about:
NOTE: If you use warnings (as you should) then Perl will alert you to
what's wrong. (While you're adding 'use warnings' or the -w flag to
your scripts, you should also include 'use strict'.)
Phil
--
Ignore coming events if you wish to send me e-mail
------------------------------
Date: Thu, 27 Feb 2003 07:45:34 GMT
From: pjlees@ics.forthcomingevents.gr (Philip Lees)
Subject: Re: FAQ proposal: Why can't I compare two strings using == ?
Message-Id: <3e5dc05e.63527078@news.grnet.gr>
On Wed, 26 Feb 2003 17:19:07 +0000 (UTC), ansok@alumni.caltech.edu
(Gary E. Ansok) wrote:
>In article <3e5b385c.69650578@news.grnet.gr>,
>Philip Lees <pjlees@ics.forthcomingevents.gr> wrote:
>>
>>How about: 'Why don't my equality tests work right?'
>Is that a question that new users will find when they look
>through the FAQ list? Personally, I don't think so.
>
>Imagine yourself a user fairly new to Perl, who's just discovered
>the -q option to perldoc. What keywords would you be likely to
>use to find the answer you're looking for?
>
>I think the original title is more likely to be found by such a
>user -- the keywords that come to my mind are "compare", "strings",
>"equal", and maybe "==" if that's allowed. "Tests" and "equality"
>are way down my list.
A good point, and one made by jue elsewhere in the thread. I believe
that perldoc would find my suggested question given "equal" as a
search term, but I agree with the rest.
>I prefer the original title -- it's more direct, and immediately
>tells the reader what this FAQ deals with. When I see Philip's
>proposal, I think of floating-point inaccuracies (also an FAQ,
>but not part of the same topic).
Quite right. I hadn't thought of that.
>If we want to make the topic more general, I agree with
>"Why can't I compare two strings using == (or = ) ?"
Now you've lost the "equal" altogether. How about something like:
'When I compare two different strings using == (or =) Perl thinks
they're equal. Why is that?'
Phil
--
Ignore coming events if you wish to send me e-mail
------------------------------
Date: Thu, 27 Feb 2003 07:48:17 GMT
From: pjlees@ics.forthcomingevents.gr (Philip Lees)
Subject: Re: FAQ proposal: Why can't I compare two strings using == ?
Message-Id: <3e5dc294.64092500@news.grnet.gr>
On Thu, 27 Feb 2003 07:37:42 GMT, pjlees@ics.forthcomingevents.gr
(Philip Lees) wrote:
>NOTE: If you use warnings (as you should) then Perl will alert you to
Gak! I did it again. Of course, I meant 'perl'.
Phil
--
Ignore coming events if you wish to send me e-mail
------------------------------
Date: Wed, 26 Feb 2003 21:54:32 -0800
From: Alex <usenet_poster_a@tranzoa.com>
Subject: Re: Feedback request: photobrowser
Message-Id: <BNCcnV0_A9tNNcCjXTWc-g@speakeasy.net>
Tad McClellan wrote:
> A. Sinan Unur <asu1@c-o-r-n-e-l-l.edu> wrote:
>
>
>>I spent some time over the last few days, incorporating comments I
>>received on an earlier version of this script, and looking for more code
>>to steal :).
>
> ^^^^^^^^
>
> The correct term is "to reuse". :-)
He "steals".
You "reuse".
I "enhance the value of" .
:)
------------------------------
Date: 27 Feb 2003 07:54:09 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: Feedback request: photobrowser
Message-Id: <b3kg71$8lb$1@nets3.rz.RWTH-Aachen.DE>
Also sprach John W. Krahn:
> "Tassilo v. Parseval" wrote:
>> opendir PHOTO_DIR, $photo_path) || bail_out($photo_path);
>> while (<PHOTODIR>) {
>
> This won't work because the directory handle name is spelled incorrectly
> and, more importantly, <> doesn't work on directory handles, just file
> handles.
>
> while ( definded( $_ = readdir PHOTO_DIR ) ) {
Oh, right on both. I try this '<DIR_HANDLE>' trick often in my scripts
just to realize that it's still an un-feature. I guess I'll never quite
get rid of this mistake in cognition.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Wed, 26 Feb 2003 21:07:59 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: getting prmature end of script headers
Message-Id: <Xns932EE1121F382sdn.comcast@216.166.71.239>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
"matt" <urzaserra@home.com> wrote in
news:Gac7a.1359$Pa.117742@news2.west.cox.net:
> I just got this perl cgi program that is a web based database searcher
> and editor but i am getting the premature end of script header errors.
> #######################################################################
>
> # Parse Form Contents
> &parse_form;
Unbelievable. Where the hell do people come up with this? After all these
years, we're still seeing "&parse_form" shit. Who the hell is handing this
crap out?
Matt, I'm not yelling at you -- you're the victim here. Where did you get
this piece of shit? Whoever gave it to you was completely irresponsible.
You should scrap it, get a quality book on Perl and CGI, read up on the
CGI.pm docs, and rewrite it from scratch. Yes, that will take a fair
amount of time and effort on your part -- but I promise you that it will be
less time and effort than you're in for if you try to work with the program
as it is. Your other option is to hire an experienced programmer to
rewrite it.
- --
Eric
print scalar reverse sort qw p ekca lre reh
ts uJ p, $/.r, map $_.$", qw e p h tona e;
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBPl2A4WPeouIeTNHoEQJIKACgtVgZVYqGKa2qI2yE6IaZzVAhdUQAn2Zp
E7ZO+SSTxAif5cFhzznzlcwy
=QURb
-----END PGP SIGNATURE-----
------------------------------
Date: Thu, 27 Feb 2003 05:03:12 GMT
From: "matt" <urzaserra@home.com>
Subject: Re: getting prmature end of script headers
Message-Id: <k_g7a.2317$Pa.285343@news2.west.cox.net>
"Eric J. Roode" <REMOVEsdnCAPS@comcast.net> wrote in message
news:Xns932EE1121F382sdn.comcast@216.166.71.239...
> -----BEGIN xxx SIGNED MESSAGE-----
> Hash: SHA1
>
> "matt" <urzaserra@home.com> wrote in
> news:Gac7a.1359$Pa.117742@news2.west.cox.net:
>
> > I just got this perl cgi program that is a web based database searcher
> > and editor but i am getting the premature end of script header errors.
>
> > #######################################################################
> >
> > # Parse Form Contents
> > &parse_form;
>
>
> Unbelievable. Where the hell do people come up with this? After all
these
> years, we're still seeing "&parse_form" shit. Who the hell is handing
this
> crap out?
I got it from a free cgi script website after doing a search free perl
scripts this is the website from where i got it.
http://www.summersault.com/software/db_browser/
>
> Matt, I'm not yelling at you -- you're the victim here. Where did you get
> this piece of shit? Whoever gave it to you was completely irresponsible.
>
> You should scrap it, get a quality book on Perl and CGI, read up on the
> CGI.pm docs, and rewrite it from scratch. Yes, that will take a fair
> amount of time and effort on your part -- but I promise you that it will
be
> less time and effort than you're in for if you try to work with the
program
> as it is. Your other option is to hire an experienced programmer to
> rewrite it.
>
> - --
> Eric
> print scalar reverse sort qw p ekca lre reh
> ts uJ p, $/.r, map $_.$", qw e p h tona e;
>
> -----BEGIN xxx SIGNATURE-----
> Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
>
> iQA/AwUBPl2A4WPeouIeTNHoEQJIKACgtVgZVYqGKa2qI2yE6IaZzVAhdUQAn2Zp
> E7ZO+SSTxAif5cFhzznzlcwy
> =QURb
> -----END PGP SIGNATURE-----
------------------------------
Date: 27 Feb 2003 07:43:24 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: How Do I Clone An Object
Message-Id: <b3kfis$83l$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Anno Siegel:
> I'm not sure if there's a dedicated deep-copy module (which is what
> you're looking for), but Data::Dumper and similar serialization
> modules do a good job. You basically dump the object to a string and
> immediately restore it again. The restored object will be a perfect
> clone of the original (blessed and all). This way you can change the
> object structure whichever way you want, the clone method will
> automatically adapt.
The need for eval() is a slight red-herring when using Data::Dumper for
that so I prefer Storable::dclone(). One problem with Storable however
is that it can't deal with GLOB-refs stored in a structure. Not sure
about Data::Dumper, but since it does a string-eval (and GLOBs always
live in a package) it should not have this limitation.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Wed, 26 Feb 2003 21:00:56 -0600
From: Joe Creaney <mail@annuna.com>
Subject: More help.
Message-Id: <3E5D7F68.4060601@annuna.com>
I am trying to program a simple rpg. I am a self taught programmer and
not very good. I am getting fustrated with the ammount of data I am
trying to pass. Right now I am having trouble with these snipis of code:
my %weapon = ('knife' => 2, 'club' => 4, 'spear' => 6, 'sword'=> 8, 'Ax'
=> 10);
my %armor = ('leather' => 9, 'ring mail' => 7, 'chain mail' => 5,'plate'
=> 3);
my @p=(" ",10,1,0,$weapon {'kinfe'},$armor {'leather'});
foreach $v (@p) {
print "$v : $p[$v] \n";
From my knowlege of perl it should work but I get all kinds of errors.
Am I using the wrong language. I am reading up on C++ would that be
better at writing a game?
------------------------------
Date: Thu, 27 Feb 2003 03:24:32 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: More help.
Message-Id: <3E5D83F7.5030306@rochester.rr.com>
Joe Creaney wrote:
> I am trying to program a simple rpg. I am a self taught programmer and
> not very good. I am getting fustrated with the ammount of data I am
> trying to pass. Right now I am having trouble with these snipis of code:
>
>
> my %weapon = ('knife' => 2, 'club' => 4, 'spear' => 6, 'sword'=> 8, 'Ax'
> => 10);
> my %armor = ('leather' => 9, 'ring mail' => 7, 'chain mail' => 5,'plate'
> => 3);
>
> my @p=(" ",10,1,0,$weapon {'kinfe'},$armor {'leather'});
knife-------------------------^^^^^
>
>
> foreach $v (@p) {
> print "$v : $p[$v] \n";
In the above, $v is aliased to each element of array @p in turn.
Printing that is fine, but using the array elements as array subscripts
generally won't work so well unless the array elements are integers, or
at least numbers or numeric strings. The first element of p isn't such.
But the numbers in your @p array don't really look like they are
intended to subscripts of the same array. Perhaps if you described what
it is that you want your code to do, someone could give some better
suggestions.
>
> From my knowlege of perl it should work but I get all kinds of errors.
not helpful -- what errors exactly?------------------^^^^^^^^^^^^^^^^^^^
I don't get any errors from your verbatim code, other than the compile
error due to the missing backet at the end. With use strict, I need to
add a "my" in front of the $v in the foreach. With use warnings, there
are warnings about nonnumeric array subscripts and uninitialized values
-- but warnings aren't errors.
>
> Am I using the wrong language. I am reading up on C++ would that be
> better at writing a game?
>
Depends on the game. If it is a text-based adventure-type game, Perl
would be great.
--
Bob Walton
------------------------------
Date: Wed, 26 Feb 2003 21:20:46 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: More help.
Message-Id: <slrnb5r10e.6o9.tadmc@magna.augustmail.com>
Joe Creaney <mail@annuna.com> wrote:
> Subject: More help.
Please put the subject of your article in the Subject of your article.
Please don't make us keep repeating this.
> Right now I am having trouble with these snipis of code:
>
>
> my %weapon = ('knife' => 2, 'club' => 4, 'spear' => 6, 'sword'=> 8, 'Ax'
>=> 10);
> my %armor = ('leather' => 9, 'ring mail' => 7, 'chain mail' => 5,'plate'
>=> 3);
>
> my @p=(" ",10,1,0,$weapon {'kinfe'},$armor {'leather'});
^^^^^
^^^^^
^^^^^ huh?
> foreach $v (@p) {
> print "$v : $p[$v] \n";
So you will print out the values of:
$p[ ] (space as the index?)
$p[10] (but @p does not have ten elements)
$p[1] (10)
$p[0] (space)
...
> From my knowlege of perl it should work but I get all kinds of errors.
$v takes on the _values_ from @p: space, then 10, then 1, then 0...
I think you want $v to be the _indexes_ for @p?
foreach $v ( 0 .. $#p) {
or
foreach $v ( 0 .. 5) { # for fixed-size @p
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 27 Feb 2003 03:32:02 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: More help.
Message-Id: <SEf7a.32264$ep5.10014@nwrddc02.gnilink.net>
Joe Creaney wrote:
> my %weapon = ('knife' => 2, 'club' => 4, 'spear' => 6, 'sword'=> 8,
> 'Ax' => 10);
> my %armor = ('leather' => 9, 'ring mail' => 7, 'chain mail' =>
> 5,'plate' => 3);
>
> my @p=(" ",10,1,0,$weapon {'kinfe'},$armor {'leather'});
>
>
> foreach $v (@p) {
> print "$v : $p[$v] \n";
>
> From my knowlege of perl it should work but I get all kinds of
> errors.
Unfortunately you don't tell us what those errors are.
When I run your code I get
Global symbol "$v" requires explicit package name at C:\tmp\t.pl line
11.
Global symbol "$v" requires explicit package name at C:\tmp\t.pl line
12.
Global symbol "$v" requires explicit package name at C:\tmp\t.pl line
12.
These are easily fixed by adding a "my" to the foreach loop:
for my $v (@p) {
Missing right curly or square bracket at C:\tmp\t.pl line 15, at end of
line>
And this one is easily fixed by adding a right curly bracket to the end of
your code (you didn't close the for loop).
Please let us know if this doesn't fixes your problem.
jue
------------------------------
Date: Thu, 27 Feb 2003 00:32:36 -0500
From: "Smiley" <smiley@uvgotemail.com>
Subject: Question about text processing
Message-Id: <v5r8tqhddpm443@corp.supernews.com>
Does anybody know if there's a way to edit a scalar that has a number of
extra unwanted blank spaces in it to remove those blank spaces in Perl?
Thanks.
------------------------------
Date: Thu, 27 Feb 2003 05:41:40 GMT
From: "codeWarrior" <GPatnude@adelphia.net>
Subject: Re: Question about text processing
Message-Id: <oyh7a.299$Xu.167376@news1.news.adelphia.net>
"Smiley" <smiley@uvgotemail.com> wrote in message
news:v5r8tqhddpm443@corp.supernews.com...
> Does anybody know if there's a way to edit a scalar that has a number of
> extra unwanted blank spaces in it to remove those blank spaces in Perl?
>
> Thanks.
>
>
Can do.... -- Realize: the \s corresponds to ANY whitespace character--
tabs, linefeeds, spaces, carriage-returns (^m's on the Mac...)
# Assuming $VAL is your scalar variable...
$VAL =~ s/\s//gisx;
Look into regular ezxpressions when you can....
------------------------------
Date: Thu, 27 Feb 2003 05:49:33 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Question about text processing
Message-Id: <x7r89ue0id.fsf@mail.sysarch.com>
>>>>> "c" == codeWarrior <GPatnude@adelphia.net> writes:
c> "Smiley" <smiley@uvgotemail.com> wrote in message
c> news:v5r8tqhddpm443@corp.supernews.com...
>> Does anybody know if there's a way to edit a scalar that has a number of
>> extra unwanted blank spaces in it to remove those blank spaces in Perl?
>>
>> Thanks.
>>
>>
c> Can do.... -- Realize: the \s corresponds to ANY whitespace character--
c> tabs, linefeeds, spaces, carriage-returns (^m's on the Mac...)
c> # Assuming $VAL is your scalar variable...
c> $VAL =~ s/\s//gisx;
that removes all spaces and not just the extra ones.
also the isx options are useless.
$str =~ tr/ //s ;
is the best way to remove extra regular spaces. that can be changed
easily to handle cr/lf/tab
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Damian Conway Perl Classes - January 2003 -- http://www.stemsystems.com/class
------------------------------
Date: Thu, 27 Feb 2003 05:53:31 GMT
From: "Jodyman" <Jodyman@hotmail.com>
Subject: Re: Question about text processing
Message-Id: <vJh7a.3865$Wl3.348399@newsread1.prod.itd.earthlink.net>
"Smiley" <smiley@uvgotemail.com> wrote in message
> Does anybody know if there's a way to edit a scalar that has a number of
> extra unwanted blank spaces in it to remove those blank spaces in Perl?
If you want to get rid of all the spaces:
#!/usr/bin/perl -w
use strict;
while (<DATA>) {
chomp($_);
print "\$_ had: $_\n";
s/\s+//g;
print "\$_ has: $_\n";
}
__DATA__
This is a test
This is a test
How about this?
W h a t a b o u t t h i s ?
#Hope this helps!
#Jody
------------------------------
Date: Thu, 27 Feb 2003 03:43:01 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Question
Message-Id: <9Pf7a.32272$ep5.14429@nwrddc02.gnilink.net>
Emil wrote:
> Is there similar command ( option ) under Win98 ( dos ) like "grep -l"
> uder UNIX.
That question would be better asked in a NG that deals with Windows.
However, because you asked in a Perl NG you may want to check out a Perl
solution. What about "perldoc -f grep"?
> I tried with "find" but didn't find similar option.
That question would be better asked in a NG that deals with Windows.
However, because you asked in a Perl NG you may want to check out a Perl
solution. What about "perldoc File::Find"?
> Depending of the existence of some string in a Word file ( ".doc" ) it
> has to be copied or moved to a specific directory.
> Second problem is with executing "copy" and "move" command with "
> `copy ... ...`
That question would be better asked in a NG that deals with Windows.
However, because you asked in a Perl NG you may want to check out a Perl
solution. What about "perldoc File::Copy"?
> from the program. The paths that are requested are shortenned ones,
> like they appear in the command window ( not like in Explorer ).
That question would be better asked in a NG that deals with Windows.
But if you use the 32 bit cmd.exe instead of the 16 bit command.com then you
can use long filenames.
> I can
> keep two lines in some configuration file, one with the Full Name Path
> and other with Shortened Path like in Command Window, and use first
> one for Perl file manipulation ( opens ), and the other for ` ` (
> command evaluation ).
> Any help or direction is welcome.
And if you use the portable perlish solution then you don't have to bother
about those details anyhow.
jue
------------------------------
Date: Thu, 27 Feb 2003 05:02:30 GMT
From: "Jodyman" <Jodyman@hotmail.com>
Subject: Re: Reading Multiple Input Files with <>
Message-Id: <GZg7a.3755$Wl3.359283@newsread1.prod.itd.earthlink.net>
"Jodyman" <jodyman@hotmail.com> wrote in message
> How can I go through 2 files simultaneously using while?
> Is there a trick to doing this?
>
> For example:
>
> while ($in1=<IN1>) {
> while (<IN2>) {
> do something with $_
> do something with $in1
> }
> }
>
> With the above the whole <IN2> is read and acted upon
> before the next <IN1> is accessed.
>
> Any help would be appreciated. I have a mental block here.
Thanks for all the replys, I was having a senior moment and
solved it with $rec=<IN2>; Thanks again.
Jody
------------------------------
Date: 26 Feb 2003 22:32:51 -0800
From: bennett@peacefire.org (Bennett Haselton)
Subject: regexp to *not* match a certain character sequence
Message-Id: <e614455c.0302262232.25cbead2@posting.google.com>
Pretty elementary I know, but I've read the sections about regular
expressions in 3 Perl books and I can't find anything about how to
match a string of characters that does not contain a given character
sequence. For example, if I have a string of the form:
<a href = "http://www.yahoo.com/">first link</a><a href =
"http://www.peacefire.org/">This <b>might</b> work</a>
and I'm not sure whether or not the first link will be present, but I
want to get the text of the second link, then how do I extract the
'This <b>might</b> work' part?
I can't do:
$string =~ /<a href = ".*">(.*)<\/a>/;
because the ".*" will expand as much as it can, to match all of this:
first link</a><a href = "http://www.peacefire.org/">This <b>might</b>
work
and I can't modify the regexp to exclude angle brackets in what it's
matching:
$string =~ /<a href = ".*">([^<>]*)<\/a>/;
because the text that I'm trying to match, contains angle brackets.
How do I say that I don't want the ".*" part to have the string "</a>"
in it anywhere?
-Bennett
------------------------------
Date: Thu, 27 Feb 2003 06:46:49 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: regexp to *not* match a certain character sequence
Message-Id: <Xns932F4E7093D07elhber1lidotechnet@62.89.127.66>
Bennett Haselton wrote:
> Pretty elementary I know, but I've read the sections about regular
> expressions in 3 Perl books and I can't find anything about how to
> match a string of characters that does not contain a given character
> sequence. For example, if I have a string of the form:
>
> <a href = "http://www.yahoo.com/">first link</a><a href =
> "http://www.peacefire.org/">This <b>might</b> work</a>
>
> and I'm not sure whether or not the first link will be present, but I
> want to get the text of the second link, then how do I extract the
> 'This <b>might</b> work' part?
How about this:
$string =~ m!<a href[^>]+>(.*)</a>$!;
> I can't do:
>
> $string =~ /<a href = ".*">(.*)<\/a>/;
>
> because the ".*" will expand as much as it can, to match all of this:
If that is indeed the problem you can make the match non-greedy by
changing ".*" to ".*?". To read more about this and other things you
asked about run the following:
perldoc perlre
--
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'
------------------------------
Date: Thu, 27 Feb 2003 03:45:36 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: remove unwanted characters
Message-Id: <ARf7a.32273$ep5.16793@nwrddc02.gnilink.net>
Bing Du Test wrote:
> We need to use Perl to process files transferred from Windows machines
> to UNIX. Sometimes, ^M is appended at the end of each line when a PC
> file arrives on Unix.
> Just wondering if there is anyway to remove all the ^M's?
Just use any of the plethora of Dos2Unix conversion programs out there.
jue
------------------------------
Date: Wed, 26 Feb 2003 23:59:44 -0600
From: Lars Eighner <eighner@io.com>
Subject: Re: remove unwanted characters
Message-Id: <slrnb5ra0j.1r8.eighner@pearl.io.com>
In our last episode,
<3E5D149F.99A9B677@tamu.edu>,
the lovely and talented Bing Du Test
broadcast on comp.lang.perl.misc:
> Greetings,
> We need to use Perl to process files transferred from Windows machines
> to UNIX. Sometimes, ^M is appended at the end of each line when a PC
> file arrives on Unix.
> Just wondering if there is anyway to remove all the ^M's?
> Thanks in advance for any help.
> Bing
perl -pi -e 's#\r\n#\n#' <filespecs>
--
Lars Eighner -finger for geek code- eighner@io.com http://www.io.com/~eighner/
War on Terrorism: Bad News from the Sanity Front
"Tactical nuclear capabilities should be used against the bin Laden
camps in the desert of Afghanistan." -Thomas Woodrow,_Washington Times_
------------------------------
Date: Thu, 27 Feb 2003 03:09:57 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: sort, uniq -c
Message-Id: <3E5D808D.8090701@rochester.rr.com>
david wrote:
> I have a list of data in the format of:
>
> group <tab> dept <tab> group2 <tab> dept2
>
> (The tabs donate a tab in the datafile).
> What I want to do is something like sort and uniq -c, I want to sort
> the data and only print the unique lines. For each unique line, I want
> to know the number of other lines like it. I have accomplished the
> same thing with AWK and sort,uniq, but would like to be able to do
> this in perl. What would be the best way to do this?
...
Well, you could stuff your lines into hash keys and then sort. Maybe
something like:
use Data::Dumper;
use warnings;
use strict;
my @lines=('this is line one','this is line two',
'this is line three','line four',
'line 5','line 6','line 7',
'this is line two','line 6',);
my %h;
@h{@lines}=1;
my @result=sort keys %h;
print Dumper(\@result);
If you want the counts, replace the line
@h{@lines}=1;
with:
$h{$_}++ for @lines;
and then subtract one from each hash value to get the number of other
lines which were duplicates of each line.
--
Bob Walton
------------------------------
Date: Wed, 26 Feb 2003 21:27:55 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: sort, uniq -c
Message-Id: <slrnb5r1dr.6o9.tadmc@magna.augustmail.com>
david <dwlepage@yahoo.com> wrote:
> I have a list of data in the format of:
>
> group <tab> dept <tab> group2 <tab> dept2
>
> (The tabs donate a tab in the datafile).
Please say it in Perl instead of in English, as suggested in
the Posting Guidelines that are posted here frequently.
$_ = "group\tdept\tgroup2\tdept2";
It is unambiguous, plus shorter to write.
> What I want to do is something like sort and uniq -c, I want to sort
> the data and only print the unique lines.
Then you've chosen very poor sample data, as there *are no*
duplicates in it, so you won't know if the part of your
spec has been met or not...
> For each unique line, I want
> to know the number of other lines like it.
> I have accomplished the
> same thing with AWK
Then run your awk through the "a2p" (awk to Perl) program
that came with your perl distribution.
> What would be the best way to do this?
---------------------------
#!/usr/bin/perl
use strict;
use warnings;
$_ = "group\tdept\tgroup2\tdept\tgroup2\tdept";
my %cnt;
foreach ( split ) {
$cnt{$_}++;
}
print "$_ appeared $cnt{$_} times\n" for sort keys %cnt;
---------------------------
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 27 Feb 2003 07:47:29 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: splitting
Message-Id: <b3kfqh$8a3$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Johannes Fürnkranz:
> Martien Verbruggen wrote:
>> On Wed, 26 Feb 2003 23:41:17 +0100,
>> Johannes Fürnkranz <johannes.fuernkranz@t-online.de> wrote:
>>
>>>I want to split a line on commas, but only if they are not preceded by a
>>>backslash.
>>
>>
>> my @fields = split /(?<!\\),/, $line;
>>
>> See the perlre documentation for the zero-width negative look-behind
>> assertion.
>
> Apologies, I should have checked. I was absolutely certain that there is
> only look-ahead...
...with variable length at least. Look-behind is a little crippled since
it must be of fixed-width. I still hope this limitation goes away in one
of the next releases of Perl to make it even more useful.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
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 4632
***************************************