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

Re: Combining Files using Hash

by dasgar (Priest)
on Sep 05, 2017 at 05:47 UTC ( [id://1198677]=note: print w/replies, xml ) Need Help??


in reply to Combining Files using Hash

I haven't tested your code or looked closely at your regexes. But here are a few thoughts.

I believe that the two lines where you are trying to parse a line from a file need to have the regex within parentheses. In other words, change these original lines:

my($key,$value1,$value2,$value3) = $line =~ /(\w+),(\d+.\d+),(.\d+\s+\ +d+.\d+.)/g; my($key,$value1,$value2,$value3,$value4,$value5,$value6,$value7) = $li +ne =~ /(\w+|\S+),(\d+),(\d+),(\d+),(\d+.\d+),(\d+.\d+),(\d+),(\d+.\d+ +)/g ;

to make them look like the following:

my($key,$value1,$value2,$value3) = ($line =~ /(\w+),(\d+.\d+),(.\d+\s+ +\d+.\d+.)/g); my($key,$value1,$value2,$value3,$value4,$value5,$value6,$value7) = ($l +ine =~ /(\w+|\S+),(\d+),(\d+),(\d+),(\d+.\d+),(\d+.\d+),(\d+),(\d+.\d ++)/g);

An easy debugging step is to print out the variables to verify that they are indeed holding what you think they are. Based on your description of the error message, it sounds like one of your regex lines isn't matching for all lines of the file (such as the header line or blank lines).

In looking at your data, it looks like the files are in CSV format. Although it might be tempting to use split to parse those lines, I think it probably would be better to use something like Text::CSV to parse those files.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1198677]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-24 22:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found