Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fetching Data File

Status
Not open for further replies.

pollock77

Programmer
Aug 9, 2004
25
US
Code:
open(ACCOUNT, $data_file) || die("Could not open file!");
@raw_data=<ACCOUNT>;
close(ACCOUNT);


foreach $account (@raw_data){
   chop($account);
   ($username,$rank,$handle,$password,$group,$word)=split(/\|/,$account);

I want the ($username,$rank,$handle,$password,$group,$word) in a separate file but can't seem to get it right.

How could I go about doing this?
 
Code:
open(ACCOUNT, $data_file) || die("Could not open file!");
open(OTHER, ">>otherfile.txt") || die("Could not open file!");
while (<ACCOUNT>) {
  chomp;
 ($username,$rank,$handle,$password,$group,$word)=split(/\|/,$_);
  print OTHER "$username|$rank|$handle|$password|$group|$word\n";
  or more simply
  print OTHER "$_\n";
}

I think this is waht you asked for but why are you splitting on pipes, just to write back the file?

HTH
--Paul



It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
I see why you would be confused, but that's not what I meant.

I want one file to be
($username,$rank,$handle,$password,$group,$word)

Then, I want to call it up in this program, something like
Code:
open(ACCOUNT, $data_file) || die("Could not open file!");
@raw_data=<ACCOUNT>;
close(ACCOUNT);


foreach $account (@raw_data){
   chop($account);
   @var=split(/\|/,$account);

where @var = ($username,$rank,$handle,$password,$group,$word)

 
show us a line, and obfuscate username and password, and handle, and tell us what you want to do with it?

--Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
pollock77|Admin|John Smith|abc123|admin|Programmer
 
and tell us what you want to do with it?

--Paul


It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
In this case, $group will be used to determine whether or not a user has access to a given page.
 
Code:
$privaccounts="admins|gborbs|gnorks ...";

open(ACCOUNT, $data_file) || die("Could not open file!");
@raw_data=<ACCOUNT>;
close(ACCOUNT);
foreach $account (@raw_data){
   chop($account);
   @var=split(/\|/,$account);
   if (index $privaccounts,$var[4]!=-1) {
#      group is listed in privaccnts
   } else {
#      they aren't
   }
}
??Paul


It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
I guess I'm not describing it very well.

I want ($username,$rank,$handle,$password,$group,$word) to be in a separate file, so that if I need to add a new variable, ex: ($username,$rank,$handle,$password,$group,$word,$NEW), then I wouldn't want to go through every program and add ,$NEW to every place I used it
 
Try out this code to see if it's what you're looking for
Code:
  $rec="1|2|3|4|5|6|7|8|9|0";
  ($field1,$field2,$field3,@rest)=split/\|/,$rec;
  print "$field1\n";
  print "$field2\n";
  print "$field3\n";
  print "@rest";

HTH
--Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
Not what I meant, but that works just as well, I think. Like, if I wanted to print the number nine, I'd just use $rec[9] correct?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top