nested replace string

2005-04-08 Thread N. Ganesh Babu
Dear All,
I am converting citations present in books to xml coding using regular 
expressions. Anybody can suggest best resources on this topic.
Here I am having one small problem. Please help.

"D.Turnbull 
in Solid State Physics: Advances in Research and 
Application, edited by 
F.Seitzand 
D.Turnbull, 
(Academic, New York, 1956), Vol. 
3,  p. 226"

With the help of regular expression I have modified the text into these 
tags.

Now I want to change the  tags after "edited by" string into 
 tags. I am changing the whole file with $line=.

I have written the following code. But I can not able to print the 
desired output. In FOUT I am getting same as input. 

   $line=~s!``(.+)''!``$1''!g;
**while($line=~m!edited by\s?(.+?)\(!g){$ed=$1;$ed=~s!refauth!editor!g;}
   print FOUT $line;
Please help me in where I am going wrong and suggest me the solution.
Regards,
Ganesh
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



file m-/a-/ctime comparison fails

2005-04-08 Thread lars
Hi all,
My complete script should check /home/root/.ssh/authorized_keys,
look for patterns, cut them out, copy the product to directories
created if certain entries are in /etc/passwd and write a log.
Every run of the script creates a new entry
/var/tmp/scriptname/scriptname.numbers.numbers.log
The script is run by crontab in 10min intervalls.
I'd like my script to check whether /home/root/.ssh/authorized_keys
in the meantime (between crontab runs) and if yes execute the whole cycle.
All seems to work, except the part, where I want to check whether 
/home/root/.ssh/authorized_keys have changed in the meantime.

In this excerpt I wanted to compare the modification time of
/home/root/.ssh/authorized_keys to the modification time of
my log entries.
If one entry is older than the modified key, run the rest.
The problem here is, that (stat($n))[9] always gives me a number
smaller than (stat($root_auth_keys))[9])
I believe because this part here already updates
the mtime of (stat($root_auth_keys))[9]).
I don't want to use a file as trigger.
my $logdir = "path/to/logdir";
opendir(LOGDIR, $logdir) or die "Can't open $logdir\n";
while ($_ = readdir LOGDIR) {
next if $_ =~ /^\./;
$_ = "$logdir/$_";
if ((stat($_))[9] > (stat($root_auth_keys))[9]) {
print "stat: ", (stat($_))[9];#debug
print "stat: ", (stat($root_auth_keys))[9];   #debug
I'd be very thankful for any input to solve this.
Kind regards,
lars.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Newbie Regular expression question

2005-04-08 Thread John W. Krahn
N. Ganesh Babu wrote:
Thank you very much for you help. One more small help.
fourth string
B. van Sures to be tagged as B.van Sures
fifth string
van Sures, B., to be tagged as van 
SuresB.

sixth string
Bockris, O. M. J., to be tagged as  
BockrisO. 
M.J.

All 6 should be converted in a single regex.
It looks like you need the module:
http://search.cpan.org/~kimryan/Lingua-EN-NameParse-1.20/
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Win32::IE::Mechanize load question

2005-04-08 Thread Ing. Branislav Gerzo
Hi all,

I am playing with this module (I need it, it is good), but I have one
quiestion about loading complete page:

my code snippet:

use strict;
use warnings;
use Win32::IE::Mechanize;
my $ie = Win32::IE::Mechanize->new( visible => 1,
left => 0,
top => 0,
height => 950,
width => 1280,
  );
$ie->get('http://www.google.com');  #example!
sleep 5;
$, = "\n";
print my @links = $ie->links;

This works ok, but I have quiestion about "sleep 5;". I didn't found
any method, which return status of page. I don't want use sleep 5.

in doc I found:
$ie->success
Return true for ReadyState >= 2;
in source is
sub success { $_[0]->{agent}->ReadyState >= 2 }

so I played with these values, also put $ie->get in loop, but nothing
helps. So there is no workaround and I have to use sleep ?

resources:
[1] 
http://search.cpan.org/~abeltje/Win32-IE-Mechanize-0.008/lib/Win32/IE/Mechanize.pm

--

 --. ,--  ,- ICQ: 7552083  \|||/`//EB: www.2ge.us
,--' |  - |--IRC: [2ge](. .),\\SN: 2ge!2ge_us
`+==+=+===~  ~=-o00-(_)-00o-~
"When the spit hits the Spam..." -- Frank Burns
 




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Win32::IE::Mechanize load question

2005-04-08 Thread Ing. Branislav Gerzo
Ing. Branislav Gerzo [IBG], on Friday, April 8, 2005 at 12:47 (+0200)
typed the following:

another problem I have. It seems to me a bug in Win32::IE::Link, resp.
Win32::IE::Mechanize

I'd like to use link method: $ie->find_link( [%options] ), but I can't
use "find_link(url_abs_regex => qr/regexp/i);"
I get error:
Can't locate object method "url_abs" via package "Win32::IE::Link" at D:/Perl/si
te/lib/Win32/IE/Mechanize.pm line 514,  line 164.

anyone can confirm this? It is interesting, because I can use
"url_abs" from Mechanize

I use latest version of module.

-- 

 ...m8s, cu l8r, Brano.

[*  <- Tribble.  *-~  <- Tribble After Sex.]



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Newbie Regular expression question

2005-04-08 Thread N. Ganesh Babu
Hi John,
I am new to understanding and how to use modules in perl programs. I 
have downloaded and installed the Modules you specified. The 
documentation in that I can not able to understand. Can you please help 
with a sample code.

Thanks in advance.
Regards,
Ganesh
John W. Krahn wrote:
N. Ganesh Babu wrote:
Thank you very much for you help. One more small help.
fourth string
B. van Sures to be tagged as B.van 
Sures

fifth string
van Sures, B., to be tagged as van 
SuresB.

sixth string
Bockris, O. M. J., to be tagged as  
BockrisO. 
M.J.

All 6 should be converted in a single regex.

It looks like you need the module:
http://search.cpan.org/~kimryan/Lingua-EN-NameParse-1.20/
John

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Net::SSH::Perl bind socket problem

2005-04-08 Thread gui
John Doe wrote:
Am Dienstag, 5. April 2005 15.20 schrieb gui:
[snip]
Net::SSH: Can't bind socket to port 1023: Adresse déjà utilisée at
./test_ssh.pl line 50

There's also a mailing list dedicated to Net::SSH::Perl (from man page):
"SUPPORT
   For samples/tutorials, take a look at the scripts in eg/ in the 
distribution directory.

   There is a mailing list for development discussion and usage questions.  
Posting is limited to subscribers only.  You can sign up at 
http://lists.sourceforge.net/lists/listinfo/ssh-sftp-perl-users

   Please report all bugs via rt.cpan.org at 
https://rt.cpan.org/NoAuth/ReportBug.html?Queue=net%3A%3Assh%3A%3Aperl
"
joe
I totally forgot about that, thanks!
I just subscribe, and send an email... I'll post the responses
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



sub declarations

2005-04-08 Thread Manish Sapariya
Hi List,
Can anybody tell me difference among all of the following
sub declaration.
1. sub abc {}
2. sub xyz() {} # Please not round brackets, When I had this definition,
I got following error.
-
Too many arguments for main::smtp at ./gencap.pl line 201, near "$temp_capfile)"

After removing the round bracket, it compiled/executed successfully.
3. sub pqr (@) {}
4. sub lmn ($) {}
Thanks and Regards,
Manish
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: Match filename and attach

2005-04-08 Thread Brian Volk
 
> Hi All, 
>  
> I have a directory full of .html documents ( 2000 ) named:
>  
> 12345.html
> 1.html
> 77548.html
> 45451.html
> 12132.html
> and so on
>  
> I have another directory of files w/ item numbers that match the .html
> documents. :
>  
> file_1.txtfile_2.txtfile_3.txt
> 11213245451
> 77548775481
> 12132 77548
> 77548
>  
> I want to read the first item # in file_1.txt ( 1)  and select
> 1.html from the .html dir and send it as an email 
> attachment.  I have
> been reading up on hash(s) but I'm not sure if that is what I 
> should be
> using...  Maybe File::Find, not sure  so I went w/  @ARGV 
> for the .txt
> files and foreach for the .html's.  Below is what I have put 
> together so
> far... I really need help w/ the while <> and the foreach...  
> :~)   I think
> I have the email piece working OK Any advice would be greatly
> appreciated.   Thanks!
>  
>  
> --- begin
> #!/usr/bin/perl
>  
> use strict;
> use warnings;
> use MIME::Lite;
> use Net::SMTP;
>  
> # email information 
> my $from_address = '[EMAIL PROTECTED]'  ;
> my $to_address = '[EMAIL PROTECTED]' 
>  ;
> my $mail_host = 'smtp.bvolk.com';
> my $subject = $ARGV;
> my $message_body = "Attached is the msds for" $ARGV "\n ...";
> my $html_file_zip = 'c:\brian\test\orders';
> my $email_file_zip = '$file';
>  
> # directory or .html doc's 
> my $html_dir = "C:/brian/test/html";
>  opendir (HTML, $html_dir) or die "Can't open $html_dir: $!";
>  
> my @files = map { "$html_dir/$_" } grep { !/^\./ } readdir HTML;
>  
> close HTML;
>  
> # directory of .txt doc's
> my $orders_dir = "C:/brian/test/orders";
>  opendir (ORDERS, $orders_dir) or die "Can't open $orders_dir: $!";
>  
> # load @ARGV for <> operator
> @ARGV = map { "$orders_dir/$_" } grep { !/^\./ } readdir ORDERS;
>  
> foreach my $file (@files) { 
>  
>  while (<>) { 
>if $ARGV =~ $file {
>   my $msg = MIME::Lite->new (
>   From => $from_address,
>   To => $to_address,
>   Subject => $subject,
>   Type =>'multipart/mixed'
>   ) or die "Error creating multipart container: $!\n";   
>  
>   $msg->attach (
>   Type => 'TEXT',
>   Data => $message_body
>   ) or die "Error adding the text message part: $!\n";
>  
>   $msg->attach (
>   Type => 'application/zip',
>   Path => $html_file_zip,
>   Filename => $email_file_zip,
>   Disposition => 'attachment'
>   ) or die "Error adding $email_file_zip: $!\n";
> 
>   MIME::Lite->send('smtp', $mail_host, Timeout=>60);
>   $msg->send;
>  
>}
>}
>   
> closedir (ORDERS);
>  
> ---end
>  

I think a hash is what I need to be doing but I'm not sure how to load the
keys and the values.  I'm sure I want the keys to be the files in the .html
directory and the values to be the item numbers in all the .txt files.  This
way I can create the hash to function as a table lookup..  Right?  

Could someone pls point me in the right direction

# directory or .html doc's 
my $html_dir = "C:/brian/test/html";
 opendir (HTML, $html_dir) or die "Can't open $html_dir: $!";
  
my @htmls = map { "$html_dir/$_" } grep { !/^\./ } readdir HTML;

# directory of .txt doc's
my $orders_dir = "C:/brian/test/orders";
 opendir (ORDERS, $orders_dir) or die "Can't open $orders_dir: $!";
  
# load @ARGV for <> operator
@ARGV = map { "$orders_dir/$_" } grep { !/^\./ } readdir ORDERS;

# -  not sure how to get above values in to hash - 
my %hash = ( );
my @htmls = keys %hash;
my @item_numbers = values %hash;

And then I realize I'll need to create a subroutine that will attach the key
($htmls) that matches the value ($item_number) to an email.

TIA!

Brian Volk 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: How can I take subarray without second array (drop other elements)?

2005-04-08 Thread John Doe
Am Donnerstag, 7. April 2005 16.33 schrieb Vladimir D Belousov:
> John Doe wrote:
> >Am Donnerstag, 7. April 2005 14.54 schrieb Vladimir D Belousov:
[...]
> >>I do this:
> >>$#array = $N+100;
> >>print_array($array[$N]);
> >
> >this should be
> >
> >   print $array->[$N]
>
> I see, but $array here is undefined. It doen't exists.
> I have @array - the array, and not the array reference.

*aarggh*! Yes, my suggestion is obviously totally wrong - how could I have 
overseen that :-(

[...]

Sorry (to all)

joe

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




glean distro version from /etc/*release

2005-04-08 Thread D. J. Birkett
I'm writing a script that will be run from a mount point on many 
different linux distros.  I'm just about to code a sub that will try and 
determine the distro (version isn't that important) from the 
/etc/*release file, and just wondered if anyone has already done this, 
or if there is some handy util that I don't know about that will do it 
for me?

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Migration of perl code based on Sybase::CTlib module from perl 5.8.0 to 5.004

2005-04-08 Thread Kunal Uskaikar
Hi ,

I have written a module "DbSession" which uses CTlib. I did my testing 
using perl 5.8.0 and it worked fine. I now realise that I have to get my 
module working with perl 5.004 and sybperl version 2.13_A1_561. I am using 
Sypase OCS 12.5.1(64 - bit).

But when I try to run my code I get the following error:

[EMAIL PROTECTED]<17> /opt/PRperl5.004/bin/perl Extract.pl

Can't load '/opt/perl/5.8.0/lib/sun4-solaris/auto/Sybase/CTlib/CTlib.so' 
for module Sybase::CTlib: ld.so.1: /opt/PRperl5.004/bin/perl: fatal: 
relocation error: file 
/opt/perl/5.8.0/lib/sun4-solaris/auto/Sybase/CTlib/CTlib.so: symbol 
PL_Xpv: referenced symbol not found at 
/opt/lib/perl5.004/sun4-solaris/5.00404/DynaLoader.pm line 166.

 at /opt/solarserv/lib/DbSession.pm line 58
BEGIN failed--compilation aborted at /opt/solarserv/lib/DbSession.pm line 
58.
BEGIN failed--compilation aborted at /opt/solarserv/lib/SolarInfo.pm line 
84.
BEGIN failed--compilation aborted at /opt/solarserv/lib/SolarExtract.pl 
line 46.
[EMAIL PROTECTED]<18> 

Being new to perl I am not being able to get to the root cause of the 
problem. Could you please help. 

If possible could you also suggest what I should be doing to solve the 
problem ?

Regards,
Kunal



__

IO::Socket Disconection Detection

2005-04-08 Thread Leip !
Imediatly after I execute the script I get one of the
"disconected" messages that are printed when
$sock->connected() no longer equals $server. 

"connected
If the socket is in a connected state the the peer
address is returned. If the socket is not in a
connected state then undef will be returned."

#!/usr/bin/perl

use IO::Socket;
use threads;
use threads::shared;

use strict;
use warnings;

my $port = 80; 
my $connected : shared; 
my $user : shared; 
my $sender;
my $receiver;  
my $checker;  
my $sock;   
my $skey;   
my $server : shared;

print "Enter username: ";
$user = <>;
chomp $user;

print "Enter server: ";
$server = <>;
chomp $server;

$sock = IO::Socket::INET->new(
PeerAddr => $server,
PeerPort => $port,
Proto => "tcp",
Type => SOCK_STREAM) or die "Cannot connect to
remote host";

if (login($user, $skey)){
$connected = 1;
}else{
$connected = 0;
shutdown($sock, 2);
exit;
}

#$checker = threads->new(\&checker);
$sender   = threads->new(\&sender);
$receiver = threads->new(\&receiver);

while($connected){}
sleep 4;

shutdown($sock, 2);

sub login {
#put handshaking stuff here
return 1;
}

sub logoff {
#put exiting stuff here
$connected = 0;
}

sub sender {
my $msg;
while($connected){
if($sock->connected() eq $server){
$msg = <>;
if($msg eq "^quit"){
logoff;
}else{
print $sock $msg;
}
}else{
print "Disconected1";
$connected = 0;
}
}
}

sub receiver {
my $msg;
while ($connected){
if( $sock->connected() eq $server){
$msg = <$sock>;
print $msg;
}else{
print "Disconected2";
$connected = 0;
}
}
}

sub checker { #not currently in use
while ($sock->sockhost() eq $server){}
print "Disconected\n";
$connected = 0;
sleep 2;
shutdown($sock, 2);
}





__ 
Do you Yahoo!? 
Yahoo! Mail - You care about security. So do we. 
http://promotions.yahoo.com/new_mail

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: sub declarations

2005-04-08 Thread Xavier Noria
On Apr 7, 2005, at 14:47, Manish Sapariya wrote:
Hi List,
Can anybody tell me difference among all of the following
sub declaration.
1. sub abc {}
2. sub xyz() {} # Please not round brackets, When I had this 
definition,
	I got following error.
The former is a regular subroutine, whereas the latter has a prototype. 
That prototype says xyz receives _no_ arguments, so an error is raised 
if one is passed:

% perl -wle 'sub xyz () { print "foo" } xyz(3)'
Too many arguments for main::xyz at -e line 1, at end of line
Execution of -e aborted due to compilation errors.
This is documented in perlsub (section "Prototypes"), where the meaning 
of the other two prototypes (@) and ($) is explained.

There's an excellent article by Tom Christiansen about prototypes:
Far More Than Everything You've Ever Wanted to Know about 
Prototypes in Perl
http://library.n0i.net/programming/perl/articles/fm_prototypes/

-- fxn
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: glean distro version from /etc/*release

2005-04-08 Thread Chris Devers
On Fri, 8 Apr 2005, D. J. Birkett wrote:

> I'm writing a script that will be run from a mount point on many 
> different linux distros.  I'm just about to code a sub that will try 
> and determine the distro (version isn't that important) from the 
> /etc/*release file, and just wondered if anyone has already done this, 
> or if there is some handy util that I don't know about that will do it 
> for me?
 
>From the what file ?

The only Linux I have access to at the moment is Debian, but neither it 
nor OSX (which, admittedly, isn't Linux) has any /etc/*elease* files. 
For that matter...

[EMAIL PROTECTED] ~]# find /etc -type f | grep -i elease
[EMAIL PROTECTED] ~]# 

So that pattern doesn't show up *anywhere* under /etc on Debian.

This might be useful though:

[EMAIL PROTECTED] ~]$ cat /etc/debian_version
3.0
[EMAIL PROTECTED] ~]$ 

This (currently) corresponds to Debian Stable.

You may possibly have better luck with `uname -a`, which is portable:

[EMAIL PROTECTED] ~]$ uname -a
Linux debian 2.4.26-smp-p4 #1 SMP Thu Apr 29 17:20:05 EDT 2004 i686 unknown
[EMAIL PROTECTED] ~]$ 

[EMAIL PROTECTED] ~]$ uname -a
Darwin osx 7.8.0 Darwin Kernel Version 7.8.0: Wed Dec 22 14:26:17 PST 2004; 
root:xnu/xnu-517.11.1.obj~1/RELEASE_PPC  Power Macintosh powerpc
[EMAIL PROTECTED] ~]$ 

(And that should work on other Linux distros, Solaris, BSD, Irix, etc.)


But the real question is what are you trying to do that is dependendant 
on the Linux distribution? The path you're on now implies that you're 
going to build up some kidn of database of what functionality is 
available on which platforms, and respond accordingly. This is not a 
very easy approach to maintain -- it's exactly the same wrong approach 
that makes browser handling such a pain in most Javascript code.

You may find that a *much* easier approach is to just go ahead and do 
what you intend to do, perhaps in an eval{} block, and if something goes 
wrong, *then* try to handle the error and make a note of what platform 
you were on when things went wrong. In that way, you can automatically 
build up a list of what platforms are causing problems and find ways to 
handle them as needed. 

As a rule of thumb, I suspect that this kind of "just do it and note the 
environment if things blow up" approach will be much more robust than a 
"identify the platform, then try based on the platform detection, then 
handle any problems" approach.

But YMMV of course :-)


-- 
Chris Devers

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Measuring Substring with Hash

2005-04-08 Thread Edward Wijaya
Hi,
I have following code that measure the substring.
It basically the number of positions of substrings
that occur (dotted count)
CASE A:
......   ..
GATTACGAGTGGCGCTCGTGTAACGGCA#Score 21
GATTACGGCGCTCG   AACGGCA
CASE B:
  ....  #Score 4
GATTACGAGTGGCGCTCGTGTAACGGCA
  GGGG

But how come for CASE B, the code below returns Score = 2 instead of 4?
__BEGIN__
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
my $s1 = 'GATTACGAGTGGCGCTCGTGTAACGGCA';
my @CASE_A  =  ('GATTACG','GCGCTCG','AACGGCA');  # 21
my @CASE_B  =  ('GG','GG');  # 4
print &score($s1,[EMAIL PROTECTED]) , "\n";
print &score($s1,[EMAIL PROTECTED]) , "\n";
sub score
{
  my ($str,$array) = @_;
  my %position_score;
  for my $frag (@{$array}) {
  my $idx = index($str, $frag) + 1;
  for my $pos ($idx .. $idx + (length($frag) - 1)) {
 $position_score{$pos} = 1;
  };
  };
  my $total_score = 0;
  for my $score (values %position_score) {
 $total_score += $score;
  };
  return $total_score;
};
__END__
--
Edward WIJAYA
Singapore
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: Measuring Substring with Hash

2005-04-08 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Edward Wijaya wrote:
> Hi,
> 
> I have following code that measure the substring.
> It basically the number of positions of substrings
> that occur (dotted count)
> 
> CASE A:
> ......   ..
> GATTACGAGTGGCGCTCGTGTAACGGCA#Score 21
> GATTACGGCGCTCG   AACGGCA
> 
> 
> CASE B:
>....  #Score 4
> GATTACGAGTGGCGCTCGTGTAACGGCA
>GGGG
> 
> 
> 
> But how come for CASE B, the code below returns Score = 2 instead of
> 4?
Your first case were 3 uniques and the the second had two alike.  If 
you had a dup in the first it would not have worked correctly.  You will need 
to use the offset value within index to get it to work.  I placed a couple of 
print statements and you see it goes right back to the same position on the 
second one.  I added three lines see below and it came out with the counts you 
were expecting.
 
> 
> 
> __BEGIN__
> #!/usr/bin/perl -w
> use strict;
> use Data::Dumper;
> 
> my $s1 = 'GATTACGAGTGGCGCTCGTGTAACGGCA';
> my @CASE_A  =  ('GATTACG','GCGCTCG','AACGGCA');  # 21
> my @CASE_B  =  ('GG','GG');  # 4
> 
> print &score($s1,[EMAIL PROTECTED]) , "\n";
> print &score($s1,[EMAIL PROTECTED]) , "\n";
> 
> 
> sub score
> {
>my ($str,$array) = @_;
>my %position_score;
 my $offset = 0;
> 
>for my $frag (@{$array}) {
>my $idx = index($str, $frag) + 1;
   my $idx = index($str, $frag, $offset) + 1;
> 
>for my $pos ($idx .. $idx + (length($frag) - 1)) {
>   $position_score{$pos} = 1;
>};
$offset = $idx;

Wags ;)

>};
> 
>my $total_score = 0;
>for my $score (values %position_score) {
>   $total_score += $score;
>};
> 
>return $total_score;
> 
> };
> 
> __END__
> 
> 
> --
> Edward WIJAYA
> Singapore



***
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
***


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: glean distro version from /etc/*release

2005-04-08 Thread Stephen Day
On Friday 08 April 2005 5:11 pm, Chris Devers wrote:
>     [EMAIL PROTECTED] ~]$ uname -a
>     Linux debian 2.4.26-smp-p4 #1 SMP Thu Apr 29 17:20:05 EDT 2004 i686
> unknown [EMAIL PROTECTED] ~]$

uname -a does not return the distribution. The second field is the hostname,
which in your case seems to be 'debian'.


Stephen Day

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: glean distro version from /etc/*release

2005-04-08 Thread Chris Devers
On Fri, 8 Apr 2005, Stephen Day wrote:

> On Friday 08 April 2005 5:11 pm, Chris Devers wrote:
> >     [EMAIL PROTECTED] ~]$ uname -a
> >     Linux debian 2.4.26-smp-p4 #1 SMP Thu Apr 29 17:20:05 EDT 2004 i686
> > unknown [EMAIL PROTECTED] ~]$
> 
> uname -a does not return the distribution. The second field is the 
> hostname, which in your case seems to be 'debian'.
 
Right.

My line of thinking is that `uname -a` should be able to portably 
identify the operating system, kernel version, and hardware 
architecture, and anything beyond that you can infer by just trying 
things and seeing what works.

In general, Perl scripts should be pretty portable across at least 
POSIX-ish systems (any Linux version, OSX, Solaris, BSD, etc), and you 
shouldn't need to know any more than what you'd get from $^O. If you 
need some more detail, `uname -a` (among other ways) can give you most 
of what you need.

There must be a module for this, but I can't think of the name...
 

-- 
Chris Devers
-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 


Simple MySQL Example?

2005-04-08 Thread Siegfried Heintze
I was looking at the example code in the mysql examples directory. They seem
to have been created for testing things like very large records.

Does anyone have a minimal example that executes a SQL SELECT command and
displays the results?

I need something really simple to get me started.

It's not a big deal, I could probably figure it out from the examples in the
mysql installation. They are just a bit more convoluted than necessary. I
just thought that if someone had a simple sample lying around it would save
me some time.

Thanks,
Siegfried



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Measuring Substring with Hash

2005-04-08 Thread John W. Krahn
Edward Wijaya wrote:
Hi,
Hello,
I have following code that measure the substring.
It basically the number of positions of substrings
that occur (dotted count)
CASE A:
......   ..
GATTACGAGTGGCGCTCGTGTAACGGCA#Score 21
GATTACGGCGCTCG   AACGGCA
CASE B:
  ....  #Score 4
GATTACGAGTGGCGCTCGTGTAACGGCA
  GGGG

But how come for CASE B, the code below returns Score = 2 instead of 4?
__BEGIN__
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
my $s1 = 'GATTACGAGTGGCGCTCGTGTAACGGCA';
my @CASE_A  =  ('GATTACG','GCGCTCG','AACGGCA');  # 21
my @CASE_B  =  ('GG','GG');  # 4
print &score($s1,[EMAIL PROTECTED]) , "\n";
print &score($s1,[EMAIL PROTECTED]) , "\n";
sub score
{
  my ($str,$array) = @_;
  my %position_score;
  for my $frag (@{$array}) {
  my $idx = index($str, $frag) + 1;
  for my $pos ($idx .. $idx + (length($frag) - 1)) {
 $position_score{$pos} = 1;
  };
  };
  my $total_score = 0;
  for my $score (values %position_score) {
 $total_score += $score;
  };
  return $total_score;
};
__END__
It looks like this will do what you want:
sub score {
  my ( $str, $array ) = @_;
  my $total_score = 0;
  for my $frag ( @$array ) {
my $len = length $frag;
my $idx = index $str, $frag;
if ( $idx >= 0 and substr $str, $idx, $len, '' ) {
  $total_score += $len;
  }
}
  return $total_score;
  }

John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Newbie Regular expression question

2005-04-08 Thread John W. Krahn
N. Ganesh Babu wrote:
Hi John,
Hello,
I am new to understanding and how to use modules in perl programs. I 
have downloaded and installed the Modules you specified. The 
documentation in that I can not able to understand. Can you please help 
with a sample code.
I'm sorry, I haven't used that module myself but it looked like it might be
useful to you.
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Simple MySQL Example?

2005-04-08 Thread Lawrence Statton
> I was looking at the example code in the mysql examples directory. They seem
> to have been created for testing things like very large records.
> 
> Does anyone have a minimal example that executes a SQL SELECT command and
> displays the results?
> 
> I need something really simple to get me started.
> 
> It's not a big deal, I could probably figure it out from the examples in the
> mysql installation. They are just a bit more convoluted than necessary. I
> just thought that if someone had a simple sample lying around it would save
> me some time.
> 
> Thanks,
> Siegfried
> 
> 

#!/usr/bin/perl

use strict;
use warnings;
use DBI ;
use Data::Dumper; 

our $dbh; 

sub DBH
{
unless ( $dbh && $dbh->ping ) {
$dbh = DBI->connect ( 'dbi:mysql:dbname=fuzzy', 'alrwneec', 
'top-secret-password-dont-tell-anyone' ) ;
die DBI->errstr unless $dbh && $dbh->ping; 
}
return $dbh;
}

my $sth = DBH->prepare ( q {
SELECT city, population 
FROM city 
WHERE population > 5
} );

die "No sth: " . DBH->errstr unless $sth; 

$sth->execute || die "no select: " $sth->errstr;

while ( my $row = $sth->fetch ) {
my ($city, $population) = @$row;
print "$city has a population of $population \n"; 
}




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Measuring Substring with Hash

2005-04-08 Thread John W. Krahn
John W. Krahn wrote:
It looks like this will do what you want:
sub score {
  my ( $str, $array ) = @_;
  my $total_score = 0;
  for my $frag ( @$array ) {
my $len = length $frag;
my $idx = index $str, $frag;
if ( $idx >= 0 and substr $str, $idx, $len, '' ) {
  $total_score += $len;
  }
}
  return $total_score;
  }
Which can be written more compactly as:
sub score {
  my ( $str, $array ) = @_;
  my $total_score = 0;
  for my $frag ( @$array ) {
( my $idx = index $str, $frag ) >= 0 or next;
$total_score += length substr $str, $idx, length $frag, '';
}
  return $total_score;
  }

:-)
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: Measuring Substring with Hash

2005-04-08 Thread Wagner, David --- Senior Programmer Analyst --- WGO
John W. Krahn wrote:
> John W. Krahn wrote:
>> 
>> It looks like this will do what you want:

John,
Since you are not using the offset, and you have the same value 
GG twice and index starts over from the first, you are counting the same GG 
twice.  If you remove the last GG, you will still come up with 4 and it should 
be 2 unless I am missing something. I believe the individual was wanting to 
seek down the path and not restart each time, though they can correct us if 
wrong there.

Wags ;)

Wags ;)
>> 
>> sub score {
>>   my ( $str, $array ) = @_;
>>   my $total_score = 0;
>> 
>>   for my $frag ( @$array ) {
>> my $len = length $frag;
>> my $idx = index $str, $frag;
>> 
>> if ( $idx >= 0 and substr $str, $idx, $len, '' ) {  
>>   $total_score += $len; }
>> }
>>   return $total_score;
>>   }
> 
> Which can be written more compactly as:
> 
> sub score {
>my ( $str, $array ) = @_;
>my $total_score = 0;
> 
>for my $frag ( @$array ) {
>  ( my $idx = index $str, $frag ) >= 0 or next;
>  $total_score += length substr $str, $idx, length $frag, '';
>  }
>return $total_score;
>}
> 
> 
> 
> :-)
> 
> John
> --
> use Perl;
> program
> fulfillment



***
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
***


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Measuring Substring with Hash

2005-04-08 Thread John W. Krahn
Wagner, David --- Senior Programmer Analyst --- WGO wrote:
John W. Krahn wrote:
John W. Krahn wrote:
It looks like this will do what you want:
John,
Since you are not using the offset, and you have the same value
GG twice and index starts over from the first, you are counting the
same GG twice.  If you remove the last GG, you will still come up
with 4 and it should be 2 unless I am missing something.
I think that you are missing something.  :-)   Did you try the code?
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: Measuring Substring with Hash

2005-04-08 Thread Wagner, David --- Senior Programmer Analyst --- WGO
John W. Krahn wrote:
> Wagner, David --- Senior Programmer Analyst --- WGO wrote:
>> John W. Krahn wrote:
>> 
>>> John W. Krahn wrote:
>>> 
 It looks like this will do what you want:
>> 
>> John,
>> Since you are not using the offset, and you have the same value
>> GG twice and index starts over from the first, you are counting the
>> same GG twice.  If you remove the last GG, you will still come up
>> with 4 and it should be 2 unless I am missing something.
> 
> I think that you are missing something.  :-)   Did you try the code?
> 
> 
> John
> --
> use Perl;
> program
> fulfillment

I missed that you were deleting what you found as you worked along.  
Wags ;)


***
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
***


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




trying to create my first exe with pp

2005-04-08 Thread Matthew Ryan
I am trying to use pp to create an exe file. I have installed PAR with ppm and 
installed ScanDeps.pm from cpan with nmake, all tests worked and install went 
fine. Now when running pp with the following code I get the following error. 
Can some one please tell me what is happening here.

C:\>pp -o printit print.pl
Compress::Zlib object version 1.22 does not match bootstrap parameter 1.16 at 
/loader/0x9c1194/DynaLoader.pm line 225.
Compilation failed in require at /loader/0x9c1194/Archive/Zip.pm line 24.
BEGIN failed--compilation aborted at /loader/0x9c1194/Archive/Zip.pm line 24.
Compilation failed in require at par.pl line 252. 

When DynaLoader comes up everything starts to look like a foreign language.

Fw: trying to create my first exe with pp

2005-04-08 Thread Matthew Ryan
I just wrote:


>I am trying to use pp to create an exe file. I have installed PAR with ppm and 
>installed ScanDeps.pm from cpan with nmake, all tests worked and install went 
>fine. Now when running pp with the following code I get the following error. 
>Can some one please tell me what is happening here.

>C:\>pp -o printit print.pl
>Compress::Zlib object version 1.22 does not match bootstrap parameter 1.16 at 
>/loader/0x9c1194/DynaLoader.pm line 225.
>Compilation failed in require at /loader/0x9c1194/Archive/Zip.pm line 24.
>BEGIN failed--compilation aborted at /loader/0x9c1194/Archive/Zip.pm line 24.
>Compilation failed in require at par.pl line 252. 

>When DynaLoader comes up everything starts to look like a foreign language.

I forgot to ad my script to this plea..

print.pl contains-

print "this";


RE: Match filename and attach

2005-04-08 Thread Brian Volk

 
> > Hi All, 
> >  
> > I have a directory full of .html documents ( 2000 ) named:
> >  
> > 12345.html
> > 1.html
> > 77548.html
> > 45451.html
> > 12132.html
> > and so on
> >  
> > I have another directory of files w/ item numbers that 
> match the .html
> > documents. :
> >  
> > file_1.txtfile_2.txtfile_3.txt
> > 11213245451
> > 77548775481
> > 12132 77548
> > 77548
> >  
> > I want to read the first item # in file_1.txt ( 1)  and select
> > 1.html from the .html dir and send it as an email 
> > attachment.  I have
> > been reading up on hash(s) but I'm not sure if that is what I 
> > should be
> > using...  Maybe File::Find, not sure  so I went w/  @ARGV 
> > for the .txt
> > files and foreach for the .html's.  Below is what I have put 
> > together so
> > far... I really need help w/ the while <> and the foreach...  
> > :~)   I think
> > I have the email piece working OK Any advice would 
> be greatly
> > appreciated.   Thanks!
> >  
> >  
> > --- begin
> > #!/usr/bin/perl
> >  
> > use strict;
> > use warnings;
> > use MIME::Lite;
> > use Net::SMTP;
> >  
> > # email information 
> > my $from_address = '[EMAIL PROTECTED]'  ;
> > my $to_address = '[EMAIL PROTECTED]' 
> >  ;
> > my $mail_host = 'smtp.bvolk.com';
> > my $subject = $ARGV;
> > my $message_body = "Attached is the msds for" $ARGV "\n ...";
> > my $html_file_zip = 'c:\brian\test\orders';
> > my $email_file_zip = '$file';
> >  
> > # directory or .html doc's 
> > my $html_dir = "C:/brian/test/html";
> >  opendir (HTML, $html_dir) or die "Can't open $html_dir: $!";
> >  
> > my @files = map { "$html_dir/$_" } grep { !/^\./ } readdir HTML;
> >  
> > close HTML;
> >  
> > # directory of .txt doc's
> > my $orders_dir = "C:/brian/test/orders";
> >  opendir (ORDERS, $orders_dir) or die "Can't open $orders_dir: $!";
> >  
> > # load @ARGV for <> operator
> > @ARGV = map { "$orders_dir/$_" } grep { !/^\./ } readdir ORDERS;
> >  
> > foreach my $file (@files) { 
> >  
> >  while (<>) { 
> >if $ARGV =~ $file {
> >   my $msg = MIME::Lite->new (
> >   From => $from_address,
> >   To => $to_address,
> >   Subject => $subject,
> >   Type =>'multipart/mixed'
> >   ) or die "Error creating multipart container: $!\n";   
> >  
> >   $msg->attach (
> >   Type => 'TEXT',
> >   Data => $message_body
> >   ) or die "Error adding the text message part: $!\n";
> >  
> >   $msg->attach (
> >   Type => 'application/zip',
> >   Path => $html_file_zip,
> >   Filename => $email_file_zip,
> >   Disposition => 'attachment'
> >   ) or die "Error adding $email_file_zip: $!\n";
> > 
> >   MIME::Lite->send('smtp', $mail_host, Timeout=>60);
> >   $msg->send;
> >  
> >}
> >}
> >   
> > closedir (ORDERS);
> >  
> > ---end
> >  
> 
> I think a hash is what I need to be doing but I'm not sure 
> how to load the
> keys and the values.  I'm sure I want the keys to be the 
> files in the .html
> directory and the values to be the item numbers in all the 
> .txt files.  This
> way I can create the hash to function as a table lookup..  Right?  
> 
> Could someone pls point me in the right direction
> 
> # directory or .html doc's 
> my $html_dir = "C:/brian/test/html";
>  opendir (HTML, $html_dir) or die "Can't open $html_dir: $!";
>   
> my @htmls = map { "$html_dir/$_" } grep { !/^\./ } readdir HTML;
> 
> # directory of .txt doc's
> my $orders_dir = "C:/brian/test/orders";
>  opendir (ORDERS, $orders_dir) or die "Can't open $orders_dir: $!";
>   
> # load @ARGV for <> operator
> @ARGV = map { "$orders_dir/$_" } grep { !/^\./ } readdir ORDERS;
> 
> # -  not sure how to get above values in to hash - 
> my %hash = ( );
> my @htmls = keys %hash;
> my @item_numbers = values %hash;
> 
> And then I realize I'll need to create a subroutine that will 
> attach the key
> ($htmls) that matches the value ($item_number) to an email.
> 
> TIA!
> 
> Brian Volk 
> 

Hi All, again.. :~)

Sorry to keep responding to my own posts... but I keep reading and learning
new things..  I did get my loop working and thought I would share!!  Not
that I'm splitting atoms or anything... but it was very exciting and
rewarding for me to figure it out!  :~)

Now I just need to replace the print "$_\n" w/ my $msg = MIME::Lite->new (
so I can email the html's.  so back to work I go!   

BTW: I ended up just adding ".htm" to all the item numbers, I didn't know
how to do this "if ($_ eq $html\.*) 

#!/usr/bin/perl 

use strict;
use warnings;

my $html_dir = "C:/brian/test/html";

opendir(DIR, $html_dir) or die "Can't open the $html_dir: $!\n";

# read file/directory names in that directory into @names

my @htmls = readdir(DIR) or die "Unable to read current dir:$!\n";

closedir(DIR);

my $orders_dir = 

Re: Match filename and attach

2005-04-08 Thread Chris Charley
I think a hash is what I need to be doing but I'm not sure how to load the
keys and the values.  I'm sure I want the keys to be the files in the 
.html
directory and the values to be the item numbers in all the .txt files. 
This
way I can create the hash to function as a table lookup..  Right?

Could someone pls point me in the right direction
TIA!
Brian Volk
Hello Brian
I see many questions in your problem before even attempting to code.
1.Your names in the text files are duplicated in the sample data you 
provided. I'm sure you don't want to send the same web page more than once, 
right?
2.Are all the .html files names, (2000+), included in the text files? In 
other words, will you be sending
out all the .htm files?
3.Your code shows all the pages going to the same recipient. Is this 
correct?

In addition, there are many problems with your code - it won't compile as 
is. So before reviewing the code, it would be helpful to know exactly what 
you want to accomplish.

Chris 


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Measuring Substring with Hash

2005-04-08 Thread John W. Krahn
Wagner, David --- Senior Programmer Analyst --- WGO wrote:
John W. Krahn wrote:
Wagner, David --- Senior Programmer Analyst --- WGO wrote:
   Since you are not using the offset, and you have the same value
GG twice and index starts over from the first, you are counting the
same GG twice.  If you remove the last GG, you will still come up
with 4 and it should be 2 unless I am missing something.
I think that you are missing something.  :-)   Did you try the code?
I missed that you were deleting what you found as you worked along.  
Right, since $str is a local copy in the sub it is alright to modify it 
which
ensures that the same substring is not found twice.  Another way to do it:
sub score {
  my ( $str, $array ) = @_;
  my $total_score = 0;
  for my $frag ( @$array ) {
$total_score += length $frag if $str =~ s/\Q$frag//;
}
  return $total_score;
  }

John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Measuring Substring with Hash

2005-04-08 Thread Edward Wijaya
Hi John and David,
Thanks so much for your reply.
I forgot to mentioned another variances of scoring apart from
this two
......   ..
GATTACGAGTGGCGCTCGTGTAACGGCA#Score 21
GATTACGGCGCTCG   AACGGCA
CASE B:
   ....  #Score 4
GATTACGAGTGGCGCTCGTGTAACGGCA
   GGGG
They are cases where they overlap:
CASE C:
.   ...   #score 16
GATTACGAGTGGCGCTCGTGTAACGGCA
GATTACG
  TTACGAG   CGTGTAA
CASE D:
 GCTCGTG #score 17
  ..
GATTACGAGTGGCGCTCGTGTAACGGCA
   TACGAGT
GTGGCGC
my @ar2 =  ('GATTACG','TTACGAG','CGTGTAA');  #16
my @ar3 =  ('TACGAGT','GTGGCGC','GCTCGTG');  #17
And Dave's modification below (that includes $offset) works just fine for  
it.

__BEGIN__
#!/usr/bin/perl -w

   my %position_score;
 my $offset = 0;
[snip]
 	   my $idx = index($str, $frag, $offset) + 1;
[snip]
$offset = $idx;
Don't mean to nitpick.
Just wondering if it's possible to modify Krahn's snippet to accomodate
the overlapping cases?
yet another fans request ;-)
--
Edward WIJAYA
Singapore
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Measuring Substring with Hash

2005-04-08 Thread John W. Krahn
Edward Wijaya wrote:
Hi John and David,
Hello,
Don't mean to nitpick.
Just wondering if it's possible to modify Krahn's snippet to accomodate
the overlapping cases?
No, it won't work if they overlap.
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]