in reply to I just want IF, OR, OR not every one

This statement:  if($line =~ /!bgs/){  is syntactically correct, but probably isn't doing what you want: it's checking to see whether $line contains the string "!bgs" somewhere, not the rather longer string defined by your here document. Presuming $bgs is just a string, and not a command to be executed you may want something more like this:

while(<SH>){ if(/$bgs/) {# Note $ means it's a variable, to be interpolated; ! +doesn't #do processing for true case } else{ #do processing for false case }

You really, really should study the documentation. I think Perl has quite clear, well organized documentation (it's not perfect, but then producing perfect documentation is at least as hard as producing perfect code); you're missing something. I also think you may be failing to tell us something. Your $bgs string looks a lot like a command, and if you want to capture its output, you'll have to use backticks.


emc

Information about American English usage here and here.

Floating point issues? Read this before posting: http://docs.sun.com/source/806-3568/ncg_goldberg.html

Replies are listed 'Best First'.
Re^2: I just want IF, OR, OR not every one
by CountZero (Bishop) on Feb 29, 2008 at 07:41 UTC
    I think you are close, but still you don't get a cookie!
    I'm trying to test to see if bgs is in the file.

    if it is not. I add the here document $bgs above syslogd.

    But, if it is there. It adds the $here document anyway.

    Perhaps the OP wanted to test if $line does NOT contain the literal string 'bgs' and was what he really meant to write $line !~ /bgs/ rather than $line =~ /!bgs/

    Then of course his first test falls through (although he thinks erroneously that it succeeds) and to his utter confusion the other conditions in the elsif chain get tested until one succeeds. Hence his question about how the if -- elsif -- else construct works and how to avoid multiple results in this chain to apply, which got us all confused as only one condition can succesfully apply.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      Count, That that was a good thought. I like where your head is. But, that continuously prints $bgs here documents. Thanks,
        Well that should not surprise you.

        Your program reads a line from your file and puts this line in $line. You then check if this line contains the literal string bgs and if not you print the content of your HERE-doc variable $bgs. Due to the next instruction, program execution then jumps straight to the continue block and prints the contents of $line

        NOW WATCH THIS!

        You then read the next line of the file and check again if this new line contains the literal string bgs ...

        So for every line not containing the literal string bgs the contents of $bgs get printed. This is not what you want:

        I'm trying to test to see if bgs is in the file.
        You will have to rethink the logic of your program to make sure that you test for the presence of bgs in the whole of the file and for each line.

        CountZero

        A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James