You can use a regular expression. The
/g modifier in a while-loop will match as many times as possible:
#! /usr/bin/perl
use warnings;
use strict;
use Data::Dumper;
while (<DATA>) {
my %hash;
while (/([A-Z])([0-9.]+)/g) {
my ($key, $num) = ($1, $2);
$hash{$key} = $num;
}
print Dumper(\%hash);
}
__DATA__
N260G02X142.05Y649.62I77.33J58.34H2M25
N265M20
N270G45
N275G01X304.78Y608.8C45.91M25
N280M20
N285G46C0
N290G03X324.39Y638.4I-69.58J67.4H2M25
N295M20
N300G45
N305G01X180.04Y592.89C326.5M25
N310X279.77Y586.78C26.5
N315X195.39Y584.57C336.5
N320X228.31Y579.58C355.92
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.