Re: Using regex special characters from a string

2011-03-09 Thread Brian F. Yulga
Thanks for the reading suggestions! Brian Fraser wrote: On Wed, Mar 9, 2011 at 2:22 PM, Brian F. Yulga mailto:byu...@langly.dyndns.org>> wrote: Uri and Jim have hit upon one of my major stumbling blocks with learning Perl. There seems to be a difference of opinion on the proper ti

Re: Using regex special characters from a string

2011-03-09 Thread Brian Fraser
On Wed, Mar 9, 2011 at 2:22 PM, Brian F. Yulga wrote: > Uri and Jim have hit upon one of my major stumbling blocks with learning > Perl. There seems to be a difference of opinion on the proper times to use > hashes vs. arrays/lists...and how best to use them. http://perldoc.perl.org/perlfaq4.ht

Re: Using regex special characters from a string

2011-03-09 Thread Brian F. Yulga
Ben Lavery wrote: > there must be a slight trade-off... the processing required to > initialize the hash table with it's keys and values is probably > more intensive than defining an array with its respective values? > Unless, internally, Perl stores arrays as hashes, with the indexes > as the ke

Re: Using regex special characters from a string

2011-03-09 Thread Ben Lavery
> there must be a slight trade-off... the processing required to initialize the > hash table with it's keys and values is probably more intensive than defining > an array with its respective values? Unless, internally, Perl stores arrays > as hashes, with the indexes as the keys. I would have

Re: Using regex special characters from a string

2011-03-09 Thread Ben Lavery
On 9 Mar 2011, at 03:01, Ben Lavery wrote: > I shall change from a hash to an array and use grep, or looking into it I may > use List::MoreUtils as it has a "first_value" sub which should make it > somewhat more efficient. OK, so about an hour after I wrote this I was on the train home thinking

Re: Using regex special characters from a string

2011-03-09 Thread Brian F. Yulga
Jim Gibson wrote: On 3/9/11 Wed Mar 9, 2011 9:22 AM, "Brian F. Yulga" scribbled: > > foreach ( @word_list ) { if ( /^$temp_word$/i ) { push( > @all_combinations, ( $_ )); } } That is pretty much what the grep function is doing. It has to iterate over the entire array and evaluate its code

Re: Using regex special characters from a string

2011-03-09 Thread Jim Gibson
On 3/9/11 Wed Mar 9, 2011 9:22 AM, "Brian F. Yulga" scribbled: > Uri and Jim have hit upon one of my major stumbling blocks with learning > Perl. There seems to be a difference of opinion on the proper times to > use hashes vs. arrays/lists...and how best to use them. For those that > have he

Re: Using regex special characters from a string

2011-03-09 Thread Brian F. Yulga
Uri Guttman wrote: >> "BL" == Ben Lavery writes: > > > BL> #Here, using a hash looks much cleaner than iterating through an array > > hashes are almost always better for token lookups than scanning > arrays. don't doubt yourself in this area. > > Jim Gibson wrote: > On 3/8/

Re: Using regex special characters from a string

2011-03-08 Thread Ben Lavery
Hi Jim, thanks for replying :) >> >> $word_list{$_} = 0; > > If you assign 1 to the hash value, you can dispense with the 'exists' in > your test, below. >> #Here, using a hash looks much cleaner than iterating through an array >> push(@all_combinations, $temp_word) if (exists $word_list{$temp_w

Re: Using regex special characters from a string

2011-03-08 Thread Jim Gibson
On 3/8/11 Tue Mar 8, 2011 2:51 PM, "Ben Lavery" scribbled: > Here is my code, I've taken out a few irrelevant bits, but this is the main > guts: > use warnings; > use strict; > use Math::Combinatorics; > > #Set up a hash for searching later > my %word_list; > > #Read list of valid words into

Re: Using regex special characters from a string

2011-03-08 Thread Uri Guttman
> "BL" == Ben Lavery writes: BL> use warnings; BL> use strict; good! BL> use Math::Combinatorics; BL> #Read list of valid words into hash BL> my $WORDFILE='Words'; BL> open(WORDFILE, "$WORDFILE") or die "can't open $WORDFILE: $!"; BL> while () { BL> chomp; BL> $word_l

Re: Using regex special characters from a string

2011-03-08 Thread Ben Lavery
Hi Rob, Thank you for your response, sorry it wasn't as clear as I thought it might have been. > I have a script, and I want to feed it a special thing to let it know that > any character (A-Z or a-z does upper lower case matter?) is valid, but I > also want to use other characters at the same t

Re: Using regex special characters from a string

2011-03-08 Thread Rob Coops
Hi Ben, Not sure I get your point... but this is what it sounds like to me. I have a script, and I want to feed it a special thing to let it know that any character (A-Z or a-z does upper lower case matter?) is valid, but I also want to use other characters at the same time. So ./script.pl -s ABC