Greetings wise brothers and sisters,

As the saying goes, "It is better to remain silent and be thought a fool, than to speak up and remove all doubt." I'm going to go for it anyway, though. My problem is this:

I am creating a utility to parse a simple text file. I need to capture the text on certain lines into a single scalar variable, so I thought to use split thus:

($spectext) = split (0);

where the 0 is the Limit. Fine, but when the text on one of my lines is this: 10 minutes or less, my variable for that line comes back as a "1". All the other lines come back as expected. I get that when it sees the 0 in the line, it assumes it's the delimiter instead of the default whitespace. I tried the following,($spectext) = split (" ",$_,0); which, from my handy copy of Perl by Example, looks like it should work, (specifying delimiter,string and limit) but now all I get is the first word of every line, which is not at all what I want. My code is here

#!/usr/bin/perl use strict; use diagnostics; use warnings; my ($qnum,$qtext,$spectext,$p); while (<DATA>){ if (^[0-9]\.|^[0-9][0-9]\.|^[0-9][A-Za-z]\.|^[0-9][0-9][A-Za-z]\.){ $p = 1; ($qnum,$qtext) = split (/\./); print "L Q$qnum\nttlQ$qnum. $qtext\nn10base - total respondents\n" +; } elsif (^[A-Z]|^[0-9]){ ($spectext) = split (0); chomp $spectext; print "n01$spectext;c=c{Q$qnum}'$p'\n"; $p++; } else { print; } } ----DATA---- 1. Question text? 2 minutes or less 3 to 4 minutes 5 to 9 minutes 10 minutes or more 2. Question text? Excellent Very good Good Fair Poor ----Desired output------ L Q1 ttlQ1. Question text? n10Base - Total Respondents n012 minutes or less;c=c{Q1}'1' n013-4 minutes;c=c{Q1}'2' etc....
if anyone cares to see it, and of course comments are welcome. I'm sure it's something very simple. Usually is. Blessings upon you all for the help, or heckling. I will take either in good grace, wise friends.

Pax,

NovMonk


In reply to Split problem using limit by NovMonk

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.