Re: Help With signals. Got it working Thanks.

2006-01-06 Thread Leif Ericksen
This is the person that gave me the direction I needed to get my signals
working.. (Sorry for the top post here...  I wanted the most important
part out first..)

For the actual FULL code that I am working with at present see the
bottom of the message.

On Sat, 2006-01-07 at 01:14 +0100, John Doe wrote:
> Leif Ericksen am Samstag, 7. Januar 2006 00.12:
> > On Fri, 2006-01-06 at 15:58 -0700, Wiggins d'Anconia wrote:
> > > Please bottom post...
> > >
> > > Leif Ericksen wrote:
> > > > Actually not quite what you thought on the output...
> > > > $ ./myt.pl
> > > > ZERO:0   => SIG{'ZERO'} = &sigcat
> > > > HUP:1=> SIG{'HUP'} = &sigcat
> > > > INT:2=> SIG{'INT'} = &sigcat
> > > > QUIT:3   => SIG{'QUIT'} = &sigcat
> > > > ILL:4=> SIG{'ILL'} = &sigcat
> > > > TRAP:5   => SIG{'TRAP'} = &sigcat
> > > > ABRT:6   => SIG{'ABRT'} = &sigcat
> > > > BUS:7=> SIG{'BUS'} = &sigcat
> > > > FPE:8=> SIG{'FPE'} = &sigcat
> > > > KILL:9   => SIG{'KILL'} = &sigcat
> > >
> > > Ah yep missed the double quotes.
> > >
> > > > Also if I use the double quote as opposed to a single quote in:
> > > > SIG{'$name'} = \&sigcat;
> > >
> > > The above should be:
> > >
> > > $SIG{$name} = \&sigcat;
> >
> > That causes...
> > ./myt.pl
> > ZERO:0   => SIG{'ZERO'} = &sigcat
> > Segmentation fault
> 
> perldoc perlipc states:
> 
> "Another interesting signal to send is signal number zero.  
> This doesn't actually affect a child process, but instead 
> checks whether it's alive or has changed its UID."
> 
> I'm not a signal guru, but I think you can't assign a handler to the ZERO 
> signal. I also got a segfault.
> 
> Look at the following code, modified from yours.
> 
> BTW, your chances for answers are bigger if you provide code that can be run 
> by list members.
> 
> #!/usr/bin/perl
> use strict;
> use warnings;
> 
> use Config;
> 
> my $i = 0;
> my (@signames, %signos); 
> 
> defined $Config{sig_name}
>   or
>   die "The Stupid System does not support Signals?";
> 
> sub sigcat {print "sigcat called"; exit;};
> 
> foreach my $name (split(' ', $Config{sig_name})) {
>next if $name eq 'ZERO';  
>$signos{$name} = $i; 
>$signames[$i] = $name;
>print "$name:$i \t => SIG{$name} = \&sigcat\n"; 
>$SIG{$name}=\&sigcat;  
>$i++;
> }
> 
> {} while 1;
> 
> 
> 
> hth joe
> 

Changing the variable name signame to signames, seemed to be the big key
in making things work better...  Also to avoid the 0 issue we should be
able to start our counter at 1.  Now I know that I have more CASE
variables than may be require, but I am messing around with this to have
some fun and work on some projects that are both personal and business
in nature. I think the big thing is that signame must be in the Config
and it did not like being used as I was trying to use it.  Thanks to the
two Gents that offered help!  I will be back if I have additional
questions as I grow this program.

#!/usr/bin/perl
use strict;
use warnings;

use Config;

my $i = 0;
my (@signames, %signos); 

defined $Config{sig_name}
  or
  die "The Stupid System does not support Signals?";

sub sigcat {print "sigcat called"; exit;};

foreach my $name (split(' ', $Config{sig_name})) {
   next if $name eq 'ZERO';  
   $signos{$name} = $i; 
   $signames[$i] = $name;
   print "$name:$i \t => SIG{$name} = \&sigcat\n"; 
   $SIG{$name}=\&sigcat;  
   $i++;
}

{} while 1;


-- 
Leif Ericksen <[EMAIL PROTECTED]>


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




Re: Need some help and direction

2006-01-06 Thread JupiterHost.Net



Daniel Gladstone wrote:
I thought this would be easy but I can not get it to work - can someone 
please help me:


Problem: I have a file of 7.5 million records that are pipe delimted, 
the first field is a record
number. I want to search for around 10 records with a specific record 
number and if they
meet that condition, output them to a secondary output. And if it does 
not meet the record

number criteria, output to the primary output.

Code so far(Please don't laugh - I am a newbie)


You used -w and strict, thats awesome!!! I might recommend Damian 
Conway's "Perl Best Practices" to help you get started on the right foot :)



#!/usr/bin/perl -w
use strict;
# pullbad filename fieldtocount
die "usage: count   \n" unless (@ARGV == 2);
my ($filename, $cntfldnum) = @ARGV;
$cntfldnum--; # zero-base fldnum
my $records = 0; # count records processed

open(IN, $filename) or die "could not open $filename $!\n";
my %count = (); # hash the count key and value here
while () {
 $records++;
 my @rec=split(/\|/,$_);
 #$count{$rec[$cntfldnum]}++;
 if ($rec[$cntfldnum] =~ m/\D/g) {
print STDERR $rec[$cntfldnum] . " -> " . $rec[0] . " record # = " . 
$records . "\n";

 }


So what seems to be the trouble?

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




Need some help and direction

2006-01-06 Thread Daniel Gladstone
I thought this would be easy but I can not get it to work - can someone 
please help me:


Problem: I have a file of 7.5 million records that are pipe delimted, the 
first field is a record
number. I want to search for around 10 records with a specific record number 
and if they
meet that condition, output them to a secondary output. And if it does not 
meet the record

number criteria, output to the primary output.

Code so far(Please don't laugh - I am a newbie)

#!/usr/bin/perl -w
use strict;
# pullbad filename fieldtocount
die "usage: count   \n" unless (@ARGV == 2);
my ($filename, $cntfldnum) = @ARGV;
$cntfldnum--; # zero-base fldnum
my $records = 0; # count records processed

open(IN, $filename) or die "could not open $filename $!\n";
my %count = (); # hash the count key and value here
while () {
 $records++;
 my @rec=split(/\|/,$_);
 #$count{$rec[$cntfldnum]}++;
 if ($rec[$cntfldnum] =~ m/\D/g) {
print STDERR $rec[$cntfldnum] . " -> " . $rec[0] . " record # = " . 
$records . "\n";

 }



Daniel Gladstone
Email: [EMAIL PROTECTED]



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




Re: new for reading file containing multiple records

2006-01-06 Thread Wijaya Edward

Hi,

I would suggest you use the built-in BioPerl method for reading 
fasta (or other) format, for example:

sub get_sequence_from_fasta
{
#designed for getting sequences into array from a file  (fasta format),
#input: file name

   use Bio::SeqIO;

my $file = shift;
my @seqs= ();

open INFILE, "<$file" or die "$0:  Can't open file $file: $!";
my $in = Bio::SeqIO->new(-format => 'fasta',
 -noclose => 1 ,
 -fh => \*INFILE);

while ( my $seq = $in->next_seq() ) {
push @seqs, $seq->seq();
} #end while

return [EMAIL PROTECTED];
}

Hope that helps.

Regards,
Edward WIJAYA

- Original Message -
From: chen li <[EMAIL PROTECTED]>
Date: Saturday, January 7, 2006 9:27 am
Subject: Re: new for reading file containing multiple records

> Hi Shawn,
> 
> I use the your code to do the job:
> 
> #!/usr/bin/perl
> 
> use strict;
> use warnings;
> use Data::Dumper;
> my $filename='sequence.fasta';
> open (DATA,$filename) or die;
> 
> {local $/ = '>';
> while(  ){
>   print Dumper \$_;
>  }
> }
> exit;
> 
> 



--
This email is confidential and may be privileged.  If you are not the intended 
recipient, please delete it and notify us immediately. Please do not copy or 
use it for any purpose, or disclose its contents to any other person. Thank you.
--

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




Re: new for reading file containing multiple records

2006-01-06 Thread chen li
Hi Shawn,

I use the your code to do the job:

#!/usr/bin/perl

use strict;
use warnings;
use Data::Dumper;
my $filename='sequence.fasta';
open (DATA,$filename) or die;

{local $/ = '>';
while(  ){
   print Dumper \$_;
  }
}
exit;


And I get the following output:

$VAR1 = \'>';
$VAR1 = \'gi|618748|dbj|D21618.1| MUS74F01 mouse
embryonal carcinoma cell line F9 Mus musculus cDNA
clone 74F01, mRNA sequence
GCTGCCTCGACGATCTTCGCTTGCNTCCTCGCTCGCTGTCCCGTTGTCCTAGCCCGCCGCCGCCCGCTGAGCTTGTCTTT
ACCCTGCTTGCAGACATGGCTGACATCAAGAACAAGAATATTTCTTTCGTNANCCGGTGTNATGGCGCTCGTCCGC
AATGAGCGGCATGGGCCGCTATTGACAGCAAGAG
>';
$VAR1 = \'gi|618749|dbj|D21619.1| MUS74F09 mouse
embryonal carcinoma cell line F9 Mus musculus cDNA
clone 74F09, mRNA sequence
GGCGNNNTGGCCTCGGGCGGCTGGACGTGCCCAGCGCCCGATTAACAAGATACATTTAATTGCTGTGTTTAACCAAATGT
TTGAAGGCTGTGGGACTGAAATCATATGATCTCCTGCTGTTCACATTGTTCATTAA
';

Is it possible to remove ($VAR1 = \'>';), ($VAR1 =
\'), (>';), and (';) from the output direclty or
several lines containing regular expression needed to
do the job?

Thanks,

Li 



 
 
> Here is a simple script which might do:
> 
> #!/usr/bin/perl
> 
> use strict;
> use warnings;
> 
> use Data::Dumper;
> 
> $/ = ">";
> while(  ){
>print Dumper \$_;
> }
> 
> __END__
>  >gi|618748|dbj|D21618.1| MUS74F01 mouse embryonal
> carcinoma cell line 
> F9 Mus mus culus cDNA clone 74F01, mRNA sequence
>
GCTGCCTCGACGATCTTCGCTTGCNTCCTCGCTCGCTGTCCCGTTGTCCTAGCCCGCCGCCGCCCGCTGAGCTTGTCTTTACCCTGCTTGCAGACATGGCTGACATCAAGAACAAGAATATTTCTTTCGTNANCC
>
GGTGTNATGGCGCTCGTCCGCAATGAGCGGCATGGGCCGCTATTGACAGCAAGAG
>  >gi|618749|dbj|D21619.1| MUS74F09 mouse embryonal
> carcinoma cell line 
> F9 Mus mus culus cDNA clone 74F09, mRNA sequence
>
GGCGNNNTGGCCTCGGGCGGCTGGACGTGCCCAGCGCCCGATTAACAAGATACATTTAATTGCTGTGTTTAACCAAATGTTTGAAGGCTGTGGGACTGAAATCATATGATCTCCTGCTGTTCACATTGTTC
> ATTAA
> 
> 




__ 
Yahoo! DSL – Something to write home about. 
Just $16.99/mo. or less. 
dsl.yahoo.com 


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




Re: Help With signals.

2006-01-06 Thread John Doe
Leif Ericksen am Samstag, 7. Januar 2006 00.12:
> On Fri, 2006-01-06 at 15:58 -0700, Wiggins d'Anconia wrote:
> > Please bottom post...
> >
> > Leif Ericksen wrote:
> > > Actually not quite what you thought on the output...
> > > $ ./myt.pl
> > > ZERO:0   => SIG{'ZERO'} = &sigcat
> > > HUP:1=> SIG{'HUP'} = &sigcat
> > > INT:2=> SIG{'INT'} = &sigcat
> > > QUIT:3   => SIG{'QUIT'} = &sigcat
> > > ILL:4=> SIG{'ILL'} = &sigcat
> > > TRAP:5   => SIG{'TRAP'} = &sigcat
> > > ABRT:6   => SIG{'ABRT'} = &sigcat
> > > BUS:7=> SIG{'BUS'} = &sigcat
> > > FPE:8=> SIG{'FPE'} = &sigcat
> > > KILL:9   => SIG{'KILL'} = &sigcat
> >
> > Ah yep missed the double quotes.
> >
> > > Also if I use the double quote as opposed to a single quote in:
> > > SIG{'$name'} = \&sigcat;
> >
> > The above should be:
> >
> > $SIG{$name} = \&sigcat;
>
> That causes...
> ./myt.pl
> ZERO:0   => SIG{'ZERO'} = &sigcat
> Segmentation fault

perldoc perlipc states:

"Another interesting signal to send is signal number zero.  
This doesn't actually affect a child process, but instead 
checks whether it's alive or has changed its UID."

I'm not a signal guru, but I think you can't assign a handler to the ZERO 
signal. I also got a segfault.

Look at the following code, modified from yours.

BTW, your chances for answers are bigger if you provide code that can be run 
by list members.

#!/usr/bin/perl
use strict;
use warnings;

use Config;

my $i = 0;
my (@signames, %signos); 

defined $Config{sig_name}
  or
  die "The Stupid System does not support Signals?";

sub sigcat {print "sigcat called"; exit;};

foreach my $name (split(' ', $Config{sig_name})) {
   next if $name eq 'ZERO';  
   $signos{$name} = $i; 
   $signames[$i] = $name;
   print "$name:$i \t => SIG{$name} = \&sigcat\n"; 
   $SIG{$name}=\&sigcat;  
   $i++;
}

{} while 1;



hth joe

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




Re: Help With signals.

2006-01-06 Thread Leif Ericksen
On Fri, 2006-01-06 at 15:58 -0700, Wiggins d'Anconia wrote:
> Please bottom post...
> 
> Leif Ericksen wrote:
> > Actually not quite what you thought on the output...
> > $ ./myt.pl
> > ZERO:0   => SIG{'ZERO'} = &sigcat
> > HUP:1=> SIG{'HUP'} = &sigcat
> > INT:2=> SIG{'INT'} = &sigcat
> > QUIT:3   => SIG{'QUIT'} = &sigcat
> > ILL:4=> SIG{'ILL'} = &sigcat
> > TRAP:5   => SIG{'TRAP'} = &sigcat
> > ABRT:6   => SIG{'ABRT'} = &sigcat
> > BUS:7=> SIG{'BUS'} = &sigcat
> > FPE:8=> SIG{'FPE'} = &sigcat
> > KILL:9   => SIG{'KILL'} = &sigcat
> > 
> 
> Ah yep missed the double quotes.
> 
> > Also if I use the double quote as opposed to a single quote in:
> > SIG{'$name'} = \&sigcat;
> 
> The above should be:
> 
> $SIG{$name} = \&sigcat;

That causes...
./myt.pl
ZERO:0   => SIG{'ZERO'} = &sigcat
Segmentation fault

and if I just use
$SIG{'INT'} = /&sigcat;  outside of the ;oop it seems to work just fine
so  I am a little confused as to why this does not want to work.  I even
tried creating a $temp and I assigned it like $temp = "'$name'"; and it
did not like that, unless I missed something when I did that.  ;)


--
Leif


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




Re: Help With signals.

2006-01-06 Thread Wiggins d'Anconia
Please bottom post...

Leif Ericksen wrote:
> Actually not quite what you thought on the output...
> $ ./myt.pl
> ZERO:0   => SIG{'ZERO'} = &sigcat
> HUP:1=> SIG{'HUP'} = &sigcat
> INT:2=> SIG{'INT'} = &sigcat
> QUIT:3   => SIG{'QUIT'} = &sigcat
> ILL:4=> SIG{'ILL'} = &sigcat
> TRAP:5   => SIG{'TRAP'} = &sigcat
> ABRT:6   => SIG{'ABRT'} = &sigcat
> BUS:7=> SIG{'BUS'} = &sigcat
> FPE:8=> SIG{'FPE'} = &sigcat
> KILL:9   => SIG{'KILL'} = &sigcat
> 

Ah yep missed the double quotes.

> Also if I use the double quote as opposed to a single quote in:
> SIG{'$name'} = \&sigcat;

The above should be:

$SIG{$name} = \&sigcat;

$name can't be single quoted, and you have to call the SIG hash as a hash...

http://danconia.org

> 
> I get a like result it does not work as desired and a complete lack of quotes 
> gives me a
> segmentation fault.
> 
> 
> On Fri, 2006-01-06 at 15:37 -0700, Wiggins d'Anconia wrote:
> 
>>Leif Ericksen wrote:
>>
>>>I am trying to set up a routine to trap signals so that I can pass it to
>>>a sub that will act on the signals and it does not seem to be
>>>functioning as I would think.
>>>
>>>SAMPLE: 
>>>I will admit some of the code was taken from the camel book.  :)  I do
>>>have use strict on.
>>>
>>>my $name = "\n";
>>>my $i = 0;
>>>
>>>defined $Config{sig_name} || die "The Stupid System does not support
>>>Signals?";
>>>foreach $name(split(' ', $Config{sig_name}))
>>> {
>>>   $Config::signo{$name} = $i;
>>>   $Config::signame[$i] = $name;
>>>  #print "$name:$i \t => SIG{'$name'} = \&sigcat\n";
>>>   $SIG{'$name'} = \&sigcat;
>>
>>In the above line you are single quoting $name so that it is not
>>interpolated.
>>
>>HTH,
>>
>>http://danconia.org
>>
>>
>>>   $i++;
>>> }
>>>
>>>Now I do have an while (1){}; setup so that I can test the break.  Using
>>>the above code I do not seem to enter my sub sigcat I do not see my
>>>'special' signal catch message if I press ^C.  HOWEVER, if I add the
>>>following lines:
>>>
>>>$SIG{'INT'} = \&sigcat;
>>>$SIG{'HUP'} = \&sigcat;
>>>$SIG{'STOP'} = \&sigcat;
>>>$SIG{'ABRT'} = \&sigcat;
>>>$SIG{'TERM'} = \&sigcat;
>>>
>>>It does break out and lets me know that it received a HUP. 
>>>
>>>If I take the single quote ' off of the $name in the loop I get a
>>>segmentation fault so I guess I need the quotes.
>>>
>>>Can anybody tell me what is wrong with the loop and why it is not
>>>working?  Also if I uncomment the line:
>>>#print "$name:$i \t => SIG{'$name'} = \&sigcat\n";
>>
>>Might want to examine the output more closely, $name should be being
>>printed as $name rather than INT, HUP, etc.
>>
>>
>>>It appears to be running the correct set routine as in the 5 I have
>>>shown above.  I know I must have something simple but I just can not see
>>>what it is...
>>

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




Re: Help With signals.

2006-01-06 Thread Leif Ericksen
Actually not quite what you thought on the output...
$ ./myt.pl
ZERO:0   => SIG{'ZERO'} = &sigcat
HUP:1=> SIG{'HUP'} = &sigcat
INT:2=> SIG{'INT'} = &sigcat
QUIT:3   => SIG{'QUIT'} = &sigcat
ILL:4=> SIG{'ILL'} = &sigcat
TRAP:5   => SIG{'TRAP'} = &sigcat
ABRT:6   => SIG{'ABRT'} = &sigcat
BUS:7=> SIG{'BUS'} = &sigcat
FPE:8=> SIG{'FPE'} = &sigcat
KILL:9   => SIG{'KILL'} = &sigcat

Also if I use the double quote as opposed to a single quote in:
SIG{'$name'} = \&sigcat;

I get a like result it does not work as desired and a complete lack of quotes 
gives me a
segmentation fault.


On Fri, 2006-01-06 at 15:37 -0700, Wiggins d'Anconia wrote:
> Leif Ericksen wrote:
> > I am trying to set up a routine to trap signals so that I can pass it to
> > a sub that will act on the signals and it does not seem to be
> > functioning as I would think.
> > 
> > SAMPLE: 
> > I will admit some of the code was taken from the camel book.  :)  I do
> > have use strict on.
> > 
> > my $name = "\n";
> > my $i = 0;
> > 
> > defined $Config{sig_name} || die "The Stupid System does not support
> > Signals?";
> > foreach $name(split(' ', $Config{sig_name}))
> >  {
> >$Config::signo{$name} = $i;
> >$Config::signame[$i] = $name;
> >   #print "$name:$i \t => SIG{'$name'} = \&sigcat\n";
> >$SIG{'$name'} = \&sigcat;
> 
> In the above line you are single quoting $name so that it is not
> interpolated.
> 
> HTH,
> 
> http://danconia.org
> 
> >$i++;
> >  }
> > 
> > Now I do have an while (1){}; setup so that I can test the break.  Using
> > the above code I do not seem to enter my sub sigcat I do not see my
> > 'special' signal catch message if I press ^C.  HOWEVER, if I add the
> > following lines:
> > 
> > $SIG{'INT'} = \&sigcat;
> > $SIG{'HUP'} = \&sigcat;
> > $SIG{'STOP'} = \&sigcat;
> > $SIG{'ABRT'} = \&sigcat;
> > $SIG{'TERM'} = \&sigcat;
> > 
> > It does break out and lets me know that it received a HUP. 
> > 
> > If I take the single quote ' off of the $name in the loop I get a
> > segmentation fault so I guess I need the quotes.
> > 
> > Can anybody tell me what is wrong with the loop and why it is not
> > working?  Also if I uncomment the line:
> > #print "$name:$i \t => SIG{'$name'} = \&sigcat\n";
> 
> Might want to examine the output more closely, $name should be being
> printed as $name rather than INT, HUP, etc.
> 
> > It appears to be running the correct set routine as in the 5 I have
> > shown above.  I know I must have something simple but I just can not see
> > what it is...
> 
-- 
Leif Ericksen <[EMAIL PROTECTED]>


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




Re: Help With signals.

2006-01-06 Thread Wiggins d'Anconia
Leif Ericksen wrote:
> I am trying to set up a routine to trap signals so that I can pass it to
> a sub that will act on the signals and it does not seem to be
> functioning as I would think.
> 
> SAMPLE: 
> I will admit some of the code was taken from the camel book.  :)  I do
> have use strict on.
> 
> my $name = "\n";
> my $i = 0;
> 
> defined $Config{sig_name} || die "The Stupid System does not support
> Signals?";
> foreach $name(split(' ', $Config{sig_name}))
>  {
>$Config::signo{$name} = $i;
>$Config::signame[$i] = $name;
>   #print "$name:$i \t => SIG{'$name'} = \&sigcat\n";
>$SIG{'$name'} = \&sigcat;

In the above line you are single quoting $name so that it is not
interpolated.

HTH,

http://danconia.org

>$i++;
>  }
> 
> Now I do have an while (1){}; setup so that I can test the break.  Using
> the above code I do not seem to enter my sub sigcat I do not see my
> 'special' signal catch message if I press ^C.  HOWEVER, if I add the
> following lines:
> 
> $SIG{'INT'} = \&sigcat;
> $SIG{'HUP'} = \&sigcat;
> $SIG{'STOP'} = \&sigcat;
> $SIG{'ABRT'} = \&sigcat;
> $SIG{'TERM'} = \&sigcat;
> 
> It does break out and lets me know that it received a HUP. 
> 
> If I take the single quote ' off of the $name in the loop I get a
> segmentation fault so I guess I need the quotes.
> 
> Can anybody tell me what is wrong with the loop and why it is not
> working?  Also if I uncomment the line:
> #print "$name:$i \t => SIG{'$name'} = \&sigcat\n";

Might want to examine the output more closely, $name should be being
printed as $name rather than INT, HUP, etc.

> It appears to be running the correct set routine as in the 5 I have
> shown above.  I know I must have something simple but I just can not see
> what it is...

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




Help With signals.

2006-01-06 Thread Leif Ericksen
I am trying to set up a routine to trap signals so that I can pass it to
a sub that will act on the signals and it does not seem to be
functioning as I would think.

SAMPLE: 
I will admit some of the code was taken from the camel book.  :)  I do
have use strict on.

my $name = "\n";
my $i = 0;

defined $Config{sig_name} || die "The Stupid System does not support
Signals?";
foreach $name(split(' ', $Config{sig_name}))
 {
   $Config::signo{$name} = $i;
   $Config::signame[$i] = $name;
  #print "$name:$i \t => SIG{'$name'} = \&sigcat\n";
   $SIG{'$name'} = \&sigcat;
   $i++;
 }

Now I do have an while (1){}; setup so that I can test the break.  Using
the above code I do not seem to enter my sub sigcat I do not see my
'special' signal catch message if I press ^C.  HOWEVER, if I add the
following lines:

$SIG{'INT'} = \&sigcat;
$SIG{'HUP'} = \&sigcat;
$SIG{'STOP'} = \&sigcat;
$SIG{'ABRT'} = \&sigcat;
$SIG{'TERM'} = \&sigcat;

It does break out and lets me know that it received a HUP. 

If I take the single quote ' off of the $name in the loop I get a
segmentation fault so I guess I need the quotes.

Can anybody tell me what is wrong with the loop and why it is not
working?  Also if I uncomment the line:
#print "$name:$i \t => SIG{'$name'} = \&sigcat\n";
It appears to be running the correct set routine as in the 5 I have
shown above.  I know I must have something simple but I just can not see
what it is...
-- 
Leif Ericksen <[EMAIL PROTECTED]>


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




Re: How to improve speed of returning value from calling method on an array of objects?

2006-01-06 Thread Tom Phoenix
On 1/6/06, Sai Tong <[EMAIL PROTECTED]> wrote:

> The problem is this code runs too slowly for a large array of objects.
> Its seems that it might be a little too slow to "push" each
> returned value into @return_values . Can anyone suggest the best way to
> improve the speed of putting the returned value of
> each object into an array?

It sounds as if you're using intuition to determine what needs
optimizing. Forgive me for not trusting your intuition, but I
recommend using a profiler to determine what needs optimizing. It's
rare that intuition can do as well as good debugging tools can do in
telling what your code is actually doing.

Having said that, I should also mention that the perldata manpage
says, "You can also gain some minuscule measure of efficiency by
pre-extending an array that is going to get big." I believe that that
means code like this:

my @return_values;   # new, empty array
$#return_values = 999_999;   # room for a million items
@return_values = ();   # but empty to start

After that, your first up-to-one-million elements shouldn't take so
long to push. But I haven't been able to verify this by benchmarking,
so I suspect that either the documentation is right about the
improvement being "minuscule", or I've misunderstood what it says
about pre-extending arrays.

My own intuition (which is not necessarily better than any other)
suggests that you may be accumulating so much data in memory at once
that your process has become unwieldy. If you're collecting more than
a few million items in @return_values, or if those items are
collectively taking up a lot of memory, perhaps you should be keeping
them on disk instead of in memory. There are some modules on CPAN that
can help in making a tied data structure.

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

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




Re: how do I avoiding zombie processes without interfering with " die if system(ls) " type calls

2006-01-06 Thread Tom Phoenix
On 1/5/06, Rahul <[EMAIL PROTECTED]> wrote:

>   if (fork() == 0){

Because your process table can become full and temporarily prevent
forking new processes, you should check the return value of fork
whenever you're making more than N processes. The value of N depends
upon a number of factors, so I generally assume N=0. Most of the time,
I just call this safe_fork routine in place of fork, since this
handles the retries for me automatically.

sub safe_fork () {
use Errno;
my $retries = 10;
while ($retries--) {
my $rv = fork;
return $rv if defined $rv;  # it worked
return unless $retries;
return unless $!{EAGAIN};
sleep 3;
}
die "Well, how did I get here?";
}

> now, since the parent does not wait upon the child to finish (i don't want
> it to explicitly wait, since i want to have multiple children run
> simultaneously), so there are lot of zombie children left, thereby making
> the system slow, and finally hang.
>
> i researched a lot, there are 2 ways to avoid this.
>
> 1) $SIG{'CHLD'} = 'IGNORE';
> 2) $SIG{'CHLD'} = sub { while(waitpid(-1,WNOHANG)>0) {} } ;

There are other ways, too. One popular way is the "double-fork" trick.
Instead of making a child process, you make a grandchild process. That
is, the first fork makes a child process which forks again to make the
grandchild, then exits. The grandchild does the work, the parent
continues running. Because the grandchild process's parent process is
gone, the responsibility for reaping the zombie passes to init(8). At
least, that's what happens on most Unix-like systems.

If you're starting many such processes, you can use one child process
to start a number of grandchild processes at once, limited of course
by your system's abilities. That's more efficient than starting just a
single grandchild per child process.

And with all this talk about fork, I have to ask everyone playing
along at home whether they know what you can get when your program has
both a fork and an infinite loop? If you're the only user on your box,
you can do whatever you want. But other users may not appreciate a
fork bomb.

http://catb.org/~esr/jargon/html/F/fork-bomb.html

Cheers!

--Tom Phoenix
Stonehenge Perl Training

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




Re: new for reading file containing multiple records

2006-01-06 Thread Tom Phoenix
On 1/5/06, chen li <[EMAIL PROTECTED]> wrote:
> Each record starts with ">". I want to read each
> record once at a time.I hear about a special variable
> call $/ might do the job but not sure how to use it.

The perlvar manpage documents $/ and all of Perl's other special
variables. In particular, this variable contains a string ("\n" by
default) which Perl expects to come at the end of every "line" of
input.

Although it's tempting to set $/ to "\n>" for the file format you
describe, that's probably not correct for the first or last record in
your file. I recommend that you write code to identify each record
(with regular expressions, perhaps?) instead of using $/.
Alternatively, you could pre-process the data file in some way so that
using $/ would be a good solution.

Good luck with it!

--Tom Phoenix
Stonehenge Perl Training

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




Re: arguments in closure

2006-01-06 Thread JupiterHost.Net

sub make_binary
{
my $vars = shift;
return eval "sub { $vars; }";
}

I understand the mechanism of the closure, but I don't figure out how 
the anonymous subroutine puts the two arguments in $_[0] and in $_[1] ?


Its evaling a string and $vars is being interpolated so the eval, in 
that example is just like:


 return eval 'sub { $_[0] + $_[1] }';

which ends up being just like

 return sub { $_[0] + $_[1] };

after the eval :)

HTH

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




Re: How to improve speed of returning value from calling method on an array of objects?

2006-01-06 Thread Adriano Ferreira
On 1/6/06, Sai Tong <[EMAIL PROTECTED]> wrote:
> I have an array of many objects and I want to call a method on
> each of these objects and the save the returned values into an array:

> my @return_values;
> foreach my $retrievedObject (@array_of_objects) {
> push (@return_values , $retrievedObject->method );
> }

Maybe you can use C

   my @return_values = map { $_->method } @array_of_objects;

But that's not going to be fast (as well as the for construction) if
the repeated calls of C<$_->method> aren't fast enough (for your
purposes).

Adriano.

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




How to improve speed of returning value from calling method on an array of objects?

2006-01-06 Thread Sai Tong

Hi,

I have an array of many objects and I want to call a method on
each of these objects and the save the returned values into an array:

my @return_values;
foreach my $retrievedObject (@array_of_objects) {
push (@return_values , $retrievedObject->method );
}

The problem is this code runs too slowly for a large array of objects.
Its seems that it might be a little too slow to "push" each
returned value into @return_values . Can anyone suggest the best way to
improve the speed of putting the returned value of
each object into an array?

thanks,
Sai




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




Re: new for reading file containing multiple records

2006-01-06 Thread Shawn Corey

chen li wrote:

Each record starts with ">". I want to read each
record once at a time.I hear about a special variable
call $/ might do the job but not sure how to use it. I
wonder if anyone could help me out.


See `perldoc perlvar` and search for INPUT_RECORD_SEPARATOR.

Here is a simple script which might do:

#!/usr/bin/perl

use strict;
use warnings;

use Data::Dumper;

$/ = ">";
while(  ){
  print Dumper \$_;
}

__END__
>gi|618748|dbj|D21618.1| MUS74F01 mouse embryonal carcinoma cell line 
F9 Mus mus culus cDNA clone 74F01, mRNA sequence

GCTGCCTCGACGATCTTCGCTTGCNTCCTCGCTCGCTGTCCCGTTGTCCTAGCCCGCCGCCGCCCGCTGAGCTTGTCTTTACCCTGCTTGCAGACATGGCTGACATCAAGAACAAGAATATTTCTTTCGTNANCC
GGTGTNATGGCGCTCGTCCGCAATGAGCGGCATGGGCCGCTATTGACAGCAAGAG
>gi|618749|dbj|D21619.1| MUS74F09 mouse embryonal carcinoma cell line 
F9 Mus mus culus cDNA clone 74F09, mRNA sequence

GGCGNNNTGGCCTCGGGCGGCTGGACGTGCCCAGCGCCCGATTAACAAGATACATTTAATTGCTGTGTTTAACCAAATGTTTGAAGGCTGTGGGACTGAAATCATATGATCTCCTGCTGTTCACATTGTTC
ATTAA


--

Just my 0.0002 million dollars worth,
   --- Shawn

"Probability is now one. Any problems that are left are your own."
   SS Heart of Gold, _The Hitchhiker's Guide to the Galaxy_

* Perl tutorials at http://perlmonks.org/?node=Tutorials
* A searchable perldoc is available at http://perldoc.perl.org/

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




Re: arguments in closure

2006-01-06 Thread John Doe
root am Freitag, 6. Januar 2006 13.15:
> Hello,
> about closure I read the
>
> Perl literacy course
>
> lecture #9 Closures
>
> Shlomo Yona  http://cs.haifa.ac.il/~shlomo/
>
>
> The explanations are clear but in this example:
> (it's an excerpt of an example of Shlomo)
>
> #!/usr/bin/perl
> use warnings;
> use strict;
>
> my $sumform = make_binary('$_[0] + $_[1]');
>
> print "7 + 8 = ", $sumform -> (7, 8), "\n";
>
> print "5 + 3 = ", $sumform -> (5, 3), "\n";
>
>
> sub make_binary
> {
>   my $vars = shift;
>   return eval "sub { $vars; }";
> }
>
> I understand the mechanism of the closure, but I don't figure out
> how the anonymous subroutine puts the two arguments in $_[0] and in $_[1] ?

Well, the anonymous sub returned by make_binary is

sub { $_[0] + $_[1] };

and it is called with

$sumform -> (7, 8)

so the list (7,8) is passed via @_ to the anonymous sub and retrieved from 
there with $_[0] and $_[1].

It's the "normal" way to access the arguments directly.



Maybe the term 'vars' in '$vars' is misleading, since it describes the 
actually anonymous sub created with the argument '$_[0] + $_[1]' to 
make_binary. Consider 

make_binary (100);

There are no vars, but only a constant.

So, $code instead of $vars would be a better variable name in the eval line of 
the _generic_ sub make_binary(), which could also be used to make a sub 
forking processes or with any other functionality.


hth, joe

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




arguments in closure

2006-01-06 Thread root

Hello,
about closure I read the

Perl literacy course

lecture #9 Closures 


Shlomo Yona  http://cs.haifa.ac.il/~shlomo/


The explanations are clear but in this example: 
(it's an excerpt of an example of Shlomo)


#!/usr/bin/perl
use warnings;
use strict;

my $sumform = make_binary('$_[0] + $_[1]');

print "7 + 8 = ", $sumform -> (7, 8), "\n";

print "5 + 3 = ", $sumform -> (5, 3), "\n";


sub make_binary
{
my $vars = shift;
return eval "sub { $vars; }";
}

I understand the mechanism of the closure, but I don't figure out 
how the anonymous subroutine puts the two arguments in $_[0] and in $_[1] ?


tia
--
Gérard


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




Re: new for reading file containing multiple records

2006-01-06 Thread John Doe
chen li am Freitag, 6. Januar 2006 11.27:
> Hi Xicheng,

Hi Chen

> Thanks. I search the list before I post the question
> but I can't find similar topics. Could you please tell
> me some ealier posts? Also I try to use your code to
> read a very small file containing only these two
> records. Here is what I got:
>
> This is record 1.
> This is sequence:
> This is record 2.
> This is sequence:
> This is record 3.
> This is sequence:
>
> I can't print each record out. How do I fix it?
>
> And here is my code:
>
> #!/usr/bin/perl-w

A space before -w is missing. Alternatively, just add the following line above 
use strict;

use warnings;

> use strict;
>
> my $filename='sequence.fasta';
> open(FILENAME,$filename) or die " This $filename
> cannot be open!!!\n\n";
>
> {local $/='>';
>
> my $count_record=0;
>
> while (){
>  ++$count_record;
>
>  print "This is record $count_record.\n";
>
>  print "This is sequence:$sequence\n"; 

$sequence is not defined; when you run the script under 'use warnings;' (or 
'#!/usr/bin/perl -w', a warning should be displayed.

To actually print the sequence out:

  print "This is sequence: $_\n"; 

see (on the cmdline)

perldoc perlvar

for documentation of all the funny $... vars


>  } 
>
> }
> exit;

exit is not needed.



[top posting history:]
> ~
>
> --- Xicheng <[EMAIL PROTECTED]> wrote:
> > This is a FAQ problem, so I would not post it in the
> > group, pls see the
> > following code.
> > ===
> > #!/usr/bin/perl -w
> > use strict;
> > open FH, " > $!";
> > {
> > local $/='>';
> > while () {
> >  # do sth on $_;  # $_ does not include the
> > leading '>' though.
> > }
> > }
> > Dont know if this can go smoothly with your 2.7G
> > file though. Good
> > luck,
> > XC
> > =
> >
> > Chen Li wrote:
> > > Hi all,
> > >
> > > I have a big file (2.7G) containing multiple
> >
> > records
> >
> > > in this format:
> > > >gi|618748|dbj|D21618.1| MUS74F01 mouse embryonal
> > >
> > > carcinoma cell line F9 Mus mus culus cDNA clone
> >
> > 74F01,
> >
> > > mRNA sequence
>
> GCTGCCTCGACGATCTTCGCTTGCNTCCTCGCTCGCTGTCCCGTTGTCCTAGCCCGCCGCCGCCCGCTGAGCTTG
>TCTTT
>
>
> ACCCTGCTTGCAGACATGGCTGACATCAAGAACAAGAATATTTCTTTCGTNANCCGGTGTNATGGCGCTCG
>TCCGC
>
> > > AATGAGCGGCATGGGCCGCTATTGACAGCAAGAG
> > >
> > > >gi|618749|dbj|D21619.1| MUS74F09 mouse embryonal
> > >
> > > carcinoma cell line F9 Mus mus culus cDNA clone
> >
> > 74F09,
> >
> > > mRNA sequence
>
> GGCGNNNTGGCCTCGGGCGGCTGGACGTGCCCAGCGCCCGATTAACAAGATACATTTAATTGCTGTGTTTAACCA
>AATGT
>
>
> TTGAAGGCTGTGGGACTGAAATCATATGATCTCCTGCTGTTCACATTGTTCATTAA
>
> > > Each record starts with ">". I want to read each
> > > record once at a time.I hear about a special
> >
> > variable
> >
> > > call $/ might do the job but not sure how to use
> >
> > it. I
> >
> > > wonder if anyone could help me out.
> > >
> > > Thanks,
> > >
> > > Li
> > >
> > >
> > >
> > >
> > >
> > >
> > > __
> > > Yahoo! DSL - Something to write home about.
> > > Just $16.99/mo. or less.
> > > dsl.yahoo.com
>
> __
> Yahoo! DSL – Something to write home about.
> Just $16.99/mo. or less.
> dsl.yahoo.com

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




Re: new for reading file containing multiple records

2006-01-06 Thread chen li
 
> Word wrapping possibly mangled the example records,
> could you please  
> upload a handful of them in a file somewhere?
> 
> -- fxn


Hi,

I am just a newbie. What is word wrapping? Is it a
perl module or something else?

Thanks,

Li 



__ 
Yahoo! DSL – Something to write home about. 
Just $16.99/mo. or less. 
dsl.yahoo.com 


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




Re: new for reading file containing multiple records

2006-01-06 Thread chen li
Hi Xicheng,

Thanks. I search the list before I post the question
but I can't find similar topics. Could you please tell
me some ealier posts? Also I try to use your code to
read a very small file containing only these two
records. Here is what I got:

This is record 1.
This is sequence:
This is record 2.
This is sequence:
This is record 3.
This is sequence:

I can't print each record out. How do I fix it?

And here is my code: 

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

my $filename='sequence.fasta';
open(FILENAME,$filename) or die " This $filename
cannot be open!!!\n\n";

{local $/='>';

my $count_record=0;

while (){
 ++$count_record;

 print "This is record $count_record.\n";

 print "This is sequence:$sequence\n"; }

}
exit;
~
 

--- Xicheng <[EMAIL PROTECTED]> wrote:

> This is a FAQ problem, so I would not post it in the
> group, pls see the
> following code.
> ===
> #!/usr/bin/perl -w
> use strict;
> open FH, " $!";
> {
> local $/='>';
> while () {
>  # do sth on $_;  # $_ does not include the
> leading '>' though.
> }
> }
> Dont know if this can go smoothly with your 2.7G
> file though. Good
> luck,
> XC
> =
> 
> Chen Li wrote:
> > Hi all,
> >
> > I have a big file (2.7G) containing multiple
> records
> > in this format:
> > >gi|618748|dbj|D21618.1| MUS74F01 mouse embryonal
> > carcinoma cell line F9 Mus mus culus cDNA clone
> 74F01,
> > mRNA sequence
> >
>
GCTGCCTCGACGATCTTCGCTTGCNTCCTCGCTCGCTGTCCCGTTGTCCTAGCCCGCCGCCGCCCGCTGAGCTTGTCTTT
> >
>
ACCCTGCTTGCAGACATGGCTGACATCAAGAACAAGAATATTTCTTTCGTNANCCGGTGTNATGGCGCTCGTCCGC
> > AATGAGCGGCATGGGCCGCTATTGACAGCAAGAG
> > >gi|618749|dbj|D21619.1| MUS74F09 mouse embryonal
> > carcinoma cell line F9 Mus mus culus cDNA clone
> 74F09,
> > mRNA sequence
> >
>
GGCGNNNTGGCCTCGGGCGGCTGGACGTGCCCAGCGCCCGATTAACAAGATACATTTAATTGCTGTGTTTAACCAAATGT
> >
>
TTGAAGGCTGTGGGACTGAAATCATATGATCTCCTGCTGTTCACATTGTTCATTAA
> >
> > Each record starts with ">". I want to read each
> > record once at a time.I hear about a special
> variable
> > call $/ might do the job but not sure how to use
> it. I
> > wonder if anyone could help me out.
> >
> > Thanks,
> >
> > Li
> >
> >
> >
> >
> >
> >
> > __
> > Yahoo! DSL - Something to write home about.
> > Just $16.99/mo. or less. 
> > dsl.yahoo.com
> 
> 




__ 
Yahoo! DSL – Something to write home about. 
Just $16.99/mo. or less. 
dsl.yahoo.com 


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




Re: new for reading file containing multiple records

2006-01-06 Thread Xavier Noria

On Jan 6, 2006, at 4:12, chen li wrote:


Hi all,

I have a big file (2.7G) containing multiple records
in this format:

gi|618748|dbj|D21618.1| MUS74F01 mouse embryonal

carcinoma cell line F9 Mus mus culus cDNA clone 74F01,
mRNA sequence
GCTGCCTCGACGATCTTCGCTTGCNTCCTCGCTCGCTGTCCCGTTGTCCTAGCCCGCCGCCGCCCGCTGA 
GCTTGTCTTT
ACCCTGCTTGCAGACATGGCTGACATCAAGAACAAGAATATTTCTTTCGTNANCCGGTGTNATGGC 
GCTCGTCCGC

AATGAGCGGCATGGGCCGCTATTGACAGCAAGAG

gi|618749|dbj|D21619.1| MUS74F09 mouse embryonal

carcinoma cell line F9 Mus mus culus cDNA clone 74F09,
mRNA sequence
GGCGNNNTGGCCTCGGGCGGCTGGACGTGCCCAGCGCCCGATTAACAAGATACATTTAATTGCTGTGTTT 
AACCAAATGT

TTGAAGGCTGTGGGACTGAAATCATATGATCTCCTGCTGTTCACATTGTTCATTAA

Each record starts with ">". I want to read each
record once at a time.I hear about a special variable
call $/ might do the job but not sure how to use it. I
wonder if anyone could help me out.


Word wrapping possibly mangled the example records, could you please  
upload a handful of them in a file somewhere?


-- fxn



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