in reply to Different behaviours in the similar scripts

You said:

"In the above script i am splitting the server name like this my ($hostname) = split /\./, $NODE;"

But in the new script, you don't assign $hostname the same way:

$hostname = split /\./, $NODE;

You need to put parens () around $hostname like you have in the first script. From perldoc -f split:

"Splits the string EXPR into a list of strings and returns the list in list context, or the size of the list in scalar context."

Which means that using a scalar instead of a list on the left-hand side, it'll return the number of items returned from the split. ($hostname) is retrieving in list context, whereas $hostname is looking for the scalar return.

Also, you're still not properly indenting. I highly recommend spending the few minutes it would take to go through the entire script and indent it consistently.

Replies are listed 'Best First'.
Re^2: Different behaviours in the similar scripts
by shroh (Acolyte) on Aug 06, 2015 at 21:18 UTC
    Thanks Steive, It is working now. Identation is a big problem for me. I am very poor in the basics of the indentation like which braces will come when.. Do you have any guide which has some documentation on how to do that.
      You can use perltidy to cleanup the formatting.
      "Do you have any guide which has some documentation on how to do that."

      As part of the core documentation which comes with Perl: perlstyle - Perl Style Guide.

      — Ken

      It depends a bit on whether your bosses have a syntax style that you must follow. If you are free to choose, I suggest paying attention to the syntax of the Perl code you read on this site, and also the source of modules you use. You should find that one style or another is easiest for you to read and understand, and that should be the basis of the choice.

      See this article for some examples of formal styles.

      The way forward always starts with a minimal test.
        The utility perltidy (recommended by FishMonger) can be configured for almost any style requirement.
        Bill