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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

file problem

Status
Not open for further replies.

WebGoat

MIS
Jul 16, 2005
85
US
Code:
$file = '/etc/passwd';		# Name the file
open(INFO, $file);		# Open the file

The first parameter is the filehandle which allows Perl to refer to the file in future. The second parameter is an expression denoting the filename. If the filename was given in quotes then it is taken literally without shell expansion. So the expression '~/notes/todolist' will not be interpreted successfully. If you want to force shell expansion then use angled brackets: that is, use <~/notes/todolist> instead

i made the bold statements . i just could not understand those statements. will you plese tell me in a simpler way ?
what those statements wants to say ? please rovide an easy example.
thanks for your time.
 
In a shell, ~ usually expands to your home directory so in your case ~/notes/todolist might expand to /home/webgoat/notes/todolist.
As the reference indicates, with quotes, this expansion will not take place and so the file will not be found. With angled brackets, perl will use shell expansion to process the filename and find the file successfully.


Trojan.
 
With angled brackets, perl will use shell expansion to process the filename and find the file successfully
ohh, yea, you mean the absolute path. ok . all right.
thanks

glad to talk with perl experts
 
Code:
@lines = <INFO>;

lines reads the file

my god ! if the file is huge, then the prgranm may crash at any time . how many MAXIMUM lines an perl array can contain ?





 
You're right.
If it's possible that your script might have to process large files then it is far better to process the file line by line:
Code:
while(<>) {
  # $_ contains each line from the file, one at a time
  # process the line here.
}
The maximum file size that you can store in an array is system dependant. It depends primarily on the free memory available.
Therefore I would recommend that you process line by line as I showed above wherever possible to avoid memory issues like this.


Trojan.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top