In perl, how do you store multiple values from a single test file line into an array -
here couple of typical lines input file trying crunch:
icc2_dpd 2.7v ma 0.006 0.006 0.006 ... ... dpd_rel 2.7v ma 0.062 0.054 0.040 0.065 0.037 0.066 0.071 0.073 ... ... ...
(the number of floats can vary) here started with:
if(/^(\w+)\s+(\d+\.?\d*)v\s+(\w+)/) { print $out "$1 $2 $3\n"; }
how capture , store floating point values array/hash given number of values varies. stuck on how manage termination of array.
well, in case, consider using split
, separating fields on whitespace:
while (<data>) { @vals = split; # default split fine print join(" ", @vals[3 .. $#vals]), "\n"; }
or if want store them, push them onto array, or use hash suitable key. like...
push @array, [ @vals[3 .. $#vals] ]; # push array ref $hash{$vals[0]} = [ @vals[3 .. $#vals] ]; # use hash
the [ ... ]
part creating anonymous array ref, can store line's values in single scalar slot.
Comments
Post a Comment