Re: Why is my regex so slow?

2008-10-31 Thread Li, Jialin
On Fri, Oct 31, 2008 at 2:54 PM, Mark Wagner <[EMAIL PROTECTED]> wrote: > I've got a script I'm using to search through a list of Wikipedia > article titles to find ones that match certain patterns. > > As-written, if you run it and supply '.*target.*' on standard input, > it will process my test

Re: Why is my regex so slow?

2008-10-31 Thread Li, Jialin
try this: print "Match\n" if($target =~ /^$regex$/*o*); only compile regex only once On Fri, Oct 31, 2008 at 2:54 PM, Mark Wagner <[EMAIL PROTECTED]> wrote: > I've got a script I'm using to search through a list of Wikipedia > article titles to find ones that match certain patterns. > > As-

Re: How to catch error message instead of printing to stderr for rmtree

2008-09-25 Thread Li, Jialin
On Fri, Sep 26, 2008 at 12:17 AM, Yue Chen <[EMAIL PROTECTED]> wrote: > Hi > > I want to use rmtree to delete a dir and use variables to catch the > error message. However, when i am about to delete a dir that does not > belong to me, it still print the error message to stderr. Does anyone > have

Re: send die "" to a file

2008-09-25 Thread Li, Jialin
On Thu, Sep 25, 2008 at 11:55 PM, aa aa <[EMAIL PROTECTED]> wrote: > > Hi, > > I try to open several files, if one of them failed, my program will die and > then send the died information to a file. > > eg. > open(AA, "a.txt") or die "can't open file a.txt\n"; > > But I want to this string "can't

Re: Parsing Key/Value pairs

2008-09-24 Thread Li, Jialin
On Wed, Sep 24, 2008 at 2:25 PM, Dan Fish <[EMAIL PROTECTED]> wrote: > I've got a data file with a bunch of key/value pairs in the format > "key=value;". There may be only one to a line, or there may be several. I > know I can figure out how to do this using split, but I thought surely > there >

Re: Filtering contetn in a variable

2008-07-09 Thread Li, Jialin
i am not so sure what the input is, this simple regex should solve your problem: ($ip_filtered) = /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/ or to match more exactly, you can use: Regexp::Common On Wed, Jul 9, 2008 at 8:22 AM, luke devon <[EMAIL PROTECTED]> wrote: > Hi > I am storing IP in to a va

Re: how to implement this with perl

2008-06-26 Thread Li, Jialin
On Thu, Jun 26, 2008 at 9:42 AM, yitzle <[EMAIL PROTECTED]> wrote: > On Thu, Jun 26, 2008 at 8:18 AM, vikingy <[EMAIL PROTECTED]> wrote: > > Hi all, > > > > I have two files,one is label file,another is thickness file, they are > one to one correspondence, for example: > > the label file is :

Re: Sorting a hash

2008-06-02 Thread Li, Jialin
On Mon, Jun 2, 2008 at 1:53 PM, Iain Adams <[EMAIL PROTECTED]> wrote: > Hello, > > I am trying to sort a hash of hashes. > > my code looks like this > > foreach $cnt (sort keys %{ $relations{ $uid }{ "instances" } }){ > print OUT "$cnt 1, "; > } > > This prints out the correct number

Re: efficient max() function from sort

2008-05-28 Thread Li, Jialin
On Wed, May 28, 2008 at 9:17 AM, Ramprasad A Padmanabhan <[EMAIL PROTECTED]> wrote: > > I use sort to give the max of an array something like this > > - > my @z = qw(12 24 67 89 77 91 44 5 10); > my $max = ((reverse sort{$a <=> $b} (@z))[0]); > print "MAX = $max\n"; > --- > > but when

Re: Comparing file contents, the perl way

2008-05-21 Thread Li, Jialin
On Wed, May 21, 2008 at 9:40 PM, beast <[EMAIL PROTECTED]> wrote: > Good morning, > > I have 2 files which contains some IDs. Basically I want to search ID > in the file A which is missing on the file B. > > This program is ugly, but its work :-) > > use strict; > > my $target_file =

Re: Sorting and grouping question

2008-05-15 Thread Li, Jialin
On Thu, May 15, 2008 at 12:13 PM, ANJAN PURKAYASTHA < [EMAIL PROTECTED]> wrote: > Hi, > here is a problem I'm working on. It's not PERL-specific, rather it is a > problem in sorting followed by grouping. > Suppose I have a set of lines that have tab-delimited text, thus: > 1 w 3 wer > 2 a

Re: items in array

2008-05-14 Thread Li, Jialin
On Wed, May 14, 2008 at 4:01 PM, Tech list <[EMAIL PROTECTED]> wrote: > what is the correct way to get the number of items in an array? > > I used to use $#array > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > http://learn.perl.org/ > > >

Re: faster ways than perl?

2008-05-14 Thread Li, Jialin
the first sort will be slow considering the amount of data and can be replaced by using hash the 21st conlumn should be $F[20] perl -F"\|" -ane '++$hash{$F[20]}; END { @sorted = sort {$a <=> $b} keys %hash; print $hash{$_}, $_, "\n" for @sorted}' data - Show quoted text - On Wed, May 14, 2008

Re: comparing two binary numbers

2008-05-11 Thread Li, Jialin
On 5/11/08, Johnson Lau <[EMAIL PROTECTED]> wrote: > > Dear all, > > I need to compare two binary numbers and need perl to return the > number of matching bits. > > For example: > > $aaa = "1000"; > $bbb = "00101100"; > > In this case, the number of matching bits is 6. > > I know I could split

Re: simple question

2008-04-27 Thread Li, Jialin
for your fast answer. > > what do you mean by perldoc perldsc? how do i get that? > > what is "use strict" and "use warnings" > > sorry to bother you and thanks again! > > - Original Message > From: "Li, Jialin" <[EMAIL PROTECTED]&g

Re: Following links: What's wrong with me????

2008-04-27 Thread Li, Jialin
>From my experience, Mechanize is much easier to use than LWP. On Sun, Apr 27, 2008 at 7:28 AM, J. Peng <[EMAIL PROTECTED]> wrote: > On Sun, Apr 27, 2008 at 2:52 AM, hotkitty <[EMAIL PROTECTED]> wrote: > > This is my first experience w/ PERL and I've searched everywhere but > > haven't found th

Re: How to delete old directories with perl script?

2008-04-23 Thread Li, Jialin
you can use File::Find module to traverse the directory. I think this module is simulating the unix find command. On Wed, Apr 23, 2008 at 10:58 PM, Siegfried Heintze (Aditi) <[EMAIL PROTECTED]> wrote: > I have directory names in the format of "-mm-dd_hh-mm-ss". Sometimes I > want to delete

Re: Building/defining variables from an value in string

2008-04-22 Thread Li, Jialin
use strict; my $string = 'field1,int,10#field2,string,abc'; my @values = split /#/,$string; my @vars; no strict 'refs'; for (@values) { my @tmp = split /,/; push @vars, $tmp[0]; ${$tmp[0]} = $tmp[2]; } for (@vars) { print $_, ": ", ${$_}, "\n"; } __END__

Re: Joining/Merging AoA

2008-04-22 Thread Li, Jialin
use strict; use warnings; my @a = ( ['id', 'name', 'age'], ['1', 'Fred', '24'], ['2', 'Frank', '42'],); my @b = ( ['id', 'sex'], ['1', 'm' ], ['2', 'm'],); my %hash_id; for my $i (1 .. $#b) { $hash_id{ $b[$i][0] } = $i; } my @merged; push @merged, ['id', 'name', '