in reply to How Do I Read Data From A File?
Assuming that your password file has a format like (since this matches your regex):
username tommelly opensesame some optional junk
Then...
open (PSSWD, "<passwordfile") or die "could not able to open the file" + ; while ($line=<PSSWD>) { chomp($line); ($uname,$password) = $line = ~ m/username\s+(\S+)\s+(\S+)\s*\S*/; print "username: $uname, password: $password\n"; }
A problem with your version is that you only handled the last username/password in the file - printf is not required, but may account for the lack of password in the output shown (I don't often use printf and am not sure what it does in the context you use), or the format of your password file might not match your regex.
There are other problems with your script that will make it harder for you to debug - mainly you don't check whether your regex actually matched against the line... I'd suggest...
open (PSSWD, "<passwordfile") or die "could not able to open the file" + ; while ($line=<PSSWD>) { chomp($line); if($line = ~ m/username\s+(\S+)\s+(\S+)\s*\S*/){ print "username: $1, password: $2\n"; } else{ print "$line did not match regex\n"; } }
Tom Melly, pm@tomandlu.co.ukmap{$a=1-$_/10;map{$d=$a;$e=$b=$_/20-2;map{($d,$e)=(2*$d*$e+$a,$e**2 -$d**2+$b);$c=$d**2+$e**2>4?$d=8:_}1..50;print$c}0..59;print$/}0..20
|
|---|