Putting multiple files into 1 array?

They have: 117 posts

Joined: Mar 2000

I need to know how to put multiple files into the same array. They're all in the same directory and they're called poll1.txt, poll2.txt, poll3.txt, etc. Theirs also a file that keeps track of how many polls there are. So, how would I go about getting them into the same array?? I thought I had it, but it doesn't work.

Thanks!

--Edge

Ken Elliott's picture

They have: 358 posts

Joined: Jun 1999

Well this is a simple suggestion. You could assign each file to a scalar.
$file1 = "file1.txt";
$file2 = "file2.txt"; #etc.

And then add the scalars to the array.

@files = "$file1, $file2"; #etc.

Just a simple suggestion. PERL has many ways of accomplishing the same things.

Hope it helps.
VulKen
Keepin' It Realistic

Pimpin like a pimp with an electrofied pimpin machine!

They have: 850 posts

Joined: Jul 1999

The easiest way would to go
@polls = </dir/*.txt>;
This would get all the different .txt files and place them in an array.

Hope that helps.

------------------
click here to help save lives
http://www.wiredstart.com : The Technology Start Page

They have: 117 posts

Joined: Mar 2000

Okay, I can't tell if that works yet because I think another part of my script is messing.

Is this an okay login script?

code:

sub checkuser {
	foreach $line (@memberfile) {
     		($member, $username, $email, $userpass, $blabla) = split(/\|/, $line);
        if ($FORM{'email'} eq "") {
		  			 &header;
                print "<B><FONT FACE=\"Verdana\" SIZE=\"2\">E-mail Required</B><BR>I'm sorry,\n";
                print "but you need a to enter your e-mail address to login.</FONT>\n";
					 &footer;
                exit;
		  }
		  elsif ($FORM{'userpass'} eq "") {
		  			 &header;
                print "<B><FONT FACE=\"Verdana\" SIZE=\"2\">Password Required</B><BR>I'm sorry,\n";
                print "but you need a password to login.</FONT>\n";
					 &footer;
                exit;
        }
        if ($FORM{'email'} eq $email) {
		          if ($FORM{'userpass'} ne $userpass) {
		  			 &header;
                print "<B><FONT FACE=\"Verdana\" SIZE=\"2\">Bad Password</B><BR>\n";
                print "I'm sorry, but the password you entered,\n";
                print "<i>$FORM{'userpass'}</i>, is incorrect.</FONT>";
					 &footer;
                exit;
        			}
		  }
        elsif ($FORM{'email'} ne $email) {
		  			 &header;
                print "<B><FONT FACE=\"Verdana\" SIZE=\"2\">Bad E-mail</B><BR>\n";
                print "I'm sorry, but the e-mail address you entered,\n";
                print "<i>$FORM{'email'}</i>, is incorrect.</FONT>";
					 &footer;
                exit;
       	}
        elsif ($FORM{'email'} eq $email) {
		          if ($FORM{'userpass'} eq $userpass) {
}
[/code]

It works if you enter anything wrong, but if you enter the correct login info, the next page doesn't display correctly. Once I get this fixed, I'll be able to see if my "multiple files in same array" problem is solved since the page that is displayed after I login is where the array is being used.

--Edge 
Ken Elliott's picture

They have: 358 posts

Joined: Jun 1999

I am not sure if this is the problem with your script, and I am not 100% sure if I am right. But I think you need to escape those single ticks "'" (ie. I'm = I\'m). I might be wrong. I am not a professional PERL scripter, but I have yet to use the exit; key thingy. I don't know if you would need it in your script, if it is checking all of the conditions in succession.

I don't think you meant to print it like this but at the end of your script you never added anything to do to the last if statement. Also it is not closed with a curly bracket "}".

Well that is all that I can think of. If none of that works tell us what happens when all of the correct info is entered.

Pimpin like a pimp with an electrofied pimpin machine!

Ken Elliott's picture

They have: 358 posts

Joined: Jun 1999

Ah man...I just wrote a whole post and couldn't post it because of flood control or something. It was more then 60 secs. Oh well here I go again. Well I guess it did add my post. I will delete this one.

[Deleted]

VulKen
Keepin' It Realistic

[This message has been edited by VulKen (edited 19 June 2000).]

Pimpin like a pimp with an electrofied pimpin machine!

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.