[23616] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 5823 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 18 14:05:53 2003

Date: Tue, 18 Nov 2003 11:05: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           Tue, 18 Nov 2003     Volume: 10 Number: 5823

Today's topics:
        "yield"  doesnt work (sangeetha)
    Re: Creating UNICODE filenames with PERL 5.8 (Allan Yates)
    Re: Creating UNICODE filenames with PERL 5.8 <usenet@morrow.me.uk>
        Find::File and taint mode <dave.nospam@ntlworld.com>
    Re: Find::File and taint mode <noreply@gunnar.cc>
        How can I append todays date to the file name? (Dariush)
    Re: How can I append todays date to the file name? <josef.moellers@fujitsu-siemens.com>
    Re: How do I substitute the 2nd occurance of a comma fr <tore@aursand.no>
    Re: How do I substitute the 2nd occurance of a comma fr <pinyaj@rpi.edu>
    Re: How do I substitute the 2nd occurance of a comma fr <krahnj@acm.org>
        Image::Info::TIFF - multi-page tiff images page count (ifiaz)
    Re: Is there a quick way.... <someone@somewhere.com>
    Re: multilinepattern match <jwillmore@remove.adelphia.net>
        Multiplication not commutitive in Perl? <mdudley@execonn.com>
    Re: Multiplication not commutitive in Perl? <asu1@c-o-r-n-e-l-l.edu>
    Re: Multiplication not commutitive in Perl? <mdudley@execonn.com>
    Re: Multiplication not commutitive in Perl? <pinyaj@rpi.edu>
        Perl sendmail going to spam folders? (Duke of Hazard)
    Re: perldoc installation <usenet@morrow.me.uk>
        Program that prints its source code <usenet@dwall.fastmail.fm>
    Re: running a sub inside regex (Thomas Isenbarger)
    Re: running a sub inside regex <pinyaj@rpi.edu>
    Re: running a sub inside regex (Steve)
    Re: where is DBI::DWIM? <ben.liddicott@comodogroup.com>
    Re: where is DBI::DWIM? <ewilhelm@somethinglike.sbcglobalDOTnet>
    Re: where is DBI::DWIM? <tore@aursand.no>
        why doesn't /^$_$/ behave? (Sara)
    Re: why doesn't /^$_$/ behave? <pinyaj@rpi.edu>
        Writing lex-like scanners in Perl <clint@0lsen.net>
    Re: Writing lex-like scanners in Perl <usenet@morrow.me.uk>
    Re: Writing lex-like scanners in Perl <clint@0lsen.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 18 Nov 2003 10:26:47 -0800
From: sangeetha_b@india.com (sangeetha)
Subject: "yield"  doesnt work
Message-Id: <4fde56d3.0311181026.28a62be2@posting.google.com>

Hello,

Yesterday, i have started reading thread model programming in perl. (
using Programming PERL by Larry wall, Tom, Jon). The following
programming has been given to explain the LOCK CONCEPT and given that
output of this program is "2". But, i'm getting "0" only. Any help y
it is?

I'm using "v5.8.0 built for i386-linux-thread-multi" version of perl.

##############################################
use Thread qw/async yield/;
my $var=0;
sub abump {
    if ( $var == 0 ){
       yield;
       $var++;
    }
}

my $t1 = new Thread \&abump;
my $t2 = new Thread \&abump;

for my $t ( $t1, $t2 ) { $t ->join; }
print "var is $var\n";
##############################################

If my understanding is wrong please explain. What is the exact use of
"yield" in the thread model programming. Thanks a lot.

Sangeetha


------------------------------

Date: 18 Nov 2003 06:30:34 -0800
From: allan@yates.ca (Allan Yates)
Subject: Re: Creating UNICODE filenames with PERL 5.8
Message-Id: <d6f51524.0311180630.27996609@posting.google.com>

But 

You are correct that unicode is not an acronym and should not be
capitalised. My deepest apologies for offending you through the use of
my grammer. I was not aware that grammer police were covering this
newsgroup. PERL is an acronym, "Practical Extraction and Report
Language", and thus may be capitalised.


Allan.

P.S. Please don't even think of chastising me for top posting versus
bottom posting. Different people have different preferences.

P.P.S. For the people who have ignored my grammer and helped me in my
quest, I am very appeciative.

Abigail <abigail@abigail.nl> wrote in message news:<slrnbrilm8.6vj.abigail@alexandra.abigail.nl>...
> Allan Yates (allan@yates.ca) wrote on MMMDCCXXX September MCMXCIII in
> <URL:news:d6f51524.0311170636.2f956afa@posting.google.com>:
> \\  I have been having distinct trouble creating file names in PERL
> \\  containing UNICODE characters. I am running ActiveState PERL 5.8 on
> \\  Windows 2000.
> 
> Neither Perl, nor Unicode are acronyms, so they aren't spelled in
> all caps. If you do, it's like you are shouting. And that's rude.
> 
> 
> Abigail


------------------------------

Date: Tue, 18 Nov 2003 15:20:25 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Creating UNICODE filenames with PERL 5.8
Message-Id: <bpddbp$mck$2@wisteria.csv.warwick.ac.uk>

allan@yates.ca (Allan Yates) wrote:
> You are correct that unicode is not an acronym and should not be
> capitalised. My deepest apologies for offending you through the use of
> my grammer. I was not aware that grammer police were covering this
> newsgroup.

'Grammar police' cover every ng worth having, the reason being that it
is very much easier to understand people when their spelling/grammar/
punctuation is correct.

> PERL is an acronym, "Practical Extraction and Report Language", and
> thus may be capitalised.

Nope, it isn't. from perlfaq1:

| But never write "PERL", because perl is not an acronym, apocryphal
| folklore and post- facto expansions notwithstanding.

> P.S. Please don't even think of chastising me for top posting versus
> bottom posting. Different people have different preferences.

No they don't. Only idiots prefer top-posting.

*PLONK*

Ben

-- 
If I were a butterfly I'd live for a day, / I would be free, just blowing away.
This cruel country has driven me down / Teased me and lied, teased me and lied.
I've only sad stories to tell to this town: / My dreams have withered and died.
  ben@morrow.me.uk   <=>=<=>=<=>=<=>=<=>=<=>=<=>=<=>=<=>=<=>=<=>   (Kate Rusby)


------------------------------

Date: Tue, 18 Nov 2003 18:41:17 +0000 (GMT)
From: "Dave Saville" <dave.nospam@ntlworld.com>
Subject: Find::File and taint mode
Message-Id: <qnirfnivyyragyjbeyqpbz.hokn4t0.pminews@text.news.ntlworld.com>

I have a cgi script that uses File::Find. 

find(\&wanted, 'D:/Apps/SouthSide/PMMail');

I am getting:

Insecure dependency in chdir while running with -T switch at
D:/usr/lib/perl/lib
/5.8.0/File/Find.pm line 807.

How can I get around this?

TIA

Regards

Dave Saville

NB switch saville for nospam in address




------------------------------

Date: Tue, 18 Nov 2003 19:55:16 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Find::File and taint mode
Message-Id: <bpdq7q$1m05og$1@ID-184292.news.uni-berlin.de>

Dave Saville wrote:
> I have a cgi script that uses File::Find. 
> 
> find(\&wanted, 'D:/Apps/SouthSide/PMMail');
> 
> I am getting:
> 
> Insecure dependency in chdir while running with -T switch at
> D:/usr/lib/perl/lib
> /5.8.0/File/Find.pm line 807.
> 
> How can I get around this?

By using the 'untaint' option. See the File::Find docs.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



------------------------------

Date: 18 Nov 2003 07:15:54 -0800
From: LinuxTeam@yahoo.com (Dariush)
Subject: How can I append todays date to the file name?
Message-Id: <d83f36a4.0311180715.5f89eb1f@posting.google.com>

Hello every one.

I'm no expert at perl.

I would like to append todays date to the file name

I have many files that arrive daily 

filename.pdf and so on

How can I rename the files to 

filename_DDMMYY.pdf

so the output would be

filename_18112003.pdf

thank you all.


------------------------------

Date: Tue, 18 Nov 2003 16:20:29 +0100
From: Josef =?iso-8859-1?Q?M=F6llers?= <josef.moellers@fujitsu-siemens.com>
Subject: Re: How can I append todays date to the file name?
Message-Id: <3FBA38BD.DB9D293A@fujitsu-siemens.com>

Dariush wrote:
> =

> Hello every one.
> =

> I'm no expert at perl.
> =

> I would like to append todays date to the file name
> =

> I have many files that arrive daily
> =

> filename.pdf and so on
> =

> How can I rename the files to
> =

> filename_DDMMYY.pdf
> =

> so the output would be
> =

> filename_18112003.pdf
> =

> thank you all.

What have you tried so far? It's a fairly simple task involving
localtime, strftime, rename and various standard Perl techniques.

perldoc -f localtime
also has an example of strftime

Josef
-- =

Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett


------------------------------

Date: Tue, 18 Nov 2003 19:54:32 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: How do I substitute the 2nd occurance of a comma from a text	file
Message-Id: <pan.2003.11.18.18.21.50.146721@aursand.no>

On Tue, 18 Nov 2003 04:12:38 -0800, Greg Gallagher wrote:
> ..",12345678,9999999999,"...
> 
> I need to find the position of the 2nd comma (between the 2 digits)
> and replace it with a verticle bar.

While many others have supplied you with excellent answers on how to solve
your problem by using regular expression, I must ask:  Are you, or are you
not, dealing with CSV data? :-)

If you are, you should take a look at the CSV modules on CPAN.  With one
of them you could have retrieved the specific column and substituted the
last comma with a '|' (which I guess you're capable of doing).


-- 
Tore Aursand <tore@aursand.no>


------------------------------

Date: Tue, 18 Nov 2003 09:46:39 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: Greg Gallagher <ggallagher@swcis.nhs.uk>
Subject: Re: How do I substitute the 2nd occurance of a comma from a text file
Message-Id: <Pine.SGI.3.96.1031118094555.199439B-100000@vcmr-64.server.rpi.edu>

[posted & mailed]

On 18 Nov 2003, Greg Gallagher wrote:

>..",12345678,9999999999,"...
>
>I need to find the position of the 2nd comma (between the 2 digits)
>and replace it with a verticle bar.

  $str =~ m/,[^,]*/g and $str =~ s/\G,/|/;

-- 
Jeff Pinyan            RPI Acacia Brother #734            2003 Rush Chairman
"And I vos head of Gestapo for ten     | Michael Palin (as Heinrich Bimmler)
 years.  Ah!  Five years!  Nein!  No!  | in: The North Minehead Bye-Election
 Oh.  Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)



------------------------------

Date: Tue, 18 Nov 2003 16:17:45 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: How do I substitute the 2nd occurance of a comma from a text file
Message-Id: <3FBA4626.39911232@acm.org>

Greg Gallagher wrote:
> 
> Dear perl oracles!!
> 
> Here's an snippet of the text I'm attempting to manipulate:
> 
> ..",12345678,9999999999,"...
> 
> I need to find the position of the 2nd comma (between the 2 digits)
> and replace it with a verticle bar.

s/(?<=\d),(?=\d)/|/;


John
-- 
use Perl;
program
fulfillment


------------------------------

Date: 18 Nov 2003 07:52:45 -0800
From: ifiaz@hotmail.com (ifiaz)
Subject: Image::Info::TIFF - multi-page tiff images page count
Message-Id: <93c1947c.0311180752.4041d637@posting.google.com>

How can I get a page count of a multi-page .tif image.

I browsed in CPAN, but I can't find the TIFF.pm.

Is there any way to get the page count in perl?

If not, what is the easiest way to do it using C, etc.?

Could someone give me the easiest steps to do it as I am quite
new to perl and programming?

Just a side question:
Is tiff the only format that supports multi-page images,
or are there any other and if any, what are those?

Thank you.


------------------------------

Date: Tue, 18 Nov 2003 15:48:47 -0000
From: "Bigus" <someone@somewhere.com>
Subject: Re: Is there a quick way....
Message-Id: <bpdf10$14as@newton.cc.rl.ac.uk>


"John J. Trammell" <trammell+usenet@hypersloth.invalid> wrote in message
news:slrnbriob3.e11.trammell+usenet@hypersloth.el-swifto.com.invalid...
> On Mon, 17 Nov 2003 23:43:21 -0000, Bigus <bigus_34@yahoo.co.uk> wrote:
> > . you know when you have a HTML form with a load of fields on it where
the
> > user enters various details. The user doesn't fill in a mandatory field
or
> > enters something in an incorrect format, so you want to return the form
to
> > them as they filled it out but with a suitable message telling them
where
> > they went wrong?
> >
> > Is there a quick way to do that? At the moment I have a HTML template
with
> > subsitution codes in the value parts of each form element, and to feed
it
> > back to the user I perform a load of s///; regexps to re-populate the
> > fields.. is there a module that does thi automatically?
> >
>
> HTML::FillInForm

Thanks.. that does the job nicely :)




------------------------------

Date: Tue, 18 Nov 2003 14:54:16 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: multilinepattern match
Message-Id: <20031118095416.761244c9.jwillmore@remove.adelphia.net>

On 18 Nov 2003 12:24:28 GMT
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> James Willmore <jwillmore@myrealbox.com> wrote in
> comp.lang.perl.misc:
> > genericax@hotmail.com (Sara) wrote in message
> > news:<776e0325.0311171042.1adbfb60@posting.google.com>...
<snip>
> > > $_ = "a bunch of
> > > stuff 
> > > is here..
> > > end;
> > > /
> > > thats all
> > > folks"; 
> > 
> > Another suggestion is avoid setting '$_'.  It's a special variable
> > and one should avoid setting it.  Again - I understand what you're
> > trying to demonstrate, but those less experienced may not.
> 
> There is nothing wrong with setting $_ in your main script when it's
> handy (and it often is).  Care must be taken when doing this in a
> subroutine.  Then you *must* localize $_ before setting it, or
> you're in for some nasty surprise.

True.  However, that wasn't done in the related post.

I guess it would have been better phrased:
Don't use $_ unless you know what you're doing.

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
Parsley   is gharsley.   -- Ogden Nash 



------------------------------

Date: Tue, 18 Nov 2003 11:06:31 -0500
From: Marshall Dudley <mdudley@execonn.com>
Subject: Multiplication not commutitive in Perl?
Message-Id: <3FBA4386.4EE42667@execonn.com>

If I have the following code intended to do rounding to the nearest 8:

$qty = 9;
$user4 = 8;
$qty2 = int($qty/$user4)*$user4;
print "$qty2\n";

I get a result of 0.
If I change the order of the terms to be multiplied together as below:

$qty = 9;
$user4 = 8;
$qty2 = $user4*int($qty/$user4);
print "$qty2\n";

I get the correct answer of 8.

Any ideas what the problem might be?  Multiplication suppose to be
communitive.

This is perl, version 5.005_03 built for i386-freebsd

Marshall





------------------------------

Date: 18 Nov 2003 17:45:37 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: Multiplication not commutitive in Perl?
Message-Id: <Xns943781D018757asu1cornelledu@132.236.56.8>

Marshall Dudley <mdudley@execonn.com> wrote in news:3FBA4386.4EE42667
@execonn.com:

> If I have the following code intended to do rounding to the nearest 8:
> 
> $qty = 9;
> $user4 = 8;
> $qty2 = int($qty/$user4)*$user4;
> print "$qty2\n";
> 
> I get a result of 0.
> If I change the order of the terms to be multiplied together as below:
> 
> $qty = 9;
> $user4 = 8;
> $qty2 = $user4*int($qty/$user4);
> print "$qty2\n";
> 
> I get the correct answer of 8.

I do not have that problem:

C:\Home>cat t.pl
#! perl

$qty = 9;
$user4 = 8;
$qty2 = int($qty/$user4)*$user4;
print "$qty2\n";

$qty = 9;
$user4 = 8;
$qty2 = $user4*int($qty/$user4);
print "$qty2\n";


C:\Home>t.pl
8
8

C:\Home\>perl -v

This is perl, v5.8.1 built for MSWin32-x86-multi-thread
(with 1 registered patch, see perl -V for more detail)

or on FreeBSD:

$ cat t.pl
#! /usr/bin/perl

$qty = 9;
$user4 = 8;
$qty2 = int($qty/$user4)*$user4;
print "$qty2\n";

$qty = 9;
$user4 = 8;
$qty2 = $user4*int($qty/$user4);
print "$qty2\n";

$ ./t.pl
8
8

$ perl -v

This is perl, version 5.005_03 built for i386-freebsd

-- 
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov


------------------------------

Date: Tue, 18 Nov 2003 11:51:53 -0500
From: Marshall Dudley <mdudley@execonn.com>
Subject: Re: Multiplication not commutitive in Perl?
Message-Id: <3FBA4E29.F84183A7@execonn.com>

Opps, you are right. I had a $ missing from the user4 in the one that was
not working.  Odd, I would have expected a compiler error with that.  I
can't believe how many times I can look at something yet miss something as
obvious as that. :<

Thanks,

Marshall

"A. Sinan Unur" wrote:

> Marshall Dudley <mdudley@execonn.com> wrote in news:3FBA4386.4EE42667
> @execonn.com:
>
> > If I have the following code intended to do rounding to the nearest 8:
> >
> > $qty = 9;
> > $user4 = 8;
> > $qty2 = int($qty/$user4)*$user4;
> > print "$qty2\n";
> >
> > I get a result of 0.
> > If I change the order of the terms to be multiplied together as below:
> >
> > $qty = 9;
> > $user4 = 8;
> > $qty2 = $user4*int($qty/$user4);
> > print "$qty2\n";
> >
> > I get the correct answer of 8.
>
> I do not have that problem:
>
> C:\Home>cat t.pl
> #! perl
>
> $qty = 9;
> $user4 = 8;
> $qty2 = int($qty/$user4)*$user4;
> print "$qty2\n";
>
> $qty = 9;
> $user4 = 8;
> $qty2 = $user4*int($qty/$user4);
> print "$qty2\n";
>
> C:\Home>t.pl
> 8
> 8
>
> C:\Home\>perl -v
>
> This is perl, v5.8.1 built for MSWin32-x86-multi-thread
> (with 1 registered patch, see perl -V for more detail)
>
> or on FreeBSD:
>
> $ cat t.pl
> #! /usr/bin/perl
>
> $qty = 9;
> $user4 = 8;
> $qty2 = int($qty/$user4)*$user4;
> print "$qty2\n";
>
> $qty = 9;
> $user4 = 8;
> $qty2 = $user4*int($qty/$user4);
> print "$qty2\n";
>
> $ ./t.pl
> 8
> 8
>
> $ perl -v
>
> This is perl, version 5.005_03 built for i386-freebsd
>
> --
> A. Sinan Unur
> asu1@c-o-r-n-e-l-l.edu
> Remove dashes for address
> Spam bait: mailto:uce@ftc.gov



------------------------------

Date: Tue, 18 Nov 2003 13:35:31 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: Multiplication not commutitive in Perl?
Message-Id: <Pine.SGI.3.96.1031118133452.201743B-100000@vcmr-64.server.rpi.edu>

On Tue, 18 Nov 2003, Marshall Dudley wrote:

>Opps, you are right. I had a $ missing from the user4 in the one that was
>not working.  Odd, I would have expected a compiler error with that.  I
>can't believe how many times I can look at something yet miss something as
>obvious as that. :<

You won't get compiler errors or warnings if you don't ask for them.
ALWAYS WRITE YOUR PROGRAMS WITH

  use strict;
  use warnings;

and then you will be told when you have erred.

-- 
Jeff Pinyan            RPI Acacia Brother #734            2003 Rush Chairman
"And I vos head of Gestapo for ten     | Michael Palin (as Heinrich Bimmler)
 years.  Ah!  Five years!  Nein!  No!  | in: The North Minehead Bye-Election
 Oh.  Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)



------------------------------

Date: 18 Nov 2003 10:21:03 -0800
From: faraz_hussain@yahoo.com (Duke of Hazard)
Subject: Perl sendmail going to spam folders?
Message-Id: <d5052c5d.0311181021.5211bdfa@posting.google.com>

I am using sendmail in a perl script to send a message to the email
address provided in a web form. The problem is that this message
always end up in the person's spam/bulk folder. I don't know what it
is about the sendmail that makes yahoo think it is spam. Below is my
code pasted below:

##################################

$mail_prog = '/usr/sbin/sendmail -t' ; 

if ($email) 	{

open (MAIL, "|$mail_prog");
print MAIL "From: $r0\n";
print MAIL "To: $r0,$email\n";
print MAIL "Subject: Form results\n";

print MAIL "blah blah blah";

close (MAIL);

	} # end of if statement


------------------------------

Date: Tue, 18 Nov 2003 15:10:49 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: perldoc installation
Message-Id: <bpdcpp$mck$1@wisteria.csv.warwick.ac.uk>


"Tintin" <me@privacy.net> wrote:
> This is just a comment/observation about people who reply that if perldoc
> isn't on the system, then your Perl installation is broken/defective.
> 
> Well, that maybe one interpretation, but keep in mind that Perl as included
> on later releases of Solaris doesn't include the Perl documentation.

IMHO, that is a bug and you should shout at Sun about it... this is
using the fairly wide definition of 'bug' prevalent in the open source
community, of course :).

Ben

-- 
If I were a butterfly I'd live for a day, / I would be free, just blowing away.
This cruel country has driven me down / Teased me and lied, teased me and lied.
I've only sad stories to tell to this town: / My dreams have withered and died.
  ben@morrow.me.uk   <=>=<=>=<=>=<=>=<=>=<=>=<=>=<=>=<=>=<=>=<=>   (Kate Rusby)


------------------------------

Date: Tue, 18 Nov 2003 18:56:02 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Program that prints its source code
Message-Id: <Xns94378DBE9339Bdkwwashere@216.168.3.30>


If I want a program to print its own source code, is there any reason 
to prefer one of these code snippets over the other?  Or is there an 
even better way to do it?

The context I'm thinking of is a CGI program that can be used as 
working code and also optionally provide a copy of itself to interested 
persons.  (Obviously I'd have to provide proper HTTP headers....)


Snippet 1:

seek DATA, 0, 0; 
print <DATA>;
__DATA__


Snippet 2:

open SELF, $0 or die "Error opening self for reading";
print <SELF>;


-- 
David Wall


------------------------------

Date: Tue, 18 Nov 2003 09:18:40 -0500
From: isen@molbio.mgh.harvard.edu (Thomas Isenbarger)
Subject: Re: running a sub inside regex
Message-Id: <isen-1811030918400001@ruvkung4pb3.mgh.harvard.edu>

thanks for all your help people.

here is a (perhaps) better description of what i want to do:

first, I want to allow the user to input a literal sequence to match such
as 'ACCCUCUAUUCUC', and also allow the user to match arbitrary seqeunce
elements of any length and then be able to match that pattern again, the
reverse, or the reverse complement of that sequence.  I also want to allow
the user to input his own pairing rules for revcomp matches.  For example,
if you would want to match an RNA hairpin structure of 10-20 bases with a
4 base loop, allowing for non watson and crick pairing, I would think of
it this way:

match any sequence that is a minimum length of 10 to a maximum length of
20, followed by any 4 bases, followed by the reverse complement of what
was matched in the first part as defined by the pairing rules A-U, C-G,
G-C, U-A, U-G, G-U.

in my program this would be:

(AU, CG, GC, UA, UG, GU)
1s=10-20
4-4
1r

of course, i don't want any of these particular values hard wired, I want
them all to be input by the user.  the elements I want to include (so far)
are these:

-arbitrary sequence of length N to M for matching later:  1s=N-M
-literal:  some string of ACGU such as:  ACCCUAUA
-literal to match and remember for later:  1s=ACCCUA (for example)
-match a remembered sequence again:  1s  (for example to find tandem
repeats 1 to 10 bases long I would use:

1s=1-10
1s

-match the reverse of a sequence already matched:  1p  (for example to
find inverted repeats 1 to 10 bases long I would use:

1s=1-10
1p

-match the revcomp of a sequence already matched:  1r  (for example to
find hairpins:

1s=1-10
1r

-pairing rules:  (AU, CG, UA, GC, AG, GA, UG, GU)

I also want to eventually do this with approximate matching to allow
mismatches, insertions, and deletions.

I am essentially trying to duplicate the PatSearch program (Nucleic Acids
research 2003, 31(13):3608) that is available on the web, but not as an
executable I can install locally.

Thanks for the offer to help and let me know what more information you
need from me.


------------------------------

Date: Tue, 18 Nov 2003 09:45:12 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: running a sub inside regex
Message-Id: <Pine.SGI.3.96.1031118094420.199439A-100000@vcmr-64.server.rpi.edu>

On Mon, 17 Nov 2003, Jeff 'japhy' Pinyan wrote:

>A context-free grammar for this would be:
>
>  S -> a S u | u S a | c S g | g S c | [nothing]
>
>You *could* do this with Perl regexes, but it's unweildy (and inefficient,
>I can assure you):

Actually, in my tests, this method is faster than the "match a lot and
then match its reverse" method.

>  my $pair;
>  $pair = qr{
>    a (??{ $pair }) u |
>    u (??{ $pair }) a |
>    c (??{ $pair }) g |
>    g (??{ $pair }) c |
>    (?# nothing )
>  }x;
>  if ("acgu" =~ /^($pair)$/) {
>    print "matched '$1'\n";
>  }

This is also more easily extensible.

-- 
Jeff Pinyan            RPI Acacia Brother #734            2003 Rush Chairman
"And I vos head of Gestapo for ten     | Michael Palin (as Heinrich Bimmler)
 years.  Ah!  Five years!  Nein!  No!  | in: The North Minehead Bye-Election
 Oh.  Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)



------------------------------

Date: 18 Nov 2003 06:57:53 -0800
From: ineverlookatthis@yahoo.com (Steve)
Subject: Re: running a sub inside regex
Message-Id: <f0d57f86.0311180657.342379bc@posting.google.com>

isen@molbio.mgh.harvard.edu (Thomas Isenbarger) wrote in message news:<isen-1711031631500001@ruvkung4pb3.mgh.harvard.edu>...
 .....
> for molecular biologists out there, I am trying to find the reverse
> complement on the fly inside the regex.  the @pairing array is something
> like @pairing = (AU, CG, GC, UA) and defines the substitutions to be made
> in order to build a reverse complement.
>

I haven't looked in detail at what you are trying to do - I can't
readily follow it !
However, your revcomp sub seems a very complex way to go about it. Why
not just do this:

############################################################################
sub revcompl()  #reverse complements primer
{
  $_[0]=lc($_[0]);          # to lowercase 
  $_[0]=reverse($_[0]);     # reverse order
  $_[0] =~ tr/gatc/ctag/;   # complement
 }
############################################################################

or am I missing something ?

Steve


------------------------------

Date: Tue, 18 Nov 2003 14:25:58 -0000
From: "Ben Liddicott" <ben.liddicott@comodogroup.com>
Subject: Re: where is DBI::DWIM?
Message-Id: <bpda5r$icl$1@kylie.comodogroup.com>

Not sure why you want to do this, but....

--given
create table myTable(
    field1 type1,
    field2 type2,
    field3 type3
)


Below we assume you are using the standard-ish command parameter % syntax,
where % is replaced with parameters.
If you want to update/create a value and PK:


declare @val1 type1
declare @val2 type2
select @val1 = %
select @val2 = %

-- Imaginary syntax:
-- UPDATE OR REPLACE set field1 = @val1, field2 = @val2 from myTable where
field1 = @val1

if not exists (select 1 from myTable where field1 = @val1 and field2 =
@val2) begin
    if exists (select 1 from myTable where field1 = @val1) begin
        update myTable set field2 = @val2 where field1 = @val1
    end else begin
        insert myTable(field1, field2)
        select @val1, @val2
    end
end

If you are only interested in the one value:

-- UPDATE OR REPLACE set field1 = @val1 from myTable
declare @val1 type1
select @val1 = %
if not exists(select 1 from myTable where field1 = @val1) begin
    insert myTable(field1)
    select @val1
end


The above should be close to working in MS T/SQL. You will have to jiggle it
about a bit to make it work in PostgreSQL/PL/SQL or Oracle/PL/SQL. It should
give you the basic idea though.

Cheers,
Ben Liddicott

"Eric Wilhelm" <ewilhelm@somethinglike.sbcglobalDOTnet> wrote in message
news:pan.2003.11.17.14.05.50.969954.1618@somethinglike.sbcglobalDOTnet...
> This is partly an SQL question but I'm also trying to find out if there is
> a perl module that has already solved it.  Searching CPAN, google, and
> reading the DBI/DBD docs seems to indicate that this is just the status
> quo.
>
> I am new to SQL, but I'm shocked by the fact that there is no "set the
> value of this column in this row" command.  I can INSERT or UPDATE, but
> first I must SELECT to see if the row already exists (unless I disable
> some warnings, do with autocommit and just '$ins->(@vals) or
> $upd->(@vals)', but this still requires me to write two SQL statements
> which basically express the same desire and then prepare two statement
> handles.
>
> At best, it seems to double (or triple) the amount of SQL-related code,
> but at worst, it inherently violates the "single point of truth" rule.
>
> REPLACE is not a good solution, since the rest of the row's contents
> should be left intact (but if it isn't there, we just want to create it
> and get on with our lives.)
>
> It seems like an UPDATE statement could easily enough be translated into
> the required INSERT statement (but maybe I haven't thought forward far
> enough in this idea.)
>
> If anyone could give me a tip that would allow one "statement of intent"
> to create whatever SQL statements are needed, that would be great.
>
> Otherwise, tell me why this is crazy before I go write DBI::DWIM
>
> With all of the sql use via Perl and the tendency of Perl to make you
> want to be consise, I would think that some kind of "make it so" function
> would have been cooked up by now.
>
> Thanks,
> Eric




------------------------------

Date: Tue, 18 Nov 2003 15:27:10 GMT
From: Eric Wilhelm <ewilhelm@somethinglike.sbcglobalDOTnet>
Subject: Re: where is DBI::DWIM?
Message-Id: <pan.2003.11.18.09.27.56.187312.1618@somethinglike.sbcglobalDOTnet>

On Tue, 18 Nov 2003 05:12:33 -0600, Tore Aursand wrote:

> Everywhere on this way you know for sure what/who the instance is, so
> why do you need to re-create your relationship with the instance for
> each of the parts above?
> 
> More code-related, these three would look like this:
> 
>   1. Read data from a database
>   2. Do something with the data
>   3. Get rid of the data (ie. save and dispose, or just dispose)
> 
> Where do _you_, in _your_ application, loose control over what you're
> working with?

The situation that I have is that 3-4 programs are responsible for
creating one record in a table.  The first application may set 2-3
columns, another application sets 1 column, etc.

If there were a pre-ordained order in which they had to run, it would make
sense that the first to run sets the name and values with an INSERT,
except that it must also assume that it may have run before, therefore it
could use a REPLACE.

All other applications could then require that the row is already present
and they could use an UPDATE to set their column(s) (each column is the
responsibility of only one program.)

The problem is that all of the column values are independent of each
other, so if the programs are forced to run in the order C,D,E,A,B and C
always does a REPLACE, you would have to re-run D,E,A,B to get the
previous (unchanged) values back into the table.

Now, we could eliminate this "row-smashing" by adding code to C which did
UPDATE or INSERT, but that still leaves us tied to the order C,D,E,A,B
when the data does not logically require that order.

To allow the programs to run in any order, each one would have to UPDATE
or INSERT which means that each one needs twice as much SQL code.

If this were a monolithic program, sure a REPLACE would solve all of my
problems, but I would prefer to keep each of the tools small and sharp.

Should the table be broken into smaller tables (one program, one table?) 
The administrator seems to be against this, but we are all new to this,
so nothing is closed to argument.

Thanks,
Eric


------------------------------

Date: Tue, 18 Nov 2003 19:54:32 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: where is DBI::DWIM?
Message-Id: <pan.2003.11.18.18.19.03.228120@aursand.no>

On Tue, 18 Nov 2003 15:27:10 +0000, Eric Wilhelm wrote:
>> Where do _you_, in _your_ application, loose control over what you're
>> working with?

> The situation that I have is that 3-4 programs are responsible for
> creating one record in a table.  The first application may set 2-3
> columns, another application sets 1 column, etc.

Aha!  Just what I needed to know! :-)  It seems, though, that this is a
special situation, and thus it requires a special solution.  Perl can, of
course, help you with this.

As long as you don't want to - or can't - use REPLACE, I don't think you
can avoid having two (at least) SQL statements.  You could, however, let
Perl do the job for you - under the hood.

I don't know enough about your application(s) to offer the best solution,
but it seems pretty clear that you need a function (in Perl) which does
all the dirty work for you;

  1. Lookup record (if it exists)
  2. UPDATE or INSERT, depending on #1


-- 
Tore Aursand <tore@aursand.no>


------------------------------

Date: 18 Nov 2003 10:30:51 -0800
From: genericax@hotmail.com (Sara)
Subject: why doesn't /^$_$/ behave?
Message-Id: <776e0325.0311181030.595b819d@posting.google.com>

OK, $_ is "1", and my aray contains "13", but not "1". 

This matches:

   grep /^$_$/, @a;

But this doesn't match:

   my $xi = $_;
   grep /^$xi$/, @a;

p 5.6.1 on RH.


------------------------------

Date: Tue, 18 Nov 2003 13:39:53 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: Sara <genericax@hotmail.com>
Subject: Re: why doesn't /^$_$/ behave?
Message-Id: <Pine.SGI.3.96.1031118133853.201743C-100000@vcmr-64.server.rpi.edu>

[posted & mailed]

On 18 Nov 2003, Sara wrote:

>OK, $_ is "1", and my aray contains "13", but not "1". 
>
>This matches:
>
>   grep /^$_$/, @a;

Because in grep() and map(), $_ is locally set to the value in the list
you're looking at.  That's why you write

  grep /foo/, @a;

because /foo/ is really $_ =~ /foo/.

  $_ = 10;
  grep print("_ = $_\n"), 1, 2, 3;

-- 
Jeff Pinyan            RPI Acacia Brother #734            2003 Rush Chairman
"And I vos head of Gestapo for ten     | Michael Palin (as Heinrich Bimmler)
 years.  Ah!  Five years!  Nein!  No!  | in: The North Minehead Bye-Election
 Oh.  Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)



------------------------------

Date: Tue, 18 Nov 2003 15:59:25 GMT
From: Clint Olsen <clint@0lsen.net>
Subject: Writing lex-like scanners in Perl
Message-Id: <slrnbrkget.2f4p.clint@poly.0lsen.net>

I read the example in perlre(1) regarding writing lexical analyzers in Perl
using /gc, but I was wondering if there might be another approach.  One
problem with doing the if{}elsif{}..else{} technique is that this does not
really simulate traditional scanner behavior.  Scanners always try to make
the longest match, not the first.  One way to mimic the behavior more
faithfully would be to put the entire lexical analyzer in one pattern.  But
I wasn't sure if it was possible (even legibly) using extended regular
expressions (/x) to put executable code and embed it in the patterns:

/(alt1) {return "alt1"} |(alt2) { return "alt2"}|(alt3) { return
"alt3"}.../iogc

and so on.

If anyone has any experience with this kind of application, I'd like to
hear from you.

Thanks,

-Clint


------------------------------

Date: Tue, 18 Nov 2003 16:47:47 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Writing lex-like scanners in Perl
Message-Id: <bpdifj$rk3$1@wisteria.csv.warwick.ac.uk>


Clint Olsen <clint@0lsen.net> wrote:
> I read the example in perlre(1) regarding writing lexical analyzers in Perl
> using /gc, but I was wondering if there might be another approach.  One
> problem with doing the if{}elsif{}..else{} technique is that this does not
> really simulate traditional scanner behavior.  Scanners always try to make
> the longest match, not the first.  One way to mimic the behavior more
> faithfully would be to put the entire lexical analyzer in one pattern.  But
> I wasn't sure if it was possible (even legibly) using extended regular
> expressions (/x) to put executable code and embed it in the patterns:
> 
> /(alt1) {return "alt1"} |(alt2) { return "alt2"}|(alt3) { return
> "alt3"}.../iogc

See (?{...}) and (??{...}) in perlre.

Ben

-- 
For the last month, a large number of PSNs in the Arpa[Inter-]net have been
reporting symptoms of congestion ... These reports have been accompanied by an
increasing number of user complaints ... As of June,... the Arpanet contained
47 nodes and 63 links. [ftp://rtfm.mit.edu/pub/arpaprob.txt] * ben@morrow.me.uk


------------------------------

Date: Tue, 18 Nov 2003 17:10:44 GMT
From: Clint Olsen <clint@0lsen.net>
Subject: Re: Writing lex-like scanners in Perl
Message-Id: <slrnbrkkkk.2f4p.clint@poly.0lsen.net>

On 2003-11-18, Ben Morrow <usenet@morrow.me.uk> wrote:
>
> See (?{...}) and (??{...}) in perlre.

I did look at this, but I believe I found a problem with pos() for the
search string not being updated if I returned from the function from this
kind of code.  So, I would repeat from the beginning of the string every
time.  I'll give it a try again and defer the return until after the search
block.

Thanks,

-Clint


------------------------------

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 5823
***************************************


home help back first fref pref prev next nref lref last post