in reply to how to place rows information into column (2)
in thread how to place rows information into column?

$file = '0.000000e+000 1.502947e+000 1.162272e-012 1.508957e+001 2.324544e-012 1.508948e+000'; my $regex = { 'first' => qr{^(\S+)}, # anything non-blank from the beginning '^' 'second' => qr{\s+(\S*)} # anything non-blank after the fist blank '\ +s+' }; for(split '\n', $file){ /$regex->{first}$regex->{second}/o # 'o' compiles the regex and # and upon success we take the first column and/or the second one print "Key: $1 and Value: $2\n"; # So hash structure can have $hash{$1} = $2 }

Replies are listed 'Best First'.
Re^2: how to place rows information into column (2)
by riz (Initiate) on Feb 02, 2005 at 22:06 UTC
    Hi sh1n,

    are we assigning these lines
    '0.000000e+000 1.502947e+000
    1.162272e-012 1.508957e+001
    2.324544e-012 1.508948e+000';
    to the variable $file. With '...' in the middle means some 2000 more pairs in continuity. Kindly explain your very first line of the code.
    many thanks,
    riz.
      Hi riz,

      The very first line is scalar instead of file handler for simplicity.
      As fas as I understand more important is the way we match (or split) these two columns.
      Do you really think that another 2000 lines matter something?
      As conserns RAM or performance - it doesn't matter.