I don't know if this is the right board to ask

This is a discussion on I don't know if this is the right board to ask within the Tech Board forums, part of the Community Boards category; Is there any condition when the following code might fail and/or crash? Code: $ more filter.pl #!/usr/bin/perl my $cont = ...

  1. #1
    Banned
    Join Date
    May 2007
    Location
    Berkeley, CA
    Posts
    329

    I don't know if this is the right board to ask

    Is there any condition when the following code might fail and/or crash?

    Code:
    $ more filter.pl
    #!/usr/bin/perl
    
    my $cont = 0;
    while ($line = <STDIN>) {
        if ($line =~ /^ /) {
            next if $cont;
        }
        $cont = 0;
            
        foreach $i (@ARGV) {
            if ($line =~ /^$i:/) {
                $cont = 1;
            }
        }
        if (!$cont) { print $line; }
    }

  2. #2
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    yeah, if you try to compile it as a C/C++ file it will fial, since it isnt C/C++, you should try a perl board for help on that code.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  3. #3
    Banned
    Join Date
    May 2007
    Location
    Berkeley, CA
    Posts
    329
    Quote Originally Posted by abachler View Post
    yeah, if you try to compile it as a C/C++ file it will fial, since it isnt C/C++, you should try a perl board for help on that code.
    Maybe you should learn how to read. And I quote

    Tech Board (5 Viewing)
    Computer questions not related to C/C++/C# programming

  4. #4
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717
    Well, I guess the board description kinda fails there a bit xP
    But it's meant for technical questions, most in the line of hardware I'd say... But Cprogramming.com is more made for the C languages, except for C# I think...
    Currently research OpenGL

  5. #5
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Most of the requests for a Java board have been referred to the use of the Tech board, IIRC. I don't see a problem with a Perl question here - a lot of C programmers know Perl too. If he's already an active member, he might as well utilize the community.

    It's been a long time since I was familiar with Perl, but considering that the only statements inside your loops are simple assignments and explicit conditionals, I think it's a safe bet your code wont fail or crash.

  6. #6
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    I agree, looks pretty safe. Unless you or the user can find a way to harm your <STDIN> handle from outside of the program, then I don't see anything that could halt this unexpectedly.
    Sent from my iPadŽ

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need a second opinion - code error and i cant see it
    By bigfootneedhelp in forum C Programming
    Replies: 19
    Last Post: 10-25-2007, 06:02 AM
  2. Constructor problem
    By rebel in forum C++ Programming
    Replies: 22
    Last Post: 01-11-2006, 05:45 AM
  3. function trouble
    By rebel in forum C++ Programming
    Replies: 4
    Last Post: 12-21-2005, 04:23 AM
  4. Pick a number....
    By Salem in forum A Brief History of Cprogramming.com
    Replies: 39
    Last Post: 01-19-2003, 06:27 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21