Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hi,

I have looked at the code and I have written a program that could be used as a starting point for what you are trying to achieve.

This program does not cover all of what you are trying to do, it simply goes up to splitting the milcar file and loading a hash. I hope this gives you an idea of some perl's best practises (or what I would consider best practises), and help you complete your task.

Kind regards.

Arnaud
use strict; # Please use these 2 pragmas use warnings; use autodie; #this one comes handy as well if (@ARGV !=4 ) { die "Ooops etc.."; } # a more descriptive name for your vars, otherwise you may as well # use $ARV[0], $ARGV[1] etc... my ($milcar_filename, $check_file, $matches_file, $three_column_file) += @ARGV; #use the 3 args version of open; open my $fh, '<', $milcar_filename; #prg will 'die' if file error due to the autodie pragm +a #store some values into a hash my %hash; while my $line(<$fh>) { chomp $line; # I assume here that the milcar file is pipe separated # but replace the separator with the separaor of your choice my ($last_name, $first_name, $integer1, $word1, $integer2, $word2, $real_number) = split /\|/, $line; #build a key, see if the key already exists, and # update with the latest int2 value, if larger. my $key = $last_name . '_' . $first_name; if (exists $hash{$key} ) { if ($integer2 > $hash{key} ) { $hash{$key} = $integer2; } } else { $hash{$key} = $integer2; } }

In reply to Re: Writing Program With Hashes and Loops For Files With Data in Columns by arnaud99
in thread Writing Program With Hashes and Loops For Files With Data in Columns by prpheart

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-03-19 09:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found