A small problem I can't quite work out.

Discussion in 'Perl Misc' started by sj, Mar 19, 2009.

  1. sj

    sj Guest

    I'm making a program just for the joy of it, really, but I'm getting a
    bug I just can't work out. Basically, when I run it, I get the message
    'uninitiated value $whatever in pattern match (m//) at C:\wherever
    line whatever'.
    The problem is, they are initiated...I can post the code if it would
    make this easier, but all variables are declared with 'my' not
    'local'...I've tried putting them in different places in the code,
    within loops or all at the begining etc...it used to work :/ maybe I
    should just start again!
     
    sj, Mar 19, 2009
    #1
    1. Advertising

  2. sj <> wrote:

    > Subject: A small problem I can't quite work out.



    Please put the subject of your article in the Subject of your article.

    Subject: Use of uninitialized value

    or some such.


    > I'm making a program just for the joy of it, really, but I'm getting a
    > bug I just can't work out. Basically, when I run it, I get the message
    > 'uninitiated value $whatever in pattern match (m//) at C:\wherever
    > line whatever'.



    Please post the *actual text* of messages rather than paraphrase them.

    Have you seen the Posting Guidelines that are posted here frequently?


    > The problem is, they are initiated...



    The word is "uninitialized", not uninitiated.


    > I can post the code if it would
    > make this easier,



    It would not make it easier.

    It would make it *possible*.


    > but all variables are declared with 'my' not



    "declaring a variable" and "defining a variable" are separate
    and distinct concepts.

    my() has to do with declaring variables.

    Your message has to do with defining variables.


    > 'local'...I've tried putting them in different places in the code,
    > within loops or all at the begining etc...it used to work :/ maybe I
    > should just start again!



    We cannot repair code that we cannot see...


    --
    Tad McClellan
    email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
     
    Tad J McClellan, Mar 19, 2009
    #2
    1. Advertising

  3. sj

    sj Guest

    Sorry, I'm completely new to both programming and usenet, I'll attempt
    to pick it up as fast as possible.
    I *think* it's the 'special' and 'checkinput' subs that are having the
    problems...

    #use strict;
    #use warnings;

    my $checked2;
    my $flag = 1;
    my $flag2 = 1;

    while ($flag) {
    print $flag;
    my $usec;
    if ($flag == 1) {
    $usec = start();
    } else {
    $usec = restart();
    }
    $flag = $flag + 1;

    my $use = checkinput ($usec);

    writechat ($use);

    printchatall ();

    if ($use =~ /exit\n/i) {
    $flag = 0;
    }
    }

    sub start {
    intro();
    my $in = input();
    $flag2 = 1;
    return $in;
    }

    sub restart {
    print "what would you like me to say?: \n";
    my $in2 = input();
    $flag2 = 1;
    return $in2;
    }

    sub input {
    my $input = <>;
    return $input;
    }

    sub helprint {
    open (HELP,"< help.txt") || die("can't find help file: $!");
    while (<HELP>) {
    print $_;
    }
    close HELP;
    return 0;
    }

    sub checkinput {
    while ($flag2 >= 1) {
    my $checked2;
    my $test2 = shift;
    my $checked;
    $checked = special($test2);
    unless ($checked =~ /\n/i || $checked =~ /help\n/i || $checked =~ /
    clear\n/i || $checked =~ /""/ || $checked =~ /exit\n/i) {
    $flag2 = 0;
    }
    $flag2 = $flag2 + 1;
    if ($flag2 >= 2) {
    $checked2 = special($checked);
    }
    }
    return $checked2;
    }
    sub special {

    my $test = (shift);

    if ($test =~ /^help\n$/i) {
    helprint ();
    my $newans = input();
    return $newans;
    } elsif ($test =~ /^exit\n$/i) {
    $flag = 0;
    return 0;
    } elsif ($test =~ /^clear\n$/i) {
    open (CLEAR,"> chatthing.txt") || die("can't clear: $!");
    print CLEAR "";
    my $newans1 = input();
    return $newans1;
    }else {
    return $test;
    }
    return "/n"
    }

    sub intro {
    open (INTRO,"< intro.txt") || die("can't find the intro: $!");
    while (<INTRO>) {
    print $_;
    }
    close INTRO;
    }

    sub writechat {
    my $answer = shift;
    open (CHATW,">> chatthing.txt") || die("can't open datafile: $!");
    print CHATW $answer;
    close CHATW;
    }

    sub printchatall {
    open (CHATR,"< chatthing.txt") || die("can't read datafile: $!");
    while (<CHATR>) {
    print $_;
    }
    close CHATR;
    }
     
    sj, Mar 19, 2009
    #3
  4. sj

    sj Guest

    Okay, fixed it myself *is embarassed*
    tried to delete the thread, but did it wrong.
    Oh gosh, I'm a complete n00b...Never mind.
     
    sj, Mar 19, 2009
    #4
  5. sj

    Jim Gibson Guest

    In article
    <>, sj
    <> wrote:

    > Sorry, I'm completely new to both programming and usenet, I'll attempt
    > to pick it up as fast as possible.
    > I *think* it's the 'special' and 'checkinput' subs that are having the
    > problems...


    Thank you for making the effort to help us help you.

    >
    > #use strict;
    > #use warnings;


    use strict and warnings are very valuable tools. However, they don't
    work if they are commented out. Some people here will not look at your
    code unless both of these are present.

    >
    > my $checked2;
    > my $flag = 1;
    > my $flag2 = 1;
    >
    > while ($flag) {
    > print $flag;
    > my $usec;
    > if ($flag == 1) {
    > $usec = start();
    > } else {
    > $usec = restart();
    > }
    > $flag = $flag + 1;
    >
    > my $use = checkinput ($usec);
    >
    > writechat ($use);
    >
    > printchatall ();
    >
    > if ($use =~ /exit\n/i) {
    > $flag = 0;
    > }
    > }
    >
    > sub start {
    > intro();
    > my $in = input();
    > $flag2 = 1;
    > return $in;
    > }
    >
    > sub restart {
    > print "what would you like me to say?: \n";
    > my $in2 = input();
    > $flag2 = 1;
    > return $in2;
    > }
    >
    > sub input {
    > my $input = <>;
    > return $input;
    > }


    This routine can be simplified to:

    sub input {
    return <>;
    }

    or even

    sub input {
    <>;
    }

    but you might want to remove the newline at the end of the input string:
    sub input {
    my $line = <>;
    chomp($line);
    return $line;
    }

    >
    > sub helprint {
    > open (HELP,"< help.txt") || die("can't find help file: $!");
    > while (<HELP>) {
    > print $_;
    > }
    > close HELP;
    > return 0;
    > }
    >
    > sub checkinput {
    > while ($flag2 >= 1) {
    > my $checked2;
    > my $test2 = shift;


    This statement is inside a while loop. Therefore, it can be executed
    more than once, depending upon the logic involved in setting the value
    of $flag2. While your program logic is convoluted, I do believe that
    this loop will iterate more than once unless the user has entered a
    special string (empty line, 'help', 'clear', etc.). You have called
    this routine with one argument. The first time through the loop, the
    argument (the user input) will be assigned to $test2 and shifted off
    the @_ array. However, the second time through the loop, the @_ array
    will be empty and $test2 will be undefined. This is the source of your
    "Uninitialized" warnings.

    You need to rethink the logic behind your user input processing logic.


    > my $checked;
    > $checked = special($test2);
    > unless ($checked =~ /\n/i || $checked =~ /help\n/i || $checked =~ /
    > clear\n/i || $checked =~ /""/ || $checked =~ /exit\n/i) {


    $checked =~ /\n/i tests for the presence of a newline character in
    the user input. Since such a character will always be present, this
    test will never succeed. If you are trying to test for an empty line,
    you need to anchor the R.E. at the beginning of the string:

    $checked =~ /^\n/;

    (there is no need to test case-insentively here).

    It is better to use the regular expression meta-character '$' to test
    for end of the string, and if you chomp the input, then this becomes:

    unless ($checked =~ /^$/;

    You are checking user input for special values both here and below. You
    should only be doing this in one place. Checking just once will
    simplify and improve your program logic.

    > $flag2 = 0;
    > }
    > $flag2 = $flag2 + 1;
    > if ($flag2 >= 2) {
    > $checked2 = special($checked);
    > }
    > }
    > return $checked2;
    > }
    > sub special {
    >
    > my $test = (shift);
    >
    > if ($test =~ /^help\n$/i) {
    > helprint ();
    > my $newans = input();
    > return $newans;
    > } elsif ($test =~ /^exit\n$/i) {
    > $flag = 0;
    > return 0;
    > } elsif ($test =~ /^clear\n$/i) {
    > open (CLEAR,"> chatthing.txt") || die("can't clear: $!");


    You are using the string 'chatthing.txt' three times in your program.
    You should put this string in a variable and use the variable
    throughout your program.

    Using the three-argument version of open and lexically-scoped (my)
    variables for file handles is recommended:

    open( my $clear, '>', $outfile ) or die("Can't open $outfile: $!");

    > print CLEAR "";


    print $clear "";

    however, printing an empty string is a no-operation.

    > my $newans1 = input();
    > return $newans1;
    > }else {
    > return $test;
    > }
    > return "/n"
    > }
    >
    > sub intro {
    > open (INTRO,"< intro.txt") || die("can't find the intro: $!");
    > while (<INTRO>) {
    > print $_;
    > }
    > close INTRO;
    > }
    >
    > sub writechat {
    > my $answer = shift;
    > open (CHATW,">> chatthing.txt") || die("can't open datafile: $!");
    > print CHATW $answer;
    > close CHATW;
    > }
    >
    > sub printchatall {
    > open (CHATR,"< chatthing.txt") || die("can't read datafile: $!");
    > while (<CHATR>) {
    > print $_;
    > }
    > close CHATR;
    > }


    --
    Jim Gibson
     
    Jim Gibson, Mar 19, 2009
    #5
  6. sj

    sj Guest

    On Mar 19, 9:05 pm, Jim Gibson <> wrote:
    > In article
    > <>, sj
    >
    > <> wrote:
    > > Sorry, I'm completely new to both programming and usenet, I'll attempt
    > > to pick it up as fast as possible.
    > > I *think* it's the 'special' and 'checkinput' subs that are having the
    > > problems...

    >
    > Thank you for making the effort to help us help you.
    >
    >
    >
    > > #use strict;
    > > #use warnings;

    >
    > use strict and warnings are very valuable tools. However, they don't
    > work if they are commented out. Some people here will not look at your
    > code unless both of these are present.
    >
    >
    >
    >
    >
    > > my $checked2;
    > > my $flag = 1;
    > > my $flag2 = 1;

    >
    > > while ($flag) {
    > >   print $flag;
    > >   my $usec;
    > > if ($flag == 1) {
    > >   $usec = start();
    > > } else {
    > >   $usec = restart();
    > > }
    > > $flag = $flag + 1;

    >
    > > my $use = checkinput ($usec);

    >
    > > writechat ($use);

    >
    > > printchatall ();

    >
    > > if ($use =~ /exit\n/i) {
    > > $flag = 0;
    > > }
    > > }

    >
    > > sub start {
    > >   intro();
    > >   my $in = input();
    > >   $flag2 = 1;
    > >   return $in;
    > > }

    >
    > > sub restart {
    > >   print "what would you like me to say?: \n";
    > >   my $in2 = input();
    > >   $flag2 = 1;
    > >   return $in2;
    > > }

    >
    > > sub input {
    > >   my $input = <>;
    > >   return $input;
    > > }

    >
    > This routine can be simplified to:
    >
    >   sub input {
    >     return <>;
    >   }
    >
    > or even
    >
    >   sub input {
    >     <>;
    >   }
    >
    > but you might want to remove the newline at the end of the input string:
    >   sub input {
    >     my $line = <>;
    >     chomp($line);
    >     return $line;
    >   }
    >
    >
    >
    > > sub helprint {
    > >   open (HELP,"< help.txt") || die("can't find help file: $!");
    > >   while (<HELP>) {
    > >     print $_;
    > >   }
    > >   close HELP;
    > >   return 0;
    > > }

    >
    > > sub checkinput {
    > >   while ($flag2 >= 1) {
    > >     my $checked2;
    > >     my $test2 = shift;

    >
    > This statement is inside a while loop. Therefore, it can be executed
    > more than once, depending upon the logic involved in setting the value
    > of $flag2. While your program logic is convoluted, I do believe that
    > this loop will iterate more than once unless the user has entered a
    > special string (empty line, 'help', 'clear', etc.). You have called
    > this routine with one argument. The first time through the loop, the
    > argument (the user input) will be assigned to $test2 and shifted off
    > the @_ array. However, the second time through the loop, the @_ array
    > will be empty and $test2 will be undefined. This is the source of your
    > "Uninitialized" warnings.
    >
    > You need to rethink the logic behind your user input processing logic.
    >
    > >     my $checked;
    > >     $checked = special($test2);
    > >     unless ($checked =~ /\n/i || $checked =~ /help\n/i || $checked =~ /
    > > clear\n/i || $checked =~ /""/ || $checked =~ /exit\n/i) {

    >
    >   $checked =~ /\n/i tests for the presence of a newline character in
    > the user input. Since such a character will always be present, this
    > test will never succeed. If you are trying to test for an empty line,
    > you need to anchor the R.E. at the beginning of the string:
    >
    >   $checked =~ /^\n/;
    >
    > (there is no need to test case-insentively here).
    >
    > It is better to use the regular expression meta-character '$' to test
    > for end of the string, and if you chomp the input, then this becomes:
    >
    >   unless ($checked =~ /^$/;
    >
    > You are checking user input for special values both here and below. You
    > should only be doing this in one place. Checking just once will
    > simplify and improve your program logic.
    >
    >
    >
    > >       $flag2 = 0;
    > >     }
    > >     $flag2 = $flag2 + 1;
    > >     if ($flag2 >= 2) {
    > >       $checked2 = special($checked);
    > >     }
    > >   }
    > >   return $checked2;
    > > }
    > > sub special {

    >
    > >   my $test = (shift);

    >
    > >   if ($test =~ /^help\n$/i) {
    > >     helprint ();
    > >     my $newans = input();
    > >     return $newans;
    > >   } elsif ($test =~ /^exit\n$/i) {
    > >     $flag = 0;
    > >     return 0;
    > >   } elsif ($test =~ /^clear\n$/i) {
    > >     open (CLEAR,"> chatthing.txt") || die("can't clear: $!");

    >
    > You are using the string 'chatthing.txt' three times in your program.
    > You should put this string in a variable and use the variable
    > throughout your program.
    >
    > Using the three-argument version of open and lexically-scoped (my)
    > variables for file handles is recommended:
    >
    >   open( my $clear, '>', $outfile ) or die("Can't open $outfile: $!");
    >
    > >     print CLEAR "";

    >
    >   print $clear "";
    >
    > however, printing an empty string is a no-operation.
    >
    >
    >
    > >     my $newans1 = input();
    > >     return $newans1;
    > >   }else {
    > >     return $test;
    > >   }
    > >   return "/n"
    > > }

    >
    > > sub intro {
    > >   open (INTRO,"< intro.txt") || die("can't find the intro: $!");
    > >   while (<INTRO>) {
    > >     print $_;
    > >   }
    > >   close INTRO;
    > > }

    >
    > > sub writechat {
    > >   my $answer = shift;
    > >   open (CHATW,">> chatthing.txt") || die("can't open datafile: $!");
    > >   print CHATW $answer;
    > >   close CHATW;
    > > }

    >
    > > sub printchatall {
    > >   open (CHATR,"< chatthing.txt") || die("can't read datafile: $!");
    > >   while (<CHATR>) {
    > >     print $_;
    > >   }
    > >   close CHATR;
    > > }

    >
    > --
    > Jim Gibson


    Cheers, that really helps a lot! I'll keep all that in mind. The
    strict and warnings were commented out because I was trying to see
    what difference it makes, I only just did it and forgot to undo it
    before I posted. I'll make notes of all of this :)
     
    sj, Mar 19, 2009
    #6
  7. On Thu, 19 Mar 2009 14:05:18 -0700,
    Jim Gibson <> wrote:
    > In article
    ><>, sj
    ><> wrote:
    >
    >>
    >> sub input {
    >> my $input = <>;
    >> return $input;
    >> }

    >
    > This routine can be simplified to:
    >
    > sub input {
    > return <>;
    > }


    Except that the original always uses <> in a scalar context, while yours
    uses <> in whatever context the input subroutine was used in.

    Martien
    --
    |
    Martien Verbruggen | Since light travels faster than sound,
    | is that why some people appear bright
    | until you hear them speak?
     
    Martien Verbruggen, Mar 19, 2009
    #7
  8. On Thu, 19 Mar 2009 14:31:05 -0700, sj wrote:

    > Cheers, that really helps a lot! I'll keep all that in mind. The strict
    > and warnings were commented out because I was trying to see what
    > difference it makes, I only just did it and forgot to undo it before I
    > posted. I'll make notes of all of this :)


    Keep in mind that people are really sensitive to such errors. Post the
    exact code, with use strict and use warnings and the exact output from
    the exact code you posted. Doing so will tremendously increase the
    response from this group.

    M4
     
    Martijn Lievaart, Mar 19, 2009
    #8
  9. sj

    Uri Guttman Guest

    >>>>> "JG" == Jim Gibson <> writes:

    >> sub input {
    >> my $input = <>;
    >> return $input;
    >> }


    JG> This routine can be simplified to:

    JG> sub input {
    JG> return <>;
    JG> }

    JG> or even

    JG> sub input {
    JG> <>;
    JG> }

    not exactly. his will always return 1 line but yours could slurp in the
    whole <> until eof if called in list context. but there is no need for
    this sub to begin with.

    JG> but you might want to remove the newline at the end of the input string:
    JG> sub input {
    JG> my $line = <>;
    JG> chomp($line);
    JG> return $line;
    JG> }

    now it becomes a slightly more useful sub but not really if it is only
    called in 1 place.


    JG> You need to rethink the logic behind your user input processing logic.

    the OP is new at coding and stuck in the old way of using flags for
    state. it will take some real world experience and time for him to
    unlearn this.

    JG> print $clear "";

    JG> however, printing an empty string is a no-operation.

    actually that would print "" to the handle in $clear! :)

    uri

    --
    Uri Guttman ------ -------- http://www.sysarch.com --
    ----- Perl Code Review , Architecture, Development, Training, Support ------
    --------- Free Perl Training --- http://perlhunter.com/college.html ---------
    --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
     
    Uri Guttman, Mar 19, 2009
    #9
  10. sj <> wrote:
    > On Mar 19, 9:05 pm, Jim Gibson <> wrote:
    >> In article
    >> <>, sj
    >>
    >> <> wrote:
    >> > Sorry, I'm completely new to both programming and usenet, I'll attempt
    >> > to pick it up as fast as possible.



    [ snip 200 lines ]


    > Cheers, that really helps a lot! I'll keep all that in mind.



    When composing a followup, quote only enough text to establish the
    context for the comments that you will add.

    Quoting 200 lines and adding 5 lines is seen as impolite.

    Have you seen the Posting Guidelines that are posted here frequently?


    --
    Tad McClellan
    email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
     
    Tad J McClellan, Mar 19, 2009
    #10
  11. Martijn Lievaart <> wrote in
    news:p:

    > On Thu, 19 Mar 2009 14:31:05 -0700, sj wrote:
    >
    >> Cheers, that really helps a lot! I'll keep all that in mind. The
    >> strict and warnings were commented out because I was trying to see
    >> what difference it makes, I only just did it and forgot to undo it
    >> before I posted. I'll make notes of all of this :)

    >
    > Keep in mind that people are really sensitive to such errors. Post the
    > exact code, with use strict and use warnings and the exact output from
    > the exact code you posted. Doing so will tremendously increase the
    > response from this group.


    This poster has already established a good example for others to follow
    by responding positively to Tad's suggestions.

    To the OP: It is a good idea to read the posting guidelines for this
    group a few times. Also, Don't wait until you have a question to read
    the documentation. Read the FAQ once every few months even though the
    questions and the answers may not make sense yet. Take a look at perldoc
    perltoc, and select topics that look interesting and/or relevant to what
    you are doing.

    Sinan

    --
    A. Sinan Unur <>
    (remove .invalid and reverse each component for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://www.rehabitation.com/clpmisc/
     
    A. Sinan Unur, Mar 19, 2009
    #11
  12. sj

    sj Guest

    On Mar 19, 10:27 pm, Uri Guttman <> wrote:
    > >>>>> "JG" == Jim Gibson <> writes:

    >
    >   >> sub input {
    >   >> my $input = <>;
    >   >> return $input;
    >   >> }
    >
    >   JG> This routine can be simplified to:
    >
    >   JG>   sub input {
    >   JG>     return <>;
    >   JG>   }
    >
    >   JG> or even
    >
    >   JG>   sub input {
    >   JG>     <>;
    >   JG>   }
    >
    > not exactly. his will always return 1 line but yours could slurp in the
    > whole <> until eof if called in list context. but there is no need for
    > this sub to begin with.
    >
    >   JG> but you might want to remove the newline at the end of the input string:
    >   JG>   sub input {
    >   JG>     my $line = <>;
    >   JG>     chomp($line);
    >   JG>     return $line;
    >   JG>   }
    >
    > now it becomes a slightly more useful sub but not really if it is only
    > called in 1 place.
    >
    >   JG> You need to rethink the logic behind your user input processing logic.
    >
    > the OP is new at coding and stuck in the old way of using flags for
    > state. it will take some real world experience and time for him to
    > unlearn this.
    >
    >   JG>   print $clear "";
    >
    >   JG> however, printing an empty string is a no-operation.
    >
    > actually that would print "" to the handle in $clear! :)
    >
    > uri
    >
    > --
    > Uri Guttman  ------    --------  http://www.sysarch.com--
    > -----  Perl Code Review , Architecture, Development, Training, Support ------
    > --------- Free Perl Training ---http://perlhunter.com/college.html---------
    > ---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com---------


    Thanks for everyones help once again! I know it's a bit of a useless
    program in reality but it's really helping me learn how to deal with
    the basics, I'm learning a lot just from reading your replies. I
    learned what I know thusfar about the concepts of programing from a
    friend, in Visual Basic which he used to own, as well as bits and bobs
    from the internet, which is probably why I'm a bit behind with my
    techniques. I'll keep lurking here and pick up as much second hand
    knowledge as I can :)

    as for the code:

    print $clear "";

    I was using this to empty the file of contents, I don't know any other
    way to do this so any advice would be appreciated.
    Cheers again,
    Sam
     
    sj, Mar 20, 2009
    #12
  13. sj <> wrote:
    > On Mar 19, 10:27 pm, Uri Guttman <> wrote:


    >> --
    >> Uri Guttman  ------    --------  http://www.sysarch.com--
    >> -----  Perl Code Review , Architecture, Development, Training, Support ------
    >> --------- Free Perl Training ---http://perlhunter.com/college.html---------
    >> ---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com---------



    Never quote a .signature (unless that is what you are commenting on).

    Have you seen the Posting Guidelines that are posted here frequently?


    > from a
    > friend, in Visual Basic which he used to own,



    Microsoft owns Visual Basic.

    Your friend only licensed it from them.


    > print $clear "";
    >
    > I was using this to empty the file of contents,



    That could never have worked.

    It was not that print() statement that emptied the file, it might
    have been an open() that emptied it though.


    > I don't know any other
    > way to do this so any advice would be appreciated.



    perldoc -f truncate


    --
    Tad McClellan
    email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
     
    Tad J McClellan, Mar 20, 2009
    #13
  14. sj

    sj Guest

    On Mar 20, 12:42 am, Tad J McClellan <> wrote:
    > sj <> wrote:
    > > On Mar 19, 10:27 pm, Uri Guttman <> wrote:
    > >> --
    > >> Uri Guttman  ------    --------  http://www.sysarch.com--
    > >> -----  Perl Code Review , Architecture, Development, Training, Support ------
    > >> --------- Free Perl Training ---http://perlhunter.com/college.html---------
    > >> ---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com---------

    >
    > Never quote a .signature (unless that is what you are commenting on).
    >
    > Have you seen the Posting Guidelines that are posted here frequently?
    >
    > > from a
    > > friend, in Visual Basic which he used to own,

    >
    > Microsoft owns Visual Basic.
    >
    > Your friend only licensed it from them.
    >
    > > print $clear "";

    >
    > > I was using this to empty the file of contents,

    >
    > That could never have worked.
    >
    > It was not that print() statement that emptied the file, it might
    > have been an open() that emptied it though.
    >
    > > I don't know any other
    > > way to do this so any advice would be appreciated.

    >
    >     perldoc -f truncate
    >
    > --
    > Tad McClellan
    > email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


    I apologise for my misuse of 'owned', I should have said he owned a
    licence for Visual Basic.
    Thank you for showing me truncate, I'll give that a go now.
    Cheers,
    Sam
     
    sj, Mar 20, 2009
    #14
  15. sj <> wrote:
    >I'm making a program just for the joy of it, really, but I'm getting a
    >bug I just can't work out. Basically, when I run it, I get the message
    >'uninitiated value $whatever in pattern match (m//) at C:\wherever
    >line whatever'.


    I don't believe you. That is not an error message issued by perl. Maybe
    you meant "uninitialized" instead of 'uninitiated'? Please copy and
    paste error messages, the exact wording is important.

    >The problem is, they are initiated...


    Maybe. I don't know what an initiated variable is. Whoever it has no
    bearing on a variable being initialized.

    >I can post the code if it would
    >make this easier,


    That would certainly make it easier. Finding an error in a piece of code
    without seeing the code requires some unusual levels of paranormal
    abilities.

    >but all variables are declared


    The declaration of a variable has nothing to do with its initialization.

    >with 'my' not
    >'local'...I've tried putting them in different places in the code,
    >within loops or all at the begining etc...


    Well, fine, but those declare variables, they don't assign any value to
    them.

    >it used to work :/ maybe I
    >should just start again!


    It might be easier to just assign a value to the variable $whatever.

    jue
     
    Jürgen Exner, Mar 21, 2009
    #15
  16. sj <> wrote:
    >Sorry, I'm completely new to both programming and usenet, I'll attempt
    >to pick it up as fast as possible.
    >I *think* it's the 'special' and 'checkinput' subs that are having the
    >problems...


    Your code does not have a variable $whatever, which -as you claimed in
    your first posting- was named in the error message.

    >#use strict;
    >#use warnings;


    Why are you disabling the two most helpful weapons against frequent
    programmer mistakes in perl's arsenal? Enable them, fix all the warnings
    and error messages you get now, and then we can talk again. In all
    likelyhood your original problem will be gone by then.

    [rest of code snipped]

    jue
     
    Jürgen Exner, Mar 21, 2009
    #16
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RXNraW1v?=

    C# Databinder.Eval didn't work quite right...

    =?Utf-8?B?RXNraW1v?=, Nov 5, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    3,483
    Scott Allen
    Nov 7, 2004
  2. Jack
    Replies:
    0
    Views:
    777
  3. Simon Mansfield

    Cant quite figure out whats wrong!? Help??

    Simon Mansfield, Dec 5, 2004, in forum: C Programming
    Replies:
    6
    Views:
    403
    Lawrence Kirby
    Dec 6, 2004
  4. Gabriel Genellina
    Replies:
    2
    Views:
    268
    Miles
    Sep 25, 2007
  5. Guillaume Ebuprofen
    Replies:
    1
    Views:
    115
    Robert Klemme
    Oct 22, 2010
Loading...

Share This Page