Help with files

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
zRaze [ So, 19 September 2004 14:06 ] [ ID #18650 ]

Re: Help with files

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
Gunnar Hjalmarsson [ So, 19 September 2004 15:29 ] [ ID #18651 ]

Re: Help with files

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 [at] gunnar.cc> wrote:

>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.
zRaze [ Mo, 20 September 2004 18:16 ] [ ID #18655 ]

Re: Help with files

In article <jf0uk0hjqovei80smta3l3ujk13p7heh1s [at] 4ax.com>,
zRaze <abuse [at] 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!)
Larry [ Sa, 25 September 2004 07:54 ] [ ID #18660 ]

Re: Help with files

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...
Dave Cross [ Sa, 25 September 2004 09:50 ] [ ID #18661 ]

Re: Help with files

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 [at] gunnar.cc> wrote in message
news:2r5fscF15s084U1 [at] uni-berlin.de...
> 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
gharrison64 [ Sa, 14 Januar 2006 05:43 ] [ ID #1141872 ]
Perl » alt.perl » Help with files

Vorheriges Thema: Dates with Perl
Nächstes Thema: Mutex and Semaphore