G'day juanito23,

What you show at the start is invalid syntax. If that's returned from Text::CSV's getline() method, you have an arrayref (["m2000_id", ...]). If it's really an array, it looks like ("m2000_id", ...). Furthermore, as you've said "already done", this would seem to suggest that this is partially processed data: perhaps you started with string of comma-separated values. Not knowing the data you're working with is not a good start.

Your other code fragment is incomplete. Where's the if block? What value does $_ hold? How does it get that value? (By the way, 0 .. 10 is a range of 11 values!)

Here's how I might have iterated over an array testing both element content and array index:

#!/usr/bin/env perl -l use strict; use warnings; my @array = qw{! 1 A @ 2 b $ 3 c % 4 D ^ 5 e}; for my $i (0 .. $#array) { if ($array[$i] =~ /[a-zA-Z]/ || $i < 10) { print "[$i] Quote: '$array[$i]'"; } else { print "[$i] Don't quote: '$array[$i]'"; } }

Output:

[0] Quote: '!' [1] Quote: '1' [2] Quote: 'A' [3] Quote: '@' [4] Quote: '2' [5] Quote: 'b' [6] Quote: '$' [7] Quote: '3' [8] Quote: 'c' [9] Quote: '%' [10] Don't quote: '4' [11] Quote: 'D' [12] Don't quote: '^' [13] Don't quote: '5' [14] Quote: 'e'

That might at least give you a starting point.

-- Ken


In reply to Re: array range positions by kcott
in thread array range positions by juanito23

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.