[23199] in Perl-Users-Digest
Perl-Users Digest, Issue: 5420 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 24 18:11:38 2003
Date: Sun, 24 Aug 2003 15:10:10 -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 Sun, 24 Aug 2003 Volume: 10 Number: 5420
Today's topics:
Probably a dereferencing problem - maybe??? <mikeflan@earthlink.net>
Re: Probably a dereferencing problem - maybe??? (Tad McClellan)
Re: Probably a dereferencing problem - maybe??? <mikeflan@earthlink.net>
Re: Probably a dereferencing problem - maybe??? (Tad McClellan)
Re: Probably a dereferencing problem - maybe??? <mpapec@yahoo.com>
regexp mystery <compiler@bahamutirc.net>
Re: regexp mystery (Tad McClellan)
Re: regexp mystery <sv99oya02@sneakemail.com>
Re: regexp mystery <krahnj@acm.org>
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 24 Aug 2003 19:01:44 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Probably a dereferencing problem - maybe???
Message-Id: <3F490C2F.5A966E95@earthlink.net>
I have some code below that works fine. It finds duplicates on
one field and marks them as duplicates. But I'd like to also
remove all quotes (") from the file also. The 3 commented out
lines are some of my attempts at doing this. They all give errors
like:
"Applying substitution (s///) to @array will act on scalar
(@array) at . . . line 31. Can't modify private array in
substitution (s///0 at . . . line 31 near "s/"//s;"
I can get this done outside this script, but was wondering if
there is an easy way to do this inside this script.
Mike Flannigan
________________________________
use strict;
use warnings;
my $old_file = 'bb1.txt';
my $new_file = 'bb2.txt';
open WPIN, $old_file or die "Cannot open $old_file: $!";
my @data = map [ split /\t/, $_, 6 ], <WPIN>;
close WPIN;
#@data =~ s/"//gs;
open WPOUT, ">", $new_file or die "$0: open $new_file: $!";
my %saw;
for my $line (@data) {
# $line =~ tr/"//d;
if ($saw{ $line->[ 4 ] }++) {
print "found dup\n";
$line->[ 0 ] .= "+++++";
}
# @$line =~ tr/"//d;
print WPOUT join("\t" => @$line);
}
close WPOUT or warn "$0: close $new_file: $!";
__END__
DATA
Canoe Valley Grapevine Hills Brewster valley 292756N1030910W "TX, Texas"
Cantrell Mountain Hacienda Uvalde summit 291204N0995833W "TX, Texas"
Casa Grande Peak The Basin Brewster summit 291603N1031711W "TX, Texas"
Cassiano Park San Antonio West Bexar park 292449N0983144W "TX, Texas"
Cedar Grove Cemetery Sanderson Terrell cemetery 300754N1022309W "TX,
Texas"
Centeno Park San Antonio West Bexar park 292513N0983232W "TX, Texas"
------------------------------
Date: Sun, 24 Aug 2003 14:35:08 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Probably a dereferencing problem - maybe???
Message-Id: <slrnbki4rc.dfg.tadmc@magna.augustmail.com>
Mike Flannigan <mikeflan@earthlink.net> wrote:
> I'd like to also
> remove all quotes (") from the file also.
^^^^^^^^^^^^^
It looks to me like you want to remove all quotes (") from an *array*.
> #@data =~ s/"//gs;
The s///s is a no-op, so it should not be there.
"s" only affects dot, it is a mistake to apply it when there
are no dots in the pattern.
s/"//g foreach @data;
or, better yet, use the Right Tool for jobs involving characters
(rather than patterns):
tr/"//d foreach @data;
or
tr/"//d for @data;
or, if you don't like that "reversed" form:
foreach ( @data ) {
tr/"//d
}
See the "Foreach Loops" section in perlsyn.pod to learn about
the "alias"ing that foreach() does for you.
> # $line =~ tr/"//d;
That looks familiar. :-)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 24 Aug 2003 20:07:21 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Re: Probably a dereferencing problem - maybe???
Message-Id: <3F491B8F.73456FAB@earthlink.net>
Tad McClellan wrote:
> Mike Flannigan <mikeflan@earthlink.net> wrote:
>
> It looks to me like you want to remove all quotes (") from an *array*.
Right you are.
> The s///s is a no-op, so it should not be there.
>
> "s" only affects dot, it is a mistake to apply it when there
> are no dots in the pattern.
I don't follow you entirely there, but that's OK. I know what
you are saying ( . as in match any character), but don't know
what that has to do with /s. I think I am totally confused about
the difference between /s and /m. I'll figure it out someday.
> s/"//g foreach @data;
Thank you. I was just signing on again to say I found the
answer myself, though not as good an answer as yours
above. I tried
$line->[ 0 ] =~ tr/"//d;
$line->[ 5 ] =~ tr/"//d;
and it worked.
>
> or, better yet, use the Right Tool for jobs involving characters
> (rather than patterns):
>
> tr/"//d foreach @data;
> or
> tr/"//d for @data;
>
> or, if you don't like that "reversed" form:
>
> foreach ( @data ) {
> tr/"//d
> }
>
> See the "Foreach Loops" section in perlsyn.pod to learn about
> the "alias"ing that foreach() does for you.
>
> > # $line =~ tr/"//d;
>
> That looks familiar. :-)
>
------------------------------
Date: Sun, 24 Aug 2003 15:43:16 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Probably a dereferencing problem - maybe???
Message-Id: <slrnbki8r4.dkv.tadmc@magna.augustmail.com>
Mike Flannigan <mikeflan@earthlink.net> wrote:
> Tad McClellan wrote:
>> "s" only affects dot, it is a mistake to apply it when there
>> are no dots in the pattern.
> I don't follow you entirely there, but that's OK. I know what
> you are saying ( . as in match any character), but don't know
> what that has to do with /s.
dot does NOT match any character.
dot matches any character except a newline.
the "s" option makes dot match any character.
it is senseless to change the meaning of dot when there is no dot.
> I think I am totally confused about
> the difference between /s and /m. I'll figure it out someday.
Why not today?
/s makes dot match a newline character.
/m makes ^ and $ match beginning/end of a _line_ rather than
beginning/end of the string. ie. It matches "interior" lines begins/ends.
If there is no dot in your pattern, then you do not _need_ to
understand /s, because you should not be using it.
If there is no anchor ( ^ or $ ) in your pattern, then you do not _need_ to
understand /m, because you should not be using it.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 24 Aug 2003 22:48:05 +0200
From: Matija Papec <mpapec@yahoo.com>
Subject: Re: Probably a dereferencing problem - maybe???
Message-Id: <0n8ikvs2cdin1cvp43h119e42hrtf4a0ff@4ax.com>
X-Ftn-To: Mike Flannigan
Mike Flannigan <mikeflan@earthlink.net> wrote:
>I don't follow you entirely there, but that's OK. I know what
>you are saying ( . as in match any character), but don't know
>what that has to do with /s. I think I am totally confused about
>the difference between /s and /m. I'll figure it out someday.
You want to use /s in case you want to . match the newline, and /m
only to say anchors(^ and $) to match begining/end of line.
perldoc perlretut
* no modifiers (//): Default behavior. '.' matches any character
except "\n". "^" matches only at the beginning of the string and "$"
matches only at the end or before a newline at the end.
* s modifier (//s): Treat string as a single long line. '.' matches
any character, even "\n". "^" matches only at the beginning of the
string and "$" matches only at the end or before a newline at the
end.
* m modifier (//m): Treat string as a set of multiple lines. '.'
matches any character except "\n". "^" and "$" are able to match at
the start or end of *any* line within the string.
* both s and m modifiers (//sm): Treat string as a single long line,
but detect multiple lines. '.' matches any character, even "\n". "^"
and "$", however, are able to match at the start or end of *any*
line within the string.
--
Matija
------------------------------
Date: Sun, 24 Aug 2003 20:22:17 GMT
From: "John Davison" <compiler@bahamutirc.net>
Subject: regexp mystery
Message-Id: <Z792b.80790$hc.31225@fe3.columbus.rr.com>
The solution to this one eludes me. Let's say I have a string as follows:
6.hello everybody!
I want to match the first N letters after the period after the number N. The
regular expression has to be built first, so it has to be something like
/$regexp/.
Here's what I was working with:
$regexp = '(\\d+)(?{ $reg_1 = $^N })\\.(.{$reg_1})';
where $reg_1 gets the number, but I can't make it become the quantifier later.
I tried the (??{ $reg_1 }) but I couldn't get that to go either. I get the
feeling that $reg_1 never gets evaluated.
Any suggestions?
- john
compiler@bahamutirc.net <-- spam trap
------------------------------
Date: Sun, 24 Aug 2003 15:52:05 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: regexp mystery
Message-Id: <slrnbki9bl.dme.tadmc@magna.augustmail.com>
John Davison <compiler@bahamutirc.net> wrote:
> Let's say I have a string as follows:
> 6.hello everybody!
>
> I want to match the first N letters after the period after the number N.
But there are only 5 letters after the period and N = 6.
So what is it supposed to do then?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 24 Aug 2003 23:57:22 +0200
From: =?ISO-8859-15?Q?Steffen_M=FCller?= <sv99oya02@sneakemail.com>
Subject: Re: regexp mystery
Message-Id: <bibcbl$kls$1@news.rz.uni-karlsruhe.de>
John Davison wrote:
> The solution to this one eludes me. Let's say I have a string as
> follows: 6.hello everybody!
>
> I want to match the first N letters after the period after the number
> N. The regular expression has to be built first, so it has to be
> something like /$regexp/.
>
> Here's what I was working with: $regexp = '(\\d+)(?{ $reg_1 = $^N
> })\\.(.{$reg_1})';
>
> where $reg_1 gets the number, but I can't make it become the
> quantifier later. I tried the (??{ $reg_1 }) but I couldn't get that
> to go either. I get the feeling that $reg_1 never gets evaluated.
What's wrong with using two regexes?
(This was a win32 shell, hence the ")
perl -e "$s='6.helloeverybody'; $s =~ /^(\d+)/ or die; $c = $1; $s =~
/^\d+\.(.{$c})/; print $1"
prints 'helloe'
Steffen
--
@n=([283488072,6076],[2105905181,8583184],[1823729722,9282996],[281232,
1312416],[1823790605,791604],[2104676663,884944]);$b=6;@c=' -/\_|'=~/./g
;for(@n){for$n(@$_){map{$h=int$n/$b**$_;$n-=$b**$_*$h;$c[@c]=$h}reverse
0..11;push@p,map{$c[$_]}@c[reverse$b..$#c];$#c=$b-1}$p[@p]="\n"}print@p;
------------------------------
Date: Sun, 24 Aug 2003 22:01:20 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: regexp mystery
Message-Id: <3F4935B1.8647F884@acm.org>
John Davison wrote:
>
> The solution to this one eludes me. Let's say I have a string as follows:
> 6.hello everybody!
>
> I want to match the first N letters after the period after the number N. The
> regular expression has to be built first, so it has to be something like
> /$regexp/.
>
> Here's what I was working with:
> $regexp = '(\\d+)(?{ $reg_1 = $^N })\\.(.{$reg_1})';
>
> where $reg_1 gets the number, but I can't make it become the quantifier later.
> I tried the (??{ $reg_1 }) but I couldn't get that to go either. I get the
> feeling that $reg_1 never gets evaluated.
>
> Any suggestions?
Yes, don't use a regular expression, use unpack instead.
my $string = '6.hello everybody!';
my ( $result ) = unpack 'A/A*', $string;
print "$result\n";
John
--
use Perl;
program
fulfillment
------------------------------
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 5420
***************************************