in reply to Re^2: For- loop increment not passing to inner block
in thread For- loop increment not passing to inner block
This is bread and butter stuff for Perl and there are many better ways to achieve what you are after. Some are likely to be outside your current comfort zone so sift through the following and see what you like the look of:
use warnings; use strict; while (<DATA>) { chomp; my @numbers = unpack ("(a2)*", $_); print "unpacked: @numbers, "; @numbers = /(..)/g; print "matched: @numbers, "; @numbers = (); push @numbers, substr $_, 0, 2, '' while length $_; print "substr'd: @numbers\n"; } __DATA__ 0912203749 0725284648 0608294149 0622424347 1219303436 1729313449 1015162331
Prints:
unpacked: 09 12 20 37 49, matched: 09 12 20 37 49, substr'd: 09 12 20 +37 49 unpacked: 07 25 28 46 48, matched: 07 25 28 46 48, substr'd: 07 25 28 +46 48 unpacked: 06 08 29 41 49, matched: 06 08 29 41 49, substr'd: 06 08 29 +41 49 unpacked: 06 22 42 43 47, matched: 06 22 42 43 47, substr'd: 06 22 42 +43 47 unpacked: 12 19 30 34 36, matched: 12 19 30 34 36, substr'd: 12 19 30 +34 36 unpacked: 17 29 31 34 49, matched: 17 29 31 34 49, substr'd: 17 29 31 +34 49 unpacked: 10 15 16 23 31, matched: 10 15 16 23 31, substr'd: 10 15 16 +23 31
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: For- loop increment not passing to inner block
by Anonymous Monk on Mar 31, 2008 at 05:51 UTC | |
by GrandFather (Saint) on Mar 31, 2008 at 20:06 UTC |