yitzle wrote:
On Thu, Jun 26, 2008 at 11:00 AM, Li, Jialin <[EMAIL PROTECTED]> wrote:
another way to handle the one line input is to read the whole line at once
and then use
regex to extract each column


__CODE__
#!/usr/bin/perl
use strict;
use warnings;
my $label_file = "label.in";
my $thickness_file = "thickness.in";

open my $fp_l, "<", $label_file or die "Cannot open $label_file";
my $label = <$fp_l>;
close $fp_l;

open my $fp_t, "<", $thickness_file or die "Cannot open $thickness_file";
my $thick = <$fp_t>;
close $fp_t;

my @labels = ($label =~ /(\d+)\s+/g);
my @thicks = ($thick =~ /(\d*\.\d*)\s+/g);
This approach will not capture the last value on the line if the file
does not end with whitespace. Split might be better suited.
@labels = split ( $label );

That is the same as:

@labels = split ( /$label/, $_ );

But you probably meant:

@labels = split ' ', $label;



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to