Re: how to implement this with perl



Li, Jialin 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);

Or simply:

my @labels = $label =~ /\d+/g;
my @thicks = $thick =~ /\d*\.\d*/g;


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
.



Relevant Pages

  • Re: Problem with uninitialized char.
    ... John W. Krahn wrote: ... > Perl arrays are zero based so you are not assigning a value to the first ... >> char, so tried to ... so the first possition is always empty and i recive these warnings. ...
    (perl.beginners)
  • Re: Substituting in a group
    ... And avoid using the substitution operator or capturing parentheses. ... John ... Perl isn't a toolbox, but a small machine shop where you ...
    (comp.lang.perl.misc)
  • Re: Displaying a users group memberships
    ... use strict; ... use warnings; ... Perl isn't a toolbox, but a small machine shop where you can special-order ...
    (perl.beginners)
  • Re: ISALPHA
    ... The script does not give error message but it doesn't ... John ... Perl isn't a toolbox, but a small machine shop where you ...
    (comp.lang.perl.misc)
  • Re: how to find how many items are in a reference?
    ... John ... Perl isn't a toolbox, but a small machine shop where you ...
    (comp.lang.perl.misc)