Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

And the (not shown) code runs perfectly fine

great

the colours in the __DATA__ section asign perfectly with the phone models.

can't see this section in the post. How is this data section structured?

...to adding a second column into the phones.txt file

Already with two columns... but only in some rows

iphone samsung s2 Apple iPhone 4s test1

(Well in fact, with a number of columns between one and four, maybe more depending on the name of the phone, who knows?)

I added a column with values (seperated by tab) into the text file however that is also getting printed in the output file aswell as the first column? I want to differentiate between the columns at the beginning of the loop... I hope this makes sense? please can someone help me?

I read it three times and still don't understand your post, sorry, what is the question?. You can not use split like this if you have a variable number of columns in each row. Can we see a sample of your data?

Let see:

#!/usr/bin/perl use warnings; use strict; open (my $PHONE_FILE, '<', 'phones.txt') or die "Can't open file: $!\n +"; while(<$PHONE_FILE>) { chomp; my ($col1,$col2,@columns) = split /\t/, $_; print "$col1\t$col2\n"; }

In reply to Re: Separate column results?! by pvaldes
in thread Separate column results?! by perlnoobster

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (7)
    As of 2014-08-29 10:07 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (277 votes), past polls