-
PERL Help...
Hmmm, Im trying to learn a few programming languages for the summer and im starting out with PERL because.
1) Someone in IRC reccommended it to me and
2) Its a good language to start on.
Anyway, on to my problem... In the tutorial on PERL that I am reading I have to code a program to open a file, print the contents into an array and the print out the contents of that file so that every line has a prefix of #... The code I have so far is:
Code:
#!/usr/bin/perl
#
#
$file = '/root/perl/food';
open(INFO, $file);
@lines = <INFO>;
close(INFO);
print ( "#", @lines);
But when I run the file the text from the /root/perl/food file doesnt show at all, and when it did show it only the first line had the prefix of # (I understand that !#/usr/bin/perl already has a #, before it had 2)
-
Ok, think about what you did for a minute...last line of the script...
you issued a print...
what is @lines ? an array...so what would that translate to ?
print ("#", "@lines[0], @lines[1], ... @lines[n]");
see the problem yet ?
try :
foreach (@lines)
{
print ("#", "$_");
}
-
Ohhh! I just got it!!!! Thanks!
An array is a group of sclar variables that have to be accessed by $array[1]
Thanks!
-
Ok, Right now I have
Code:
#!/usr/bin/perl
#
#
$file = '/root/perl/food';
open(INFO, $file);
@lines = <INFO>;
close(INFO)
foreach (@lines)
{
print ( "#", "$_");
}
But I get no output...... Any ideas?
-
/root/perl/food
is blank or doesn't exist ? Works when I run it ...]
Neb
PS, probably a typo on your part ...but you don't have a semicolon after the close (INFO)