[27531] in Perl-Users-Digest
Perl-Users Digest, Issue: 9097 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 27 21:05:37 2006
Date: Mon, 27 Mar 2006 18:05:03 -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, 27 Mar 2006 Volume: 10 Number: 9097
Today's topics:
Re: file renamer... request feedback <matthew.garrish@sympatico.ca>
Ignore PGP Poser Keith Keller. <ee@eeerrr.org>
Why is my substitution doubling up on brackets? <dragnet@internalysis.com>
Re: Why is my substitution doubling up on brackets? <someone@example.com>
Re: Why is my substitution doubling up on brackets? <rvtol+news@isolution.nl>
Re: XML::Simple and utf8 woes <noone@nowhere.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 27 Mar 2006 20:01:52 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: file renamer... request feedback
Message-Id: <0W%Vf.1015$m35.92504@news20.bellglobal.com>
"John Bokma" <john@castleamber.com> wrote in message
news:Xns9792D6168F7B8castleamber@130.133.1.4...
> "Matt Garrish" <matthew.garrish@sympatico.ca> wrote:
>
>> Why do keep writing gibberish?
>
> Because people like you keep replying? (Just a wild guess)
>
Guess your rules don't apply to you...
Matt
------------------------------
Date: Mon, 27 Mar 2006 23:36:17 GMT
From: Reeeee eerrttts <ee@eeerrr.org>
Subject: Ignore PGP Poser Keith Keller.
Message-Id: <RF_Vf.853$u15.192689@news20.bellglobal.com>
Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us> trolled:
> On 2006-03-27, Mogens V. <NOSPAMmogensv@vip.cybercity.dk> wrote:
> > @keller: I wish there would be some way of enforcing policies to NG's.
> There is: create a moderated newsgroup under the Big 8 hierarchy.
> Anything goes in an alt.*, so judicious use of killfiles is best.
> (Like killfiling chronic trollfeeders *ahem*.)
PGP Poser Keith Keller is a phoney and a hypocrite. He curries
favour in one group by promoting PGP in the signature
(alt.os.linux.slackware) and he curries favour in another group
(comp.lang.perl.misc) by hiding his PGP in his headers.
PGP Poser Keith Keller is a phoney and a hypocrite.
------------------------------
Date: Mon, 27 Mar 2006 17:47:12 -0600
From: Marc Bissonnette <dragnet@internalysis.com>
Subject: Why is my substitution doubling up on brackets?
Message-Id: <Xns9793BF1851F31dragnetinternalysisc@216.196.97.131>
Hi all;
I'm at a bit of a loss to figure out why the following code, when
substituting the matches, doubles up the brackets:
(I've commented out the loop that fixes it, but I am curious as to what
I've missed) - Any pointers would be most appreciated.
#####################################################################
#!/usr/bin/perl
$text = 'Albertsons (40,100ct), Vons(40ct), Stater Brothers(40ct), Ralphs
(48ct), Food 4 Less, Walmart';
$text2=$text;
local @matches;
@matches = $text=~ m/(\(.*?\))/g;
$count=0;
foreach $match ( @matches ) {
if ($match =~ /\,/) {
$newmatch=$match;
$newmatch=~s/\,/\|/g;
$matches{$count}=$newmatch;
$originals{$count}=$match;
++$count;
} else {
$originals{$count}=$match;
$matches{$count}=$match;
++$count;
}
}
for (0..$count) {
next if ($originals{$_} eq undef);
$text=~ s/$originals{$_}/$matches{$_}/g;
}
#while ($text =~ /\(\(/ or $text =~ /\)\)/) {
# $text =~ s/\(\(/\(/g;
# $text =~ s/\)\)/\)/g;
#}
print "The original string: $text2\nThe modified string: $text\n";
print "\n\nDONE";
#####################################################################
--
Marc Bissonnette
Looking for a new ISP? http://www.canadianisp.com
Largest ISP comparison site across Canada.
------------------------------
Date: Tue, 28 Mar 2006 01:12:16 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Why is my substitution doubling up on brackets?
Message-Id: <Q30Wf.11158$B_1.8488@edtnps89>
Marc Bissonnette wrote:
>
> I'm at a bit of a loss to figure out why the following code, when
> substituting the matches, doubles up the brackets:
>
> (I've commented out the loop that fixes it, but I am curious as to what
> I've missed) - Any pointers would be most appreciated.
> #####################################################################
> #!/usr/bin/perl
use warnings;
use strict;
> $text = 'Albertsons (40,100ct), Vons(40ct), Stater Brothers(40ct), Ralphs
> (48ct), Food 4 Less, Walmart';
> $text2=$text;
> local @matches;
> @matches = $text=~ m/(\(.*?\))/g;
> $count=0;
> foreach $match ( @matches ) {
> if ($match =~ /\,/) {
> $newmatch=$match;
> $newmatch=~s/\,/\|/g;
> $matches{$count}=$newmatch;
> $originals{$count}=$match;
> ++$count;
> } else {
> $originals{$count}=$match;
> $matches{$count}=$match;
> ++$count;
> }
> }
> for (0..$count) {
You have an off-by-one error because $count will always be one greater then
the last element. Why not just use arrays instead of hashes if all the
indexes are contiguous integers?
> next if ($originals{$_} eq undef);
You cannot use undef in that way, you have to use the defined() function.
> $text=~ s/$originals{$_}/$matches{$_}/g;
The parentheses in $originals{$_} are interpreted by the regular expression
engine as capturing parentheses thus do not match the literal parentheses in
the string.
> }
> #while ($text =~ /\(\(/ or $text =~ /\)\)/) {
> # $text =~ s/\(\(/\(/g;
> # $text =~ s/\)\)/\)/g;
> #}
> print "The original string: $text2\nThe modified string: $text\n";
> print "\n\nDONE";
> #####################################################################
Your program could more simply be written as:
#!/usr/bin/perl
use warnings;
use strict;
my $text = 'Albertsons (40,100ct), Vons(40ct), Stater Brothers(40ct), Ralphs
(48ct), Food 4 Less, Walmart';
my $text2 = $text;
$text =~ s{ ( \( [^()]+ \) ) }{ ( my $x = $1 ) =~ tr!,!|!; $x }exg;
print "The original string: $text2\nThe modified string: $text\n";
print "\n\nDONE";
John
--
use Perl;
program
fulfillment
------------------------------
Date: Tue, 28 Mar 2006 03:00:06 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Why is my substitution doubling up on brackets?
Message-Id: <e0a91u.1bo.1@news.isolution.nl>
Marc Bissonnette schreef:
> I'm at a bit of a loss to figure out why the following code, when
> substituting the matches, doubles up the brackets:
> @matches = $text=~ m/(\(.*?\))/g;
@matches = $text=~ m/\((.*?)\)/g;
But you also need to put
use strict;
use warnings;
at te start, and properly declare your variables.
I assume that you want to change each embedded comma to a bar.
#!/usr/bin/perl
use strict;
use warnings;
my $old = 'Albertsons (40,100ct), Vons(40ct), Stater Brothers(40ct),
Ralphs (48ct), Food 4 Less, Walmart';
my $new = $old;
1 while $new =~ s/([(][^(,)]*),([^)]*[)])/$1|$2/);
print "old: $old\n";
print "new: $new\n";
--
Affijn, Ruud
"Gewoon is een tijger."
echo 014C8A26C5DB87DBE85A93DBF |perl -pe 'tr/0-9A-F/JunkshoP cartel,/'
------------------------------
Date: Mon, 27 Mar 2006 18:31:33 -0500
From: Dennis Roesler <noone@nowhere.com>
Subject: Re: XML::Simple and utf8 woes
Message-Id: <1143502283.106084@newsreg.cos.agilent.com>
corff@zedat.fu-berlin.de wrote:
>
> If, in a fit of desperation, I modify the output of XMLout() with
> NumericEscape=>2, all I get in the output is that, eg. a umlaut of
> Morgendämmerung (sorry for this encoding-independet symbolic
> notation here!) is represented as ä which happens to be the
> decimal values of the two octets comprising U+00e4, or Latin small a
> with umlaut.
I've been following this thread because I have been struggling with
XML::Simple writing/sourcing an XML file in cp932 encoding. The
NumericEscape is what resolved the writing and setting the encoding in
the xml declaration of the cp932 encoded file to x-sjis-cp932 so
XML::Simple would source it properly took me awhile to figure out :-(.
#!/usr/bin/perl
use strict;
use warnings;
use XML::Simple;
use Data::Dumper;
use Encode qw(:all);
my $file = $ARGV[0];
my $outfile = "cp932out.xml";
open my $utf8in, "<:encoding(utf8)", $file or die "In $file: $!";
open my $cp932out, ">:encoding(cp932)", $outfile or die "Out $outfile: $!";
my $utf8So = XMLin($utf8in, KeepRoot => 1, ForceArray => 1,
SuppressEmpty => undef);
print Dumper($utf8So);
XMLout($utf8So, OutputFile => $cp932out,
AttrIndent => 1, KeepRoot => 1,
NumericEscape => 1,
XMLDecl => "<?xml version='1.0' encoding='x-sjis-cp932'?>");
close $utf8in;
close $cp932out;
open my $cp932in, "<:encoding(cp932)", "cp932out.xml" or die "XML In
$outfile: $!";
my $cp932So = XMLin($cp932in, ForceArray => ['Line_Items'],
SuppressEmpty => undef);
print Dumper($cp932So);
Without the NumericEscape in the XMLout I get the following error when
writing the cp932 encoded data.
not well-formed (invalid token) at line 75, column 41, byte 3001 at
/opt/perl/lib/site_perl/5.8.0/PA-RISC1.1-thread-multi/XML/Parser.pm line 185
My first attempt was to just use IO layers.
open my $utf8in, "<:encoding(utf8)", $file or die "In $file: $!";
open my $cp932out, ">:encoding(cp932)", $outfile or die "Out $outfile: $!";
my $fline = <$utf8in>;
print $cp932out qq~<?xml version='1.0' encoding='x-sjis-cp932'?>~;
while (<$utf8in>) { print $cp932out $_; }
open my $cp932in, "<:encoding(cp932)", "cp932out.xml" or die "XML In
$outfile: $!";
my $cp932So = XMLin($cp932in, ForceArray => ['Line_Items'],
SuppressEmpty => undef);
print Dumper($cp932So);
This results in:
not well-formed (invalid token) at line 37, column 35, byte 886 at
/opt/perl/lib/site_perl/5.8.0/PA-RISC1.1-thread-multi/XML/Parser.pm line 185
Cheers
Dennis
------------------------------
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 9097
***************************************