Gossamer Forum
Home : General : Perl Programming :

How to have a delimeter be a return

Quote Reply
How to have a delimeter be a return
/codeI know in Links that the delimeter between fields is "|", but how would one make the delimeter be a return? For example:

Code:
open (PASS,"/home/web/yadda/yadda/pass.cgi");
LINE: while(<PASS> ){
@pass=split (/\return?/);
if ($pass[1]==$password){
push @passed,$_;
} # End of if
} #end of while
close (PASS);

What would I put for return?

------------------
Quote Reply
Re: How to have a delimeter be a return In reply to
Hey CEGlobe,

I would suggest to use this:

Code:

open(DAT, "<passwords.db");
@entries = <DAT>;
close DAT;
foreach $line (@entries) {
@fields = split(/\|/,$line);
print "$fields[0]\n";
};

because you might (in the future) have another fields.
In this case the script will take every [0] field from every line in your database. Is this what you wanted? Smile


Regards,

Pasha

------------------
webmaster@find.virtualave.net
http://find.virtualave.net
Quote Reply
Re: How to have a delimeter be a return In reply to
Thank Pasha. That would normally work, but I was reading from a file in which the second line had to be the password. If I did it your way, the first line could be entered as the password instead. Here is what I did:

Code:
open (PASS,"/web/ceglobe/cgi-bin/ubb/members/$passfile.cgi");

$counter = 0;

LINE: while(<PASS> ){
$counter = $counter + 1;
next LINE if (/^#/); # Skip comment lines.
next LINE if (/^\s*$/); # Skip blank lines.

@pass=split(/\n/);

if (($counter==2) && ($pass[0] eq $password)) { $newpass = 1 }

} #end of while

close (PASS);

------------------


[This message has been edited by CEGlobe (edited April 03, 1999).]
Quote Reply
Re: How to have a delimeter be a return In reply to
Yeah, I didn't think of this Smile

Code:

@pass=split(/\n/);

might work Smile

BTW, you could replace:

Code:

$counter = 0;

$counter = $counter + 1;

with just:

Code:

$counter++;


Regards,

Pasha

------------------
webmaster@find.virtualave.net
http://find.virtualave.net
Quote Reply
Re: How to have a delimeter be a return In reply to
I used the $counter = $counter +1 because I am used to making little programs on my calculator at school. I wish perl were that simple! Smile Thanks,

Nicholas

Oh, and that thing about your friend committing suicide -- april fools?
------------------


[This message has been edited by CEGlobe (edited April 03, 1999).]
Quote Reply
Re: How to have a delimeter be a return In reply to
No fools, he really did. He was a great guy, but he smoked to much crap. So, I guess he went crazy or something, and...
Any way, it's not what we should talk about in this forum.

Regards,

Pasha

------------------
webmaster@find.virtualave.net
http://find.virtualave.net
Quote Reply
Re: How to have a delimeter be a return In reply to
If the delimiter is a newline (i.e. each line in the file is one field), then you could just do:

my @record = <DB>;
chomp @record; # Remove newlines

and you have all the fields in @record. I assume this is only one record per file? If not, you might have to rethink your delimiter.

Cheers,

Alex