使用带有多个用途的分隔符的“split”

时间:2018-05-12 20:41:19

标签: perl delimiter

所以我在电影数据库上有一个csv文件,我正在把它读成一个数组。我需要将数组的每个部分拆分成另一个数组,或至少让它可以操作。

以下是csv文件的示例:

adult,belongs_to_collection,budget,genres,homepage,id,imdb_id,original_language,original_title,overview,popularity,poster_path,production_companies,production_countries,release_date,revenue,runtime,spoken_languages,status,tagline,title,video,vote_average,vote_count

实际元组的一个例子

False,"{'id': 10194, 'name': 'Toy Story Collection', 'poster_path': '/7G9915LfUQ2lVfwMEEhDsn3kT4B.jpg', 'backdrop_path': '/9FBwqcd9IRruEDUrTdcaafOMKUq.jpg'}",30000000,"[{'id': 16, 'name': 'Animation'}, {'id': 35, 'name': 'Comedy'}, {'id': 10751, 'name': 'Family'}]",http://toystory.disney.com/toy-story,862,tt0114709,en,Toy Story,"Led by Woody, Andy's toys live happily in his room until Andy's birthday brings Buzz Lightyear onto the scene. Afraid of losing his place in Andy's heart, Woody plots against Buzz. But when circumstances separate Buzz and Woody from their owner, the duo eventually learns to put aside their differences.",21.946943,/rhIRbceoE9lR4veEXuwCC2wARtG.jpg,"[{'name': 'Pixar Animation Studios', 'id': 3}]","[{'iso_3166_1': 'US', 'name': 'United States of America'}]",1995-10-30,373554033,81.0,"[{'iso_639_1': 'en', 'name': 'English'}]",Released,,Toy Story,False,7.7,5415 

这是我的代码:

open (NAMEFILE, "movies_metadata.csv");
my @topgrossmovie = <NAMEFILE>;
close NAMEFILE;

foreach $x ( @topgrossmovie ) {
    my ($adult,$belongs_to_collection,$budget,$genres,$homepage,$id,$imdb_id,$original_language,$original_title,$overview,$popularity,$poster_path,$production_companies,$production_countries,$release_date,$revenue,$runtime,$spoken_languages,$status,$tagline,$title,$video,$vote_average,$vote_count) = split /,/, $x;
}

由于它们在元组中是逗号,,因此非常困难。

0 个答案:

没有答案