Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: generating rows(matrix) based on file content

by blue_cowdawg (Monsignor)
on Apr 23, 2013 at 13:16 UTC ( #1030137=note: print w/replies, xml ) Need Help??

in reply to generating rows(matrix) based on file content

      What I want to generate is this. (I also need to keep the row descriptors : run1, run2 etc)

There are many ways to skin this cat and the cat isn't happy about it.

#!/usr/bin/perl -w use strict; while (my $line=<DATA>){ chomp $line; my($run,@sw)=split(/[\s]+/,$line); my @switches=(); $switches[$_] = 0 foreach (0..5); # initialize switch array $switches[$_ -1]=1 foreach (@sw); printf "%s %s\n",$run,join(" ",@switches); } exit(0); __END__ run1 2 4 run2 1 6 run3 1 run4 1 3 run5 2 5

Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1030137]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (10)
As of 2018-06-20 19:49 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (117 votes). Check out past polls.