in reply to Re: Really dumb question... ('ne' not working)
in thread Really dumb question... ('ne' not working)

Two things: (1) the error message says you're trying to treat a string as a number. ne tests for unequal *strings*, while != tests for unequal *numbers*.

Perl (which, as you're finding out, is Not Java =) provides the defined() function to test for null values. So write that as

while (defined ( my $line = <INPUT>) ) {

Actually, go ahead and try

while ($line = <INPUT>) {

as even blank lines contain newlines, and so evaluate to true.

(2) it makes more sense to write parseDown1 as a subroutine that accepts $filename as an argument than as something that expects a global to be set. Here it's not causing problems but it's not a good design to use in any script you'll keep (or cadge code from!).

sub parseDown { my $filename = shift @_; # or $_[0] or just plain shift # rest of sub }

(3) use strict and warnings (-w in pre-5.6.0 Perl). Doing this will require that you declare your variables with my2 and pay attention to scope. This is a Good thing.

(4) don't blindly use $1 and $2 without checking to see whether your regex matched. If it doesn't weird things can happen. Instead, do this:

if (my ($tmp_dir, $file) = $line =~ m%(.*)\\(.*)% ) { # do the rest of the stuff } else { warn "$line has incorrect format!\n"; }

(5) I can't count.

HTH

1 That spelling, and the != null test, suggest you're coming from a Java background. Apologies if that's incorrect.
2(update) or our (5.6.0) or use vars. Included for completeness. Ignore this for now, I just don't want to say anything false.

Replies are listed 'Best First'.
Re: (arturo): Re: Really dumb question... ('ne' not working)
by Anonymous Monk on May 22, 2001 at 17:42 UTC
    wow. i actually come from a c++ background, but ive been doing _waaaaayyy_ too much java lately. good call. :) i cant believe i forgot that i use "defined" and not testing to see if it's != null....but i did, and we all make mistakes. ;-) anyways, thanks for the mini-lesson on standards and proper coding techniques -- i seriously lack these in perl, and i really need to start learning them.

    anyways, thanks a lot for your help, it was exactly what i needed!

    justin