in reply to Changing the numerical value from 0 to 1
G'day hellohello1,
Welcome to the monastery.
Here's a short script that tests solutions offered:
#!/usr/bin/env perl use strict; use warnings; my @tests = ('0', '1', '000', '101', '010', '1 * 0 = 0'); my $format = '%9s | ' x 4 . "\n"; printf $format => qw{initial boundary start/end assign}; for (@tests) { my ($init, $bound, $start, $assign) = ($_) x 4; $bound =~ s/\b0\b/1/; $start =~ s/^0$/1/; $assign = 1 if $assign == 0; printf $format => $init, $bound, $start, $assign; }
Output:
initial | boundary | start/end | assign | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 000 | 000 | 000 | 1 | 101 | 101 | 101 | 101 | 010 | 010 | 010 | 010 | Argument "1 * 0 = 0" isn't numeric in numeric eq (==) at ./pm_example. +pl line 16. 1 * 0 = 0 | 1 * 1 = 0 | 1 * 0 = 0 | 1 * 0 = 0 |
Results:
So, with the data and solutions used here, only s/^0$/1/ works consistently.
You can change @tests to a list of representative examples from your data to get more realistic output. You can add tests for any other solutions that may present themselves.
Also, if you find more than one solution that works, and processing speed is important to you, you can compare them with Benchmark.
-- Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Changing the numerical value from 0 to 1
by hellohello1 (Sexton) on Jan 28, 2014 at 03:03 UTC | |
by kcott (Archbishop) on Jan 28, 2014 at 05:31 UTC | |
by hellohello1 (Sexton) on Jan 28, 2014 at 06:30 UTC | |
by AnomalousMonk (Archbishop) on Jan 28, 2014 at 09:12 UTC | |
by kcott (Archbishop) on Jan 29, 2014 at 05:59 UTC |