Name: vande Date: March 26, 2008 at 07:39:59 Pacific Subject: perl coding OS: Windows xp, Windows CPU/Ram: 2.4 quad core Intel Model/Manufacturer: Dell, Dell, Dell, Ho
Comment:
$lines = 0; open(FILE, $filename) or die "Can't open `$filename': $!"; while (sysread FILE, $buffer, 4096) { $lines += ($buffer =~ tr/\n//); } close FILE;
How is the above code work where it says file do i /home/vandelin/hello.pl? or $filename gets replaced by the above? i tried both none seem to work i am just exploring and want to count the lines in hello.pl located under /home/vandelin
$filename is a variable that holds the name of the file that you want to count its lines. There are several ways to assign that var, either hard coding or dynamically set.
# hard code the assignment $filename = '/home/vandelin/hello.pl';
$lines = 0; open(FILE, $filename) or die "Can't open `$filename': $!"; while (sysread FILE, $buffer, 4096) { $lines += ($buffer =~ tr/\n//); } close FILE;
Well i was reading some doccumentation and i came accross this and was like hmm i will try this and i did try i tried a couple ways so its not that i came right here i tried really..... I just thought it would be cool to do i mean im going through some tutorials and doing this and that and just came to a standstill
Right cause if you ask me thats a pretty simple instruction. Why does it matter how you get it done ? or the tool you use to get it done? what are the benefits of using this tool compared to others ? is it easier?
The information on Computing.Net is the opinions of its users. Such
opinions may not be accurate and they are to be used at your own risk.
Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE