Hi, Anonymous:

Well, you have a couple of issues going on here, that are likely to confuse you. First, when you use a '$' for your variable's sigil (the sign in front), you're telling Perl that the variable is a scalar. It contains a single item of data, even though that item is "1, 2, 3, 4, 5, 6, 70". That is not a list, nor is it an array. It's a string. In order to create an array, you would use the '@' symbol, as in '@a'. This tells Perl that this variable will contain a set of scalar values, and that their order is important.

To set up an array, you can't do the quoted list of numbers. That would just create an array with a single element, containing the string. You were on the right track - separating the individual elements with a comma - but you need to place the list in parentheses, not quotes. The assignment would look like this: @a = (1, 2, 3, 4, 5, 6, 70); Once you've created your arrays, you can then try some of the things [id://ptum], [id://Tanktalus], or [id://GrandFather] have shown you. I am partial to using hashes myself, but that may not be something you've learned yet.

I might as well warn you now that it's generally a good idea to place two lines at the beginning of your code:

use warnings; use strict;
Those two 'pragmas' will save you much grief. They tell Perl to apply stricter rules to your code, meaning your code will show more things as errors and warnings. Although it's a real pain to get a bunch of warnings, it's good discipline to learn how to write code that avoids all the errors and warnings these pragmas cause. They're actually warning you about programming techniques that, although permitted, are very often ones that lead to problems. First, learn to write within the limitations of these pragmas. When you know what the rules are, then you'll know when it's a good idea to break them. At least, theoretically ;-)

And finally, if you're not already confused enough: avoid using $a and $b as variables. They have a special meaning in Perl that could create difficulties for you if you some day need to use them (they're used for sorting). You'll be OK as long as you're not sorting anything, but it's just a good habit to avoid things that might some day lead to problems if you forget.


In reply to Re: removing doubles by comparing two strings - newbie question! by spiritway
in thread removing doubles by comparing two strings - newbie question! by Anonymous Monk

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.