That's because in this case the 'x' is acting as an operator which takes in
a string on the left side, a number on the right side, and returns the
string replicated as many times as the number.

When you flip them, it tries to treat the string as a number, which is a
problem. So it returns undef or "", can't remember which right now and when
you print that you get nothing.


On Sat, Dec 29, 2012 at 10:42 AM, Om Prakash Singh
<torque.in...@gmail.com>wrote:

> Hi All,
>
> I am new to perl and while going through the chapters of Learning perl, i
> just came through one excessive, while i was able to complete it, i just
> came across something that didn't work and i couldn't find any explanation
> for it. Would be great if i get some help in understanding this behavior.
>
> below is the code
>
> print "the string: ";
> $string = <STDIN>;
> print "the no.: ";
> chomp($number = <STDIN>);
> $result = $string x $number;
> print "the result is:\n$result";
>
>
> in the above code when i use
> $result = $string x $number;
> i get the right result, i.e. strings printed on two lines.
>
> but, when i use
> $result = $number x $string;
> I don't get any output at all, just wondering why this happens, any help
> would be highly appreciable.
>
> Regards,
> Omps
>



-- 
Danny Gratzer

Reply via email to