[30743] in Perl-Users-Digest
Perl-Users Digest, Issue: 1988 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 17 18:09:49 2008
Date: Mon, 17 Nov 2008 15:09: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 Mon, 17 Nov 2008 Volume: 11 Number: 1988
Today's topics:
Re: atoi/atof <hjp-usenet2@hjp.at>
Re: atoi/atof <nospam-abuse@ilyaz.org>
CoOoL Bar <anubha9903@gmail.com>
Re: File operation and Concatenation sln@netherlands.com
How would I do the following? <DaLoveRhino@hotmail.com>
Re: How would I do the following? <peter@makholm.net>
Re: How would I do the following? <tadmc@seesig.invalid>
Re: How would I do the following? <jl_post@hotmail.com>
Re: Net::SSH::W32Perl->cmd() hangs for whole night <lovecreatesbeauty@gmail.com>
OpenOffice Spreadsheet <grehom@ntlworld.com>
Regular expressions: how to skip characters from a capt <ikke@hier.be>
Re: Regular expressions: how to skip characters from a xhoster@gmail.com
Re: Regular expressions: how to skip characters from a <smallpond@juno.com>
Re: Regular expressions: how to skip characters from a <ikke@hier.be>
Re: Regular expressions: how to skip characters from a <ikke@hier.be>
Re: Regular expressions: how to skip characters from a <jurgenex@hotmail.com>
Re: Regular expressions: how to skip characters from a xhoster@gmail.com
Re: Regular expressions: how to skip characters from a <smallpond@juno.com>
Re: sharing perl code between directories <adam.at.prisma@gmail.com>
Re: Subroutine on Mutation of Codons <fawaka@gmail.com>
Re: Subroutine on Mutation of Codons <someone@example.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 17 Nov 2008 17:14:28 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: atoi/atof
Message-Id: <slrngi3638.pv6.hjp-usenet2@hrunkner.hjp.at>
On 2008-11-16 21:06, sln@netherlands.com <sln@netherlands.com> wrote:
> On Sat, 15 Nov 2008 19:37:00 +0100, "Peter J. Holzer" <hjp-usenet2@hjp.at> wrote:
>>On 2008-11-14 04:41, Jürgen Exner <jurgenex@hotmail.com> wrote:
>>> debjyoti@gmail.com wrote:
>>>>I was messing around with a perl script and realized converting
>>>>strings to integers/floats is iffy on perl (compared to C).
>>>
>>> Really?
>>
>>Yes, really. The Perl routines for converting between strings and
>>numbers are buggy.
>>
>>> I haven't noticed.
>>
>>I guess most people haven't, or the bugs would be fixed already. These
>>bugs have been there for a very long time, but they show up only if you
>>get close to the 15 digits/53 bits of FP precision.
>>
>>I'm almost sure the OP's code is even buggier, though. String/number
>>conversions aren't trivial.
>>
>> hp
>
> ">>>strings to integers/floats is iffy on perl (compared to C). "
>
> Aren't trivial? So ANSI C++ hasn't got it right yet?
"ANSI C++" is a specification. It only defines what needs to be done,
not how to do it. You would have to look at specific implementations.
Anyway, C++ is irrelevant here, as perl is written in C, not C++.
> Perl had to bypass.
ANSI C has a strtod function for string -> floating point conversion.
I'm not sure if perl uses it (it's been some time since I looked at the
code, sorry), but it probably could and should use it, as I would expect
it to be correct on all major platforms. If perl doesn't use it, it is
probably for historical reasons. Easy to fix.
Unfortunately, there is no reverse function in C: sprintf generates a
fixed number of digits after the decimal point, which is either too
little or too much. So that's something perl has to do itself.
> Its the other way around, number to string isin't trivial.
Conversion to and from integers is trivial (typical exercise for first
semester students). Conversion to and from FP numbers isn't trivial in
either direction. The situation is only asymmetric because C already has
a nice function for conversion from strings to numbers (which shields
the C programmer from all the hairy stuff), but not for the
reverse.
hp
------------------------------
Date: Mon, 17 Nov 2008 19:40:20 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: atoi/atof
Message-Id: <gfshb4$cpm$1@agate.berkeley.edu>
[A complimentary Cc of this posting was NOT [per weedlist] sent to
Peter J. Holzer
<hjp-usenet2@hjp.at>], who wrote in article <slrngi3638.pv6.hjp-usenet2@hrunkner.hjp.at>:
> ANSI C has a strtod function for string -> floating point conversion.
> I'm not sure if perl uses it (it's been some time since I looked at the
> code, sorry), but it probably could and should use it, as I would expect
> it to be correct on all major platforms. If perl doesn't use it, it is
> probably for historical reasons. Easy to fix.
In fact, this particular misfortune is quite recent. Somebody did not
realize that the question is tricky, and inserted a wrong, homegrown,
implementation...
> Unfortunately, there is no reverse function in C: sprintf generates a
> fixed number of digits after the decimal point, which is either too
> little or too much. So that's something perl has to do itself.
Nope, Perl's semantic coincides (unfortunately!) with sprintf()'s
one. It may have its own implementation of sprintf(), but no more
than that...
The alternative semantic (emit as few digits as the string==>number
function requires to reproduce the same number) is computationally
intensive. When, in 90's, a replacement was discussed, it led to
significant slowdowns. However, nobody at the moment realized that
Perl was not caching N-->S conversion agressively enough, so it was
repeating the conversion again and again. When later I found/fixed
the caching problem, the benchmarks were not (AFAIK) redone..
The third problem is that one wants to minimize loads on
newsgroup/mailing-list "why numeric calculations are so weird in
Perl"; so the precision of N-->S is deliberately chosen so low, that
indications of weirdness of FP arithmetic are not manifested as often
as it would be with "precise" algorithms...
Hope this helps,
Ilya
------------------------------
Date: Mon, 17 Nov 2008 05:44:45 -0800 (PST)
From: Anubha Sarkar <anubha9903@gmail.com>
Subject: CoOoL Bar
Message-Id: <2771388d-a08a-472a-aafe-9826acff3488@v5g2000prm.googlegroups.com>
CoOoL Bar
80000+ emoticons, ecards, wallpapers, animations & more FREE stuff!
Plus CoOolBar's advanced Weather Forecast Instrument for your
desktop! ...
http://www.freedownload.coz.bz
------------------------------
Date: Mon, 17 Nov 2008 18:59:48 GMT
From: sln@netherlands.com
Subject: Re: File operation and Concatenation
Message-Id: <c863i456lhbhsigsg1rf63fffgia4eb17b@4ax.com>
On Sun, 16 Nov 2008 21:46:48 -0800 (PST), Gokul <gokul.bits@gmail.com> wrote:
>Hi all,
>
>I need to perform a concatenation with the contents of a file(s) after
>opening the file(s).
>I am pretty new to PERL and learning its potentials.
>
>The operation I need to perform is outlines as follows:
>
>File A has the following contents:[abc,def, ghi .... etc are strings
>listed one by one in the file]
>
>abc
>def
>ghi
>jkl
>mno
>
>File B has the following contents:[Test_1,Test_2 .... etc are strings
>listed one by one in the file]
>
>Test_1
>Test_2
>Test_3
>Test_4
>Test_5
>
>I want PERL to concatenate and generate strings for me as follows:[We
>can create a new file, write strings to it and save it]
>
>Test_1 abc def ghi jkl mno
>Test_2 abc def ghi jkl mno
>Test_3 abc def ghi jkl mno
>Test_4 abc def ghi jkl mno
>Test_5 abc def ghi jkl mno
>
>
>Please help me through this.
>
>Thanks
Why do you obfuscate rotating a 5x1 to a 1x5 per Test_# getting a 5x5
of duplicate Tests_?
Does it bother you that Test_1 through Test_5 are identical?
Whats the significance of 5?
Maybe you just want to rotate (pivot) an order 5 column.
The dup's are baffeling.
I guess you know how to read files, so catenate should be easy:
(untested)
while ( ($lineA=<$fhA>) && ($lineB=<$fhB>) )
{
chomp $lineA; chomp $lineB;
push @pA,$lineA; push @pB,$lineB;
$order++;
if ($order == 5)
{
while ( my $test = shift @pB ) {
print $fhC "$test @pA\n";
}
@pA = ();
$order = 0;
}
}
sln
------------------------------
Date: Mon, 17 Nov 2008 11:10:47 -0800 (PST)
From: DaLoverhino <DaLoveRhino@hotmail.com>
Subject: How would I do the following?
Message-Id: <7ffac492-47e6-4991-adaa-9e2152b34126@e38g2000prn.googlegroups.com>
I can do this in perl:
$#array
Which prints the index value of the last element in array.
Can I do this? :
$#(expression)
To print the index value of the last element of an expression that
evaluates to an array? Or something like it? I can't get it to work.
thanks.
------------------------------
Date: Mon, 17 Nov 2008 20:19:36 +0100
From: Peter Makholm <peter@makholm.net>
Subject: Re: How would I do the following?
Message-Id: <87vdum6tyv.fsf@vps1.hacking.dk>
DaLoverhino <DaLoveRhino@hotmail.com> writes:
> Can I do this? :
>
> $#(expression)
>
> To print the index value of the last element of an expression that
> evaluates to an array? Or something like it? I can't get it to work.
I have no idea why you would want to do that. But a common trick is to
make an anonymous array reference and dereference it
immediately. Works in you case too:
print $#{[ stat '.' ]}
//Makholm
------------------------------
Date: Mon, 17 Nov 2008 13:22:42 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: How would I do the following?
Message-Id: <slrngi3h42.sk5.tadmc@tadmc30.sbcglobal.net>
DaLoverhino <DaLoveRhino@hotmail.com> wrote:
> Subject: How would I do the following?
Please put the subject of your article in the Subject of your article.
> I can do this in perl:
>
> $#array
>
> Which prints the index value of the last element in array.
>
> Can I do this? :
>
> $#(expression)
>
> To print the index value of the last element of an expression that
> evaluates to an array?
No.
But you can get it to print the index value of the last element of
an expression that evaluates to a array reference.
See "Use Rule 1" in:
perldoc perlreftut
i.e. $#{ returns_array_ref() }
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Mon, 17 Nov 2008 11:28:28 -0800 (PST)
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: Re: How would I do the following?
Message-Id: <f7dbceb6-6bd0-4353-84a9-9e93ac4b5cdb@d36g2000prf.googlegroups.com>
On Nov 17, 12:10 pm, DaLoverhino <DaLoveRh...@hotmail.com> wrote:
>
> I can do this in perl:
>
> $#array
>
> Which prints the index value of the last element in array.
>
> Can I do this? :
>
> $#(expression)
>
> To print the index value of the last element of an expression that
> evaluates to an array? Or something like it? I can't get it to work.
If "expression" returns an array, you can do this to return the
number of elements in the array:
scalar(expression)
then all you'd have to do is subtract one to get the index of the last
element.
However, this only works if "expression" returns an array. If,
instead, it returns a list, "scalar(expression)" would return the last
element. (To find out why, you can type:
perldoc -q "difference between a list and an array"
at any DOS/Unix prompt.) Be careful about this distinction, because
lists and arrays are often treated interchangeably, but they do make a
difference here.
To get around this, you can use this to get the number of elements
of a list (it also works with arrays):
() = expression
So to get the last index of the array, you subtract 1 from it, like
this:
my $lastIndex = ( () = expression ) - 1;
Assigning an array/list to a list (even an empty one) always
returns the number of elements of the list/array on the RIGHT side of
the '=' operator. (This is slightly counter-intuitive; I would think
it would return the number of elements of the list on the LEFT side,
but it that were so then the above wouldn't work.)
I hope this helps.
-- Jean-Luc
------------------------------
Date: Mon, 17 Nov 2008 01:54:39 -0800 (PST)
From: "lovecreatesbeauty@gmail.c0m" <lovecreatesbeauty@gmail.com>
Subject: Re: Net::SSH::W32Perl->cmd() hangs for whole night
Message-Id: <27e2c2c1-c1a0-4b33-9e80-2b9a5f20b64f@40g2000prx.googlegroups.com>
On Nov 12, 3:39=A0pm, "lovecreatesbea...@gmail.c0m"
<lovecreatesbea...@gmail.com> wrote:
> 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 script hangs at Line 78, the Net::SSH::Perl->cmd() call and shows
> no errors.
>
I switch to Net::SSH2. The remote server support SSH v2 and this
version of my script works on both Linux and Windows. I will replace
all perl things with C code later.
$ perl rcmd.pl ssh id 192.168.50.50 snmpuser uit
uid=3D21(snmpuser) gid=3D21(snmpuser) groups=3D21(snmpuser)
$
$ cat rcmd.pl
###########################################################################=
#####
# Filename : rcmd.pl
# Synopsis : rcmd.pl <prot> <cmd> <host> <user> <pwd> <altpw>
# Author : lovecreatesbeauty@gmail.c0m
# Date : May 30, 2008
###########################################################################=
#####
#!/usr/bin/perl -w
#use warnings;
use strict;
use Net::Telnet();
use Net::SSH2;
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) =3D @_;
my ($narg, $npwd, $naltpw) =3D (scalar(@ARGV), length($pwd),
length($altpw));
my ($lg_prom, $pw_prom, $tmout) =3D ('/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 =3D~ /[Tt][Ee][Ll][Nn][Ee][Tt]/){
$cnn =3D new Net::Telnet(Timeout =3D> $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 !=3D 0){
$cnn->waitfor($pw_prom);
$cnn->print($pwd);
}
$cnn->waitfor($cnn->prompt);
if ($naltpw !=3D 0){
$cnn->print("su -");
$cnn->waitfor($pw_prom);
$cnn->print($altpw);
$cnn->waitfor($cnn->prompt);
}
@aout =3D $cnn->cmd($cmd);
print "@aout";
} elsif ($prot =3D~ /[Ss][Ss][Hh]/){
my $cnn =3D Net::SSH2->new();
my $fl =3D "/tmp/.$0.tmp";
$cnn->connect($host);
$cnn->auth_password($user, $pwd);
my $ch =3D $cnn->channel();
$ch->exec("$cmd> $fl");
my $sf =3D $cnn->sftp();
my $fh =3D $sf->open($fl);
print $_ while <$fh>;
} else {
rcmd_usage;
return 1;
}
return 0;
}
###########################################################################=
#####
# Function : rcmd_usage
# Description : print the usage of rcmd function
###########################################################################=
#####
sub rcmd_usage
{
my $s =3D "Usage: rcmd.pl <prot> <cmd> <host> <user> <pwd>
<altpw>";
print "$s\n";
}
$
------------------------------
Date: Mon, 17 Nov 2008 10:58:14 -0800 (PST)
From: Grehom <grehom@ntlworld.com>
Subject: OpenOffice Spreadsheet
Message-Id: <d7ec6752-44e9-4f65-afdd-857e374c41d7@k24g2000pri.googlegroups.com>
I'm just trying to read a column in a spreadsheet and create a new
value in a new column to right of the others.
I tried with the following, but it doesn't create the new column, any
hints please
use OpenOffice::OODoc;
my $doc = odfDocument(file => 'iwm.ods');
$row = 3;
while ( my $cli = $doc->cellValue(0, "D$row") ) {
my $username = get_customer_account( $dbh, $cli );
print "$cli => $username\n";
$doc->cellValue(0, "E$row", $username);
$row++;
}
$doc->save();
It's reading the spreadsheet fine, but it's not inserting the new
value into 'E' column
------------------------------
Date: Mon, 17 Nov 2008 21:29:00 GMT
From: Ikke <ikke@hier.be>
Subject: Regular expressions: how to skip characters from a capture
Message-Id: <Xns9B59E4F89B182ikkehierbe@69.16.176.253>
Hi everybody,
First of all, if this is not the right group to ask, I apologize. I could
not find a specific regex group, so I decided to turn to those who know
Perl.
I am trying to build a regex, which needs to capture data from a .csv
file in a very specific format.
The first part should be a filename - either enclosed in quotes, or not.
This is the part that is giving me problems.
I've created something like: ((filename)|quote(filename)quote) which
matches the text as I would like, but it doesn't capture the text as
expected.
If there are no quotes, the text is returned as group 1. If there are
quotes, group 2 returns the filename with the quotes. I'd like the quotes
to be removed from this group. I assumed that, if the first part of the
expression matches, the double braces would indicate that group 2 would
return the name as well, but this is not the case. Apparently ((regex))
equals (regex).
Does anybody know a solution for this problem?
Thank you very much,
Ikke
------------------------------
Date: 17 Nov 2008 21:58:50 GMT
From: xhoster@gmail.com
Subject: Re: Regular expressions: how to skip characters from a capture
Message-Id: <20081117165929.798$K8@newsreader.com>
Ikke <ikke@hier.be> wrote:
> Hi everybody,
>
> First of all, if this is not the right group to ask, I apologize. I could
> not find a specific regex group, so I decided to turn to those who know
> Perl.
>
> I am trying to build a regex, which needs to capture data from a .csv
> file in a very specific format.
Are you using Perl to do your regex? Or the regex feature in some other
language? The first is on topic here, but the second is not. We generally
won't know what semantics or quirks may be present in someone else's
implementation of regex.
>
> The first part should be a filename - either enclosed in quotes, or not.
> This is the part that is giving me problems.
>
> I've created something like: ((filename)|quote(filename)quote) which
> matches the text as I would like, but it doesn't capture the text as
> expected.
>
> If there are no quotes, the text is returned as group 1. If there are
> quotes, group 2 returns the filename with the quotes.
I can't reproduce that.
perl -le '$_=qq{"filename"}; /((filename)|"(filename)")/ or die;
print foreach ($1,$2,$3)'
"filename"
filename
I get quoted filename in group 1, nothing in group 2, and unquoted filename
in group 3.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Mon, 17 Nov 2008 14:04:35 -0800 (PST)
From: smallpond <smallpond@juno.com>
Subject: Re: Regular expressions: how to skip characters from a capture
Message-Id: <bbc40a0b-4c75-4ef4-902a-d793e465e379@u18g2000pro.googlegroups.com>
On Nov 17, 4:29 pm, Ikke <i...@hier.be> wrote:
> Hi everybody,
>
> First of all, if this is not the right group to ask, I apologize. I could
> not find a specific regex group, so I decided to turn to those who know
> Perl.
>
> I am trying to build a regex, which needs to capture data from a .csv
> file in a very specific format.
>
> The first part should be a filename - either enclosed in quotes, or not.
> This is the part that is giving me problems.
>
> I've created something like: ((filename)|quote(filename)quote) which
> matches the text as I would like, but it doesn't capture the text as
> expected.
>
> If there are no quotes, the text is returned as group 1. If there are
> quotes, group 2 returns the filename with the quotes. I'd like the quotes
> to be removed from this group. I assumed that, if the first part of the
> expression matches, the double braces would indicate that group 2 would
> return the name as well, but this is not the case. Apparently ((regex))
> equals (regex).
>
> Does anybody know a solution for this problem?
>
> Thank you very much,
>
> Ikke
/"*([^",]*)/
foo,baz => foo
"foo",baz => foo
------------------------------
Date: Mon, 17 Nov 2008 22:27:16 GMT
From: Ikke <ikke@hier.be>
Subject: Re: Regular expressions: how to skip characters from a capture
Message-Id: <Xns9B59EEDA3942Fikkehierbe@69.16.176.253>
xhoster@gmail.com wrote in news:20081117165929.798$K8@newsreader.com:
<snip>
> Are you using Perl to do your regex? Or the regex feature in some
> other language? The first is on topic here, but the second is not.
> We generally won't know what semantics or quirks may be present in
> someone else's implementation of regex.
That's mostly the reason I apologized for barging in here - I'm using
Delphi and I'm not that familiar with regular expressions.
As you pointed out, I've already noticed that regular expressions come in
various "dialects", for various languages...
<snip>
>> If there are no quotes, the text is returned as group 1. If there are
>> quotes, group 2 returns the filename with the quotes.
>
> I can't reproduce that.
> perl -le '$_=qq{"filename"}; /((filename)|"(filename)")/ or die;
> print foreach ($1,$2,$3)'
> "filename"
>
> filename
>
> I get quoted filename in group 1, nothing in group 2, and unquoted
> filename in group 3.
Something similar to what I'm getting, I'm afraid. I'd like to have a
regular expression which always returns filename, whether the original
line states filename or "filename", but not "filename or filename" .
Thanks anyway,
Ikke
------------------------------
Date: Mon, 17 Nov 2008 22:28:53 GMT
From: Ikke <ikke@hier.be>
Subject: Re: Regular expressions: how to skip characters from a capture
Message-Id: <Xns9B59EF200D2A0ikkehierbe@69.16.176.253>
smallpond <smallpond@juno.com> wrote in
news:bbc40a0b-4c75-4ef4-902a-d793e465e379@u18g2000pro.googlegroups.com:
<snip>
> /"*([^",]*)/
>
> foo,baz => foo
> "foo",baz => foo
This is similar to the expression I started out with - but this will also
match:
"foo,baz => foo
or
foo",baz => foo
both of which are not valid inputs for my scenario.
Thanks anyway,
Ikke
------------------------------
Date: Mon, 17 Nov 2008 14:45:39 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Regular expressions: how to skip characters from a capture
Message-Id: <6os3i4hptop1cdp15202s7bq2gu4c9402n@4ax.com>
Ikke <ikke@hier.be> wrote:
>I am trying to build a regex, which needs to capture data from a .csv
>file in a very specific format.
>
>The first part should be a filename - either enclosed in quotes, or not.
>This is the part that is giving me problems.
Why aren't you using a parser for parsing CSV? There are several module
on CPAN.
>I've created something like: ((filename)|quote(filename)quote) which
>matches the text as I would like, but it doesn't capture the text as
>expected.
So, let me paraphrase: sometime the data elements in your CSV are
enclosed in quotes. And you want them without quotes, no matter if they
are stored with or without quotes. Right?
>Does anybody know a solution for this problem?
REs are not powerful enough to match balanced items, please see "perldoc
-q balanced" for more details.
Just use a CSV parser module, it will take care of the de-quoting
automatically.
jue
------------------------------
Date: 17 Nov 2008 22:47:35 GMT
From: xhoster@gmail.com
Subject: Re: Regular expressions: how to skip characters from a capture
Message-Id: <20081117174814.398$7g@newsreader.com>
Ikke <ikke@hier.be> wrote:
> xhoster@gmail.com wrote in news:20081117165929.798$K8@newsreader.com:
> >> If there are no quotes, the text is returned as group 1. If there are
> >> quotes, group 2 returns the filename with the quotes.
> >
> > I can't reproduce that.
> > perl -le '$_=qq{"filename"}; /((filename)|"(filename)")/ or die;
> > print foreach ($1,$2,$3)'
> > "filename"
> >
> > filename
> >
> > I get quoted filename in group 1, nothing in group 2, and unquoted
> > filename in group 3.
>
> Something similar to what I'm getting, I'm afraid.
Perl numbers the captures in the order they open. Maybe Delphi does it
in the order they close.
> I'd like to have a
> regular expression which always returns filename, whether the original
> line states filename or "filename", but not "filename or filename" .
In Perl you could use look ahead and look behind, like this:
/(filename|(?<=")filename(?="))/
There is only one capture there; the other parentheses are non-capturing
ones used for look-ahead and behind syntax. But I doubt Delphi has
look-ahead and look-behind, or at least not the same as Perl's.
I usually don't like cramming too much logic into one regex, so I'd be more
likely to break it up like this:
if ( /filename|"filename"/ ) { #just validate, no capture
/"?(filename)"?/; ## capture valid data
#....
} else {
die "not valid"
};
The capture could match things with unbalanced quotes, except that is
protected from doing so by the prior regex.
But I don't know how this fits into Delphi.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Mon, 17 Nov 2008 15:07:30 -0800 (PST)
From: smallpond <smallpond@juno.com>
Subject: Re: Regular expressions: how to skip characters from a capture
Message-Id: <08dfb04f-fac0-49da-9256-1cde309dc208@x16g2000prn.googlegroups.com>
On Nov 17, 5:28 pm, Ikke <i...@hier.be> wrote:
> smallpond <smallp...@juno.com> wrote innews:bbc40a0b-4c75-4ef4-902a-d793e465e379@u18g2000pro.googlegroups.com:
>
> <snip>
>
> > /"*([^",]*)/
>
> > foo,baz => foo
> > "foo",baz => foo
>
> This is similar to the expression I started out with - but this will also
> match:
> "foo,baz => foo
> or
> foo",baz => foo
> both of which are not valid inputs for my scenario.
>
> Thanks anyway,
>
> Ikke
You are trying to do two different things with one
regex. You want to extract the filename and validate the input.
You need to explain what the correct output of the regex is in
the invalid cases.
------------------------------
Date: Mon, 17 Nov 2008 07:18:21 -0800 (PST)
From: "adam.at.prisma" <adam.at.prisma@gmail.com>
Subject: Re: sharing perl code between directories
Message-Id: <c9233506-9454-4294-9f10-fbf80c9110bf@e38g2000prn.googlegroups.com>
On Oct 31, 9:15=A0am, "adam.at.prisma" <adam.at.pri...@gmail.com> wrote:
> I have a directory tree in our code repository containing Perl code.
> AppOne and AppTwo both use some of the same functions and as the copy-
> paste method will get out of hand really soon, I want to create a
> "Common" directory that is visible to the other two (and likely more
> than 2 in the future).
>
> I've used O'Reillys excellent "Programming Perl" but I don't get how I
> make the code in the "Common" directory available to the other two?
> Btw, this is Windows and I am using "Strawberry Perl".
>
> +---admin
> |
> +---AppOne
> | =A0 =A0 =A0 AppOne.pl
> |
> +---AppTwo
> | =A0 =A0 =A0 AppTwoFileOne.pl
> | =A0 =A0 =A0 AppTwoFileTwo.pl
> |
> |
> \---Common
> =A0 =A0 =A0 =A0 CommonCode.pm
>
> BR,
> Adam
Hi,
I read through the documentation for "use lib" and that resolved the
issue. Thanks for pointing me in the right direction folks!
BR,
Adam
------------------------------
Date: 17 Nov 2008 21:16:29 GMT
From: Leon Timmermans <fawaka@gmail.com>
Subject: Re: Subroutine on Mutation of Codons
Message-Id: <4921df2d$0$194$e4fe514c@news.xs4all.nl>
On Sun, 16 Nov 2008 13:43:32 -0800, carriehecker wrote:
> I am trying to write a subroutine for the mutation of only the third
> nucleotide in a series of three. I don't really know perl all that well,
> so I was hoping someone would be able to tell me where I am going wrong,
> and why I am getting a lot of errors when I edit my code. Here is my
> subroutine:
>
[snip]
>
> Could anyone provide some helpful hints on how to get this thing working
> correctly? I'd be happy to answer any more questions if I didn't make
> anything clear enough. Thanks so much for your time!
>
One problem of your line by line approach is that you potentially miss
nucleotides if the number of nucleotides in one line isn't dividable by
3. The safest approach would be to slurp it as a whole. If that is not an
acceptable solution (because of memory constraints) it's going to be a
lot more complicated, but it doesn't seem like you're working with whole
chromosomes at once ;-).
Your code is very very confusing, so I had to make a few hunches, here it
goes:
use File::Slurp;
sub strategy2 {
my $newDNASeq = read_file($nucFile);
$newDNASeq =~ s/ ^ > [^\n]* \n //x; # Remove the fasta header!
$newDNASeq =~ s/ \S //gx; # Remove all whitespace
$newDNASeq =~ s{ (?<=[agtc]{2}) ([agtc]) }
{ (rand(1) < $mutationRate) ? randNuc() : $nuc }gexi;
return calcIdentity( translate($newDNASeq), $origProtSeq );
}
Regards,
Leon Timmermans
------------------------------
Date: Mon, 17 Nov 2008 13:22:45 -0800
From: "John W. Krahn" <someone@example.com>
Subject: Re: Subroutine on Mutation of Codons
Message-Id: <EglUk.9318$Dw1.5843@newsfe09.iad>
Leon Timmermans wrote:
> On Sun, 16 Nov 2008 13:43:32 -0800, carriehecker wrote:
>
>> I am trying to write a subroutine for the mutation of only the third
>> nucleotide in a series of three. I don't really know perl all that well,
>> so I was hoping someone would be able to tell me where I am going wrong,
>> and why I am getting a lot of errors when I edit my code. Here is my
>> subroutine:
>>
> [snip]
>> Could anyone provide some helpful hints on how to get this thing working
>> correctly? I'd be happy to answer any more questions if I didn't make
>> anything clear enough. Thanks so much for your time!
>>
>
> One problem of your line by line approach is that you potentially miss
> nucleotides if the number of nucleotides in one line isn't dividable by
> 3. The safest approach would be to slurp it as a whole. If that is not an
> acceptable solution (because of memory constraints) it's going to be a
> lot more complicated, but it doesn't seem like you're working with whole
> chromosomes at once ;-).
>
> Your code is very very confusing, so I had to make a few hunches, here it
> goes:
>
> use File::Slurp;
>
> sub strategy2 {
> my $newDNASeq = read_file($nucFile);
> $newDNASeq =~ s/ ^ > [^\n]* \n //x; # Remove the fasta header!
> $newDNASeq =~ s/ \S //gx; # Remove all whitespace
Your comment says remove whitespace but your code says remove
non-whitespace.
> $newDNASeq =~ s{ (?<=[agtc]{2}) ([agtc]) }
> { (rand(1) < $mutationRate) ? randNuc() : $nuc }gexi;
>
> return calcIdentity( translate($newDNASeq), $origProtSeq );
> }
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
------------------------------
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 1988
***************************************