On 07/14/2006 06:04 PM, Ryan Moszynski wrote:
Mumia,
thanks for your work on answering my help request. I really
appreciate it. However, while your solution works perfectly in your
sample program, since I am new to perl, I am having trouble
understanding some of the techniques you used, and i am having trouble
integrating the solution that you came up with into my own program.
how do i get all of this inside my if statement?
Let the s/// operator eat away at (a copy of) the line and
test if
anything is left (discussion below).
I don't understand
why the second line works(I know its comparing the values for
greater/lesser, but not how in the world perl is interpreting it, if
i'm making any sense)
what are the ':'s doing?, and lastly, what is eg?
i know you spent too much time on this already, but i'd really
appreciate you clearing this up for me. this stuff isn't in my perl
book. . .
########
1: $str =~ s/(?:(\d+)-(\d+)|(\d+));?/
2: $3 ? '' : ($2 > $1 ? '' : 'y')
/eg;
3: '' eq $str;
########
[...]
That code basically eats away at a copy of the line until it's
gone. If the eating is done, but there are some characters
still left, the string is considered malformed.
The code says:
1: For each segment that looks like either digits or
digits-digits, grab the digits as $3 or the digits-digits as
$1 and $2.
2: If $3 has a value, return ''. If not, and $2 > $1, return
''. Otherwise return 'y.'
3: If all ranges in the string were processed correctly, it's
empty, so return TRUE if it's empty and FALSE (undef) if it's
not empty.
I know it's complicated because it took me at least a couple
of hours to figure it out, and I used some non-trivial
features to do it. You can get the documentation for some of
these features using, as Timothy Johnson said, perldoc:
perldoc perlop
Read the "s/PATTERN/" and the "Conditional Operator" sections.
HTH
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>