howto : $y to @x and @x to $y

K

key9

Hi all

sorry , beginner :)

suppose I have datafile
....
100-101-102-104-105-106-107-108
200-201-202-204-205-206-207-208
300-301-302-304-305-306-307-308
....

when I open file successful and read them into

@datas

and I using

foreach $data (@datas) {
my @each=();
# process
}

to process each element;


so how to translate $data into @each as numeric array? (100,101,102,103,104)

and how to merge them back to string?

what about data is

1,123123,23123,21,2,213,1231231,231
and
TFTFTFTFTFTFTFFTFTFTFTFTTTFTFTFTFTF

thank you very much!

your key9
 
B

Brian McCauley

suppose I have datafile
...
100-101-102-104-105-106-107-108
200-201-202-204-205-206-207-208
300-301-302-304-305-306-307-308
...

when I open file successful and read them into

@datas

and I using

foreach $data (@datas) {
my @each=();
# process

}to process each element;

so how to translate $data into @each as numeric array?
(100,101,102,103,104)

and how to merge them back to string?

You are asking how to split a string into a list and how to join a list
into a string.

perldoc -f split
perldoc -f join
what about data is

1,123123,23123,21,2,213,1231231,231
and

That's just spliting with a different delimiter.
TFTFTFTFTFTFTFFTFTFTFTFTTTFTFTFTFTF

That's using a empty string as a delimiter. Luckly split() can even do
that.
 
B

Brian McCauley

suppose I have datafile
...
100-101-102-104-105-106-107-108
200-201-202-204-205-206-207-208
300-301-302-304-305-306-307-308
...

when I open file successful and read them into

@datas

and I using

foreach $data (@datas) {
my @each=();
# process

}to process each element;

so how to translate $data into @each as numeric array?
(100,101,102,103,104)

and how to merge them back to string?

You are asking how to split a string into a list and how to join a list
into a string.

perldoc -f split
perldoc -f join
what about data is

1,123123,23123,21,2,213,1231231,231
and

That's just spliting with a different delimiter.
TFTFTFTFTFTFTFFTFTFTFTFTTTFTFTFTFTF

That's using a empty string as a delimiter. Luckly split() can even do
that.
 
K

key9

That's using a empty string as a delimiter. Luckly split() can even do

I got it :)
it's amazing : split string directly with regexp , who's blooded idea?
After vb c c++ ,I really think perl is what I really want .
 

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

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,660
Latest member
vidotip479

Latest Threads

Top