[22927] in Perl-Users-Digest
Perl-Users Digest, Issue: 5147 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 27 18:06:05 2003
Date: Fri, 27 Jun 2003 15:05:09 -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 Fri, 27 Jun 2003 Volume: 10 Number: 5147
Today's topics:
Better Way (mark_snyder)
Re: Better Way <uri@stemsystems.com>
Re: Better Way <johannes.fuernkranz@t-online.de>
Re: Better Way <johannes.fuernkranz@t-online.de>
Re: Better Way <abigail@abigail.nl>
Re: BTree examples ?? (Malcolm Dew-Jones)
Re: Hash::Utils lock_keys (Jay Tilton)
Re: Hash::Utils lock_keys <johannes.fuernkranz@t-online.de>
Re: how to convert all invalid UTF-8 sequences to numer (Shambo)
Re: how to convert all invalid UTF-8 sequences to numer <flavell@mail.cern.ch>
how to send html email from perl <ericosman@rcn.com>
Re: Installing CtCmd on Windows (Sherman Willden)
Pattern match with 2 conditions <sbour@niaid.nih.gov>
Re: Pattern match with 2 conditions (Andrew Perrin (CLists))
Re: Pattern match with 2 conditions <sbour@niaid.nih.gov>
Re: Pattern match with 2 conditions (Jay Tilton)
Re: problem of backslash conversion with MKS perl <bwalton@rochester.rr.com>
Problem with fork (Krishna)
Re: Regex to capture ip address from hosts file <bcraw@adelphia.net>
Re: Regex to capture ip address from hosts file <tzz@lifelogs.com>
Re: running UNIX with perl <matthew@weierophinney.net>
Re: running UNIX with perl <thens@nospam.com>
Re: running UNIX with perl <tunmaster@hotmail.com>
scalars and namespace <cyberjeff@sprintmail.com>
Re: Using local $/ <abuse@sgrail.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 27 Jun 2003 11:17:28 -0700
From: redynsm@techie.com (mark_snyder)
Subject: Better Way
Message-Id: <3659d7c5.0306271017.75c1ac09@posting.google.com>
Perl newbie question.
Is there a simpler way to write this?
$Line2 = (split ' ', $Line)[8];
$Line = "$Line2";
thanks
------------------------------
Date: Fri, 27 Jun 2003 18:47:08 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Better Way
Message-Id: <x7of0jfjdf.fsf@mail.sysarch.com>
>>>>> "ms" == mark snyder <redynsm@techie.com> writes:
ms> Perl newbie question.
ms> Is there a simpler way to write this?
ms> $Line2 = (split ' ', $Line)[8];
ms> $Line = "$Line2";
^ ^
useless use of quotes
$Line = (split ' ', $Line)[8];
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Fri, 27 Jun 2003 21:03:39 +0200
From: =?ISO-8859-1?Q?Johannes_F=FCrnkranz?= <johannes.fuernkranz@t-online.de>
Subject: Re: Better Way
Message-Id: <bdi4ep$b6r$02$1@news.t-online.com>
mark_snyder wrote:
> Perl newbie question.
>
> Is there a simpler way to write this?
>
> $Line2 = (split ' ', $Line)[8];
> $Line = "$Line2";
Did you mean @Line2 instead of $Line2?
Then use you may use join.
$line = join ' ', (split ' ',$line)[8];
Or maybe you want something like
$line = ($line =~ m/^(([^ ]+ ){8})/);
I don't know what's more (in)efficient. I'm sure there's a better way to
do this....
Juffi
------------------------------
Date: Fri, 27 Jun 2003 22:00:00 +0200
From: =?ISO-8859-1?Q?Johannes_F=FCrnkranz?= <johannes.fuernkranz@t-online.de>
Subject: Re: Better Way
Message-Id: <bdi7oa$ef0$02$1@news.t-online.com>
Johannes Fürnkranz wrote:
>
> Or maybe you want something like
>
> $line = ($line =~ m/^(([^ ]+ ){8})/);
This should have been
($line) = ....
Juffi
------------------------------
Date: 27 Jun 2003 22:01:45 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Better Way
Message-Id: <slrnbfpfm9.el.abigail@alexandra.abigail.nl>
Johannes Fürnkranz (johannes.fuernkranz@t-online.de) wrote on MMMDLXXXVII
September MCMXCIII in <URL:news:bdi4ep$b6r$02$1@news.t-online.com>:
`' mark_snyder wrote:
`'
`' > Perl newbie question.
`' >
`' > Is there a simpler way to write this?
`' >
`' > $Line2 = (split ' ', $Line)[8];
`' > $Line = "$Line2";
`'
`' Did you mean @Line2 instead of $Line2?
`'
`' Then use you may use join.
`'
`' $line = join ' ', (split ' ',$line)[8];
That join doesn't make much sense. (...)[8] indexes on a list,
returning exactly one element. The join then becomes very trivial.
$line = (split ' ', $line) [8];
`' Or maybe you want something like
`'
`' $line = ($line =~ m/^(([^ ]+ ){8})/);
That's not the same. Your regex would even fail if there are 2 spaces
in a row. If the first argument of split equals ' ', special things
happen. See the manual page of split for details.
Abigail
--
BEGIN {$^H {q} = sub {$_ [1] =~ y/S-ZA-IK-O/q-tc-fe-m/d; $_ [1]}; $^H = 0x28100}
print "Just another PYTHON hacker\n";
------------------------------
Date: 27 Jun 2003 14:17:27 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: BTree examples ??
Message-Id: <3efcb467@news.victoria.tc.ca>
Paul Marquess (paul.marquess@btinternet.com) wrote:
: "Kenjis Kaan" <tivolinewbie@canada.com> wrote in message
: news:6a8ba9f8.0306270501.1b436eb0@posting.google.com...
: > Hello. I am wondering if anyone has an example of using BTree for
: > storing data on a disk file.?? I found some BTree modules on the
: > web, but none give example of how you would then store it and retrieve
: > it from disk drive. I have a need to store hundred of thousands of
: > key, data values but told not to use a RDBMS. It would be nice if I
: > can get some sample of that actually shows the write to disk and
: > subsequent retrieval from it, which then allows you to do search for
: > records by supplying a key. TIA
: The DB_File module, that comes with Perl, has a btree opion. You can easily
: store hundres of thousands of key/data pairs in it.
Or the
BerkeleyDB
module (check the spelling, I always get it wrong). This provides access
to more features, (assuming your db install is a version that supports
them).
------------------------------
Date: Fri, 27 Jun 2003 18:54:52 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Hash::Utils lock_keys
Message-Id: <3efc926d.499294525@news.erols.com>
=?ISO-8859-1?Q?Johannes_F=FCrnkranz?=
<johannes.fuernkranz@t-online.de> wrote:
: I don't have the 3rd edition of the Camel-book, so pardon me if this is
: covered there:
If you did have a camel, where would you look for documentation of
modules that it does not cover?
Most of the competently authored modules carry their own
documentation, accessible through perldoc.
perldoc Hash::Util
: Can anybody explain the purpose of Hash::Util::lock_keys to me?
It restricts the hash's set of keys.
: I would have expected that this does something like internally convert
: the hash to an array and/or provide faster access to the hash elements
: by somehow avoiding to compute the hashing function for each element.
A non-hashing hash? Far out!
Looking at the Hash::Util code reveals the more mundane truth.
lock_keys() just invokes a routine inside perl to mark the hash as
read-only.
------------------------------
Date: Fri, 27 Jun 2003 22:15:47 +0200
From: =?ISO-8859-15?Q?Johannes_F=FCrnkranz?= <johannes.fuernkranz@t-online.de>
Subject: Re: Hash::Utils lock_keys
Message-Id: <bdi8m2$n5i$07$1@news.t-online.com>
Jay Tilton wrote:
> =?ISO-8859-1?Q?Johannes_F=FCrnkranz?=
> <johannes.fuernkranz@t-online.de> wrote:
>
> : I don't have the 3rd edition of the Camel-book, so pardon me if this is
> : covered there:
>
> If you did have a camel, where would you look for documentation of
> modules that it does not cover?
I looked through Hash::Util, of course. Sorry if this was not obvious
from my posting. But I find the assumption that sbdy posts a question on
a module w/o looking at perldoc a bit presumptious.
I think this was clearly not a newbie question.
> Most of the competently authored modules carry their own
> documentation, accessible through perldoc.
>
> perldoc Hash::Util
>
> : Can anybody explain the purpose of Hash::Util::lock_keys to me?
>
> It restricts the hash's set of keys.
>
> : I would have expected that this does something like internally convert
> : the hash to an array and/or provide faster access to the hash elements
> : by somehow avoiding to compute the hashing function for each element.
>
> A non-hashing hash? Far out!
>
> Looking at the Hash::Util code reveals the more mundane truth.
> lock_keys() just invokes a routine inside perl to mark the hash as
> read-only.
Yes, but Hash::Util also tells me that the hash-lock "is intended to
largely replace the deprecated pseudo-hashes."
Now, if I remember correctly, these pseudo-hashes were meant to combine
the better of arrays (smaller and faster) and hashes (can take any
keys). In some sense they were "non-hashing hashes", because they were
actually arrays.
So if a locked hash is only a regular hash with the entries marked
read-only, I don't really see in what way that gives you more mileage.
So I was wondering how they are implemented and whether they buy me
anything beyond an error message for new keys.
And Hash::Util doesn't really answer these questions (at least not for me).
Juffi
------------------------------
Date: 27 Jun 2003 12:20:34 -0700
From: shambo_p@yahoo.com (Shambo)
Subject: Re: how to convert all invalid UTF-8 sequences to numeric equivalent?
Message-Id: <72190192.0306271120.7ab7fa79@posting.google.com>
I guess I should start over.
When we try to validate our XML, it tells us it doesn't like
characters like £, calling them "invlaid UTF-8 sequences." I thought
if I could get Perl to translate characters like that to numeric
equivalent, the XML parser would not complain. These files will
eventually be displayed as HTML, so those characters would need to be
represented as numeric equivalent anyway.
So I was trying to identify the character set for all characters like
these, and I assumed that stuff like £ was out of the UTF-8 character
set range. I admit I was getting confused on the encoding issue.
And to answer one of your questions, I was telling Perl to output
utf8.
open(FILE, ">:outf8", "$myfile");
Using this method would simply remove any character like £, leading me
to believe something like £ is a non-UTF-8 character.
I have no idea what the input format is, and after lots of
experimentation with :latin1, :text and the like, I let it go to the
default.
I now think I'll simply have to build my own mapping table to convert
these characters to their numeirc equivalent so they will validate.
>>thanks for all your help.
> You don't seem to have used much of it yet, but I'm hopeful that it
> might be of some use to the occasional lurkers anyway.
I'm not sure why you say that, I've been reading your replies over and
over to make sure I get what you're saying. This experience has been
very informative, and I do sincerely appreciate it.
best,
S
------------------------------
Date: Fri, 27 Jun 2003 22:02:13 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: how to convert all invalid UTF-8 sequences to numeric equivalent?
Message-Id: <Pine.LNX.4.53.0306272124140.20344@lxplus076.cern.ch>
On Fri, Jun 27, Shambo inscribed on the eternal scroll:
> I guess I should start over.
If you feel it would help. A fresh start is sometimes best, when
you feel you're stalled...
> When we try to validate our XML, it tells us it doesn't like
> characters like £, calling them "invlaid UTF-8 sequences."
http://xml.apache.org/xerces-c/faq-parse.html#faq-20
| I keep getting an error: "invalid UTF-8 character". What's wrong?
Seems rather close to me.
> I thought if I could get Perl to translate characters like that to
> numeric equivalent, the XML parser would not complain.
It's an option, sure. Yes, it _is_ one possible approach, I didn't
deny that.
You have two other options:
- tell the parser correctly what character coding you're
giving it
- convert the data to utf-8 coding before feeding it to the parser,
since that's evidently what the parser expects by default.
Any one of those three options would deal with the reported problem.
I was trying to work out which one to choose for your situation.
> These files will
> eventually be displayed as HTML, so those characters would need to be
> represented as numeric equivalent anyway.
That's completely untrue. Again: it's one possible option, but it's
surely not the only one, and it might not be optimal.
See what I said at
http://ppewww.ph.gla.ac.uk/~flavell/charset/checklist.html#s2
and at http://ppewww.ph.gla.ac.uk/~flavell/charset/checklist.html#s7
(none of these things become true merely because I say so, of course:
these checklists of mine are boiled down from the authoritative
specifications).
> So I was trying to identify the character set
In HTML, the "document character set" is Unicode. What's of interest
here is not the "character set" in the HTML sense, but the character
coding (which is specified by that unfortunately named MIME parameter
"charset=" - but that confusing terminology pre-dates current usage).
> for all characters like these, and I assumed that stuff like £ was
> out of the UTF-8 character set range.
Absolutely not. utf-8 can express ANY unicode character.
> I admit I was getting confused on the encoding issue.
OK, there's a lot of it about...
> And to answer one of your questions, I was telling Perl to output
> utf8.
>
> open(FILE, ">:outf8", "$myfile");
| Unknown open() mode '>:outf8' [...]
Something wrong, see?
try starting at
http://www.perldoc.com/perl5.8.0/pod/perlopentut.html#IO-Layers
again.
Did you ever confirm that you really _are_ using Perl 5.8 ?
Or if you tried to re-type your code: please get a grasp on
copy/pasting it, so that we don't have to argue about your mis-typing.
> Using this method would simply remove any character like £,
No, it wouldn't. Provided that it had been read-in correctly, it
would output it in utf-8 coding. Sure, if you look at the result on a
display that was expecting iso-8859-1 then it might look odd, but your
XML parser will love it (assumuing it's expecting utf-8, which is
evident from what you reported above).
You still owe us a minimal complete script that can be run so that you
can be helped to understand what you're doing wrong.
> leading me
> to believe something like £ is a non-UTF-8 character.
Hmmm? I think it's fair to say that there isn't a character that you
can include in any usenet posting that isn't in Unicode, and any
character that's in Unicode can be represented in utf-8.
> I have no idea what the input format is,
Nor have you done very much to help us to advise you on that issue.
> I now think I'll simply have to build my own mapping table to convert
> these characters to their numeirc equivalent so they will validate.
I'm confident that Perl already has the mapping table waiting for you
to use it, if only you'd try to focus in on the issues.
You're just not giving us enough concrete detail here to be able to
advise you with actual code. Can't you put a sample of your input on
a web page or something, so that we at least know what we're talking
about?
------------------------------
Date: Fri, 27 Jun 2003 17:47:03 -0400
From: Eric Osman <ericosman@rcn.com>
Subject: how to send html email from perl
Message-Id: <3EFCBB57.6070500@rcn.com>
I just had the same question, and found that the following works.
If you're using the "sendmail" package (see
http://ls6-www.cs.uni-dortmund.de/cgi-bin/SFgate?language=English&verbose=1&listenv=DL&application=cpan&convert=CPAN&converthl=&refinequery=application%3dcpan%26convert%3dCPAN%26database%3dwait%252FDB%252Fcpan%26detex%3d1%26formextern%3dCPAN%26multiple%3d1%26range%3d1%26verbose%3d1%26name%3d%26synopsis%3d%26text%3dsendmail%26author%3d%26tie%3dor%26_lines%3dwhole%2bdocument%26maxhits%3d40%26language%3dEnglish&formintern=&formextern=CPAN&transquery=sendmail&_lines=&multiple=0&descriptor=wait%2fDB%2fcpan%7c1000%7c11191%7cMail::Sendmail%20v.%200.77%20-%20Simple%20platform%20independent%20mailer%20%7cCPAN%7cwait%7c%2fservices%2fwww-db%2fWAIT%2fDB%2fcpan%7c4120
)
Here's an example of sending an html message. NOTE: To actually use
this example, you will need to change the following things:
1) The first two lines might need to be swapped or otherwise modified
according to what your web server and perl require at the beginning of
perl scripts.
2) The "to" line needs to be edited to show who you're actually sending
the email to.
3) The "smtp" line needs to be changed to contain an outgoing mail
server that you are allowed to use.
ok here's the example:
#!perl
#!/usr/bin/perl
# Example of using sendmail to send html. Author: Eric Osman June 2003
use strict;
use CGI qw(:cgi);
use CGI::Carp qw(fatalsToBrowser);
use Mail::Sendmail;
my $msg = "";
$msg .= "here's some <b>boldface</b> to prove that html is being sent<br>";
$msg .= "a second line<br>";
my %mail = ( From => 'someone@somewhere.com',
To => 'enicosman@rcn.com',
Subject => "some simple html",
Message => "$msg",
Smtp => 'smtp.cn.com',
'Content-type' => 'text/html; charset="iso-8859-1"'
);
sendmail(%mail) || die $Mail::Sendmail::error;
print "Content-type: text/html\n\n";
print "your html email has been sent";
Enjoy.
/Eric
> From: Mark A. Hershberger (mah@everybody.org)
> Subject: Re: Perl, HTML to Sendmail...
>
> View this article only
> Newsgroups: comp.lang.perl.misc
> Date: 1999/09/28
>
> [mailed and posted]
>
> "Myriad" <myriad@erols.com> writes:
>
>> Hello, I'm looking for info on how to recode my Perl script to send HTML
>> enabled mail via Sendmail. Can anyone help?
>
> (Strange, I had a user ask me the same question today. Perhaps you
> are one and the same.)
>
> Find the MIME-tools package on CPAN (or, if you need a URL:
> http://www.cpan.org/modules/by-module/MIME) and install it. In the
> tar package, look at examples/mimesend for an example of how to send
> html mail.
>
> Also, please give users the option to get plain text email instead of
> HTML mail. HTML mail can be annoying.
>
> Hope that helps,
>
> Mark.
------------------------------
Date: 27 Jun 2003 11:51:59 -0700
From: sherman.willden@hp.com (Sherman Willden)
Subject: Re: Installing CtCmd on Windows
Message-Id: <3a80d8d6.0306271051.31b2fd3e@posting.google.com>
I reinstalled Visual Studio on my hosts and CtCmd installed
wonderfully on one of them. The other produces this output:
Microsoft (R) Program Maintenance Utility Version 6.00.8168.0
Copyright (C) Microsoft Corp 1988-1998. All rights reserved.
cp CtCmd.pm blib\lib\ClearCase\CtCmd.pm
AutoSplitting blib\lib\ClearCase\CtCmd.pm
(blib\lib\auto\ClearCase\CtCmd)
perl autoDef cmdsyn.conf
getOrdinal failed on cmdsyn_exec
NMAKE : fatal error U1077: 'perl' : return code '0x9d'
Stop.
H:\ClearCase\CtCmd-1.03\CtCmd>
Any ideas? Where do I look when I get errors like this?
Thanks;
Sherman
------------------------------
Date: Fri, 27 Jun 2003 15:51:31 -0400
From: Stephan Bour <sbour@niaid.nih.gov>
Subject: Pattern match with 2 conditions
Message-Id: <BB221883.8220%sbour@niaid.nih.gov>
I have a FASTA file containing alternated ID and sequence lines. I need to
find a pattern in the sequence but only return it as a match if the
corresponding ID line contains the string [Home sapiens]. The code below
returns all matches when I omit the "and $def=~ /[Homo sapiens]/" string but
gives me the following error when included:
Use of uninitialized value in concatenation (.) at blast.pl line 26, <>
chunk 22308.
Use of uninitialized value in concatenation (.) at blast.pl line 26, <>
chunk 22308.
Use of uninitialized value in concatenation (.) at blast.pl line 26, <>
chunk 22308.
Does that mean that $def is null in the regex? I don't understand because
the script still prints the ">$def\n\n part of the script but not $1, S2 and
$3.
Thanks for any pointer.
#! usr/bin/perl -w
$/="\n>";
while(<>){
$seq=$_;
@fields=split(/\n/,$_);
$i=-1;
$seq="";
foreach $line (@fields) {
$i++;
if($i==0) {
$def=$fields[$i];
}
else {
$seq.=$fields[$i];
}
}
if ($seq=~ /(.....)(LY.L..L..L)(.....)/ and $def=~ /[Homo sapiens]/) {
$j++;
print ">$def\n\n$1\t$2\t$3\n\n\n";
}
}
print "\n\nFound $j time.\n";
------------------------------
Date: 27 Jun 2003 16:59:28 -0400
From: clists@perrin.socsci.unc.edu (Andrew Perrin (CLists))
Subject: Re: Pattern match with 2 conditions
Message-Id: <847k77uthr.fsf@perrin.socsci.unc.edu>
Stephan Bour <sbour@niaid.nih.gov> writes:
> #! usr/bin/perl -w
use strict; # is your friend
>
> $/="\n>";
>
> while(<>){
>
> $seq=$_;
what's the point of this when you just set it back to "" below?
>
> @fields=split(/\n/,$_);
> $i=-1;
> $seq="";
>
> foreach $line (@fields) {
why assign $line when you never use it?
>
> $i++;
> if($i==0) {
> $def=$fields[$i];
> }
> else {
> $seq.=$fields[$i];
> }
> }
This is not in answer to your question, but you could clean this up
and get rid of that nasty $i stuff with something along the lines of
(untested):
$def = shift(@fields);
foreach my $line (@fields) {
$seq .= $line
}
> if ($seq=~ /(.....)(LY.L..L..L)(.....)/ and $def=~ /[Homo sapiens]/) {
The problems you asked about are in this line. They are:
1.) [Homo sapiens] is a character class; perldoc perlre for more
information. Drop the square brackets if (as I assume) you just
want to check for the string "Homo sapiens" somewhere in the
string. Or, if you need it at the beginning, use /^Homo sapiens/
or, for that matter, ( ...and substr($def, 0, 12) eq 'Homo sapiens')
2.) The second regex resets the $1..$3 variables to undef(), since
they refer to the last match. You could try switching the order
of the regexen, which might speed things up a little anyway.
Hope this helps.
--
----------------------------------------------------------------------
Andrew J Perrin - http://www.unc.edu/~aperrin
Assistant Professor of Sociology, U of North Carolina, Chapel Hill
clists@perrin.socsci.unc.edu * andrew_perrin (at) unc.edu
------------------------------
Date: Fri, 27 Jun 2003 17:37:51 -0400
From: Stephan Bour <sbour@niaid.nih.gov>
Subject: Re: Pattern match with 2 conditions
Message-Id: <BB22316F.823F%sbour@niaid.nih.gov>
in article 847k77uthr.fsf@perrin.socsci.unc.edu, Andrew Perrin CLists at
clists@perrin.socsci.unc.edu wrote on 6/27/03 16:59:
> Stephan Bour <sbour@niaid.nih.gov> writes:
>
>> #! usr/bin/perl -w
>
> use strict; # is your friend
>
>>
>> $/="\n>";
>>
>> while(<>){
>>
>> $seq=$_;
>
> what's the point of this when you just set it back to "" below?
>
>>
>> @fields=split(/\n/,$_);
>> $i=-1;
>> $seq="";
>>
>> foreach $line (@fields) {
>
> why assign $line when you never use it?
>
>>
>> $i++;
>> if($i==0) {
>> $def=$fields[$i];
>> }
>> else {
>> $seq.=$fields[$i];
>> }
>> }
>
> This is not in answer to your question, but you could clean this up
> and get rid of that nasty $i stuff with something along the lines of
> (untested):
> $def = shift(@fields);
> foreach my $line (@fields) {
> $seq .= $line
> }
>
>> if ($seq=~ /(.....)(LY.L..L..L)(.....)/ and $def=~ /[Homo sapiens]/) {
>
> The problems you asked about are in this line. They are:
> 1.) [Homo sapiens] is a character class; perldoc perlre for more
> information. Drop the square brackets if (as I assume) you just
> want to check for the string "Homo sapiens" somewhere in the
> string. Or, if you need it at the beginning, use /^Homo sapiens/
> or, for that matter, ( ...and substr($def, 0, 12) eq 'Homo sapiens')
> 2.) The second regex resets the $1..$3 variables to undef(), since
> they refer to the last match. You could try switching the order
> of the regexen, which might speed things up a little anyway.
>
>
> Hope this helps.
You're right, you're right and you're right. It is still very slow (the
FASTA file is over 600 MB) but it works!
Thanks for your help,
Stephan.
------------------------------
Date: Fri, 27 Jun 2003 21:45:26 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Pattern match with 2 conditions
Message-Id: <3efcba60.509523130@news.erols.com>
Stephan Bour <sbour@niaid.nih.gov> wrote:
: I have a FASTA file containing alternated ID and sequence lines. I need to
: find a pattern in the sequence but only return it as a match if the
: corresponding ID line contains the string [Home sapiens]. The code below
: returns all matches when I omit the "and $def=~ /[Homo sapiens]/" string
^^^^^^^^^^^^^^
Square brackets have meaning in a regex. That will actually match any
string containg the letters H, a, e, i, m, n, o, p, or s. Escape the
brackets to match a literal '[Homo sapiens]' .
$def=~ /\[Homo sapiens\]/
Better still, use index(), which is more suited to finding literal
substrings.
: but gives me the following error when included:
:
: Use of uninitialized value in concatenation (.) at blast.pl line 26, <>
: chunk 22308.
: Use of uninitialized value in concatenation (.) at blast.pl line 26, <>
: chunk 22308.
: Use of uninitialized value in concatenation (.) at blast.pl line 26, <>
: chunk 22308.
Those are warnings, not errors.
: Does that mean that $def is null in the regex?
The warnings point at the print statement, not at the match.
[code trimmed]
: if ($seq=~ /(.....)(LY.L..L..L)(.....)/
At this point, $1, $2 and $3 are defined when that match succeeds.
: and $def=~ /[Homo sapiens]/
And when that match succeeds, the values in $1, $2 and $3 get
clobbered. Doh!
: ) {
: $j++;
: print ">$def\n\n$1\t$2\t$3\n\n\n";
: }
Use the list returned by m// to keep captured substrings around,
if (
if (
my @grabs = $seq=~ /(.....)(LY.L..L..L)(.....)/
and
$def=~ /\[Homo sapiens\]/
) {
$j++;
print ">$def\n\n$grabs[0]\t$grabs[1]\t$grabs[2]\n\n\n";
}
or use index() in place of the second m//,
if(
$seq=~ /(.....)(LY.L..L..L)(.....)/
and
index($def, '[Homo sapiens]') >= 0
) {
$j++;
print ">$def\n\n$1\t$2\t$3\n\n\n";
}
or just swap the order of the matches in the condition.
------------------------------
Date: Fri, 27 Jun 2003 22:04:12 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: problem of backslash conversion with MKS perl
Message-Id: <3EFCBF43.9050703@rochester.rr.com>
Dozy Choi wrote:
...
>>I note that the Perl and OS I am using at the moment (Perl v5.8.0
>>ActiveState build 805 on Windoze 98SE with the command.com "shell") does
>>not have the behavior you describe. It passes alphanumeric arguments
>>containing / and \ literally, character for character. Example:
>>
>> D:\junk>type junk326.pl
>> use Data::Dumper;
>> print Dumper(@ARGV);
>>
>> D:\junk>perl junk326.pl a/b\c//d\\e
>> $VAR1 = 'a/b\\c//d\\\\e';
>>
>
> But it is still not working:
> C:\USR>perl junk.pl a/b\c//d\\e
> $VAR1 = 'a/b/c//d//e';
>
Well, you'll need to narrow it down between the Windoze 2000 cmd shell
and MKS Perl. You could easily download ActiveState Perl and see if
your problem persists when using that: www.activestate.com . If it is
the cmd shell, you're probably SOL -- try Linux, it works.
--
Bob Walton
------------------------------
Date: 27 Jun 2003 14:17:56 -0700
From: kgundlapalli@hotmail.com (Krishna)
Subject: Problem with fork
Message-Id: <19c69beb.0306271317.10255c2b@posting.google.com>
Hi -
I am using 'fork' to execute a child process (a perl program) in my
CGI.
When the user submits the page, I am displaying a status page (created
by a CGI)
and forking the my external process. However spawning of this external
process is redisplaying the the status page below the original page
(means I am getting
a TILED page of my status page).
$pid = fork;
if ($pid)
{ return 1; }
else {
close STDOUT;
exec "/usr/local/bin/perl /../../push.pl ";
exit 1;
}
Why its happenning like that?
Thanks
------------------------------
Date: Fri, 27 Jun 2003 18:49:14 GMT
From: "BC" <bcraw@adelphia.net>
Subject: Re: Regex to capture ip address from hosts file
Message-Id: <Kk0La.19266$Jw6.7848888@news1.news.adelphia.net>
thanks for the feedback. i settled on the following to capture just the
hostname as the key
and the ip address as a value. can you see anything wrong with, or a way to
optimize?
(/^#?((\d{1,3}\.){3}\d{1,3})\s+(.[a-zA-Z0-9]+.).*#/)
regards,
bc
------------------------------
Date: Fri, 27 Jun 2003 15:43:14 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Regex to capture ip address from hosts file
Message-Id: <4nd6gzux0t.fsf@lockgroove.bwh.harvard.edu>
On Fri, 27 Jun 2003, bcraw@adelphia.net wrote:
> thanks for the feedback. i settled on the following to capture just
> the hostname as the key and the ip address as a value. can you see
> anything wrong with, or a way to optimize?
>
> (/^#?((\d{1,3}\.){3}\d{1,3})\s+(.[a-zA-Z0-9]+.).*#/)
Look at the Regexp::Common module, it matches *valid* IP addresses for
you without any hard work on your part. The regex above will match
999.999.999.999 as the IP address, so I'd consider it at least
suboptimal if not buggy.
Ted
------------------------------
Date: Fri, 27 Jun 2003 18:16:10 GMT
From: Matthew Weier O'Phinney <matthew@weierophinney.net>
Subject: Re: running UNIX with perl
Message-Id: <KR%Ka.1702$8B.852@twister.nyroc.rr.com>
* joe <tunmaster@hotmail.com>:
> Thanks for the quick response, but i'm nu further. I made a shell script
> with the following lines:
>
> echo test1 > /opt/guide/www.secretaressebank.nl/HTML/dev/dbdump.txt
> mysqldump --user=username --password='password' dbname tablename >> file.txt
> echo test2 >> /opt/guide/www.secretaressebank.nl/HTML/dev/dbdump.txt
>
> When i exec this from the bash, it works just fine. But when i run it
> through a CGI-script, it 'forgets' to execute the second and most important
> line. Does it have anything to do with the rights? The CGI-script's rights
> are 755, the shell script's are 777.
It looks like the problem is that the CGI environment path is different
than your bash path -- which means it can't find where the mysqldump
executable is. In bash, type 'which mysqldump', and then copy the full
path it gives you to both your shell script and perl script -- I think
you'll find it works now.
The next thing to do if it doesn't work is to find out whether or not
the mysqldump executable has permissions that allow the CGI environment
to execute it. If it's permissions allow execution by the CGI
environment's user, group, or world permissions, than it should work; if
not, well, you're pretty much hosed.
--
Matthew Weier O'Phinney
http://weierophinney.net/matthew/
------------------------------
Date: Sat, 28 Jun 2003 00:12:54 +0530
From: Thens <thens@nospam.com>
Subject: Re: running UNIX with perl
Message-Id: <20030628001254.00650810.thens@nospam.com>
On Fri, 27 Jun 2003 18:00:19 GMT
"joe" <tunmaster@hotmail.com> wrote:
>Thanks for the quick response, but i'm nu further. I made a shell script
>with the following lines:
>
>echo test1 > /opt/guide/www.secretaressebank.nl/HTML/dev/dbdump.txt
>mysqldump --user=username --password='password' dbname tablename >> file.txt
>echo test2 >> /opt/guide/www.secretaressebank.nl/HTML/dev/dbdump.txt
Monitor the STDERR, in CGI the servers error log for the details.
>When i exec this from the bash, it works just fine. But when i run it
>through a CGI-script, it 'forgets' to execute the second and most important
>line. Does it have anything to do with the rights? The CGI-script's rights
>are 755, the shell script's are 777.
Ignore the other reply.
When you execute it from a bash your environment is set to access
mysqldump from your PATH settings. But in a CGI environment your PATH
settings are not known and hence you need to find out the actual
location of mysql in your system.
~home> which mysqldump
and invoke mysqldump with the absolute path in the shell script and the perl
script
Regards,
Thens.
------------------------------
Date: Fri, 27 Jun 2003 21:06:52 GMT
From: "joe" <tunmaster@hotmail.com>
Subject: Re: running UNIX with perl
Message-Id: <Ml2La.430303$122.40674080@amsnews02.chello.com>
Great, using the exact address, captured by 'which mysqldump', was the
solution indeed!
Thanks a lot!
------------------------------
Date: Fri, 27 Jun 2003 21:42:08 GMT
From: Jeff Thies <cyberjeff@sprintmail.com>
Subject: scalars and namespace
Message-Id: <3EFCBA74.199FFEB@sprintmail.com>
I have all these "config" files with lists of global scalars:
config_1.cfg
###########
$scalar1='something';
$scalar2='something_else';
#########
That worked for me in that I could import those scalars like this:
require 'path_to/config_1.cfg';
Now I want to import those into a sub and make that list of scalars
local to that sub. (I want to do something with the list of scalars in
all these "config" files one file at a time) How do I do that?
I can see where I would have been better off using hashes!
Jeff
------------------------------
Date: Fri, 27 Jun 2003 20:51:34 GMT
From: derek / nul <abuse@sgrail.org>
Subject: Re: Using local $/
Message-Id: <n9bpfvk7i6pcb98snn8i644e84ar76pm9j@4ax.com>
On Fri, 27 Jun 2003 08:50:43 -0500, tadmc@augustmail.com (Tad McClellan) wrote:
>derek / nul <abuse@sgrail.org> wrote:
>> On 27 Jun 2003 09:04:12 GMT, anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
>> wrote:
>>
>>>derek / nul <abuse@sgrail.org> wrote in comp.lang.perl.misc:
>
>>>> I am using the local $/
>
>> I assume it normally contains 'cr lf'? as this is how the while operator gets a
>> line at a time?
>
>It is a variable.
>
>You can print variables you know. :-)
I tried that and it appears to contain cr lf
Let me first say I am using win32
>See for yourself what it is before you local() it:
>
> print "the value of \$/ is [$/]\n";
>
>Or, even better, read the docs for it:
>
> perldoc perlvar
thanks, getting there slowly.
Let me say that navigating these documents without a knowledge of 'C' is
difficult.
My problem is that I have slurped and have my 'file' in $_
How do I now get my file to a series of characters so I can search the string
and replace the 2 lines after the successful search?
Derek
------------------------------
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 5147
***************************************