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:
Perl Tutorial: Split!

 



Alekto
Novice

Feb 9, 2011, 11:48 AM

Post #1 of 5 (615 views)
Perl Tutorial: Split! Can't Post

Assignment: http://knlp.snu.ac.kr/class/cl-nlp1002/PerlIntro/split.html#homework

Trying to solve this exercise, but something is wrong in my code, so it does not provide the desired output..
Have been trying out differen solutions for two days now, please help me.. and it would be nice if your could explain the soulutions as well :)

My code:

#!/usr/bin/perl

use strict;
use warnings;

$file = '/Perl/electricity.txt';
$i = 0;
open(INFO,$file);

while ($_ = <INFO>){
@lines = spilt(/the/);
chomp @lines;

if ($lines[$i]){
@array = "$lines[$i]","the";
$text = "@array";
$i++;
print"@array\n" }
else{
print "\n";
}
}
close(INFO); # Close the file


rovf
Veteran

Feb 10, 2011, 7:52 AM

Post #2 of 5 (597 views)
Re: [Alekto] Perl Tutorial: Split! [In reply to] Can't Post

The code you have posted, can't even be run! Unless your Perl installation is broken, you should get a compiler error message from this program.


Alekto
Novice

Feb 10, 2011, 8:11 AM

Post #3 of 5 (594 views)
Re: [rovf] Perl Tutorial: Split! [In reply to] Can't Post

When correcting the "split" error and removing the
use strict; use warnings; the code should run.

Please help!


rovf
Veteran

Feb 11, 2011, 2:02 AM

Post #4 of 5 (580 views)
Re: [Alekto] Perl Tutorial: Split! [In reply to] Can't Post

I think you should not remove strict and warning, but correct the code so that it runs *with* strict and warning. After all, these pragmas often point out errors in your program.


Alekto
Novice

Feb 11, 2011, 6:09 AM

Post #5 of 5 (573 views)
Re: [Alekto] Perl Tutorial: Split! [In reply to] Can't Post

I understand your point there!

But I've only been working with perl for a week, and are not yet skillful enough to solve this problem WITHOUT using strick and warnings. You realize maybe that it is not my main focus in the first place.

I'd appreciate if anyone out there could help me understand this problem:)

 
 


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

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