my ($temp) = 121, 122, 123, 124, 125, 126;

If you are already using that line in a program,literally (pun intended:), and you are not receiving warnings about it when you run your program, you should add -w to the shebang line (ie.#!/usr/bin/perl -w) or the command line when you run it; or add use warnings; at the top of your program.

If you had done this, you would received warnings something like:

Useless use of a constant in void context at yourscript.pl line 7. Useless use of a constant in void context at yourscript.pl line 7. Useless use of a constant in void context at yourscript.pl line 7. Useless use of a constant in void context at yourscript.pl line 7. Useless use of a constant in void context at yourscript.pl line 7.

What this would have told you is that all but the very first of your values is being thrown away. So, in your example, the scalar $temp is being given the value 121, and everything else is being discarded.

The methods shown by other monks above all work, but maybe they forgot the simplest, which would be to assign the values to an array, and then use them, as follows:

my @userids = ( 121,122,123,124,125,126 ); #etc... if ($userid[0] == 121) { do something... } if ($userid[1] == 122) { do somthing else... }

Note: When refering to individual elements of the @userids array, each of which is a scalar, we use the $ prefix character (sigil). and also that Perl arrays start at index zero, [0].

Finally, if your list of user ids keeps changing, rather than editing the script, you would be better putting them in a seperate file something like this.

#! perl use warnings; my $useridfile = 'userids'; open USERIDS, $useridfile or die "Couldn't open $useridfile; reason $! +"; my (@userids) = (<USERIDS>); close USERIDS or warn "Couldn't close userid file:$!"; for my $count (0 .. (scalar @userids) - 1) { print "userid[$count]=", $userids[$count]; } __END__ #if the file "./userids" contains: 121 122 123 124 125 126 #the above program would give C:\test>185550 userid[0]=121 userid[1]=122 userid[2]=123 userid[3]=124 userid[4]=125 userid[5]=126 userid[6]=127

In reply to Re: Splitting a dynamic comma-separated list. by BrowserUk
in thread Splitting a dynamic comma-separated list. by brentheigold

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.