CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: can't # out code or the script fails to run: Edit Log



lukdk
Novice

Jun 19, 2012, 4:05 AM


Views: 1091
can't # out code or the script fails to run

Hello,

I was wondering how it is possible adding a #-sign can break this script?

working code:
foreach my $computer (MOlib::read_file("input.txt")){
$computer=MOlib::trim($computer);
}

Not working code:
foreach my $computer (MOlib::read_file("input.txt")){
$computer=MOlib::trim($computer);
#
}

This is the error i get:
Missing right curly or square bracket at test.pl line 1, at end of line
syntax error at test.pl line 1, at EOF
Execution of test.pl aborted due to compilation errors.

This is the code for the MOlib:
sub read_file{
my $read_file=shift;
open (FILE, "<$read_file") or die "Can't open $read_file: $!\n";
my @file = <FILE>;
close FILE;
return @file;
}
sub trim{
my $str=shift;
return "" if !defined $str;
$str=~s/^\s+//;
$str=~s/\s+$//;
return ($str);
}


(This post was edited by lukdk on Jun 19, 2012, 7:16 AM)


Edit Log:
Post edited by lukdk (Novice) on Jun 19, 2012, 6:46 AM
Post edited by lukdk (Novice) on Jun 19, 2012, 6:48 AM
Post edited by lukdk (Novice) on Jun 19, 2012, 7:16 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives