splitting data?

J

Jerry Preston

I am trying to breakdown:

my $data = "..X...X... X...X...X. ..X.. ";
$data =~ s/ //g;

# $p = join ",", map /(\w)/ ? $1 .. $2 : $_, split /,/, $data;

# my $p = join ",", split /[\.|X]/, $data;

my( @wafers ) = split /[\.|X]/, $data;

so that I get an array ( @wafers ) containing each element of $data.

Ideas?

Thanks,

Jerry
 
J

Jerry Preston

OK!

This kinda work!

my @wafers = ();
my @slots = ( 0..24 );
my $data = "..X...X... X...X...X. ..X.. ";
$data =~ s/\s+//g;
@wafers = split /(\.)|(X)/, $data;


print join("*", @wafers);

This is what the printed results look like:

"*.***.****X**.***.***.****X**.***.***.****X**.***.***.****X**.***.***.****X
**.***.***.****X**.***."

Why so many "*"/spaces?

Jerry
 
T

Todd de Gruyl

I am trying to breakdown:

my $data = "..X...X... X...X...X. ..X.. ";
$data =~ s/ //g;

# $p = join ",", map /(\w)/ ? $1 .. $2 : $_, split /,/, $data;

# my $p = join ",", split /[\.|X]/, $data;

my( @wafers ) = split /[\.|X]/, $data;

so that I get an array ( @wafers ) containing each element of $data.

try splitting on //, which will just give you the characters in $data
after you remove the spaces:

#!/usr/bin/perl
use warnings;
use strict;

my $data = "..X...X... X...X...X. ..X.. ";
$data =~ s/ //g;
my @wafers = split (//, $data);
 
G

gnari

Jerry Preston said:
OK!

This kinda work!

my @wafers = ();
my @slots = ( 0..24 );
my $data = "..X...X... X...X...X. ..X.. ";
$data =~ s/\s+//g;
@wafers = split /(\.)|(X)/, $data;


print join("*", @wafers);

This is what the printed results look like:

"*.***.****X**.***.***.****X**.***.***.****X**.***.***.****X**.***.***.****X
**.***.***.****X**.***."

Why so many "*"/spaces?

the purpose of split is to get an array of what is between the separators.
in
this case, a whole bunch of empty strings.
if you use capturing parens with it you also get the captured part in
between.

what you want is to split on empty string
@wafers=split file://,$data;
or probably better:
@wafers=$data=~/(\.|X)/g;

with this method you do not need to strip the spaces first.

gnari
 
J

Jerry Preston

Todd,

Works!

Thanks,

Jerry

Todd de Gruyl said:
I am trying to breakdown:

my $data = "..X...X... X...X...X. ..X.. ";
$data =~ s/ //g;

# $p = join ",", map /(\w)/ ? $1 .. $2 : $_, split /,/, $data;

# my $p = join ",", split /[\.|X]/, $data;

my( @wafers ) = split /[\.|X]/, $data;

so that I get an array ( @wafers ) containing each element of $data.

try splitting on //, which will just give you the characters in $data
after you remove the spaces:

#!/usr/bin/perl
use warnings;
use strict;

my $data = "..X...X... X...X...X. ..X.. ";
$data =~ s/ //g;
my @wafers = split (//, $data);
 
J

Jerry Preston

Gnarl,

True.

Jerry

gnari said:
"*.***.****X**.***.***.****X**.***.***.****X**.***.***.****X**.***.***.****X

the purpose of split is to get an array of what is between the separators.
in
this case, a whole bunch of empty strings.
if you use capturing parens with it you also get the captured part in
between.

what you want is to split on empty string
@wafers=split file://,$data;
or probably better:
@wafers=$data=~/(\.|X)/g;

with this method you do not need to strip the spaces first.

gnari
 
J

John W. Krahn

Jerry said:
I am trying to breakdown:

my $data = "..X...X... X...X...X. ..X.. ";
$data =~ s/ //g;

# $p = join ",", map /(\w)/ ? $1 .. $2 : $_, split /,/, $data;

# my $p = join ",", split /[\.|X]/, $data;

my( @wafers ) = split /[\.|X]/, $data;

so that I get an array ( @wafers ) containing each element of $data.

It looks like you want something like:

my $data = '..X...X... X...X...X. ..X.. ';

my @wafers = $data =~ /[.X]/g;


John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,163
Messages
2,570,897
Members
47,435
Latest member
PhilipBelm

Latest Threads

Top