Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

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

Hi Digs27,
You have been given a load lot of help, which IMHO, are great if not better, but I thought since you mentioned CSV format, one should also look at using the likes of Text::CSV_XS like this:

use warnings; use strict; use Text::CSV_XS; use Inline::Files; #Note: Used to read multiply Virtual files my %station_data = getData( \*DATA ); my %data = getData( \*DATA2 ); for ( 0 .. $#{ $data{qw(Station)} } ) { my $key = $data{'Code'}[$_]; print join( " " => $station_data{'Station'}[$_], $station_data{"S_$key"}[$_], $station_data{"T_$key"}[$_] ), $/; } sub getData { my $file = shift(@_); my %data; my @heading = split /[\s,]/ => <$file>; my $csv = Text::CSV_XS->new( { binary => 1 } ) or die Text::CSV_XS->error_diag(); while ( my $row = $csv->getline($file) ) { push @{ $data{$_} } => shift @$row for @heading; } return %data; } __DATA__ Station,S_10,S_11,S_12,S_13,S_14,S_15,T_10,T_11,T_12,T_13,T_14,T_15 1,31,29,29,31,29,29,15,14,23,15,14,23 2,33,28,23,33,28,23,17,15,23,17,15,23 3,23,27,33,23,27,33,18,16,23,18,16,23 4,25,26,28,25,26,28,23,14,15,23,14,15 5,26,26,27,26,26,27,23,18,17,23,18,17 6,27,33,31,27,33,31,14,17,18,14,17,18 7,33,29,29,33,29,29,12,18,23,12,18,23 __DATA2__ Station,Code 1,10 2,11 3,12 4,13 5,14
Output as:
1 31 15 2 28 15 3 33 23 4 25 23 5 26 18
Using the OP data. A bit limiting though.

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me

In reply to Re: Matching Values in an Array by 2teez
in thread Matching Values in an Array by Digs27

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 rifling through the Monastery: (4)
As of 2024-04-18 20:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found