[30733] in Perl-Users-Digest
Perl-Users Digest, Issue: 1978 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 12 11:09:46 2008
Date: Wed, 12 Nov 2008 08:09:11 -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 Wed, 12 Nov 2008 Volume: 11 Number: 1978
Today's topics:
Net::SSH::W32Perl->cmd() hangs for whole night <lovecreatesbeauty@gmail.com>
new CPAN modules on Wed Nov 12 2008 (Randal Schwartz)
Removing Comma Within Digits <yancheng.cheok@gmail.com>
Re: Removing Comma Within Digits <smallpond@juno.com>
Re: Removing Comma Within Digits <cartercc@gmail.com>
Re: Removing Comma Within Digits <jurgenex@hotmail.com>
Re: Removing Comma Within Digits <wahab@chemie.uni-halle.de>
Re: Removing Comma Within Digits <yancheng.cheok@gmail.com>
Re: SUBSTR() with replacement or lvalue performance iss <nospam-abuse@ilyaz.org>
Re: SUBSTR() with replacement or lvalue performance iss <nospam-abuse@ilyaz.org>
Re: SUBSTR() with replacement or lvalue performance iss sln@netherlands.com
Re: SUBSTR() with replacement or lvalue performance iss <nospam-abuse@ilyaz.org>
Re: The end of dynamic scope <xueweizhong@gmail.com>
Re: Why does the following statement work ? <toralf.foerster@gmx.de>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 11 Nov 2008 23:39:18 -0800 (PST)
From: "lovecreatesbeauty@gmail.c0m" <lovecreatesbeauty@gmail.com>
Subject: Net::SSH::W32Perl->cmd() hangs for whole night
Message-Id: <d19da4fb-62bf-4c4d-9c80-c318dd3fb2ed@p35g2000prm.googlegroups.com>
I code ssh and telnet in script with Net::Telnet and Net::SSH::Perl.
It runs on Linux, but the ssh function of my script fails on Windows.
I then switch to Net::SSH::W32Perl and this change works on Linux
still. It issues `unimplemented getpwuid function error' on Windows. I
comment the getpwuid call in file `./Perl/site/lib/Net/SSH/Perl/
SSH2.pm' on Windows:
#my $home = $ENV{HOME} || (getpwuid($>))[7];
my $home = $ENV{HOME};
And set up an environment variable before run my script on Windows:
$ set home=%HOMEPATH%
$ perl rcmdw32.pl ssh "id" 192.168.50.50 root uit ""
[ hangs for whole night ]
$
My script hangs at Line 78, the Net::SSH::Perl->cmd() call and shows
no errors.
I manually interrupt it and see different errors accompanied with
`perl.exe application error' every time.
$ perl rcmdw32.pl ssh pwd 192.168.50.50 snmpuser uit ""
Can't coerce UNKNOWN to string in keys at C:/Perl/site/lib/Net/SSH/
Perl/Channel.
pm line 140.
Can't coerce UNKNOWN to string in method_named at C:/Perl/site/lib/
Net/SSH/Perl/
SSH2.pm line 316.
$ perl rcmdw32.pl ssh pwd 192.168.50.50 snmpuser uit ""
Can't coerce UNKNOWN to string in sassign at C:/Perl/lib/IO/Select.pm
line 78.
Use of freed value in iteration at C:/Perl/site/lib/Net/SSH/Perl/
Channel.pm line
140.
$ perl rcmdw32.pl ssh pwd 192.168.50.50 snmpuser uit ""
Terminating on signal SIG e
in an interactive session (see the docs for I<Net::SSH::Perl>),
and if so will issue a prompt, asking you to enter your password.
If the session is not interactive (if it's in batch mode), we
send a blank password to comply with the protocol, but `!@# INT(2)
$ perl rcmdw32.pl ssh pwd 192.168.50.50 snmpuser uit ""
Can't coerce UNKNOWN to string in shift at C:/Perl/site/lib/Net/SSH/
Perl/Packet.
pm line 154.
Attempt to free unreferenced scalar: SV 0x2458334, Perl interpreter:
0x276014 at
C:/Perl/site/lib/Net/SSH/Perl/Channel.pm line 139.
$
=====================================
| perl.exe - Application Error |
+-----------------------------------+
| "0x2809b0fb" instruction refers to|
| unwritable memory at "0x00000004" |
| |
| Press OK to exit, CANCEL to debug.|
| |
| [OK] [CANCEL] |
=====================================
(translation from dialog on Windows
of Chinese version )
Another problem is that I can install Net::SSH::W32Perl with CPAN
shell:
cpan> install Net::SSH::W32Perl
Net::SSH::W32Perl is up to date (0.05).
cpan>
But can't find and install this module through ActivePerl's ppm:
$ ppm install Net::SSH::W32Perl
Downloading ActiveState Package Repository packlist...not modified
Downloading ppm4.activestate.com packlist...not modified
No missing packages to install
$
Is this the cause of the problem? Can you please tell me how to find
tha install Net::SSH::W32Perl with ppm and any errors in my script.
Thank you for your time.
################################################################################
# Filename : rcmdw32.pl
# Synopsis : rcmdw32.pl <prot> <cmd> <host> <user> <pwd> <altpw>
# Author : lovecreatesbeauty@gmail.c0m
# Date : May 30, 2008
################################################################################
#!/usr/bin/perl
#use warnings;
use strict;
use Net::Telnet();
use Net::SSH::W32Perl();
sub rcmd_usage;
sub rcmd;
exit rcmd(@ARGV);
################################################################################
# Function : rcmd <prot> <cmd> <host> <user> <pwd> <altpw>
# Description : Execute command on remote host. root privilege may be
required
# on some commands. This script is intended to automatically
# telnet to remote host or ssh to remote host in which neither
# /etc/hosts.equiv nor ~/.rhosts files may be available.
# Arguments : prot - telnet or ssh protocol to connect to host,
# cmd - command is to run on host,
# host - ip or name of host,
# user - user account to log on host,
# pwd - user's password,
# altpw - an alternative roots password on host if in need.
# Return : return 0 on success, otherwise non-zero.
################################################################################
sub rcmd
{
my ($prot, $cmd, $host, $user, $pwd, $altpw) = @_;
my ($narg, $npwd, $naltpw) = (scalar(@ARGV), length($pwd),
length($altpw));
my ($lg_prom, $pw_prom, $tmout) = ('/login[: ]*$/i',
'/password[: ]*$/i', 100);
my ($cnn, @aout);
if ($narg < 4 || $narg > 6){
rcmd_usage;
return 1;
}
# telnet with non-root, roots password required to execute other
command
# on remote host; or login directly with root on ssh connection.
if ($prot =~ /[Tt][Ee][Ll][Nn][Ee][Tt]/){
$cnn = new Net::Telnet(Timeout => $tmout);
$cnn->timeout($tmout);
$cnn->open($host);
$cnn->waitfor($lg_prom);
$cnn->print($user);
# The null string "" provided as password argument indicates no
# password is required from the user to login. don't check the
# password then.
if ($npwd != 0){
$cnn->waitfor($pw_prom);
$cnn->print($pwd);
}
$cnn->waitfor($cnn->prompt);
if ($naltpw != 0){
$cnn->print("su -");
$cnn->waitfor($pw_prom);
$cnn->print($altpw);
$cnn->waitfor($cnn->prompt);
}
} elsif ($prot =~ /[Ss][Ss][Hh]/){
$cnn = Net::SSH::W32Perl->new($host);
$cnn->login($user, $pwd);
} else {
rcmd_usage;
return 1;
}
@aout = $cnn->cmd($cmd); #LINE 78
print "@aout";
return 0;
}
################################################################################
# Function : rcmd_usage
# Description : print the usage of rcmd function
################################################################################
sub rcmd_usage
{
my $s = "Usage: rcmdw32.pl <prot> <cmd> <host> <user> <pwd>
<altpw>";
print "$s\n";
}
------------------------------
Date: Wed, 12 Nov 2008 05:42:22 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Wed Nov 12 2008
Message-Id: <KA7H6M.L39@zorch.sf-bay.org>
The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN). You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.
AcePerl-1.92
http://search.cpan.org/~lds/AcePerl-1.92/
----
App-Hachero-0.051
http://search.cpan.org/~danjou/App-Hachero-0.051/
a plaggable log analyzing framework
----
Arff-Util-0.01
http://search.cpan.org/~ehsane/Arff-Util-0.01/
ARFF files processing utilities.
----
B-Hooks-OP-Check-0.15
http://search.cpan.org/~flora/B-Hooks-OP-Check-0.15/
Wrap OP check callbacks
----
B-Hooks-OP-PPAddr-0.01
http://search.cpan.org/~flora/B-Hooks-OP-PPAddr-0.01/
Hook into opcode execution
----
B-Hooks-OP-PPAddr-0.02
http://search.cpan.org/~flora/B-Hooks-OP-PPAddr-0.02/
Hook into opcode execution
----
Catalyst-Action-Serialize-SimpleExcel-0.01_01
http://search.cpan.org/~rkitover/Catalyst-Action-Serialize-SimpleExcel-0.01_01/
Serialize tables to Excel files
----
Catalyst-Plugin-ConfigComponents-0.1.49
http://search.cpan.org/~pjfl/Catalyst-Plugin-ConfigComponents-0.1.49/
Creates components from config entries
----
Catalyst-Plugin-InflateMore-0.1.34
http://search.cpan.org/~pjfl/Catalyst-Plugin-InflateMore-0.1.34/
Inflates symbols in application config
----
Class-Accessor-Fast-XS-0.02
http://search.cpan.org/~ruz/Class-Accessor-Fast-XS-0.02/
XS replacement for Class::Accessor::Fast
----
Class-OWL-0.0.4
http://search.cpan.org/~leifj/Class-OWL-0.0.4/
[One line description of module's purpose here]
----
Config-Augeas-0.303
http://search.cpan.org/~ddumont/Config-Augeas-0.303/
Edit configuration files through Augeas C library
----
Coro-4.901
http://search.cpan.org/~mlehmann/Coro-4.901/
coroutine process abstraction
----
Coro-4.911
http://search.cpan.org/~mlehmann/Coro-4.911/
coroutine process abstraction
----
DBIx-Class-AsFdat-0.03
http://search.cpan.org/~nekokak/DBIx-Class-AsFdat-0.03/
like CDBI::Plugin::AsFdat.
----
DBIx-Class-IntrospectableM2M-0.001001
http://search.cpan.org/~groditi/DBIx-Class-IntrospectableM2M-0.001001/
Introspect many-to-many shortcuts
----
DBIx-Class-Schema-Loader-0.04999_06
http://search.cpan.org/~ilmari/DBIx-Class-Schema-Loader-0.04999_06/
Dynamic definition of a DBIx::Class::Schema
----
DBIx-Class-Stash-0.06
http://search.cpan.org/~nekokak/DBIx-Class-Stash-0.06/
stash for DBIC
----
Data-UUID-1.200_02
http://search.cpan.org/~rjbs/Data-UUID-1.200_02/
Perl extension for generating Globally/Universally Unique Identifiers (GUIDs/UUIDs).
----
Devel-CheckOS-1.50
http://search.cpan.org/~dcantrell/Devel-CheckOS-1.50/
check what OS we're running on
----
File-SambaMSNRL-0.02
http://search.cpan.org/~raf/File-SambaMSNRL-0.02/
----
Geo-Coder-Cache-0.02
http://search.cpan.org/~leeym/Geo-Coder-Cache-0.02/
Add cache for Geo::Coder::*
----
Geo-Coder-Cache-0.03
http://search.cpan.org/~leeym/Geo-Coder-Cache-0.03/
Add cache for Geo::Coder::*
----
Language-Befunge-4.06
http://search.cpan.org/~jquelin/Language-Befunge-4.06/
a generic funge interpreter
----
Lingua-Jspell-1.56
http://search.cpan.org/~ambs/Lingua-Jspell-1.56/
Perl interface to the Jspell morphological analyser.
----
Log-Dispatch-2.22
http://search.cpan.org/~drolsky/Log-Dispatch-2.22/
Dispatches messages to one or more outputs
----
MyCPAN-Indexer-1.17_08
http://search.cpan.org/~bdfoy/MyCPAN-Indexer-1.17_08/
Index a Perl distribution
----
Net-BitTorrent-0.027_009
http://search.cpan.org/~sanko/Net-BitTorrent-0.027_009/
BitTorrent peer-to-peer protocol class
----
Net-DNSBL-Monitor-0.08
http://search.cpan.org/~miker/Net-DNSBL-Monitor-0.08/
Monitor DNSBL response
----
Net-DNSBL-Statistics-0.10
http://search.cpan.org/~miker/Net-DNSBL-Statistics-0.10/
gather DNSBL Statistics
----
Net-SFTP-Foreign-1.45_08
http://search.cpan.org/~salva/Net-SFTP-Foreign-1.45_08/
SSH File Transfer Protocol client
----
Nginx-Simple-0.01
http://search.cpan.org/~mjflick/Nginx-Simple-0.01/
Easy to use interface for "--with-http_perl_module"
----
POE-Component-SmokeBox-Dists-0.08
http://search.cpan.org/~bingos/POE-Component-SmokeBox-Dists-0.08/
Search for CPAN distributions by cpanid or distribution name
----
Params-Util-0.35
http://search.cpan.org/~adamk/Params-Util-0.35/
Simple, compact and correct param-checking functions
----
Perl-Dist-1.10
http://search.cpan.org/~adamk/Perl-Dist-1.10/
Perl Distribution Creation Toolkit
----
Provision-Unix-0.30
http://search.cpan.org/~msimerson/Provision-Unix-0.30/
provision accounts on unix systems
----
Rose-DBx-Object-Cached-CHI-0.10
http://search.cpan.org/~kmcgrath/Rose-DBx-Object-Cached-CHI-0.10/
Rose::DB::Object Cache using the CHI interface
----
Rose-DBx-Object-Cached-CHI-0.11
http://search.cpan.org/~kmcgrath/Rose-DBx-Object-Cached-CHI-0.11/
Rose::DB::Object Cache using the CHI interface
----
Rose-DBx-Object-Cached-CHI-0.12
http://search.cpan.org/~kmcgrath/Rose-DBx-Object-Cached-CHI-0.12/
Rose::DB::Object Cache using the CHI interface
----
Runops-Trace-0.13
http://search.cpan.org/~jjore/Runops-Trace-0.13/
Trace your program's execution
----
SNMP-Extension-PassPersist-0.02
http://search.cpan.org/~saper/SNMP-Extension-PassPersist-0.02/
Generic pass/pass_persist extension framework for Net-SNMP
----
Shipwright-1.15
http://search.cpan.org/~sunnavy/Shipwright-1.15/
Best Practical Builder
----
Slay-Makefile-0.12
http://search.cpan.org/~nodine/Slay-Makefile-0.12/
Wrapper to Slay::Maker that reads the rules from a file
----
Storable-AMF-0.14
http://search.cpan.org/~grian/Storable-AMF-0.14/
Perl extension for serialize/deserialize AMF0/AMF3 data
----
Sub-Prototype-0.02
http://search.cpan.org/~flora/Sub-Prototype-0.02/
Set a subs prototype
----
Time-y2038-20081111
http://search.cpan.org/~mschwern/Time-y2038-20081111/
Versions of Perl's time functions which work beyond 2038
----
VUser-Google-Apps-0.2.0
http://search.cpan.org/~rsmith/VUser-Google-Apps-0.2.0/
VUser extension for managing Google Apps for your domain
----
VUser-Google-ProvisioningAPI-0.22
http://search.cpan.org/~rsmith/VUser-Google-ProvisioningAPI-0.22/
----
WWW-MeGa-0.09_3
http://search.cpan.org/~fish/WWW-MeGa-0.09_3/
A MediaGallery
----
WWW-Search-Ebay-3.002
http://search.cpan.org/~mthurn/WWW-Search-Ebay-3.002/
backend for searching www.ebay.com
----
WWW-Yahoo-InboundLinks-0.04
http://search.cpan.org/~apla/WWW-Yahoo-InboundLinks-0.04/
----
WWW-Yahoo-InboundLinks-0.05
http://search.cpan.org/~apla/WWW-Yahoo-InboundLinks-0.05/
Tracking Inbound Links in Yahoo Site Explorer API
----
WWW-Yandex-TIC-0.05
http://search.cpan.org/~apla/WWW-Yandex-TIC-0.05/
Query Yandex Thematic Index of Citing (TIC) for domain
----
WebService-Google-Language-0.05
http://search.cpan.org/~hma/WebService-Google-Language-0.05/
Perl interface to the Google AJAX Language API
----
XML-DTD-0.08
http://search.cpan.org/~wohl/XML-DTD-0.08/
Perl module for parsing XML DTDs
----
XML-LibXML-1.69
http://search.cpan.org/~pajas/XML-LibXML-1.69/
Perl Binding for libxml2
----
Xacobeo-0.02_01
http://search.cpan.org/~potyl/Xacobeo-0.02_01/
XPath (XML Path Language) visualizer.
----
signatures-0.02
http://search.cpan.org/~flora/signatures-0.02/
subroutine signatures with no source filter
If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.
This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
http://www.stonehenge.com/merlyn/LinuxMag/col82.html
print "Just another Perl hacker," # the original
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
------------------------------
Date: Wed, 12 Nov 2008 05:30:23 -0800 (PST)
From: yccheok <yancheng.cheok@gmail.com>
Subject: Removing Comma Within Digits
Message-Id: <2249b151-10ce-442d-83c6-00f373c6164f@a26g2000prf.googlegroups.com>
Hi,
I try to change the following source text
"A",1,234,567,890,"A",123,456
"A",1,234,567,"A",123,456
"A",1,234,"A",123,456
"A",3,"A",123,456
i wish to change to
"A",1234567890,"A",123,456
"A",1234567,"A",123,456
"A",1234,"A",123,456
"A",3,"A",123,456
By using the following regular expression :-
",(\d{1,3})(,(\d{3}))+,"
and the replacement
",$1$3,"
Here is the result I obtain :-
"A",1890,"A"
"A",1567,"A"
"A",1234,"A"
"A",3,"A"
It seem that, I wish to have one or more $3. How can I specific that
in my code?
Thanks!
------------------------------
Date: Wed, 12 Nov 2008 05:43:37 -0800 (PST)
From: smallpond <smallpond@juno.com>
Subject: Re: Removing Comma Within Digits
Message-Id: <781b696c-9d9c-43bf-a2bc-ee5dde050aa6@g17g2000prg.googlegroups.com>
On Nov 12, 8:30 am, yccheok <yancheng.ch...@gmail.com> wrote:
> Hi,
>
> I try to change the following source text
>
> "A",1,234,567,890,"A",123,456
> "A",1,234,567,"A",123,456
> "A",1,234,"A",123,456
> "A",3,"A",123,456
>
> i wish to change to
>
> "A",1234567890,"A",123,456
> "A",1234567,"A",123,456
> "A",1234,"A",123,456
> "A",3,"A",123,456
>
> By using the following regular expression :-
>
> ",(\d{1,3})(,(\d{3}))+,"
>
> and the replacement
>
> ",$1$3,"
>
> Here is the result I obtain :-
>
> "A",1890,"A"
> "A",1567,"A"
> "A",1234,"A"
> "A",3,"A"
>
> It seem that, I wish to have one or more $3. How can I specific that
> in my code?
>
> Thanks!
Your subject says you want to remove commas within digits
but your example output still has commas within digits.
Removing commas within digits is trivial:
s/(\d),(\d)/$1$2/g;
Guessing what you mean by your question can't be done in
a regex.
------------------------------
Date: Wed, 12 Nov 2008 06:12:20 -0800 (PST)
From: cartercc <cartercc@gmail.com>
Subject: Re: Removing Comma Within Digits
Message-Id: <a8692ae7-057d-450b-a9fa-14dbe2994240@l33g2000pri.googlegroups.com>
On Nov 12, 8:30=A0am, yccheok <yancheng.ch...@gmail.com> wrote:
> Hi,
>
> I try to change the following source text
>
> "A",1,234,567,890,"A",123,456
> "A",1,234,567,"A",123,456
> "A",1,234,"A",123,456
> "A",3,"A",123,456
while (<DATA>)
{
@line =3D split/"A",/;
($line[1] =3D $line[1]) =3D~ s/,//g;
foreach $el (@line) {$el =3D '"A",' . $el; }
shift @line;
$line =3D join ',', @line;
print $line;A
}
__DATA__
"A",1,234,567,890,"A",123,456
"A",1,234,567,"A",123,456
"A",1,234,"A",123,456
"A",3,"A",123,456
------------------------------
Date: Wed, 12 Nov 2008 06:26:23 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Removing Comma Within Digits
Message-Id: <r9olh4hvetjgk6tu8kctn08k1eubda4ok0@4ax.com>
yccheok <yancheng.cheok@gmail.com> wrote:
>Hi,
>
>I try to change the following source text
>
>"A",1,234,567,890,"A",123,456
>"A",1,234,567,"A",123,456
>"A",1,234,"A",123,456
>"A",3,"A",123,456
>
>i wish to change to
>
>"A",1234567890,"A",123,456
>"A",1234567,"A",123,456
>"A",1234,"A",123,456
>"A",3,"A",123,456
First idea
s/(\d),(\d)/$1$2/g;
until I noticed at the last moment that you DON"T want to remove the
commas in the first numerical sequence only.
use warnings; use strict;
while (<DATA>){
if (/([\d,]+)/) {
my $t = $1; $t =~ tr/,//d;
substr($_, 4, length($1)-2) = $t;
}
print $_;
}
__DATA__
"A",1,234,567,890,"A",123,456
"A",1,234,567,"A",123,456
"A",1,234,"A",123,456
"A",3,"A",123,456
jue
------------------------------
Date: Wed, 12 Nov 2008 15:44:17 +0100
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: Removing Comma Within Digits
Message-Id: <gfeq3v$2k3i$1@nserver.hrz.tu-freiberg.de>
yccheok wrote:
> Hi,
>
> I try to change the following source text
>
> "A",1,234,567,890,"A",123,456
> "A",1,234,567,"A",123,456
> "A",1,234,"A",123,456
> "A",3,"A",123,456
>
> i wish to change to
>
> "A",1234567890,"A",123,456
> "A",1234567,"A",123,456
> "A",1234,"A",123,456
> "A",3,"A",123,456
>
> It seem that, I wish to have one or more $3. How can I specific that
> in my code?
You have to extract/find the sequence
in question first, then delete the
commas there ...
...
my $source_text = '
"A",1,234,567,890,"A",123,456
"A",1,234,567,"A",123,456
"A",1,234,"A",123,456
"A",3,"A",123,456
';
sub nocomma { (my $s=shift) =~ y/,//d; $s }
(my $mod_text = $source_text) =~ s/(?<=",)([^"]+)(?=,")/nocomma($1)/mge;
...
Regards
M.
------------------------------
Date: Wed, 12 Nov 2008 07:29:16 -0800 (PST)
From: yccheok <yancheng.cheok@gmail.com>
Subject: Re: Removing Comma Within Digits
Message-Id: <f275dc90-fd08-4265-a4b1-80eeaf75ed9c@40g2000prx.googlegroups.com>
I should rephrase the topic,
1) Removing comma within a digit number, where that particular digit
must in the middle of two string.
"A",1,234,567,890,"A",123,456
to
"A",1,234,567,890,"A",123,456
the comma within the last 123 and 456 are just delimiter within a csv
file. There is a bug in legacy data, where they located comma in
digits, and place the digits in csv file.
sub nocomma { (my $s=3Dshift) =3D~ y/,//d; $s }
(my $mod_text =3D $source_text) =3D~ s/(?<=3D",)([^"]+)(?=3D,")/nocomma($1)=
/
mge;
seems a nice solution. but any way i may eliminate two pass pattern
matching?
On Nov 12, 10:44=A0pm, Mirco Wahab <wa...@chemie.uni-halle.de> wrote:
> yccheok wrote:
> > Hi,
>
> > I try to change the following source text
>
> > "A",1,234,567,890,"A",123,456
> > "A",1,234,567,"A",123,456
> > "A",1,234,"A",123,456
> > "A",3,"A",123,456
>
> > i wish to change to
>
> > "A",1234567890,"A",123,456
> > "A",1234567,"A",123,456
> > "A",1234,"A",123,456
> > "A",3,"A",123,456
>
> > It seem that, I wish to have one or more $3. How can I specific that
> > in my code?
>
> You have to extract/find the sequence
> in question first, then delete the
> commas there ...
>
> ...
>
> my $source_text =3D '
> "A",1,234,567,890,"A",123,456
> "A",1,234,567,"A",123,456
> "A",1,234,"A",123,456
> "A",3,"A",123,456
> ';
>
> sub nocomma { (my $s=3Dshift) =3D~ y/,//d; $s }
>
> (my $mod_text =3D $source_text) =3D~ s/(?<=3D",)([^"]+)(?=3D,")/nocomma($=
1)/mge;
>
> ...
>
> Regards
>
> M.
------------------------------
Date: Wed, 12 Nov 2008 03:18:41 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: SUBSTR() with replacement or lvalue performance issues
Message-Id: <gfdhuh$1scq$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
<xhoster@gmail.com>], who wrote in article <20081111165556.884$HL@newsreader.com>:
> > > >> Simple experiments show that it is still buggy with 5.8.8: code
> > > >> below returns
> >
> > > >> change_nth 7, 'lazy', map{ substr $bigScalar, $_->[0], $_->[1] }
> > > ^
> > > \
> > Nope.
>
> It will work provided you make the obvious change to change_nth to do the
> dereference.
No. It would not work this way, and it would not demonstrate the bug either...
[There are many ways to work-around the bug, of course. For
example, use C instead of Perl... ;-/]
Yours,
Ilya
------------------------------
Date: Wed, 12 Nov 2008 03:25:10 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: SUBSTR() with replacement or lvalue performance issues
Message-Id: <gfdiam$1si0$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
<xhoster@gmail.com>], who wrote in article <20081111175547.178$zG@newsreader.com>:
> Also, if you assign to the lval with a string of a different length,
> the lval still remembers it's length to be the originally created one, not
> the length of the string just assigned to it. So you can assign and
> then immediately read and get a different thing than what you just
> assigned. But I don't know that the alternative would be any less odd.
Let me guess: the alternative would be a sane behaviour?
perl -wle "sub edit($) {$_[0] = $_ for qw(123 456 789)}
$x = q(abc); edit substr $x, 1, 1; print $x"
a7895623c
[BTW, thanks for your explanation; I did not know about this bug...]
Yours,
Ilya
------------------------------
Date: Wed, 12 Nov 2008 03:33:46 GMT
From: sln@netherlands.com
Subject: Re: SUBSTR() with replacement or lvalue performance issues
Message-Id: <b4hkh4pd99t9mgv690h2tdd5r8hg51qt95@4ax.com>
On 11 Nov 2008 22:55:11 GMT, xhoster@gmail.com wrote:
>sln@netherlands.com wrote:
>> On Fri, 07 Nov 2008 11:41:21 +0100, Michele Dondi
>> <bik.mido@tiscalinet.it> wrote:
>>
>> >On Fri, 07 Nov 2008 02:17:58 GMT, sln@netherlands.com wrote:
>> >
>> >>Apart from like, copy from the start of a matched position, to a
>> >>file (as opposed to another buffer), then catenating the modification
>> >>to the file, then continue on with the next match, is the substr
>> >>(lvalue or replacement) a viable option?
>> >>
>> >>I have to consider performance on such large operations.
>> >
>> >ISTR that the lvaluedness of substr()'s return value, as long as the
>> >fact that you can EVEN take references of it and modify the string
>> >with a sort of action-at-distance was put there specifically for
>> >performance issues. At some point there were problems with
>> >substitutions having a lenght larger than the substituted IalsoIRC,
>> >but they should be solved in recent enough perls.
>> >
>> >See: <http://perlmonks.org/?node_id=498434>
>> >
>> >
>> >Michele
>>
>> 5.8.6 has problems:
>
>I think it is your expectations that have problems. But you haven't
>described what your expectations are, so it is hard to tell.
>
>The lvals remember the offset and length. If the main string gets
>rearranged, the lval doesn't try to change the offset and length in an
>attempt to trace that rearrangement. Can you imagine the morass if they
>did? Instead, it keeps the "window" the same and lets characters move
>around beneath it.
>
>Also, if you assign to the lval with a string of a different length,
>the lval still remembers it's length to be the originally created one, not
>the length of the string just assigned to it. So you can assign and
>then immediately read and get a different thing than what you just
>assigned. But I don't know that the alternative would be any less odd.
>
>Xho
No I didn't have any expectations other than to try out the code from
that perlmonks link. Hey I'm happy Perl can even take references mid-string,
even though it was to an LVALUE.
It's was new to me. Sort of like taking the address of element
N in a character array ala C:
char A[] = "asfasjsadflfsdlk";
char* p = &A[5];
strncpy( p, "000", 2);
// now A is "asfas00adflfsdlk"
Dereferencing returns the string, thats good enough.
I don't pretend to understand how substr() does its LVALUE sub. However it
is, I'm sure its for good reason. Actually my original intention was to
NOT grow/shrink gigantic strings.
sln
----------------------
use strict;
use warnings;
my $str = "asdfasdf";
my $lvref = \substr($str, 0, 3);
$$lvref = "zzzzz";
print ref($lvref)." = $$lvref, length = ".length($$lvref)."\n";
print "str = $str, length = ".length($str)."\n\n";
$str = "asdfasdf";
$lvref = \(substr($str, 0, 3) = "12345");
print ref($lvref)." = $$lvref, length = ".length($$lvref)."\n";
print "str = $str, length = ".length($str)."\n\n";
$str = "asdfasdf";
substr($str, 0, 3) = "zzzzz";
print "str = $str, length = ".length($str)."\n";
substr($str, 0, 3) = "aaaaa";
print "str = $str, length = ".length($str)."\n";
substr($str, 0, 3) = "";
print "str = $str, length = ".length($str)."\n";
substr($str, 0, 3) = "aaaaa";
print "str = $str, length = ".length($str)."\n";
__END__
LVALUE = zzz, length = 3
str = zzzzzfasdf, length = 10
LVALUE = 123, length = 3
str = 12345fasdf, length = 10
str = zzzzzfasdf, length = 10
str = aaaaazzfasdf, length = 12
str = aazzfasdf, length = 9
str = aaaaazfasdf, length = 11
------------------------------
Date: Wed, 12 Nov 2008 03:38:36 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: SUBSTR() with replacement or lvalue performance issues
Message-Id: <gfdj3s$1so4$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
<xhoster@gmail.com>], who wrote in article <20081111172915.373$UB@newsreader.com>:
> > What for? Why this should not work:
> >
> > perl -wle "@a=(10..15); sub z2{$_[2]=0}; z2 map $_, @a; print for @a"
> It does work. It just doesn't do what you want :)
Well, in my book it means that it does not work...
> I think the current behavior is reasonable,
for what?
> The current behavior is consistent with what other things that
> conceptually *could* keep aliasing, but don't. Like push.
It is obvious that push, and assignements, should by default do copying.
(I think "Paradigm clash" of `perldoc overload' may be relevant here.)
> Or subroutines.
Subroutines doing an extraneous copy is an unfortunate oversight by
Larry. When I discovered this, it was too late to fix; thus the need
for `lvalue' hack to disable this... Of course, lvalueness should
have been the default...
> On the other hand, reverse does preserve aliasing.
>
> a do block also preserves aliasing, but for some odd reason I'm not
> allowed to assign to one directly.
Easily:
perl -wle "sub stomp($) {$_[0] = 123} $x = 'abc'; stomp do {$x}; print $x"
123
Anyway, do not you think that map() is just a sequence of do{}-blocks?
Thanks for your investigations,
Ilya
------------------------------
Date: Wed, 12 Nov 2008 07:49:38 -0800 (PST)
From: Todd <xueweizhong@gmail.com>
Subject: Re: The end of dynamic scope
Message-Id: <1bb1fb8a-4859-46f8-a5e6-bc5b86ca5d7d@k1g2000prb.googlegroups.com>
xhos...@gmail.com wrote:
> the block scope (or the scope is pulled up to meet them). I vaguely recall
> something from the guts that there is some kind of pseudo-scope which
> encompasses both the conditional and the block for those constructs which
> have both, and that the pseudo-scope applies only lexically not
> dynamically.
Let's check more cases:
#! /bin/perl
$a = 1;
for (;local $a=3;) { last; }
print $a;
__END__
1
#! /bin/perl
$a = 1;
for (local $a=3;;) { last; }
print $a;
__END__
3
#! /bin/perl
$a = 1;
while (local $a=3) { last; }
print $a;
__END__
1
So it's a total mess to explain it decently, isn't it? :)
-Todd
------------------------------
Date: Wed, 12 Nov 2008 08:20:47 +0000 (UTC)
From: toralf <toralf.foerster@gmx.de>
Subject: Re: Why does the following statement work ?
Message-Id: <gfe3kv$l38$1@registered.motzarella.org>
xhoster@gmail.com wrote:
> I tend not to use this trick, and would usually write it more like:
>
> perl -wne ' $h{$_}++; END {foreach $s(keys %h){print "$h{$s}\t$s"}}'
>
>
> Xho
>
Thx for both answers - B::Deparse I should really give a try - and the
"END" statement of @xhoster looks like what I'll use in future to
clarify such things.
--
MfG/Sincerely
Toralf Förster
pgp finger print: 7B1A 07F4 EC82 0F90 D4C2 8936 872A E508 7DB6 9DA3
------------------------------
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 V11 Issue 1978
***************************************