Re: Getting script to run w/o optional module

2011-06-09 Thread sono-io
On Jun 9, 2011, at 2:46 PM, John SJ Anderson wrote: > my $module_is_enabled = 0; > eval 'use My::Special::Module'; > $module_is_enabled = 1 unless $@; > > should do what you're looking for. John, Thanks for the code. Between that and wrapping a call to an external sub in an if stat

Re: solution for Regex

2011-06-09 Thread Uri Guttman
> "JD" == John Delacour writes: JD> use strict; use warnings ; JD> my $read = 0; my @genes; my %hash; why the $read flag? JD> while (){ JD> chomp; JD> $read = 1 if /^GENES/; you can always just so this and test for it. i don't know the data logic so i can't go further. at l

Re: solution for Regex

2011-06-09 Thread Rob Dixon
On 09/06/2011 09:48, venkates wrote: > Hi, > > data snippet: > > ENTRY K2 KO > NAME E1.1.1.2, adh > DEFINITION alcohol dehydrogenase (NADP+) [EC:1.1.1.2] > PATHWAY ko00010 Glycolysis / Gluconeogenesis > ko00561 Glycerolipid metabolism > ko00930 Caprolactam degradation > CLASS Metabolism; Carb

Re: Getting script to run w/o optional module

2011-06-09 Thread Robert Wohlfarth
On Thu, Jun 9, 2011 at 4:42 PM, wrote: >I'd like to find a way to make a Perl script "modular". What I mean > is that I want to be able to distribute a script either with or without a > particular module/package/lib and have the main script run no matter if it's > included or not. > >

Re: Getting script to run w/o optional module

2011-06-09 Thread John SJ Anderson
On Thu, Jun 9, 2011 at 17:42, wrote: >        Using either require, use, or do produces an error if I run the script > without the module.  Is there a specific function for this purpose, or would > I have to do something like wrap a 'use' or 'require' in an if statement?   > I've tried that an

Getting script to run w/o optional module

2011-06-09 Thread sono-io
I'd like to find a way to make a Perl script "modular". What I mean is that I want to be able to distribute a script either with or without a particular module/package/lib and have the main script run no matter if it's included or not. What I'm trying to come up with is a "lite

Re: solution for Regex

2011-06-09 Thread John Delacour
At 10:48 +0200 09/06/2011, venkates wrote: I need to retrieve all the gene entries to add it to a hash ref. Your code is very fussy with all those substrings etc. What about something like this: #!/usr/local/bin/perl use strict; my $read = 0; my @genes; my %hash; while (){ chomp; $read =

Re: solution for Regex

2011-06-09 Thread Shawn H Corey
On 11-06-09 01:48 PM, Dr.Ruud wrote: On 2011-06-09 10:48, venkates wrote: my @gene_label_array = split '\s', $gene_label; That '\s' is more clearly written as /\s/ or for example m{\s}. But best just make it ' ' (see perldoc -f split, about that special case). FYI, some people find it har

Re: solution for Regex

2011-06-09 Thread Dr.Ruud
On 2011-06-09 10:48, venkates wrote: my @gene_label_array = split '\s', $gene_label; That '\s' is more clearly written as /\s/ or for example m{\s}. But best just make it ' ' (see perldoc -f split, about that special case). -- Ruud -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org F

Re: Pulling file name from path

2011-06-09 Thread Shawn H Corey
On 11-06-09 11:42 AM, sono...@fannullone.us wrote: On Jun 9, 2011, at 7:52 AM, Shawn H Corey wrote: Use File::Spec and File::Basename together. From what I read, I thought they did the same thing, but from your post it appears that there may be differences. What's the advantage in

Re: Pulling file name from path

2011-06-09 Thread sono-io
On Jun 9, 2011, at 7:52 AM, Shawn H Corey wrote: > Use File::Spec and File::Basename together. From what I read, I thought they did the same thing, but from your post it appears that there may be differences. What's the advantage in using both instead of one or the other? Are they not

Re: solution for Regex

2011-06-09 Thread Jim Gibson
At 10:48 AM +0200 6/9/11, venkates wrote: Hi, data snippet: I need to retrieve all the gene entries to add it to a hash ref. My code does that in the first record but in the second case it also pulls out the REFERENCE information. I have provided the code below. If some one could tell me wh

Re: Pulling file name from path

2011-06-09 Thread Shawn H Corey
On 11-06-09 10:46 AM, sono...@fannullone.us wrote: Or is there a better way that I haven't run across yet? It needs to be multi-platform. Use File::Spec and File::Basename together. They offer platform independence. use File::Spec; use File::Basename; my $file_path = "../htdocs/_carts/sq

Pulling file name from path

2011-06-09 Thread sono-io
I've written a 'create_sql_table' routine which starts off by pulling the file name (sans suffix) from a path. I've posted four code snippets below. All work fine, but I'm curious to know if there is a better (or more elegant) way to do it? The second example is one line shorter

solution for Regex

2011-06-09 Thread venkates
Hi, data snippet: ENTRY K2 KO NAMEE1.1.1.2, adh DEFINITION alcohol dehydrogenase (NADP+) [EC:1.1.1.2] PATHWAY ko00010 Glycolysis / Gluconeogenesis ko00561 Glycerolipid metabolism ko00930 Caprolactam degradation CLASS Me