osdir.com
mailing list archive

Subject: Re: Perl Quiz-of-the-Week #12 - msg#00033

List: lang.perl.qotw.discuss

Date: Prev Next Index Thread: Prev Next Index

Once again my mail server has summarily discarded the quiz-of-the-week
notes. Are they on a Web page somewhere?





Was this page helpful?
Yes No
Thread at a glance:

Previous Message by Date: click to view message preview

Re: Perl 'Expert' Quiz-of-the-Week #12

Mark Jason Dominus wrote: Write a function, 'expand_escapes', which expands escape sequences in text. Escape sequences have the form X<.....> where 'X' is any letter or digit and '.....' is any string that contains balanced <...> sequences. A backslash before a <, >, or \ removes its special meaning, so, for example, A<a b c D<edfg\>hij> k l m> is a valid single escape sequence. The arguments to 'expand_escapes' are the string to be expanded, and a reference to a hash which maps the escape codes to expansion functions; for example, expand_escapes("A<a b c D<edfg\>hij> k l m>", { A => \&expand_a, D => \&escape_sequence_d, }); When 'expand_escapes' recognizes an escape sequence, say W<some text> it should first expand escape sequences in 'some text', if there are any, removing backslashes where appropriate; then look in the hash to find the associated function for 'W'; invoke the function, passing the with the expanded version of 'some text' as the argument, and finally, replace the entire sequence 'W<...>' with the return value of the function. It should do this for every escape sequence in its string argument. The example above should return the value of: expand_a("a b c " . escape_sequence_d("edfg>hij") . " k l m"); Another example: given these arguments: expand_escapes("Result: R<12\>34>, S<Give me pie!>, R<abcS<te\<xt>xyz>", { R => sub { scalar reverse $_[0] }, S => sub { join " ", split //, $_[0] }, } ); 'expand_escapes' should return the string "Result: 43>21, G i v e m e p i e !, zyxt x < e tcba" The function should be efficient, even for large argument strings. This quiz is interesting, because calling expand_escapes like: expand_escapes( ... , { q => sub { expand_escapes ($_[0]) }, # should be qq Q => sub { quotemeta $_[0] }, U => sub { uc $_[0] }, L => sub { lc $_[0] }, c => sub { eval "\\N{$_[0]}" }, x => sub { hex $_[0] }, etc => ... } ); is similar to much of the perl6 string interpolation semantics, except that the perl6 equivalant must have backslashes before the escape sequence, and the quiz doesn't cover quoting types and single character escapes. The current parser that handles all of this is large and bulky, so it would be great to see some elegant solutions. :-) Joseph F. Ryan ryan.311-ZbGKxL/pcrQ@xxxxxxxxxxxxxxxx

Next Message by Date: click to view message preview

Re: Perl Quiz-of-the-Week #12

grommel-+Kqh9TlgXRoAvxtiuMwx3w@xxxxxxxxxxxxxxxx wrote on 08:00 2003-02-13 -0600: > Once again my mail server has summarily discarded the quiz-of-the-week > notes. Are they on a Web page somewhere? RTFM: Check the message headers, follow the link: "I missed this week's quiz. Is it archived anywhere?"

Previous Message by Thread: click to view message preview

Re: Perl Quiz-of-the-Week #12

I'm sure you meant:The output should be scaled to fit ina rectangle with $HISTOGRAM_HEIGHT rows and $HISTOGRAM_WIDTH columns.But is scaling supposed to keep the columns one char wide or expand the column width to make the scale?   Both, or either, I suppose, on user aggression.  Never mind. aAndy Bach, Sys. ManglerInternet: andy_bach-TPjY3RQF+oO9IyArzxoquPIbXMQ5te18@xxxxxxxxxxxxxxxx    VOICE: (608) 261-5738  FAX 264-5030" ... even if you're mediocre/decent at perl [the cmecf] code is pretty confusing in certain areas ..." CB

Next Message by Thread: click to view message preview

Re: Perl Quiz-of-the-Week #12

> Once again my mail server has summarily discarded the quiz-of-the-week > notes. Are they on a Web page somewhere? The QOTW web pages are at http://perl.plover.com/qotw/ and have links to all the past quizzes and mailing list archives. Every qotw email message that goes out has the URL in the header. Also you can send mail to perl-qotw-help-ZxR0713JXSrQT0dZR+AlfA@xxxxxxxxxxxxxxxx for the URL.
Sign up for updates to this mailing list. email:
Loading Comments...
Home | News | Patents | Sitemap | FAQ | advertise

Advertising by