Both substitute and filter - Page 5

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Re: Both substitute and filter

Quoted text here. Click to load it

This started out as a simple remark, namely, that the assignment in

my @result = ();

was pointless because it doesn't have any effect. Using a simple example
from some other domain, assuming the solution to

(a + b) ** 2

is not presented as

a**2 + 2*a*b + b**2

but as

1 * (-17 + a**4/a**2 + (38 * a * b) / 19 + 1 / b**-2 + 17) / 1

[this term is probably wrong but a correct one could be constructed in a
similar way]

a term paper containing this won't end up in a gallery in order
demonstrate that - even in mathematics - individual, creative, stylistic
preferences are valued higher than substance but it will earn the person
who came up with this elaborate deception an energetic strike-through
and possibly, some educating remarks about wasting other people's time
with pointless nonsense.

And the situation is no different for code where 'terms' also have
exactly defined meanings.

Re: Both substitute and filter

Quoted text here. Click to load it

I just realized that I didn't make it clear that I didn't want to
modify @sources, but given that foreach aliases to each element in
turn and s/// would change it, the pseudocode kind of implied it.
(Tho' my specific solutions shown didn't modify @sources and there'd
be no reason to have @results if @sources could be munged.)  My

Tim McDaniel,

Re: Both substitute and filter

On 12/12/2014 3:49 PM, Tim McDaniel wrote:
Quoted text here. Click to load it

How about this?

use v5.14;
use strict;
use warnings;
@::sources = ("hi", "there", "TARGET23", "hello", "TARGETblarg", "world");
@::results = ();
map {my $matched = ($_ =~ s/^TARGET//); push(@::results, $_) if $matched;} @::sources;
say join(", ", @::results);

23, blarg

Robbie Hatley
Midway City, CA, USA
perl -le 'print "4o6e7o4f0w5llc7m"'

Site Timeline