Simple Issues with Pod (on verbose and help page without param).

2006-04-03 Thread Edward WIJAYA

Dear all,

Here is a code which use Getopt::Long to produce a help instruction.
As can be seen below, I also want my code to print out the help message
when no argument is passed.

My question are:

1. How can I make the code below return man page when I simpy do:
   $ perl mycode.pl

   Namely no param is passed here.

2. Verbose 1 status below doesn't return anything when I do:
   $ perl mycode.pl -help.

   What's wrong with it?



=== mycode.pl ==
!/usr/bin/perl -w
use strict;
use Data::Dumper;
use Getopt::Long;
use Pod::Usage;


my $some_param = 5; #Default value
my $help;
my $man;

GetOptions(
"someparam|s=s" => \$some_param,
"help"  => \$help,
"man"   => \$man,
  )
  or pod2usage( -verbose => 1 ) && exit;



pod2usage(-verbose => 1) && exit if defined $help;
pod2usage(-verbose => 2) && exit if defined $man;

# Do sth with param
print "PARAM IS: $some_param\n";

__END__
=head1 NAME

MYCODE - do something

=head1 SYNOPSIS

perl mycode.pl [options] [file ...]

 Options:
   -helpbrief help message
   -man full documentation

=head1 OPTIONS

=over 8

=item B<-help>

Print a brief help message and exits.

=item B<-man>

Prints the manual page and exits.

=back

=head1 DESCRIPTION

B will read the given input file(s) and do someting
useful with the contents thereof.

=cut
--
Regards,
Edward WIJAYA
SINGAPORE

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Fast way to find neighboring strings ( wth Hamming Distance)

2006-03-02 Thread Edward WIJAYA

Hi all,

Suppose I have a string ($str) and also the number of maximum mismatch  
position is given ($d).
The string may come in two types first is normal string the other is  
ambiguous.



$str = 'TTTCGG'; # (length 6)
$str_amb = '[TA]TTCGG'; # Ambiguous (length 6)
$d   = 2;

What I intend to do is to find all the string of of length 6 that has  
maximum Hamming Distance
(number of mismatches) is less or equal to $d. These strings are  
constructed with bases [ATCG].


I already have a brute-force way to do it. That is to pre-generate as many  
as 4^l, all the strings of length $l, and then find the neighbours from  
there.


But this way is way too time consuming to do it. Since there are many many  
strings to test. And also the length of the string is around 12-20  
characters. Can anybody advice what's the best way to go about it?


Here is the bruteforce way to do it.

__BEGIN__
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
use Carp;
my $str = '[TA]TTCGG';
$str_amb = '[TA]TTCGG'; # Ambiguous (length 6)
my $e= 2;

find_nbe($str,$e);

sub find_nbe {

my ($str,$d) = @_;
my $l = 6;
my @nucs = qw/A T C G/;
my @enum = enum( $l, [EMAIL PROTECTED] );

foreach my $oligo (@enum) {
my $mm_val =(mm_and_len( $str, $oligo))[0];

# Neighbours shouldn't be itself
if ( $mm_val <= $d && $mm_val > 0 ) {
print "$oligo - $mm_val\n";
}
}

return;
}

sub mm_and_len {

# Compute mismatch count with and without ambigous
# position and return length of source string
# Target is assumed to be never ambigous

my ( $source_, $target ) = @_;
my $source = $source_;
$source =~ s/N/\[ATCG\]/g;
my @sparts = ( $source =~ /(\[.*?\]|.)/g );
my $mismatch_count
= scalar grep substr( $target, $_, 1 ) !~ /^$sparts[$_]/,
0 .. $#sparts;
return ( $mismatch_count, scalar(@sparts) );
}



sub enum {
return @{ $_[1] } unless --$_[0];
map {
my $nuc = $_;
map { $nuc . $_ } @{ $_[1] }
} enum( $_[0], $_[1] );
}

__END__

--
Regards,
Edward WIJAYA
SINGAPORE

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: Hash '... => +{ ...' synatx

2005-12-10 Thread Edward WIJAYA
On Sat, 10 Dec 2005 20:15:19 +0800, Beau E. Cox <[EMAIL PROTECTED]>  
wrote:



Hi -

Hi



  Some::Module->new(
  some_option  => 'blah,blah',
  some_hash_option => +{


+{ is used to distinguish an anonymous hash from a block where the grammar  
is ambiguous.

There's probably no need for the plus in that case (after a =>)



--
Regards,
Edward WIJAYA
SINGAPORE

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: Run *.pl file from Emacs

2005-12-09 Thread Edward WIJAYA
On Fri, 09 Dec 2005 19:46:56 +0800, Andrej Kastrin  
<[EMAIL PROTECTED]> wrote:



but is there any solution to run it too.


 ESC-X path/to/executable

or other alternative is to run it
under "e-shell" accessible through CTRL-C-D.


--
Regards,
Edward WIJAYA
SINGAPORE

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Replacing a Bracketed String with "N"

2005-11-22 Thread Edward Wijaya
Hi,

Is there a fast way to replace string like this:


$str1  = "ATC[TG]CC";
# into
$ans_str1  = "ATCNCC";

#and

$str2="ATC[TG]CCGC[ACTG]";
#into
$ans_str2="ATCNCCGCN";


Thus, the position of the bracket can be in any positions with any number, 
and number of strings enclosed by the bracket can consist up to 4 bases, i.e. 
[ATCG]. 

--
Regards,
Edward WIJAYA
SINGAPORE
 
 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: chomp and chop

2005-11-16 Thread Edward WIJAYA

On Thu, 17 Nov 2005 10:10:17 +0800, The Ghost <[EMAIL PROTECTED]> wrote:

I have some code that chomps a variable, but the variable still seems to  
have a newline.  But if I chop it I am rid of the newline.  What's going  
on with that string?





Perhaps that newline is Windows specific (like \r).

To view the hidden string you can use this
command: cat -A filename.txt

Then in Perl you can remove them using regex:
 sub remove_trailing_newline {
$_[0] =~ s/[\r\n]+\Z//;
}

Hope that helps.

--
Regards,
Edward WIJAYA
SINGAPORE

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Input Example Errata -- How to put brackets ....

2005-10-28 Thread Edward WIJAYA

Dear John,

Just small correction in the input sample.

my @ar5 = qw(GTATG-4 TGGGT-1);

should be this:

my @ar5 = qw(GTATG-4 TGGGT-7);


In short they are already ordered.

--
Regards,
Edward WIJAYA
SINGAPORE

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: How to put brackets in a string given substrings

2005-10-28 Thread Edward WIJAYA

Dear John,

Thanks so much for your life saving response.
There are one minor issue I still couldn't solve.

It is the fact that when the bounded region marked
by the array may occur more than once.
(See example no. 7 and 8 in my code below)

To disambiguate the situation, I can give the array that
comes along with the index.

I tried to modify your code below to handle
the matters. But I still cannot solve it.
I think I'm almost there but not quite yet.

Can you advice, how can I go about it?
Thanks so much beforehand. Really hope to hear
from you again.

__BEGIN__
my $t1 ='CCCATCTGTCCTTATTTGCTG';  my @ar1 = qw(ATCTG-3 ATTTG-13);
my $t2 ='ACCCATCTGTCCTTGGCCAT';   my @ar2 = qw(CCATC-2);
my $t3 ='CCACCAGCACCTGTC';my @ar3 = qw(CCACC-0 CCAGC-3 GCACC-6);
my $t4 ='CCCAACACCTGCTGCCT';  my @ar4 = qw(CCAAC-1 ACACC-4);
my $t5 ='CTGGGTATGGGT';   my @ar5 = qw(GTATG-4 TGGGT-1);
my $t6 = 'AGGAACTTGCCTGTACCACAGGAAG'; my @ar6 = qw( CAGGA-18 AGGAA-19 );

#The above example should yield the same result as previously

# These two examples below are the 'ambiguous' cases.

my $t7 = 'CAGGACTTGCCTGTACCACAGGAAG'; my @ar7 = qw( CAGGA-18  );
my $t8 = 'CAGGATTTGAGGAAGTACCACAGGAAG'; my @ar8 = qw( CAGGA-18 AGGAA-19 );

# Answer 7 -- CAGGACTTGCCTGTACCA[CAGGA]AG   Instead of --  
[CAGGA]CTTGCCTGTACCACAGGAAG
# Answer 8 -- CAGGATTTGAGGAAGTACCA[CAGGAA]G  Instead of --  
[CAGGA]TTTG[AGGAA]GTACCACAGGAAG



print put_bracket_jk_idx($t8,[EMAIL PROTECTED]),"\n";

sub put_bracket_jk_idx {
my ( $str, $ar ) = @_;

for my $subs ( @$ar ) {

 my ($sb,$id) = split("-",$subs);
 print "$sb $id\n";

if ( substr( $str, $id ) =~ /$subs/i ) {
$id += $-[ 0 ];
substr( $str, $id, length $subs ) =~ tr/A-Z/a-z/;
    }
}
$str =~ s/([a-z]+)/[\U$1\E]/g;

return $str;
}


print "\n";

__END__


--
Regards,
Edward WIJAYA
SINGAPORE

On Fri, 28 Oct 2005 18:42:11 +0800, John W. Krahn <[EMAIL PROTECTED]> wrote:


Wijaya Edward wrote:


I have the following problem.
I am trying to put the bracket in a string given the set of its  
substrings.

Those bracketed region is "bounded" by the given substrings.
Like this,  given input "String" and it's "substrings"

String
1.CCCATCTGTCCTTATTTGCTG
2.ACCCATCTGTCCTTGGCCAT
3.CCACCAGCACCTGTC
4.CCCAACACCTGCTGCCT
5.CTGGGTATGGGT
6.AGGAACTTGCCTGTACCACAGGAAG

 Substrings:
 1. ATCTG ATTTG
 2. CCATC
 3. CCACC CCAGC GCAAC
 4. CCAAC ACACC
 5. GTATG TGGGT
 6. CAGGA AGGAA

The desired answer are:
1. CCC[ATCTG]TCCTT[ATTTG]CTG
2. AC[CCATC]TGTCCTTGGCCAT
3. [CCACCAGCACC]TGTC   *
4. C[CCAACACC]TGCTGCCT *
5. CTGG[GTATGGGT]  **
6. AGGAACTTGCCTGTACCA[CAGGAA]G **

Please note that  in example 3 and 4 the substrings are "overlapping".
Pay attention also to for example 5 and 6,  there exist substrings that  
occur

twice. So the answer for example 5 and 6 are NOT

5. C[TGGGTATGGGT]   this is wrong
6. [AGGAA]CTTGCCTGTACCA[CAGGAA]G  this is wrong

--

Regards,
Edward WIJAYA
SINGAPORE>


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Enlisting All Possible Ranges of An Array

2005-10-25 Thread Edward Wijaya


Dear Sirs,

Given this array:

my @array = qw (A  B  C  D  E   );  

I want to enumerate all its possible ranges
throughout the elements. Such that it gives
the following desired answer, that look like this ( I manually crafted it):.

my $ans =   [ 'A',
  'B', 
  'C',
  'D',
  'E',
  'AB',
  'ABC',
  'ABCD',
  'ABCDE',
  'BCD',
  'BCDE',
  'CD',
  'CDE',
  'DE' ];

Later, I also want to  extend this
to deal with AoA as an input. But with
the same concept.

Is there an efficient way to achieve it? 
I truly do not  know how to go about it.
Really hope to hear from you again.

--
Regards,
Edward WIJAYA
SINGAPORE


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: perl equivalent of ps

2005-10-16 Thread Edward WIJAYA
On Sun, 16 Oct 2005 22:14:05 +0800, Christopher Spears  
<[EMAIL PROTECTED]> wrote:



Does Perl have the equivalent of ps in Unix?


Check out  Proc::ProcessTable module
They have nice API for it.

or can you try this?

perl -e'print `ps --no-header -p$$ -osz`'

This is just an example snippet to measure total memory used up
with our script.

Hope that helps.

--
Regards,
Edward WIJAYA
SINGAPORE

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: dereferencing

2005-08-24 Thread Edward WIJAYA
On Thu, 25 Aug 2005 10:31:18 +0800, Christopher Spears  
<[EMAIL PROTECTED]> wrote:



I'm trying to brush up on my Perl by learning object
oriented Perl!  This may not be the best way to brush
up on this subject, but I am sure that I will learn a
lot!  Here is a script:

#!/usr/bin/perl -w
use strict;

my @array = [1, 2, ['a','b','c','d']];


I think you have unnecessarily used square [] bracket.
You want this instead:

my @array = (1, 2, ['a','b','c','d']);


As for the overall approach I don't see why you
need to go via reference to find the array size.
It's like overkilling.

Perhaps this is what you want?


$ perl -MData::Dumper -e '
@array = (1,2,['a','b','c','d']);
$aref = [EMAIL PROTECTED]; $asize = scalar(@$aref);
print "Array Size: $asize\n"; print Dumper $aref;'

Prints:
Array Size: 3
$VAR1 = [
  1,
  2,
  [
'a',
'b',
'c',
'd'
  ]
];


--
Regards,
Edward WIJAYA
SINGAPORE

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Remembering Positions in Array after processing the element

2005-07-29 Thread Edward WIJAYA

Hi,
I wanted to append two subsequent characters (non *) in
an array and then storing them into new array.
But then I also want to restore the '*' string in its
initial position in the new array result.

I have the code below but still not
achieving the task.
How can I modify them so that I can get
it to return result as stated in the example below?


__BEGIN__
#!/usr/bin/perl -w
use strict;
use Data::Dumper;

  # For first elem
  #BA also acceptable
my @array   = ('A','B','*','C');  # returns: ['AB', 'BA','*','CB']
my @array1  = ('*','A','B','C');  # returns: ['*',  'AB','BA','CB']
my @array2  = ('A','B','C','*');  # returns: ['AB', 'BA','CB','*']
my @array3  = ('A','B','C','D');  # returns: ['AB', 'BA', 'CB','DC']

my @result = get_array(@array);
print Dumper [EMAIL PROTECTED] ;  # See above ('returns') for the desired  
result


sub get_array{

 my @array = @_;
 my @result;
 foreach  ( 0 .. $#array-1  )
 {
   my $st = $array[$_+1].$array[$_];
   push @result, $st;
 }
   return @result;
}

__END__

Thanks and hope to hear from you again.

--
Regards,
Edward WIJAYA
SINGAPORE

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: perl newbie question

2005-07-25 Thread Edward WIJAYA

On Mon, 25 Jul 2005 21:39:50 +0800, <[EMAIL PROTECTED]> wrote:


Can someone suggest a perl command line snippet that will print the last  
n

lines of a file.



If you are under unix/linux
just use "tail -n" command.

However if you really want to go via Perl command line:

$perl -e '
open FH, ";
close FH or die $!;
foreach $i (($#lines - $n) .. $#lines) { print "$lines[$i]\n";}
'


--
Regards,
Edward WIJAYA
SINGAPORE

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: How do I get a Hash name after passing the ref?

2005-07-04 Thread Edward WIJAYA
On Mon, 04 Jul 2005 17:31:03 +0800, Tielman Koekemoer (TNE)  
<[EMAIL PROTECTED]> wrote:



After I passed a hash ref to a subroutine, how can I see what the hash
name was? i.e.:


I don't think that's possible. Why do you need that?

--
Regards,
Edward WIJAYA
SINGAPORE

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: Tabular Data, Group By Functions

2005-06-14 Thread Edward WIJAYA

#!/usr/bin/perl -w
use strict;
use Data::Dumper;

my @all;

while (my $line = )
{
next if ($line =~ /[A-Za-z]/);
push @all, [ split (" ", $line) ];
}

# Sort by "In" then "Out" then "Day" increasing
my @ByIn_Out_Day = sort {$a->[1] <=> $b->[1]
  ||
 $a->[2] <=> $b->[2]
  ||
 $a->[3] <=> $b->[3]
  } @all;
# Print Sort Result
print Dumper [EMAIL PROTECTED] ;
print "\n\n";

my %group_day_in;
my %group_day_out;

foreach  my $i (0 .. $#ByIn_Out_Day)
{
   my $day = $ByIn_Out_Day[$i]->[3];
   my $in  = $ByIn_Out_Day[$i]->[1];
   my $out = $ByIn_Out_Day[$i]->[2];

   $group_day_in{$day} += $in;
   $group_day_out{$day} += $out;

}   # -  end foreach  -

print "Group Day by IN\n";
print Dumper \%group_day_in ;
print "Group Day by Out\n";
print Dumper \%group_day_out ;

__DATA__
ID In Out Day
1 5 2 1
2 4 9 2
3 3 3 2
4 6 7 3
5 5 0 5
6 7 9 3
7 8 9 4
8 6 6 4


--
Regards,
Edward WIJAYA
SINGAPORE

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: columnwise analysis

2005-05-13 Thread Edward WIJAYA
On Sat, 14 May 2005 14:12:37 +0800, Aditi Gupta <[EMAIL PROTECTED]>  
wrote:

hi everybody,
Hi,
is it possible to search for a pattern in each column of a file. I've  
only

This may not exactly what you want.
But hopefully it can give you some ideas.
The idea is to get all those column in to
a hash of array, and then process each hash according
to your desired regex.
The code below prints:
$VAR1 = {
   '0' => [
   'AB', # your columnwise data
EF
 ],
  '1' => [
   'BC',
   'FG'
 ],
  '2' => [
   'CD',
   'GH',
 ]
};
which gives column (of the size 2) wise extraction
of the data.

__BEGIN__
use Data::Dumper;
my %hash;
my $sub_length = 2;
while () {
chomp;
for my $j (0 .. length - $sub_length)
{
push @{$hash{$j}}, substr $_, $j, $sub_length;
}
}
print Dumper \%hash;
foreach my $hkey (keys %hash)
{
   foreach my $i ( 0 .. $#{ $hash{$hkey} } )
   {
  print "$hash{$hkey}[$i]";
  # or do some regex with it
   }
}
__DATA__
ABDC
EFGH


--
Regards,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: about substring

2005-05-09 Thread Edward WIJAYA
After second thought
This line:
my @y = grep { $_ if ($_ =~ /\d+/)} @list;
could be simplified with this:
my @y = grep { /\d+/ } split(/\s+/,$file);
Since grep { $_ if /\d+/ } wouldn't match on 0, but grep /\d+/ would.
I'm still wondering how can I do that with "unpack" :-(
--
Regards,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: about substring

2005-05-09 Thread Edward WIJAYA
On Mon, 09 May 2005 21:34:08 +0800, Aditi Gupta <[EMAIL PROTECTED]>  
wrote:

Can we use substr function for a string like:
$file = atom 12 N  VAL  A  1  12.435  13.66 34.6  32.1 32   a N
can the decimal numbers be extracted using
$x= substr($file, offset, length)
(the exact field lenghts of each field are known).

If you want only the decimal number_s_ looks like what you need
is a list.
__BEGIN__
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
my $file = 'atom 12 N  VAL  A  1  12.435  13.66 34.6  32.1 32   a N';
my @list = split(/\s+/,$file);
my @y = grep { $_ if ($_ =~ /\d+/)} @list;
print Dumper [EMAIL PROTECTED];
__END__
Gives:
$VAR1 = [
  '12',
  '1',
  '12.435',
  '13.66',
  '34.6',
  '32.1',
      '32'
];
Hope that's what yo wanted.
--
Regards,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: Where will I find perl scripts

2005-05-07 Thread Edward WIJAYA
Charles,
On Sat, 7 May 2005 14:50:37 -0500, Charles K. Clarkson  
<[EMAIL PROTECTED]> wrote:

plain scary. (Wait, I think _she_ wrote that module, too. Just stay
away from _her_. :)
_HE_ you mean! :-)
http://www.abigail.nl/
--
Regards,
Edward WIJAYA
Singapore
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Howto Dynamically Combine Multiple Array in HoA

2005-05-03 Thread Edward WIJAYA
Hi,
 What I intend to do here is to append the corresponding array
 from all the possible combination of the keys in the given HoA.
 The number of hash maybe varying from HoA to HoA (>10 hashes/HoA).
 Size of array is fixed for each HoA.
 My question is how can I construct a dynamic way to combine (append)
 array + combined key of HoA for the new_HoA?
 Given the (idiot) working code I have below, here are the desired
 output answers:
my %set_hoa1_output = (
't1'=> ["A","A","A","A"],
't2'=> ["B","B","-","B"],
't3'=> ["C","-","-","C"],
't1t2'  => ["AB","AB","A-","AB"],
't1t3'  => ["AC","A-","A-","AC"],
't2t3'  => ["BC","B-","--","BC"],
't1t2t3'=> ["ABC","AB-","A--","ABC"]
  );
my %set_hoa2_output = (
 'k1'   => ["A","A","-"],
 'k2'   => ["D","-","-"],
 'k1k2' => ["AD","A-","--"],
  );
__BEGIN__
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
#These two hashes are *not related* they serve only as example
my %set_hoa1 = (
  't1'=> ["A","A","A","A"],
  't2'=> ["B","B","-","B"],
  't3'=> ["C","-","-","C"],
   );
my %set_hoa2 = (
 'k1'=> ["A","A","-"],
 'k2'=> ["D","-","-"],
   );
my %output_hash = get_item_set(%set_hoa1);
print Dumper \%output_hash;
sub get_item_set
{
my %hoa = @_;
  my %new_hoa;
#First, assigning hash with single key
for my $key  (keys %hoa  )
{
   $new_hoa{$key} = $hoa{$key};
}
# This is an idiot way (manual) to do it and it's not dynamic
# i.e. only satisfy for %set_hoa1
# How can I construct automatically so that it may apply to varying
# number of hashes in HoA (%set_hoa2 .. etc) ?
my @tmp =  map{ $hoa{"t1"}[$_] . $hoa{"t2"}[$_]} (0 ..  
$#{$hoa{"t1"}});
   $new_hoa{"t1"."t2"} = [EMAIL PROTECTED];

my @tmp2 =  map{ $hoa{"t2"}[$_] . $hoa{"t3"}[$_]} (0 ..  
$#{$hoa{"t1"}});
   $new_hoa{"t2"."t3"} = [EMAIL PROTECTED];

my @tmp3 =  map{ $hoa{"t1"}[$_] . $hoa{"t3"}[$_]} (0 ..  
$#{$hoa{"t1"}});
   $new_hoa{"t1"."t3"} = [EMAIL PROTECTED];

my @tmp4 =  map{ $hoa{"t1"}[$_] . $hoa{"t2"}[$_] . $hoa{"t3"}[$_]  
} (0 .. $#{$hoa{"t1"}});
   $new_hoa{"t1"."t2"."t3"} = [EMAIL PROTECTED];

return %new_hoa;
}
__END__
Thanks so much for your time.
--
Regards,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: DFA::Simple

2005-04-25 Thread Edward Wijaya
--- Alex Lisbaron <[EMAIL PROTECTED]> wrote:


> How can I install this package on WIN2K?

Use PPM, like:

dos-prompt> ppm

then

ppm> install DFA-Simple

---
Regards,
Edward WIJAYA
SINGAPORE

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




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]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



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]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: ideintifying whether a module is already installed or not

2005-03-27 Thread Edward Wijaya
On Sun, 27 Mar 2005 20:28:42 +0800, Manish Sapariya <[EMAIL PROTECTED]>  
wrote:

Hi list,
Hi
How do I know whether a given module is installed on
machine or not?
perl -MModule::Name -e 'print "it is installed\n";'
or it's simpler variant
perl -MModule::Name -e1
Hth
--
Edward WIJAYA
Singapore
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: How can I get Inline::C to deal with big number?

2005-03-26 Thread Edward Wijaya
Dear Steven,
Sorry, don't mean to nitpick.
On Sat, 26 Mar 2005 23:09:26 +0800, Steven Schubiger  
<[EMAIL PROTECTED]> wrote:

On 26 Mar, Edward Wijaya wrote:

It's fine, as it is. Typedefs most often reside in header files,
although, they can be used in the main file without suffer.
As per your suggestion, I tried the code like this:
http://sial.org/pbot/8640
But it gives some glitches, as shown here:
http://sial.org/pbot/8641
What could be the problem?
Is there a way to solve it
--
Edward WIJAYA
Singapore
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: How can I get Inline::C to deal with big number?

2005-03-26 Thread Edward Wijaya
On Sat, 26 Mar 2005 22:31:52 +0800, Steven Schubiger  
<[EMAIL PROTECTED]> wrote:


typedef (malloc(2*sizeof(long double))) Big_Double;
Big_Double var;
Sorry my C is barely Novice.
Where can I put this snippet in my C subroutine?
like this:
[snip code]
__END__
__C__
typedef (malloc(2*sizeof(long double))) Big_Double;
Big_Double factrl;
double factrl(int n)
{
  double gammln(double xx);
  void nerror(char error_text[]);
  static int ntop=4;
  static double a[33]={1.0,1.0,2.0,6.0,24.0};
  int j;
  if (n<0) nerror("Negative factorial in routine factrl");
  if (n>32) return exp(gammln(n+1.0));
  while (ntop
  return a[n];
}
double gammln(double xx)
{
  double x,y, tmp,ser;
  static double cof[6] = {76.18009172947146, -86.50532032941677,
  24.01409824083091, -1.231739572450155,
  0.12086509738661e-2, -0.5395239384953e-5};
  int j;
  y = x = xx;
  tmp= x+5.5;
  tmp -= (x+0.5)*log(tmp);
  ser=1.0190015;
  for (j=0;j<=5;j++) ser += cof[j]/++y;
  return -tmp+log(2.5066282746310005*ser/x);
}
--
Edward WIJAYA
Singapore
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: How can I get Inline::C to deal with big number?

2005-03-26 Thread Edward Wijaya
Hi Steven,
On Sat, 26 Mar 2005 22:08:44 +0800, Steven Schubiger  
<[EMAIL PROTECTED]> wrote:

Try "long double" instead, which gives you 10 Bytes and
the format char %Lf.
Still wont' do. It still return 'inf' for N>500
--
Edward WIJAYA
Singapore
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: How can I get Inline::C to deal with big number?

2005-03-26 Thread Edward Wijaya
Hi Zentara,
Thanks for the reply.
On Sat, 26 Mar 2005 21:35:17 +0800, zentara <[EMAIL PROTECTED]> wrote:

Change every occurence of the word "float" , in your script,
to "double".
It worked, but still limited. It overflowed when N>500.
Most of the value of N, I use are around 1000-2000.
Any other possibility?
--
Edward WIJAYA
Singapore
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



How can I get Inline::C to deal with big number?

2005-03-26 Thread Edward Wijaya
Hi,
I have the following code that uses Inline::C to compute factorial.
The problem is that whenever I use large N (>30) it began to return "INF".
I thougtht my C implementation already cater large number by using "float"?
Additionally I have already added Math::Pari as an attempt to solve
the problem, but again no avail.
Can anybody suggest what's the way to deal with this?
Here is my complete code:
#--Beginning of my code ---
#!/usr/bin/perl -w
use Inline C;
use strict;
use Data::Dumper;
use Math::Pari qw/ :int/;
my $n = factrl(30);  # it fails if I try factrl(40)
print "$n\n"
__END__
 __C__
#include 
float factrl(int n)
{
  float gammln(float xx);
  void nerror(char error_text[]);
  static int ntop=4;
  static float a[33]={1.0,1.0,2.0,6.0,24.0};
  int j;
  if (n<0) nerror("Negative factorial in routine factrl");
  if (n>32) return exp(gammln(n+1.0));
  while (ntop
  return a[n];
}
float gammln(float xx)
{
  double x,y, tmp,ser;
  static double cof[6] = {76.18009172947146, -86.50532032941677,
  24.01409824083091, -1.231739572450155,
  0.12086509738661e-2, -0.5395239384953e-5};
  int j;
  y = x = xx;
  tmp= x+5.5;
  tmp -= (x+0.5)*log(tmp);
  ser=1.0190015;
  for (j=0;j<=5;j++) ser += cof[j]/++y;
  return -tmp+log(2.5066282746310005*ser/x);
}
#-End of My Code--
--
Edward WIJAYA
Singapore
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: Taking Multiple Files in Pairs and Run it Iteratively

2005-03-17 Thread Edward Wijaya
On Tue, 15 Mar 2005 02:29:06 +0800, John W. Krahn <[EMAIL PROTECTED]> wrote:
Edward Wijaya wrote:

[snip]
Here is one way to do it:
my %files;
for ( @ARGV ) {
 next unless /(.+)\.(?:fa|rs)$/;
 push @{ $files{ $1 } }, $_;
 }
for my $base ( keys %files ) {
 if ( @{ $files{ $base } } != 2 ) {
 warn "Error: only one file '@{$files{$base}}'.\n";
 next;
 }
 die "Cannot open files '@{$files{$base}}'.\n"
 unless open F, '<', $files{ $base }[ 0 ]
and open G, '<', $files{ $base }[ 1 ];
 print "$base\n>\n";
 while ( my $f =  and my $g =  ) {  # LINE 32
 print $f + $g, "\n";
   ## BTW I can just do my other funky stuff here right?
 }
 }

John,
I encounter this error:
"
Value of  construct can be "0"; test with defined() at thecode.pl  
line 32.
thecode.pl syntax OK "

What could be the problem?
Thanks so much for your time.
--
Edward WIJAYA
Singapore
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Taking Multiple Files in Pairs and Run it Iteratively

2005-03-13 Thread Edward Wijaya
Hi,
Suppose I have a pair-series of files as follows:
data1.fa
data1.rs
data2.fa
data2.rs #say each of this file contain lines of numbers
  #and there are 40 of files
And I have a code that take two files that ends with *.fa and *.rs
$ perl mycode.pl data1.fa data1.rs
$ perl mycode.pl data2.fa data2.rs
So the code is like this:
__BEGIN__
use warnings;
use strict;
my $file_fa = $ARGV[0];
my $file_rs = $ARGV[1];
open FILE_FA, "< $file_fa" or die "Can't open $file_r : $!";
open FILE_RS, "< $file_rs" or die "Can't open $file_p : $!";
my @fa_data; #these two are of the same size
my @rs_data;
while (){
  chomp;
  push @fa_data, $_;
}
while (){
  chomp;
  push @rs_data, $_;
}
my @sum = map {$rdata[$_] + $pdata[$_]} 0..$#fa_data;
my ($base) = split /\./,$file_fa;
print "$base\n";
print ">\n";
foreach my $sum (@sum){
 print "$sum\n";
}
__END__
How can I make my code above such that it can take all multiple files  
iteratively? to give output sth like this:

data1
sum_of_elements from data1.fa and data1.rs
data2
sum_of_elements from data2.fa and data2.rs
--
Edward WIJAYA
Singapore
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: Calling Files automatically

2005-02-25 Thread Edward WIJAYA
Thanks for your reply Charles,
On Fri, 25 Feb 2005 09:10:54 -0600, Charles K. Clarkson  
<[EMAIL PROTECTED]> wrote:

Is it always data1, data2, data3, etc. or can data be
another word? (Like foo1, foo2, foo3, etc.)
it always comes in (R-P) pair:
data1R.fa
data1P.fa
foo1R.fa
foo1P.fa
bar2R.fa
bar2P.fa
So "data1R.fa" is always processed with "data1P.fa", and so forth.

Is the extension always .fa or can it be something else?
Yes the extension is always ".fa"
Will every R file have a matching P file or will
some extra files be located in the directory? For example,
will there sometimes be a data14R.fa file and no
corresponding data14P.fa file?
No, there will always be a corresponding file.
i.e. *R.fa always have its *P.fa file

Will there be other files located in this directory?
Yes, but they won't be any other *R.fa *P.fa type.

Charles K. Clarkson

--
Regards,
Edward WIJAYA
Singapore
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Calling Files automatically

2005-02-25 Thread Edward Wijaya
Hi,
How can I modify the early part of code below
such that I don't have to manually key in the files this way:
perl mycode.pl data1P.fa data1R.fa data2P.fa data2R.fa etc
I.e. just by typing this will do:
perl mycode.pl
Thanks so much for your time beforehand.
--
Edward WIJAYA
Singapore
__BEGIN__
#!/usr/bin/perl
use strict;
use warnings;
for (@ARGV) {
next if /P\./; # ignore the P files
my ($base, $ext)= split /R/; #assume only one 'R' in the file name
r_p_process ( $base."R".$ext, $base."P".$ext )
}
sub r_p_process {
my $r_file=shift;
my $p_file=shift;
print "processing the pair $r_file $p_file\n";
#then process two files
}
__END__

NOTE:
The code above take pair-series of files as follows:
   data1R.fa - data1P.fa
   data2R.fa - data2P.fa
From list of files in directory
data1R.fa
data2P.fa
data2R.fa
data2P.fa
  #and there are more than 40 of these type files
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: rename all files

2005-02-19 Thread Edward Wijaya
On Sat, 19 Feb 2005 16:40:43 +0800, xuantl <[EMAIL PROTECTED]> wrote:
Hi all,
Hi
I wan't to change name of all the files in a directory(incluing sub
directorys) to lowercase.
[snip]
But it only works for files in the top directory("."), and no effect to
all other files in sub directorys. Any help?
I'm a beginner. If it's a stupid question for you, please don't hit me!
Try using finddepth() instead of find()
With find(), you're going to get DIR/ DIR/file1 DIR/file2
If you rename DIR to dir, DIR/file1 no longer exists.

But finddepth returns directory contents before the directories themselves.
BTW your code  would have been clear, btw, if you'd said, for example:
rename $old, $new or warn "rename: $!\n";
also, "$new = lc $old" is more readable than  $new = "\L$old"

My suggestion is untested, it'll be nice if you let us know if it works ;-)
HtH
--
Edward WIJAYA
Singapore
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: Getting the content of a .doc file under Unix

2005-02-14 Thread Edward WIJAYA

On Mon, 14 Feb 2005 15:46:22 +0200, Octavian Rasnita <[EMAIL PROTECTED]>  
wrote:

Does anyone how to get the text from a .doc file under Unix?
I would like to make a program which is portable and also work under  
Linux,
not only under Windows, and I think Win32::OLE won't work under Linux.

Open Office reads and write .doc s, but they don't always appear the same  
as they do in MSWord.
If anything, you might have some shot of a chnace using OLE::Storage or  
OLE::Storage_Lite
(which is used by Spreadsheet::ParseExcel).

OLE::Storage comes with a parsing script -  
http://search.cpan.org/~mschwartz/OLE-Storage-0.386/tools/lhalw
Of course it's rather outated.

HtH
--
Regards,
Edward WIJAYA
Singapore
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Trying mod_perl for the first time

2005-01-26 Thread Edward Wijaya
Dear all,
I am trying my mod_perl in my Apache webserver for the first time (under  
Mdk-Linux).
I have created a simple "print hello world" script with the name 'hello.pl'
and I stored it under 'var/www/cgi-bin/' but whenever I try to open
the script with http://localhost/cgi-bin/hello.pl

It gives "Internal Server Error" like this: http://paste.phpfi.com/48050.
BTW my  httpd.confis like this: http://paste.phpfi.com/48067
and my  httpd2.perl.conf  is like this: http://paste.phpfi.com/48068
Can anybody suggest what's wrong with my approach?
Hopefully this question is not far off topic.
Thanks a lot beforehand.
--
Edward WIJAYA
Singapore
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Benchmarking a sort with array reference problem

2005-01-21 Thread Edward Wijaya
Hi,
I am trying to benchmark these two sorting algorithms.
However running the script below:
$ perl thiscode.pl
gives:
Can't use an undefined value as an ARRAY reference at radix.pl line 23.
However the code execute smoothly with the normal usage.
Only when I use 'cmpthese' the problem occur.
Any idea?
Thanks so much beforehand.
--
Edward WIJAYA
Singapore
__BEGIN__
#!/usr/bin/perl -w
use strict;
use Benchmark 'cmpthese';
my @array = qw(flow loop pool Wolf root sort tour);
#The script runs ok if I remove this 'cmpthese' snippet
cmpthese (-5, {rad   => "radix_sort([EMAIL PROTECTED])",
   nsort => "basic_sort([EMAIL PROTECTED])"
  }
 );
my @thear = basic_sort([EMAIL PROTECTED]);
print "@thear\n";
sub basic_sort {
 my $array = shift;
 my @ar2;
   @ar2 = sort @{$array};  #This is line 23, but seems that this is not  
the problem
  return @ar2;
}

sub radix_sort {
my $array = shift;
my $from = $array;
my $to;
# All lengths expected equal.
for ( my $i = length ($array->[ 0 ]) - 1; $i >= 0; $i-- ) {
# A new sorting bin.
$to = [ ];
foreach my $card ( @$from ) {
# Stability is essential, so we use push().
push @{ $to->[ ord( substr $card, $i ) ] }, $card;
}
# Concatenate the bins.
$from = [ map { @{ $_ || [ ] } } @$to ];
}
# Now copy the elements back into the original array.
@$array = @$from;
}


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: Extracting and email address

2005-01-21 Thread Edward Wijaya
On Fri, 21 Jan 2005 10:47:33 +, Andrew Black  
<[EMAIL PROTECTED]> wrote:

Is there a module to extract the real email address from a header.  e.g.
Yes there is "Email::Find"
Why would you want to extract email addresses? Spamming?
--
Edward WIJAYA
Singapore
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: A second beginner's question

2005-01-15 Thread Edward Wijaya
On Fri, 14 Jan 2005 09:47:50 -0800, John W. Krahn <[EMAIL PROTECTED]> wrote:
Perl has a FAQ on shuffling, have you read that yet?
perldoc -q shuffle
or
use CPAN module: List::Util
it has a built in *shuffle* function.
--
Edward WIJAYA
Singapore
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: Choosing between Regexp and Substr

2005-01-06 Thread Edward Wijaya
Seems that John's regex approaches are (much) faster:

   Rate  HD_string HD_jkrahn2 HD_jkrahn1
HD_string  203251/s --   -18%   -76%
HD_jkrahn2 247033/s22% --   -71%
HD_jkrahn1 848840/s   318%   244% --

__BEGIN__
#!/usr/bin/perl -w
use Benchmark 'cmpthese';
my $a = '';
my $b = 'AAAB';
print hamming_distance_string($a,$b),"\n";
print hamming_distance_jkrahn1($a,$b),"\n";
print hamming_distance_jkrahn2($a,$b),"\n";
cmpthese (-5, {HD_string => "hamming_distance_string($a,$b)",
   HD_jkrahn1 =>"hamming_distance_jkrahn1($a,$b)",
   HD_jkrahn2 =>"hamming_distance_jkrahn2($a,$b)"});
sub hamming_distance_string {
#String length is assumed to be equal
my ($a,$b) = @_;
my $len = length ($a);
my $num_match=0;
for (my $i=0; $i<$len; $i++) { # assume that the lists are of same  
length
++$num_match if substr($a, $i, 1) eq substr($b, $i, 1);
}

#my $weight = $num_match/$len;
return $num_match;
}
sub hamming_distance_jkrahn1 { my $ret = ( $_[0] ^ $_[1] ) =~ tr/\0//;  
$ret }
sub hamming_distance_jkrahn2 { my $ret = () = ( $_[0] ^ $_[1] ) =~ /\0/g;  
$ret }
__END__


--
Edward WIJAYA
Singapore
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: Choosing between Regexp and Substr

2005-01-03 Thread Edward Wijaya
Thanks so much for the reply John,
On Mon, 03 Jan 2005 04:07:05 -0800, John W. Krahn <[EMAIL PROTECTED]> wrote:

I don't know if I am a master but I wouldn't use a regular expression.
In my eyes, you certainly is a master!
BTW, can you explain what's the difference between these two?
sub hamming_distance_string { ( $_[0] ^ $_[1] ) =~ tr/\0// }
sub hamming_distance_string { () = ( $_[0] ^ $_[1] ) =~ /\0/g }
PS: Thanks to Ted and Jenda for the response as well.
--
Edward WIJAYA
Singapore
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Choosing between Regexp and Substr

2005-01-02 Thread Edward WIJAYA
Dear friends,
After a couple of months dwelling into Perl scripting especially in  
manipulating strings, I found myself resorting to use "substr" function a  
lot.

I had a feeling that the most of the "substr" function can be replaced  
with regexp in any cases. For example the simple code below. I wonder how  
would masters redo this function with pure reqexp approach.

__BEGIN__
sub hamming_distance_string{
#String length is assumed to be equal
my ($a,$b) = @_;
my $len = length ($a);
my $num_match=0;
for (my $i=0; $i<$len; $i++) {
 ++$num_match if substr($a, $i, 1) eq substr($b, $i,1);
}
return $num_match;
}
__END__
Is it true that 'substr' function can be rewritten with regexp all the  
time? If so when is it better to use which? Any rule of thumb?

Hope to hear from you again. Thanks so much for your time.
And wishing you all a very Happy and Prosperous New Year 2005!
--
Regards,
Edward WIJAYA
Singapore
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: How to install Tk.pm,LWP.pm?

2004-12-15 Thread Edward WIJAYA
On 15 Dec 2004 11:15:59 -, Prabahar Mosas  
<[EMAIL PROTECTED]> wrote:



  
Dear All,
   How to install Tk.pm,LWP.pm?
  I am new to perl, I did't know how to add
module into perl. So if anybody know regarding my doubt.
Please Mail me in simple manner.  My Perl version is
5.8.4.
TK and LWP are built in modules you don't need to
install it. Just invoke it with -> use Tk; OR use LWP;
However  to install other modules,
if you are under Linux you do this:
$CPAN
then:
CPAN> install Module::Name
if you are under Windows-Command assumed you are using Active State:
Dos> PPM
then:
ppm> install Module-Name
HtH
--
Regards,
Edward WIJAYA
Singapore
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: basic search engine

2004-12-15 Thread Edward WIJAYA
On Wed, 15 Dec 2004 15:04:56 +0800, Khairul Azmi <[EMAIL PROTECTED]>  
wrote:

Hi,
Hello,
I am planning to write a simple search engine.
[snip]
Is there any module where I could simply plug into my problem to
enable this functinality. Thanks.
Maybe "Plucene" can be useful.
http://search.cpan.org/dist/Plucene/lib/Plucene.pm
It is a search engine in itself.
HtH
--
Regards,
Edward WIJAYA
Singapore
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: receiving input from different sources

2004-12-14 Thread Edward WIJAYA

On Tue, 14 Dec 2004 20:19:23 -0800 (PST), Christopher Spears  
<[EMAIL PROTECTED]> wrote:

I need to be able to receive input from the keyboard,
but  is being used to process a file and <> is
not appropiate for this purpose.

Consider using "Getopt" module.
perldoc Getopt::Long
perldoc Getopt::Std
Show us some script, so we can see the problem in more
concrete ways.
--
Regards,
Edward WIJAYA
Singapore
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: Currency Conversions

2004-12-10 Thread Edward WIJAYA
On Fri, 10 Dec 2004 20:48:31 -0600, Mike Blezien <[EMAIL PROTECTED]>  
wrote:

Hello,
Can some recommend a good Perl Module for converting pounds, euros, and  
yin to US dollars.

TIA,
You can try searching CPAN http://search.cpan.org
Just by typing "Currency Convert" you can find many.
Like:
http://search.cpan.org/~barbie/Finance-Currency-Convert-XE-0.06/lib/Finance/Currency/Convert/XE.pm
OR
http://search.cpan.org/~janw/Finance-Currency-Convert-1.04/Convert.pm
--
Regards,
Edward WIJAYA
Singapore
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: looking a one liner "to return the value while clearing the argument"

2004-12-10 Thread Edward WIJAYA
On Fri, 10 Dec 2004 09:48:26 -0500, Felix Li <[EMAIL PROTECTED]>  
wrote:

Is there "a one liner" that performs the equivalent of
sub ReturnAndClear {
   my $temp=$_[0];
   $_[0]=undef;
   return $temp;
};
Why would you need that?
While you just can simply use like:  $val = undef;
in the code?
--
Regards,
Edward WIJAYA
Singapore
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: Good examples of POD for newbies?

2004-12-09 Thread Edward Wijaya
On Thu, 09 Dec 2004 09:17:50 -0500, KEVIN ZEMBOWER <[EMAIL PROTECTED]>  
wrote:

Can anyone suggest a small module which demonstrate good usage of POD,  
to use as an example for someone who would like to write POD correctly  
for the first time?
Check this out:
http://www.perlmonks.org/?class=node_link;node_id=252477
Regards,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: I am looking for a free perl compiler.

2004-12-08 Thread Edward WIJAYA
On Wed, 8 Dec 2004 12:56:15 +0800, Xun Yu <[EMAIL PROTECTED]> wrote:
The problem is  I can only get a evaluate license for PDK-Pro-6.0,
so what I am looking for is a compiler more powerfull than perlcc,
and must be free.

I don't know if this is really what you want,
but you can try to look at CPAN's "PAR" module:
http://search.cpan.org/search?mode=module&query=PAR
--
Regards,
Edward WIJAYA
Singapore
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: removing line from a file

2004-12-02 Thread Edward WIJAYA

Hi,
Edward: Your script doesn't work, as you are only opening the file in
read mode.  Read/write doesn't do want you want either.
{Blushes} Thanks for the correction Jon.

If you want a quick'n'easy one liner, then use -i:
-i[extension]   edit <> files in place (makes backup if extension  
supplied)

Your one liner would look like:
perl -ne 'print unless /perl/' -ibak FILENAME
Glad I learnt yet another One-Liner.
--
Regards,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: removing line from a file

2004-12-02 Thread Edward WIJAYA
On Thu, 2 Dec 2004 21:45:28 +0530, Chandu B S <[EMAIL PROTECTED]> wrote:
hi experts
I am no experts, but I guess:
but i don't want to use 2 file ,
can i do this within the original file
Yeah just use FD only
open FD , "< /home/file1 " or die " Can't open file1 file : $!";
 while()
 {
print FD $_ unless ($_=~/perl/);
 }
close FD;
--
Regards,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: Learn 2 languages

2004-12-02 Thread Edward WIJAYA
On Thu, 2 Dec 2004 12:46:12 -, Murphy,  Ged (Bolton)  
<[EMAIL PROTECTED]> wrote:

A little OT, but I'm trying to learn 2 languages at once, C++ and perl.
Is this typically a good or bad idea?
I personally thinks this is rather a good idea.
Since a lot of syntax are common among them (maybe except the OO part).
However eventually it boils down to right tool
for right job.
Perl is for its ease of use (and many more!) and
C++ is chosen for for speed.
--
Regards,
Edward WIJAYA
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



the case of "-pe" and "-ne" swtich in Perl one liner

2004-12-02 Thread Edward WIJAYA
Hi,
I just realized (don't laugh) that
perl -pe 'do_sth;'
is equivalent to
perl -ne 'do_sth; print;'
I am just thinking why would we need '-ne'
in the first place, since we would
need to print the result anyway (at least in one-liner).
Can anybody suggest the case
where we *only* need '-ne' ?
--
Regards,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: Passing hashes as parameters to construct objects

2004-12-01 Thread Edward Wijaya
On Thu, 02 Dec 2004 16:20:17 +1100, Michael Kraus 
<[EMAIL PROTECTED]> wrote:

I've noticed a lot of modules can be initialised in the form:
my $instance = Module->new( option => "value1", option2 => "value2" )
How is this implemented?  Is the above simply passing a hash reference?
Any function, including new() can take parameters as an array or a hash,
then it can do whatever it wants with the hash, values,
just like it would with array values
Please also refer to Damian Conway's "Object Oriented Perl",
a very good introduction to what you are trying to achieve.
--
Regards,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: sorting with Swartz Transform

2004-11-28 Thread Edward WIJAYA
A very good lesson to learn Schwartzian Transform.
Thanks Gunnar!
--
Regards,
Edward WIJAYA
SINGAPORE
On Sun, 28 Nov 2004 09:36:26 +0100, Gunnar Hjalmarsson <[EMAIL PROTECTED]>  
wrote:


 I have code the performs the task, but it's a Swartzian Transform, a
temporary array, another swartz transform, and just feels icky.
 any suggestions to pretty this bloat ?
 my @unsorted = (
 '5 127.0.0.1',
 '10 127.0.1.1',
 '5 27.0.0.1',
 '6 10.0.0.1',
 '1 17.0.0.1',
 '5 209.0.0.1',
 );
 my @sorted = map { $_->[0] } sort {
  $a->[1] <=> $b->[1]
   ||
  $a->[2] <=> $b->[2]
   ||
  $a->[3] <=> $b->[3]
   ||
  $a->[4] <=> $b->[4]
   ||
  $a->[5] <=> $b->[5]
 } map { [ $_, split /[. ]/ ] } @unsorted;


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: Perl cant add up with sprintf ?

2004-11-25 Thread Edward WIJAYA
Hi Dave,
my $amount2 = 0013625;
As you pointed already.
0 is an octal constant
$amount = sprintf("%011d", $amount1 + $amount2);
and: printf "%d" casts to a signed int
unfortunately the printf interface doesn't give a good way to say "deal  
with this number, whether perl stored it as signed, unsigned, or floating  
point"

So I guess your best bet is to use: %f
though that doesn't give as much precision as %d/%u on some platforms/
HtH
--
Regards,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: How to finding sting in an array

2004-11-17 Thread Edward WIJAYA
perldoc perlfaq
On Wed, 17 Nov 2004 08:20:11 -0700, Bryan R Harris  
<[EMAIL PROTECTED]> wrote:


Mauro wrote:
I have to check if $mystring is an elemen of @myarray or not.
Which is the quickest way to do this?
That's a FAQ.
 perldoc -q contained

Where can I find a list of the FAQs in perldoc?  Seems most of my  
questions
are FAQs too...

- B



--
Regards,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: How to finding sting in an array

2004-11-17 Thread Edward WIJAYA
On Wed, 17 Nov 2004 14:54:13 +0100, Gunnar Hjalmarsson <[EMAIL PROTECTED]>  
wrote:

3) Why use a regexp at all?
 print 'Yes it exists' if grep $mystring eq $_, @myarray;
4) Why continue looping through the whole array when a matching element  
has been found?

 for (@myarray) {
 print 'Yes it exists' and last if $mystring eq $_;
 }
Thanks so much guys.
Glad I learnt those...
--
Regards,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: How to finding sting in an array

2004-11-17 Thread Edward WIJAYA
On Wed, 17 Nov 2004 16:35:58 +0530, Prasanna Kothari  
<[EMAIL PROTECTED]> wrote:

try using grep function.
perldoc -f grep
Yes correct, didn't think of that before.
@exist_elems = grep {/$mystring/} @array_orgn;
#note this is untested


--
Regards,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: How to finding sting in an array

2004-11-17 Thread Edward WIJAYA
On Wed, 17 Nov 2004 11:23:24 +0100, Mauro <[EMAIL PROTECTED]> wrote:
Hi all,
I have to check if $mystring is an elemen of @myarray or not.
Which is the quickest way to do this?
  foreach (@array)
{ if ($mystring) {
 print "Exist\n";
}
  }
Thank You
Mauro

--
Regards,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: Accessing elements of an array passed by reference

2004-11-15 Thread Edward Wijaya
On Mon, 15 Nov 2004 16:52:40 +1000, Johnstone, Colin  
<[EMAIL PROTECTED]> wrote:

Gidday all,
I wish to access the elements of an array passed by reference
#get deploy list
my @$deployList = $task->GetVariable('deployList');
foreach( @$deployList ){
  print; #$_ worked automatically
}
alternatively you can assign a variable
after foreach:
foreach my $var ( @$deployList ){
  print "$var\n";
 }
Please read- perldoc perlreftut
 perldoc perlvar
for additional info on those issues.
HoH
Regards,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Best place to put collection of subroutines in a program

2004-11-09 Thread Edward WIJAYA
Hi,
Would like to know, where is the best place to
put collection of subroutines in a Perl program,
is it after "main" or before? Any caveat?
--
Regards,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: how to pass array and variable

2004-11-09 Thread Edward WIJAYA
On Tue, 9 Nov 2004 09:28:10 -, Murphy,  Ged (Bolton)  
<[EMAIL PROTECTED]> wrote:

Ajey Kulkarni wrote:
Hmmm...Whenever you pass array AND a variable with array being first,
the  subroutine takes the variable and appends to array.
Make sure you pass var first,followed by array. There is no need to
complicate with the array ref IMHO.
What if you want to pass 2 or more arrays?
Will the proceeding arrays be appended to the previous?
Is this a case when you must pass by reference?
Yes, I have asked the same question.
Please refer to this link:
http://groups.google.com/groups?hl=en&lr=&threadm=opscakjbrtq79b6q%40mailhost.i2r.a-star.edu.sg&rnum=20&prev=/groups%3Fq%3Dedward%2Bwijaya%26start%3D10%26hl%3Den%26lr%3D%26group%3Dperl.beginners.*%26selm%3Dopscakjbrtq79b6q%2540mailhost.i2r.a-star.edu.sg%26rnum%3D20
Regards,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: simple hash question

2004-11-08 Thread Edward Wijaya
use Tie::IxHash module from CPAN, to preserve order in a Hash.
Regards,
Edward WIJAYA
SINGAPORE
On Tue, 09 Nov 2004 03:06:03 +0800, Edward Wijaya <[EMAIL PROTECTED]>  
wrote:

On Mon, 8 Nov 2004 11:59:13 +0100, Ing. Branislav Gerzo <[EMAIL PROTECTED]>  
wrote:

Hi pals,
I have simple hash question, lets we have example code:
my %hash = ( 1 => 2, 2 => 3, 3 => 4, 4 => 5 );
while (my($key, $value) = each(%hash)) { print "$key => $value\n"; }
how I can print all values, if I want print that in this order:
2 => 3
4 => 5
3 => 4
1 => 2
thanks for any ideas.
--
 --. ,--  ,- ICQ: 7552083  \|||/`//EB: www.2ge.us
,--' |  - |--IRC: [2ge](. .),\\SN: 2ge!2ge_us
`+==+=+===~  ~=-o00-(_)-00o-~
Second childhood?  I haven't finished the first one.





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: simple hash question

2004-11-08 Thread Edward Wijaya
On Mon, 8 Nov 2004 11:59:13 +0100, Ing. Branislav Gerzo <[EMAIL PROTECTED]>  
wrote:

Hi pals,
I have simple hash question, lets we have example code:
my %hash = ( 1 => 2, 2 => 3, 3 => 4, 4 => 5 );
while (my($key, $value) = each(%hash)) { print "$key => $value\n"; }
how I can print all values, if I want print that in this order:
2 => 3
4 => 5
3 => 4
1 => 2
thanks for any ideas.
--
 --. ,--  ,- ICQ: 7552083  \|||/`//EB: www.2ge.us
,--' |  - |--IRC: [2ge](. .),\\SN: 2ge!2ge_us
`+==+=+===~  ~=-o00-(_)-00o-~
Second childhood?  I haven't finished the first one.



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



Installing modules in Windows through -MCPAN and "nmake" problem

2004-11-07 Thread Edward WIJAYA
Hi,
I am trying to install a module "Template::Extract"
through this command
C:> perl -MCPAN -e shell "install Template::Extract"
Since I can't find that(latest) modules in ActivePerl's PPM.
But somehow, I still fail to make install the module,
this are the error message I encontered:
  C:\Program Files\Microsoft Visual Studio\VC98\bin\nmake.EXE  -- OK
Running make test
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
  C:\Program Files\Microsoft Visual Studio\VC98\bin\nmake.EXE test -- NOT  
OK
Running make install
  make test had returned bad status, won't install without force
-

Even if I use "force install" I will still encounter the same message
Please advice how can I solve this.
Thanks so much for your time.
--
Regards,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: Getting perl to work on windows 98 se

2004-11-06 Thread Edward Wijaya
On Sat, 6 Nov 2004 22:15:43 -0800 (PST), mark McWilliams  
<[EMAIL PROTECTED]> wrote:


Where should I look?
There is a bin folder created when I tried to load
perl but it does not have any subfolders in it.
Yes, the are usually stored under C:/Perl/bin

I can not find any /usr folder in the installed perl
folder
Windows doesn't have /usr folder they have
different file systems
At school my scripts start with #! /usr/bin/perl -w
for   warnings errors which I have a lot of. :[
In windows, you still can keep  #! /usr/bin/perl -w
in factyou are adviced to keep -w and add "use strict"

None of the scripts that I know work on my schools
network work on my computer at all.
Try to set the environment in Windows, so that
the command line can access the intrepeter anytime.
I was told that it has to do with the registry but I
was not able to get any specific ideas or help.
As adviced
ANY help is very much welcome.
Thank you very much for all of your time and effort.
No problem.
Regards,
Edward WIJAYA
SINGAPORE


__
Do you Yahoo!?
Check out the new Yahoo! Front Page.
www.yahoo.com


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: how to pass array and varaible

2004-11-05 Thread Edward Wijaya
sub mysub {
my ($var, @array) = @_;
   my @new_array = ();
   #do sth to @array or $var;
   return @new_array;
}
read - perldoc perlsub
Regards,
Edward WIJAYA
On Sat, 6 Nov 2004 12:48:26 +0530, Anish Kumar K.
<[EMAIL PROTECTED]> wrote:
Hi
I want to pass a array and and a varaible to a subroutine and then some  
processing will be done at the subtroutine and the array should be  
returnedPlease help me in trying to figure out...

Thanks
Anish
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: Populating HASH from file

2004-10-25 Thread Edward WIJAYA
Hi,
Mine is not as elegant as J.Krahn's or Jeff's.
But it's an alternative.
I am just glad to contribute at least something
to the forum I have owed so much...
--
Regards,
Edward WIJAYA
SINGAPORE
---
use strict;
use warnings;
use Data::Dumper;
my %hash = ();
while () {
s/\s//g;
/(\w+)=(\w+)/;
$hash{$1} = $2;
}
print Dumper \%hash;
__DATA__
One = Hana
Two = Dool
Three = Set
--
output:
$VAR1 = {
  'Three' => 'Set',
  'Two' => 'Dool',
  'One' => 'Hana'
};
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: Howto reverse SortByValue with Tie::IxHash

2004-10-02 Thread Edward Wijaya
On Sat, 2 Oct 2004 08:53:02 -0500, Charles K. Clarkson  
<[EMAIL PROTECTED]> wrote:

This is a tough one. You need to supply a list of keys
to the Reorder() method. Getting the list of keys already
sorted by value may not be apparent to a beginner.

   $t->Reorder( reverse $t->SortByValue()->Keys() );
Thanks so much for your explanation and understanding, Clark.
I get it now.
Also thanks for your correction, Gunnar.
I know I've been rather annoying to you guys
lately...Thanks for bearing with it ... :-)
I will keep it mind your suggestions.
Gratefuly yours,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Howto reverse SortByValue with Tie::IxHash

2004-10-02 Thread Edward Wijaya
Hi,
I have a problem using Tie::IxHash.
My question is how can I sort the hash
by value in descending order.
I tried this to get the descending order,
but doesn't seem to work:
__BEGIN__
my %hash =(
   '1-1' => 3,
   '2-3' => 2,
   '2-2' => 1,
   '1-2' => 6,
   '1-3' => 3
 );
my $t = Tie::IxHash->new(%hash);
$t->SortByValue;  # ascending, ok!
$t->$hash{$b}<=>$hash{$a}SortByValue; #tried this but doesn't work
__END__
Can anybody advice how to go about this?
Thanks beforehand.
Regards,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: Problem with subroutines with hash and var as input

2004-10-02 Thread Edward Wijaya
On Sat, 02 Oct 2004 01:46:01 -0700, John W. Krahn <[EMAIL PROTECTED]> wrote:

there is an extra $ in there, it should be:
67: delete $HoH->{ $k } if keys %{ $HoH->{ $k } } < $limit;
Thanks a lot John.
Now it's ok.
RegardS,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: Problem with subroutines with hash and var as input

2004-10-01 Thread Edward Wijaya
On Fri, 01 Oct 2004 08:58:44 -0700, John W. Krahn <[EMAIL PROTECTED]> wrote:
Since $HoH now contains a reference to a hash you have to dereference it  
properly.
 delete $HoH->{ $k } if keys %${ $HoH->{ $k } } < $limit;
 return %$HoH;

I apologize for insisting John.
Tried as you suggested:
64: sub reduce_hash2 {
65:my ($HoH,$limit) = @_;
66:foreach my $k ( keys %${HoH} ) {
67: delete $HoH->{ $k } if keys %${ $HoH->{ $k } } < $limit;
68:}
69:   return %$HoH;
70: }
with this command:
my %new_hoh = reduce_hash2(\%hoh,2);
Gives error:
Not a SCALAR reference at testcode.pl line 67.
Regards,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: Problem with subroutines with hash and var as input

2004-10-01 Thread Edward Wijaya
On Fri, 01 Oct 2004 07:41:43 -0700, John W. Krahn <[EMAIL PROTECTED]> wrote:
Thanks,
No need for $count or the second for loop:
John, your one-liner certainly makes my sub
looks better.
Either put the scalar first in the list or pass a reference to the  
original hash.
Now, I also tried with pass by reference
  my ($HoH,$limit) = @_;
foreach my $k ( keys %$HoH ) {   # This two  
don't work
 delete $HoH{ $k } if keys %${ $HoH{ $k } } < $limit;# What's  
wrong with my deref?
}
   return %HoH;

What's wrong with my deref?
Regards
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: How to accumulate Hashes of Array value with the same key?

2004-10-01 Thread Edward Wijaya
On Fri, 1 Oct 2004 10:51:50 -0400, Dave Gray <[EMAIL PROTECTED]> wrote:
$HoA = ( key1 => [
  ['A',1], ['B',2], ['C',3]
]);
Which is clunky when you want to detect duplicates, which is why I
suggested the hash.

I think you are right Dave.
I will follow your suggestion.
Regards,
Edward WIJAYA
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Problem with subroutines with hash and var as input

2004-10-01 Thread Edward Wijaya
Dear Sirs,
I have the following code, that
take Hash of Hash as an iput.
Then I have function (see below) that takes
a hash and a variable as input.
This function will count the elements
of secondary hashes and delete the hash,
if it is below certain variable limit.
So with this :
my %new_hoh = reduce_hash(%hoh,3);
it should return
my %hoh = (
key2 =>  {A => 'foo',
  B => 'bar',
  C => 'qux'}, );
But my subroutine doesn't work as it should.
Is there anything wrong with it?
Yours again,
Edward WIJAYA
SINGAPORE
__BEGIN__
use strict;
use warnings;
use Data::Dumper;
my %hoh = (
key1 =>   {   A => 'foo',
  B => 'bar',},
key2 =>  {A => 'foo',
  B => 'bar',
  C => 'qux'},
  key3 =>  {A => 'foo',}
   );
my %new_hoh = reduce_hash(%hoh,3);
print Dumper \%new_hoh;
#---Subroutine that do the job---
sub reduce_hash {
my (%HoH,$limit) = @_;
foreach my $k ( keys %HoH ) {
my $count = 0;
for my $k2 ( keys %{ $HoH{$k} } ) {
$count++;
  }
  if ($count < $limit){
  delete $HoH{$k};
}
}
   return %HoH;
}
__END__
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: How to accumulate Hashes of Array value with the same key?

2004-10-01 Thread Edward Wijaya
On Thu, 30 Sep 2004 14:23:47 -0300, Shaw, Matthew <[EMAIL PROTECTED]>
wrote:
Thanks Matt,

> my %HoA = (key1 => ['A',1]);
> my %HoA2 = (key1 => ['B',2]);
> my %HoA3 = (key1 => ['C',2]);
>
> into:
>
Only this one works
push @{$HoA{key1}}, ( @{$HoA2{key1}}, @{$HoA2{key1}});

Not this
Sorry this should read:
@{$HoA{key1}}, ( @{$HoA2{key1}}, @{$HoA3{key1}});
However what it gives is that it create one single array,
and not preserving the array that group ['A',1] etc, like before
namely:
print Dumper \%HoA;
$VAR1 = {
   'key1' => [
   'A',
   1,
   'B',
   2,
   'C',
       2
 ]
 };
not;
$VAR1 = { 'key1' => ['A',1],['B',2],['C',2]};
Regards,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: How to accumulate Hashes of Array value with the same key?

2004-10-01 Thread Edward Wijaya
On Thu, 30 Sep 2004 17:03:40 -0400, Dave Gray <[EMAIL PROTECTED]> wrote:
I'm not sure what you want to do here... do you want to combine all
the values into one array reference, stored in $HoA{key1}?
As you mention above. That is exactly what I mean:
This sounds like it's part of a bigger question. Can you give us some
more background info?
What I am trying to do is to accumulate, every new HoA generated
into existing HoA, and join the values if they have the same key.
Dave

Regards,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



How to accumulate Hashes of Array value with the same key?

2004-09-30 Thread Edward Wijaya
Hi,
I have thre HoAs with the same key but different value.
How can I efficiently join the HoA:
my %HoA = (key1 => ['A',1]);
my %HoA2 = (key1 => ['B',2]);
my %HoA3 = (key1 => ['C',2]);
into:
%HoA = (key1 => ['A',1],['B',2],['C',2]);
namely accumulating the value of HoA2,HoA3 into  HoA.
Thanks very much for the time.
Regards,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: Problem iterating over diamond (while)

2004-09-29 Thread Edward Wijaya
On 29 Sep 2004 14:06:33 -, Peter Scott <[EMAIL PROTECTED]> wrote:
Nitpick - the "diamond operator" is <>.  
would be use of the "readline operator".
Thanks for making it precise Peter.
Glad that I learnt that.
Forgive me for my limited Perl vocabulary.
Regards,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: How to access first key of "Hash of Hash"

2004-09-29 Thread Edward Wijaya
On 29 Sep 2004 15:20:39 +0100, Jose Alves de Castro  
<[EMAIL PROTECTED]> wrote:


for (keys %HoH) {
  print "$_\n";
}
It seems so. Thanks a lot.
I thought 'keys' are only for simple hash.
Regards,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: How to access first key of "Hash of Hash"

2004-09-29 Thread Edward Wijaya
On 29 Sep 2004 14:58:00 +0100, Jose Alves de Castro  
<[EMAIL PROTECTED]> wrote:
If I understood this correctly, you want to do this:
So sorry for being not clear.
I will extend just a bit.
Suppose I have:
my %HoH = (
   firstkey => { A => 'blabla',
 B => 'dadada',
 C => 'tititi',}
   secondkey => { D => 'blabla',
  E => 'dadada',
  F => 'tititi',}
   );
and I generated that HoH with this:
$HoH{$fkey}{$alpha}=$text;
namely:
"firstkey, secondkey" from $fkey
"A, B, C, etc"from $alpha
"blabla etc"  from $text
my question is how can I print output like:
firstkey
secondkey
given the construction variables as mention before.
Thanks
Regards,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



How to access first key of "Hash of Hash"

2004-09-29 Thread Edward Wijaya
Hi,
I have this HoH:
my %HoH = (
   firstkey => { A => 'blabla',
 B => 'dadada',
 C => 'tititi',}
   );
generated with
$HoH{$fkey}{$alpha}=$text;
how can I access the value
of the first key, so that it gives: "firstkey"
I tried this with no avail:
print "$HoH{$fkey}\n"

Regards,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



How to find if a key exist in hash?

2004-09-29 Thread Edward Wijaya
Hi,
I have the following code,
and I know it is HORRIBLE.
I wonder if I can do it in more
efficient and elegant way?
Thanks so much
and
Regards,
Edward WIJAYA
SINGAPORE
__BEGIN__
use strict;
use warnings;
use Getopt::Std;
use Data::Dumper;
my %hash = (
  A => 'blabla',
  B => 'dadada',
  C => 'tititi',
   );
my $s = 'A';
my $get = check_ifHash_key_exist(\%hash, $s);
print "Got it: $get\n";
#--- this is how I do it (don't laugh) --
 sub check_ifHash_key_exist {
 my ($hash, $str) = @_;
 my $found_str;
 my @array = keys %{$hash};
 for (my $i= 0; $i < keys %{$hash}; $i++) {
   if ($array[$i] eq $str) {
   $found_str = $array[$i];
   last;
   }
}
 return $found_str;
 }
__END__
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: Problem iterating over diamond (while)

2004-09-28 Thread Edward Wijaya
Many many thanks Bob!
Glad to know I can do it in one-line.
   for ( ...blah... ) {
   seek(INFILE, 0, 0);   # <--- rewind file back to start
   while () {...
   }
   }

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



Re: Problem iterating over diamond (while)

2004-09-28 Thread Edward Wijaya
Thanks a lot for your reply Bob.
but can you be more specific:
You need to either close and reopen the file, or
rewind the file using seek() before you can re-read the data.

I tried seek() following "perldoc" like this:
__BEGIN__
for ( my $t = 1 ; $t <= $trial ; $t++ )
  {
for ( $curpos = tell(INFILE); $_ = ;
$curpos = tell(INFILE))
  { print "Trial ", $t, "\n";
while () {
   print;}
  }
   seek(INFILE, $curpos, 0);
}
but doesn't seem to work.
Also tried to  close and 'reopen'.
Doesn't seem to work as well.
__BEGIN__
for ( my $t = 1 ; $t <= $trial ; $t++ )
  {
print "Trial ", $t, "\n";
  while () {
   print;}
  }
close INFILE;
open INFILE; #is this how you reopen?
__END__
Hope you don't mind to elaborating it.
Thanks again.
Regards
Edward WIJAYA
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Problem iterating over diamond (while)

2004-09-28 Thread Edward Wijaya
Hi,
Suppose I have a data file that contain these lines:
output1
output2
when I run the code below
with: perl mycode.pl -f datafile
it gives:
Trial 1
output1
output2
Trial 2
instead of:
Trial 1
output1
output2
Trial 2
output1
output2
Can we actually loop over the 'while diamond'?
Please kindly advice how can I overcome this problem.
Thanks so much for your time.
Regards,
Edward WIJAYA
SINGAPORE
__BEGIN__
use strict;
use warnings;
use Getopt::Std;
our $opt_f;
getopts('f:');
open INFILE, "<$opt_f" or die "$0:  Can't open file $opt_f: $!";
my $trial = 2;
#What's wrong with running a for loop over the 'while' here?
for ( my $t = 1 ; $t <= $trial ; $t++ ) {
print "Trial ", $t, "\n";
while () {
print;
}
}
__END__
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Opening file($ARGV) with Getopt - failing

2004-09-28 Thread Edward Wijaya
Hi,
Why my code below fail to open and
print the file contents
when I do:
perl mycode.pl -f filename
Regards,
Edward WIJAYA
SINGAPORE
__BEGIN__
use strict;
use warnings;
use Getopt::Std;
use vars qw($f);
getopts('f:');
my  $f = $ARGV[0];
open ( INFILE, '<', $f)
or die "$0 : failed to open input file $f : $!\n";
close ( INFILE );   
while ( <> )
{
print $_;
}   
__END__ 
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



How to return 'k'-cliques in a graph

2004-09-24 Thread Edward WIJAYA
Dear all,
I have a following code that find
a "k-clique" within a graph.
k-Clique is a complete subgraph of size 'k'.
(Please see the attached picture).
Currently running this code gives:
$ perl graph.pl 3
5 6 9
$ perl graph.pl 4
1 2 3 4
As you can see the code below only return the
"last" k-clique found.
My question is how can I modify my code below
so it can store and then returns all the "k-clique" found?
That is:
$ perl graph.pl 3
would give:
1 2 3
1 2 4
1 3 4   
2 3 4
5 6 9
Thanks so much for your time.
Regards,
Edward WIJAYA
SINGAPORE

__BEGIN__
#! /usr/local/bin/perl
use warnings;
@V = (1, 2, 3, 4, 5, 6, 7, 8, 9); #vertices
@E = ([1,2], [1,3],[1,4], [2,3], [2,4],
[3,4],[1,5],[5,6], [5,9] ,[5,7],[7,8],[8,9],[6,9]); #Edges
[EMAIL PROTECTED] = ([1,2], [1,3],[1,4], [1,5], [5,4]);
$k = shift || 3;
#Construct a string as follows:
$string = (join ',' => @V) .  ';'
. (join ',' => map "$_->[0]-$_->[1]", @E);
#Then construct a regular expression as follows:
$regex = '^ .*\b '
   . join(' , .*\b ' => ('(\d+)') x $k)
   . '\b .* ;'
   . "\n";
for ($i = 1; $i < $k; $i++) {
for ($j = $i+1; $j <= $k; $j++) {
$regex .= '(?= .* \b ' . "\\$i-\\$j" . ' \b)' . "\n";
}
}
#graph contains a k-clique if and only if
if ($string =~ /$regex/x) {
print join(" ", map $$_, 1..$k), "\n";
}
__END__<>-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Re: compare the content of a hash

2004-09-17 Thread Edward WIJAYA
perldoc -q hash compare
On Fri, 17 Sep 2004 10:20:14 -0700 (PDT), Budi Santosa 
<[EMAIL PROTECTED]> wrote:

Hi All,
I have a problem like this. Suppose I access a web and
save the head line new and summary of this web as a
hash.
For the next access to the same web, before saving the
news I have to check if the same news already in my
database.What is the best way to compare our databasse
and the most recent head line news that I just got
from the web?
thanks,
Budi


___
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com

--
Regards,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: String to Numeric of an Array

2004-09-14 Thread Edward WIJAYA

If you treat the elements of the array as numbers,
won't things Just Work ?

Thanks a lot for the reply.
The reason I asked this because, in one
of my regex operation I doubted that the
results are correct. Turns out that I am wrong :(
I guess I am still living in C-world.
I am terribly sorry to have asked
such a trivial question.
Regards,
Edward WIJAYA
SINGAPORE

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



String to Numeric of an Array

2004-09-14 Thread Edward WIJAYA
Hi,
How can I change the value of this array:
@array = ['1','2','3']; #which contain "string" numeric
to
@arrayNum = [1,2,3];  #as pure numeric
Regards,
Edward WIJAY
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: How to dynamically taking the multiple input arguments?

2004-09-10 Thread Edward WIJAYA
Hi John,
I tried your code.
But I still cannot remove the whitespace from each line.
Suppose I have two files.
fileA.txt:fileB.txt:
A B
A B
What I get is:
A B
A B
instead of
AB
AB
I tried to play around with this
section of your code but of no avail.
# clean up whitespace
for ( @data ) {
 s/^\s+//;
 s/\s+/ /g;
 s/ $/\n/;
 }
Hope to heare from you again.
Regards
Edward WIJAYA
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



How to dynamically taking the multiple input arguments?

2004-09-10 Thread Edward WIJAYA
Hi,
I have a simple code that take
currently fixed to take 3 input files and
append each line of these files together.
I wish to know is there anyway I can
write the code more flexibly so it can
dynamically take the input argument - from minimum
2 files to more.
Is there anywhere I can find information
about dealing with this matter? Any specific
module that cater this problem?
Thanks for your time beforehand.
Regards,
Edward WIJAYA
SINGAPORE
This is my current (terribly inefficient
and unflexible) code:
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
if(scalar @ARGV ne 1)
{
print "Usage: $0 file1 file2 [file3] etc\n";
exit(1);
}
#the above part doesn't seem to be working well/useful
my $file1 = $ARGV[0];
my @set1 = get_file_data("$file1");
#Remove the whitspace and \n from each lines
@set1 = grep { s/^\s+//; s/\s+$//; s/\s+/ /g; length } @set1;
my $s1 = [EMAIL PROTECTED];
my $file2 = $ARGV[1];
my @set2 = get_file_data("$file2");
@set2 = grep { s/^\s+//; s/\s+$//; s/\s+/ /g; length } @set2;
my $s2 = [EMAIL PROTECTED];
my $file3 = $ARGV[2];
my @set3 = get_file_data("$file3");
@set3 = grep { s/^\s+//; s/\s+$//; s/\s+/ /g; length } @set3;
my $s3 = [EMAIL PROTECTED];

#Printout the appended lines from the data
print map { join("",$set1[$_],$set2[$_],$set3[$_]), "\n" } (0..$#set1);

#Subroutine
sub get_file_data {
my ($filename) = @_;
use strict;
use warnings;
# Initialize variables
my @filedata = ();
unless ( open( GET_FILE_DATA, $filename ) ) {
print STDERR "Cannot open file \"$filename\"\n\n";
exit;
}
@filedata = ;
close GET_FILE_DATA;
return (@filedata);
}
___END
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: Splicing Hash problem - possible with "map"?

2004-09-06 Thread Edward WIJAYA
Hi,
Thanks so much for the replies.
If you literally mean "starts with '1'", i.e., you don't know
any more about the key,
Yes I literally mean "1" not "10", "100", etc.
Just thought whether it is possible to do
it with "map" function? Make it into one-liner?

then first you must find the key, or
use, say, Tie::Has::Regex from CPAN.
I will install that package. Thanks again.
Regards,
Edward WIJAYA
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Splicing Hash problem

2004-09-06 Thread Edward WIJAYA
Hi,
If I have this hash:
%myhash = {
  '4 atc' => 'TGCGCatcGA',
  '5 ctg' => 'AGctgTGTTT',
  '3 NO MOTIF' => 'TCCGTGCGCT',
  '1 NO MOTIF' => 'ATGGTTAGGG', #need to splice this
  '2 caa' => 'GAAGcaaGGC'
};
How can I take out/splice(?) the element of that hash
that start with '1' and store it into another
hash. So in the end I will have two hashes:
%myNEWhash = {  '1 NO MOTIF' => 'ATGGTTAGGG'};
and the current becomes:
%myhash = {
  '4 atc' => 'TGCGCatcGA',
  '5 ctg' => 'AGctgTGTTT',
  '3 NO MOTIF' => 'TCCGTGCGCT',
  '2 caa' => 'GAAGcaaGGC'
};
Thanks so much for your time.
Regards,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: Inserting short strings into longer strings -- strncpy in Perl?

2004-09-03 Thread Edward WIJAYA

@array3 indicates the string was to overwrite at a
random position. I assume the entire string must be inside
the result.

Yes, you are right Charles.
And thanks so much too for Gunnar and Jeff.
Best,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Where to get Math-TrulyRandom for PPM?

2004-09-03 Thread Edward WIJAYA
Hi,
I've tried all the repositories
as suggested by Active State documentation,
including Jenda's repository.
But I always encounter error message
"Fail to download..."
Hope to hear from you guys again.
Regards
Edward WIJAYA
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Inserting short strings into longer strings -- strncpy in Perl?

2004-09-02 Thread Edward Wijaya
Hi,
Suppose I have these two arrays:
@arr1 =('GATGGATTAAAGGAGAGGTACTTACAGG',
'CGCCCAAGAGGCCAGAGCGGAGCA',
'CGTTAATGCATTAAAGTTCT');
   @arr2 = ('tcctcta',
'aggccac',
'agctgcg');
Is there any efficient way to copy each element
of @arr2 as part of each elements in @arr1
such that it gives result:
@arr3 =('GAtcctctaAAGGAGAGGTACTTACAGG',
'CGCCCAAGAGGCCAGaggccacCA',
'CGTTAAagctgcgAAGTTCT');
#the starting position to be copied to in @arr1 can is random.
Thanks for your time.
Regards,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Re: I want to compile my perl code!

2004-08-30 Thread Edward Wijaya
perl -c par.pl
On Mon, 30 Aug 2004 15:49:37 +0800, pagoda <[EMAIL PROTECTED]> wrote:

I want to compile my perl code, and I tried "perlcc" and "par.pl".
I don't know which one is more powerful?
It seems that both they are not very good.

Give me a hand please.
Thanks.

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



  1   2   >