in reply to Convert script to use MySQL
If you open a file for write, it's automatically emptied. What exactly is the point of the second line above, especially considering you never use @DB anywhere else in your script?open (DATABASE,">$database"); @DB=<DATABASE>;
nagent? This can't be intentional, considering this is the only line that uses nagent.if ($agent_name eq $input{'nagent_name'} && $agent_phone eq $input{'na +gent_phone'} ){
You don't have to chomp each line if you're only doing matches on the first two fields. You also don't need the variable $rec:fopen (ORGDB,"<$database"); @ODB=<ORGDB>; close (ORGDB); ... foreach $rec (@ODB){ chomp($rec); ($agent_name,$agent_phone,$agent_cell,$agent_email)=split(/\|/ +,$rec);
In addition, you can increase the efficiency of your file access by using read / split instead of assigning the contents of the file handle to an array. You may also be able to increase efficiency by modifying the found line inside the array and then writing the whole array at once (using join), but I haven't tested that yet and don't know if there's a time gain.for (@ODB) { ($agent_name,$agent_phone,$agent_cell,$agent_email)=split(/\|/);
Bottom line, you don't need a database unless you have at least several thousand records. Just modify your script for higher efficiency. Beyond that, I'd use mySQL. :)
|
|---|