For Programmers: Free Programming Magazines  


Home > Archive > PERL Programming > January 2006 > Help with files









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Help with files
zRaze

2004-09-19, 8:59 am

Hi,

I'm having problems with files-
--------------------------------------------------------
open(xHandle, "<svr.txt");

$mylist = "";

while (<xHandle> )
{
chomp;
if ( $_ != "FF" )
{
$mylist = $mylist . $_ . "\n";
}
print $mylist;
}

close(xHandle);
--------------------------------------------------------
When I run the above code, $mylist never prints out (or it is empty),
however, if I take out the If statement, it works fine.

My file (svr.txt) has two lines in it -

DF
FF

Does anyone know what I'm doing wrong?

TIA
Gunnar Hjalmarsson

2004-09-19, 3:55 pm

zRaze wrote:
>
> if ( $_ != "FF" )


<snip>

> Does anyone know what I'm doing wrong?


You are posting a problem here, which Perl would have helped you solve
if you had enabled strictures and warnings.

Add

use strict;
use warnings;

to the beginning of your program, and declare your variables using
my(). Then Perl will provide the help you need to understand what you
are doing wrong.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
zRaze

2004-09-20, 3:57 pm

Cool. I didn't know about this (I'm still quite new to Perl)

Cheers!


On Sun, 19 Sep 2004 15:29:19 +0200, Gunnar Hjalmarsson
<noreply@gunnar.cc> wrote:

>zRaze wrote:
>
><snip>
>
>
>You are posting a problem here, which Perl would have helped you solve
>if you had enabled strictures and warnings.
>
>Add
>
> use strict;
> use warnings;
>
>to the beginning of your program, and declare your variables using
>my(). Then Perl will provide the help you need to understand what you
>are doing wrong.


Larry

2004-09-25, 3:59 am

In article <jf0uk0hjqovei80smta3l3ujk13p7heh1s@4ax.com>,
zRaze <abuse@dead.com> wrote:

> Cool. I didn't know about this (I'm still quite new to Perl)
>
> Cheers!
>
>


and if you're running the code via web always keep this line at the top
of your script:

use CGI::Carp "fatalsToBrowser";

(now you can say goodbye to the hateful 500 web server error!)
Dave Cross

2004-09-25, 3:59 am

On Sat, 25 Sep 2004 05:54:02 +0000, Larry wrote:

> and if you're running the code via web always keep this line at the top
> of your script:
>
> use CGI::Carp "fatalsToBrowser";
>
> (now you can say goodbye to the hateful 500 web server error!)


Er... no. Leave the "fatalsToBrowser" there whilst you're debugging the
program but remove it before putting it live.

If crackers get Perl error messages when your site breaks then they
potentially get useful information on how to crack your server.

The 500 error page is there for a reason. It gives the user all the
information they need. The real error message is where it should be - in
the error log file where only the site's maintainer can see it.

If you really don't like the 500 error page then configure your web server
to display a different one that in more in keeping with your site's look
at feel. But don't be tempted to add any more "useful" information to it.

Dave...

G. Harrison Chiles Jr.

2006-01-14, 7:55 am

I f you are working with strings I find that if you do
if ($_ ne "FF") you should get the results you want.

"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news:2r5fscF15s084U1@uni-berlin.de...
> zRaze wrote:
>
> <snip>
>
>
> You are posting a problem here, which Perl would have helped you solve if
> you had enabled strictures and warnings.
>
> Add
>
> use strict;
> use warnings;
>
> to the beginning of your program, and declare your variables using my().
> Then Perl will provide the help you need to understand what you are doing
> wrong.
>
> --
> Gunnar Hjalmarsson
> Email: http://www.gunnar.cc/cgi-bin/contact.pl



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com