Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Think about Loose Coupling
 
PerlMonks  

Title of Column and Split Function

by eepvesity (Initiate)
on Mar 28, 2013 at 15:49 UTC ( #1025988=perlquestion: print w/ replies, xml ) Need Help??
eepvesity has asked for the wisdom of the Perl Monks concerning the following question:

In using the split function for columns and push function for placing names and heart rates in hash from files with following format:

Patient Heart Rates Melly 70 Glenn 69
How would I ensure that the column headings "Patient" and "Heart Rates" do not end up in the hash or are excluded from appearing in any data structures? Thank you.

Comment on Title of Column and Split Function
Download Code
Re: Column Heading and Split Function
by McA (Deacon) on Mar 28, 2013 at 15:57 UTC
    open my $fh, "<", "filename" or die $!; my $headerline = <$fh>; unless(defined $headerline) { die "ERROR: Couldn't read header line: Bad file format?"; } while(my $line = <$fh>) { process($line); } close $fh or die $!;

    McA

Re: Column Heading and Split Function
by hdb (Parson) on Mar 28, 2013 at 16:02 UTC

    use strict; use warnings; my %hrates; while( <DATA> ) { chomp; next if /^Patient/; my ($name, $heartrate) = split; $hrates{$name} = $heartrate; } print %hrates; __DATA__ Patient Heart Rates Melly 70 Glenn 69
Re: Column Heading and Split Function
by thirdm (Sexton) on Mar 28, 2013 at 16:24 UTC
    use File::Slurp; my %rates = (); $_ = read_file(\*DATA); /$/mg; # skip first line $rates{$1} = $2 while /^(\w+)\h+(\d+)/mg; $, = "\t"; print %rates; __DATA__ Patient Heart Rates Molly 70 Glenn 69
      hmmm.
      use File::Slurp; $_ = read_file(\*DATA); /$/mg; # skip first line my %rates = /^(\w+)\h+(\d+)/mg; $, = "\t"; print %rates; __DATA__ Patient Heart Rates Molly 70 Glenn 69

        One more reduction and we have to put this node into Obfuscation... ;-)

        But while thinking it's interesting it deserves a ++

        McA

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1025988]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2014-04-18 12:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (467 votes), past polls