[23184] in Perl-Users-Digest
Perl-Users Digest, Issue: 5405 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 21 14:11:57 2003
Date: Thu, 21 Aug 2003 11:10:18 -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 Thu, 21 Aug 2003 Volume: 10 Number: 5405
Today's topics:
Re: Regular Expression - BackReferences Question <kasp@epatra.com>
simple regex <darkage@nospamage.com.au>
Re: simple regex <tore@aursand.no>
Re: simple regex <thens@nospam.com>
Re: simple regex <dbo@xbn.nl>
Re: simple regex <usenet@dwall.fastmail.fm>
Re: simple regex (Tad McClellan)
Re: simple regex <danglesocket@no_spam>
Re: Strange INC error when using perl 5.8.0 as a cgi sc (Tony)
Text::Autoformat and 'psychosis' <usenet@dwall.fastmail.fm>
Re: undeclaring multiple arrays <ndronen@io.frii.com>
Using strict references <todd@ti.com>
Re: Using strict references <trammell+usenet@hypersloth.invalid>
Re: Using strict references <john.thetenant-s@moving-picture.com>
Re: Using strict references <todd@ti.com>
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 21 Aug 2003 16:13:36 +0530
From: "Kasp" <kasp@epatra.com>
Subject: Re: Regular Expression - BackReferences Question
Message-Id: <bi27p1$ol1$1@newsreader.mailgate.org>
"Jay Tilton" <tiltonj@erols.com> wrote in message
news:3f449629.44661415@news.erols.com...
<snip>
> : $line =~ s#(\d+)\.gif#$1++\.gif#gsi;
> "$1++" will cause a "Modification of a read-only value" error.
It did not give me any error...even with use strict and use warnings; (I am
using ActiveState's Perl 5.8 on WinDoze 2000 Prof.)
Rather the file contained http://www.somesite.com/folder/1++.gif
while $line =~ s#(\d+)\.gif#($1+1)\.gif#gsi;
writes to file http://www.somesite.com/folder/1+1.gif
> : and neither did
> : $line =~ s#(\d+)\.gif#($1+1)\.gif#gsi;
>
> Almost there. You just need to make perl treat the replacement
> portion as code, so "$1+1" will actuall perform some math.
> The /e modifier gets it done.
>
> $line =~ s#(\d+)\.gif# $1+1 . ".gif" #e;
>
> Did you have reasons for including the /g and /s modifiers?
Thanks for the /e... I tried almost everything else than what was needed.
Just didn't click me.
------------------------------
Date: Fri, 22 Aug 2003 00:26:45 +1000
From: "Darkage" <darkage@nospamage.com.au>
Subject: simple regex
Message-Id: <3f44d611_1@news.iprimus.com.au>
I've got a file with a list of ip's in brackets, fqdn's and -'s. How do
you simply remove the [ ]'s and the -'s from the file with a simple perl
script. I've thought about using a if statement to take out the -'s
lines, then maybe a double split action to get rid of the [ ] backets or
regex substition s/// with whitespaces.
[216.141.143.15]
c-24-130-128-153.we.client2.attbi.com
-
alb92-fre1.pangeatech.com
[216.141.143.15]
-
envisionpress-gw.customer.csolutions.net
c-24-130-128-153.we.client2.attbi.com
alb92-fre1.pangeatech.com
------------------------------
Date: Thu, 21 Aug 2003 16:46:55 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: simple regex
Message-Id: <pan.2003.08.21.14.46.45.644988@aursand.no>
On Fri, 22 Aug 2003 00:26:45 +1000, Darkage wrote:
> How do you simply remove the [ ]'s and the -'s from the file with a
> simple perl script.
>
> [216.141.143.15]
> c-24-130-128-153.we.client2.attbi.com
> -
> alb92-fre1.pangeatech.com
> [216.141.143.15]
> -
> envisionpress-gw.customer.csolutions.net
> c-24-130-128-153.we.client2.attbi.com alb92-fre1.pangeatech.com
cat file | perl -pe 's,\[|\]|^\-,,g'
--
Tore Aursand <tore@aursand.no>
------------------------------
Date: Thu, 21 Aug 2003 20:28:48 +0530
From: Thens <thens@nospam.com>
Subject: Re: simple regex
Message-Id: <20030821202848.398f1096.thens@nospam.com>
On Thu, 21 Aug 2003 16:46:55 +0200
Tore Aursand <tore@aursand.no> wrote:
>
>cat file | perl -pe 's,\[|\]|^\-,,g'
Why not
perl -pe 's,\[|\]|^-,,g' file
Regards,
Thens
--
------------------------------
Date: Thu, 21 Aug 2003 17:17:59 +0200
From: David Bouman <dbo@xbn.nl>
Subject: Re: simple regex
Message-Id: <3F44E2A7.94189304@xbn.nl>
On Thu, 21 Aug 2003 20:28:48 +0530 Thens wrote:
> Why not
>
> perl -pe 's,\[|\]|^-,,g' file
Or even:
perl -pe 's,\[|\]|^-$/,,g' file
--
David.
------------------------------
Date: Thu, 21 Aug 2003 15:43:04 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: simple regex
Message-Id: <Xns93DE7734F2EBDdkwwashere@216.168.3.30>
Thens <thens@nospam.com> wrote:
> perl -pe 's,\[|\]|^-,,g' file
The OP also said s?he might want to eliminate the lines with dashes:
perl -ne "next if /^-/; s,\[|\]|,,g; print" file
I don't use one-liners much, and was initially puzzled that 'next'
didn't give me the expected results until I noticed that -p puts the
print in the implicit while(){} in a continue{} block. Caveat luser.
:-)
[Off-topic] Can domain names begin with a dash? It's my impression
they can't, but perhaps they don't by convention. (I'm not sure which
RFC to check)
------------------------------
Date: Thu, 21 Aug 2003 11:20:44 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: simple regex
Message-Id: <slrnbk9sas.9uq.tadmc@magna.augustmail.com>
Darkage <darkage@nospamage.com.au> wrote:
> How do
> you simply remove the [ ]'s and the -'s from the file with a simple perl
> script.
perl -p -i -e 'tr/[]-//d' file
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 21 Aug 2003 11:28:00 -0400
From: danglesocket<danglesocket@no_spam>
Subject: Re: simple regex
Message-Id: <3f44e506@shknews01>
>>> danglesocket<danglesocket@no_spam> 8/21/2003 11:13:53 AM >>>
>>> Darkage<darkage@nospamage.com.au> 8/21/2003 10:26:45 AM >>>
I've got a file with a list of ip's in brackets, fqdn's and -'s. How do
you simply remove the [ ]'s and the -'s from the file with a simple perl
script. I've thought about using a if statement to take out the -'s
lines, then maybe a double split action to get rid of the [ ] backets or
regex substition s/// with whitespaces.
-oh yeah, what about this, with a backup.
perl -pe 's\\[|\]|^-$/\\g' -i".bk" text.txt
__danglesocket__
------------------------------
Date: 21 Aug 2003 03:07:06 -0700
From: ts@relson.net (Tony)
Subject: Re: Strange INC error when using perl 5.8.0 as a cgi script
Message-Id: <63073ce9.0308210207.3aacd567@posting.google.com>
Lou Moran <ellem52@mac.com> wrote in message news:<nbv6kvgab0ga7i7kp6q95rt8rg1tr4o5f7@4ax.com>...
> On 20 Aug 2003 05:53:25 -0700, ts@relson.net (Tony) wrote wonderful
> things about me:
>
> >Hi All,
> >
> > I have just compiled perl 5.8.0 on aix 4.3.3. I got the stable.tar
> >from cpan. It complied fine without any errors. The trouble starts
> >when I try to use it to write cgi scripts.
>
> 5.8.0 & 5.6.1 are not binary compatible. This is known and
> documented. Google is you friend. Go get new modules.
Hi All,
Just for completeness, I found out what it was /usr/local/lib was set
to 744 and not 755 doh. Don't know how these permissions got set, but
set it to 755 and it all works fine now.
Thanks for the suggestions though.
Tony
------------------------------
Date: Thu, 21 Aug 2003 17:28:09 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Text::Autoformat and 'psychosis'
Message-Id: <Xns93DE89062FA4Edkwwashere@216.168.3.30>
Here's some weirdness. When I run
use Text::Autoformat;
print autoformat 'PSYCHOSIS', {case=>'lower'};
the output is 'PSychosis' instead of 'psychosis'. Other variations
give assorted weirdnesses. (See code below)
I don't see that I've done anything wrong, so maybe this is one of
the "serious bugs lurking somewhere in code this funky". But I've
certainly been wrong before. Anyone see something I missed?
use strict;
use warnings;
use Text::Autoformat;
my @test_text;
push @test_text,
# text matching /psy/
qw/PSYCHOTIC PSYCHOSIS EPILEPSY NON-PSYCHOTIC/,
'SENILITY, WITHOUT PSYCHOSIS',
'PSYCHOTIC DISORDERS';
for my $case (qw/sentence highlight title lower/) {
print "$case:\n";
for (@test_text) {
print "\tUC: ", autoformat(uc($_), {case=>$case}),
"\tLC: ", autoformat(lc($_), {case=>$case});
}
print "\n\n";
}
--
David Wall
------------------------------
Date: 21 Aug 2003 15:19:59 GMT
From: Nicholas Dronen <ndronen@io.frii.com>
Subject: Re: undeclaring multiple arrays
Message-Id: <3f44e31f$0$200$75868355@news.frii.net>
Aaron <Chewy2426@aol.com> wrote:
A> I've looked on deja a little but couldn't find a definite answer. I
A> created an array of hashes to store a lot of data. I have everything
A> declared as locally as possible with MYs but I'm still taking up too
A> much memory.
A> Here's a shorted version of my code:
A> foreach $key (sort { $top10talkTemp{$b} <=> $top10talkTemp{$a} }
A> keys(%top10talkTemp)) {
A> foreach (@{$source{$key}}) {
A> #Stuff in here
A> }
A> @{$source{$key}} = undef;
A> }
A> The @{%hash} is new to me. Is setting @{$source{$key}} = undef the
A> best way to clear the memory space, or can I do @{%source} = undef
A> after the foreach loop? Or is there even a better method?
Have you read:
$ perldoc -q memory
Regards,
Nicholas
--
"Why shouldn't I top-post?" http://www.aglami.com/tpfaq.html
"Meanings are another story." http://www.ifas.org/wa/glossolalia.html
------------------------------
Date: Thu, 21 Aug 2003 11:37:41 -0500
From: Todd Bair <todd@ti.com>
Subject: Using strict references
Message-Id: <3F44F555.850CADB2@ti.com>
Hi,
I am trying to write all of my code using strict to improve my
code. However, the correct use of references for the following problem
eludes me. I have a work around, but I would like to know the correct
way to code this.
#!/usr/bin/perl -w
######################################
use strict;
#no strict 'refs'; ## work around ##
######################################
my %hash = qw(foo one bar two);
my $key;
foreach $key (keys %hash)
{
@{$key} = (0..5);
}
######################################
# later on in the program
######################################
foreach $key (keys %hash)
{
print "array $hash{$key} = ";
print join("\t",@{$key});
print "\n";
}
I would appreciate any help that you can offer.
Thanks,
Todd
------------------------------
Date: Thu, 21 Aug 2003 17:15:31 +0000 (UTC)
From: "John J. Trammell" <trammell+usenet@hypersloth.invalid>
Subject: Re: Using strict references
Message-Id: <slrnbk9vhj.5kk.trammell+usenet@hypersloth.el-swifto.com.invalid>
On Thu, 21 Aug 2003 11:37:41 -0500, Todd Bair <todd@ti.com> wrote:
>
> #!/usr/bin/perl -w
> ######################################
>
> use strict;
> #no strict 'refs'; ## work around ##
>
> ######################################
>
> my %hash = qw(foo one bar two);
> my $key;
>
> foreach $key (keys %hash)
> {
> @{$key} = (0..5);
> }
foreach my $key (keys %hash) { $hash{$key} = [0..5] } # untested
>
> ######################################
> # later on in the program
> ######################################
>
> foreach $key (keys %hash)
> {
> print "array $hash{$key} = ";
>
> print join("\t",@{$key});
>
> print "\n";
> }
>
#untested
foreach my $key (keys %hash)
{
print "$key => $hash{$key} => ", join "\t", @{$hash{$key}};
print "\n";
}
------------------------------
Date: Thu, 21 Aug 2003 18:26:57 +0100
From: John Strauss <john.thetenant-s@moving-picture.com>
Subject: Re: Using strict references
Message-Id: <20030821182657.7768b0cc.john.thetenant-s@moving-picture.com>
On Thu, 21 Aug 2003 11:37:41 -0500
Todd Bair <todd@ti.com> wrote:
>
> Hi,
>
> I am trying to write all of my code using strict to improve my
> code. However, the correct use of references for the following problem
> eludes me. I have a work around, but I would like to know the correct
> way to code this.
>
> #!/usr/bin/perl -w
> ######################################
>
> use strict;
> #no strict 'refs'; ## work around ##
>
> ######################################
>
> my %hash = qw(foo one bar two);
> my $key;
>
> foreach $key (keys %hash)
> {
> @{$key} = (0..5);
$hash{$key} = [0..5];
> }
>
> ######################################
> # later on in the program
> ######################################
>
> foreach $key (keys %hash)
> {
> print "array $hash{$key} = ";
>
> print join("\t",@{$key});
print join("\t",@{$hash{$key}});
>
> print "\n";
> }
>
> I would appreciate any help that you can offer.
>
> Thanks,
>
> Todd
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drop the .thetenant to get me via mail
------------------------------
Date: Thu, 21 Aug 2003 12:47:58 -0500
From: Todd Bair <todd@ti.com>
Subject: Re: Using strict references
Message-Id: <3F4505CE.83B17809@ti.com>
> @{$key} = (0..5);
$hash{$key} = [0..5];
John,
I the goal is to use the $key as the name of the array not the value of
the key.
Also, your suggestion produces the following error:
Use of uninitialized value in range (or flip) at strict_refs.pl line 15.
Use of uninitialized value in range (or flop) at strict_refs.pl line 15.
Use of uninitialized value in range (or flop) at strict_refs.pl line 15.
Can't use string ("1") as an ARRAY ref while "strict refs" in use at
strict_refs.pl line 26.
array 1 =
Thanks,
Todd
John Strauss wrote:
> On Thu, 21 Aug 2003 11:37:41 -0500
> Todd Bair <todd@ti.com> wrote:
> >
> > Hi,
> >
> > I am trying to write all of my code using strict to improve my
> > code. However, the correct use of references for the following problem
> > eludes me. I have a work around, but I would like to know the correct
> > way to code this.
> >
> > #!/usr/bin/perl -w
> > ######################################
> >
> > use strict;
> > #no strict 'refs'; ## work around ##
> >
> > ######################################
> >
> > my %hash = qw(foo one bar two);
> > my $key;
> >
> > foreach $key (keys %hash)
> > {
> > @{$key} = (0..5);
> $hash{$key} = [0..5];
> > }
> >
> > ######################################
> > # later on in the program
> > ######################################
> >
> > foreach $key (keys %hash)
> > {
> > print "array $hash{$key} = ";
> >
> > print join("\t",@{$key});
> print join("\t",@{$hash{$key}});
> >
> > print "\n";
> > }
> >
> > I would appreciate any help that you can offer.
> >
> > Thanks,
> >
> > Todd
> >
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> drop the .thetenant to get me via mail
------------------------------
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 5405
***************************************