in reply to Optimal way to read in pipe delimited files
I don't know about 'optimal', really. The code you list implies that you can rely on having 4-element rows, so this might be some fun:
while (<SRC>) { $prod{$1} = [$2,$3,$4] if m{(.+?)\|(.+?)\|(.+?)\|(.+)}; }
Or, another more general approach with regex captures, which works with any data size:
while (<SRC>) { @{ $prod{$1} } = split('\|', $2) if m/^(.+?)\|(.+)/; }
Of course, I doubt those are very fast, compared to, say:
while (<SRC>) { my @row = split(/\|/, $_); $prod{$row[0]} = \@row[1..$#row]; #using a slice; }
|
|---|