Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > multiple modifiers: a possible solution

Reply
Thread Tools

multiple modifiers: a possible solution

 
 
ioneabu@yahoo.com
Guest
Posts: n/a
 
      01-23-2005
Sorry if the formatting gets messed up. I am not on my own computer
now and Google is the only way I can post this from here. Try this
out:

#!/usr/bin/perl

use warnings;
use strict;

my @a = ('a','b','c');
my @b = ('1','2','3','4','5');
my $c = 1;
my $d = multimod('print for @a for @b if $c');
eval $d;
print "\n$d\n";

sub multimod
{
my $mods = "if|for|while|unless";
my $a = shift;
my ($b,$c,$d);
while ($a =~ /^(.*?)($mods)(.*?)($mods)(.*)/)
{
$c = $d = '';
if ($4 and $5)
{
$a = "$4$5";
$c = $4;
$d = $5;
}
if ($1) {$b = "$2($3) {$1}"}
else {$b = "$2($3) {$b}"}
}
return "$c($d) {$b}" if $c and $d;
}

 
Reply With Quote
 
 
 
 
Anno Siegel
Guest
Posts: n/a
 
      01-23-2005
<(E-Mail Removed)> wrote in comp.lang.perl.misc:
> Sorry if the formatting gets messed up.


Predictably it did.

> I am not on my own computer
> now and Google is the only way I can post this from here. Try this
> out:
>
> #!/usr/bin/perl
>
> use warnings;
> use strict;
>
> my @a = ('a','b','c');
> my @b = ('1','2','3','4','5');
> my $c = 1;
> my $d = multimod('print for @a for @b if $c');
> eval $d;
> print "\n$d\n";


Yes, that may work, but it's beside the point. The point of combining
statement modifiers is elegance, (or at least tightness) of code. Calling
a sub and eval'ing the result doesn't give us that.

Your example shows that it can be done in Perl, but there never was much
doubt about that.

[code snipped]

Anno
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Solution file not in the solution folder =?Utf-8?B?Y2FzaGRlc2ttYWM=?= ASP .Net 2 09-12-2006 11:04 AM
A Solution using Tasks Re: [Stackless] Suggestion for a Solution ? Andrew Francis Python 0 06-28-2006 06:05 PM
Re: One solution containing multiple projects and multiple hosts Stephen Miller ASP .Net 0 06-24-2003 12:55 PM



Advertisments