Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Efficient split for alpha numeric pairs in a row

by johngg (Abbot)
on Jul 01, 2015 at 09:55 UTC ( #1132784=note: print w/replies, xml ) Need Help??


in reply to Efficient split for alpha numeric pairs in a row

An alternative approach split'ing on points preceded by a letter and followed by a value or vice versa.

use 5.014; use Data::Dumper; open my $inFH, q{<}, \ <<EOD or die $!; 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 EOD my @dataLines = map { { split m{(?x) (?<=[A-Z]) (?=[-\d]) | (?<=[-\d]) (?=[A-Z]) } +} } map { chomp; $_ } <$inFH>; close $inFH or die $!; print Data::Dumper->Dumpxs( [ \ @dataLines ], [ qw{ *dataLines } ] );

The output.

@dataLines = ( { 'M' => '25', 'J' => '58.34', 'Y' => '649.62', 'H' => '2', 'I' => '77.33', 'N' => '260', 'X' => '142.05', 'G' => '02' }, { 'M' => '20', 'N' => '265' }, { 'G' => '45', 'N' => '270' }, { 'G' => '01', 'Y' => '608.8', 'X' => '304.78', 'M' => '25', 'C' => '45.91', 'N' => '275' }, { 'M' => '20', 'N' => '280' }, { 'N' => '285', 'C' => '0', 'G' => '46' }, { 'Y' => '638.4', 'J' => '67.4', 'M' => '25', 'G' => '03', 'X' => '324.39', 'I' => '-69.58', 'N' => '290', 'H' => '2' }, { 'N' => '295', 'M' => '20' }, { 'G' => '45', 'N' => '300' }, { 'N' => '305', 'C' => '326.5', 'M' => '25', 'G' => '01', 'Y' => '592.89', 'X' => '180.04' }, { 'N' => '310', 'C' => '26.5', 'X' => '279.77', 'Y' => '586.78' }, { 'Y' => '584.57', 'X' => '195.39', 'C' => '336.5', 'N' => '315' }, { 'X' => '228.31', 'Y' => '579.58', 'N' => '320', 'C' => '355.92' } );

I hope this is helpful.

Cheers,

JohnGG

Replies are listed 'Best First'.
Re^2: Efficient split for alpha numeric pairs in a row
by BrowserUk (Pope) on Jul 01, 2015 at 10:18 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1132784]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2018-02-19 14:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (265 votes). Check out past polls.

    Notices?