in reply to Read two values from input

The code is not with error, it just doesn't work the way you want. Two reasons:

1) <STDIN> reads a complete line until you hit the carriage return key.

2) The line read in by <STDIN> still has that carriage return character at the end

So instead of reading two lines you obviously want to read one line and then separate the two values:

$line=<STDIN>; chomp $line; # this removes the CR character at line end ($a,$b)= split / +/, $line; #splits the line wherever it finds spaces

Replies are listed 'Best First'.
Re^2: Read two values from input
by ikegami (Patriarch) on Nov 25, 2011 at 00:43 UTC
    split(' ', $line) has the advantage of ignoring leading whitespace and accepting tabs in addition to spaces. It also makes the chomp useless.
Re^2: Read two values from input
by Marshall (Canon) on Nov 27, 2011 at 12:18 UTC
    The default split is /\s+/;. This / +/ is a bit bizarre.

    The only difference between the default split (/\s+/, $_ ) and split (' ', $_ ) is that in the first case a leading space will generate a null field. Whereas in the second case, this is suppressed.

    The split on ' ', is a special case and although there is just a space there, it means any of the five white space characters: \f\t\r\n\0x40(space). Because both forms operate on all 5 white space characters, any trailing white space will be ignored in both syntax's (unless there is a specified field limit).

    There are a lot of tricky special case things about Perl syntax.

      s/There are a lot of tricky special case things about Perl syntax. /There are a lot of context dependent features in Perl, it has a rich (and sometimes ugly) syntax./
Re^2: Read two values from input
by knils_r00t (Novice) on Nov 29, 2011 at 10:14 UTC
    Thanks jethro... And every one who visited for help....Thanku