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
|