in reply to Break foreach and print at specific position?

How to break the foreach() loop? There is a instruction to do it?
last

See also Loop Control

The second question is how to tell to print to a specific position? For example, I always want to write starting at position 30.

Update: due to subsequent clarification of the question, this does not solve the problem:

If you only want to print a portion of a string, use substr:

print substr($s, 29);

Replies are listed 'Best First'.
Re^2: Break foreach and print at specific position?
by perlmonks12 (Novice) on May 10, 2010 at 23:25 UTC
    LAST is exactly what I was looking for, thanks. I think I was not clear on my print question. I want for example, always start printing at position 30. For example, If I do print "\nValue is $data"; it will print the value on the start of the line and it's correct since I used \n, however I want to write on the new line bug starting at the position 30, in other works I would like to print always jumping the first 29 position / chars. How to do it? Thank you
      The simplest way is simply to add 28 spaces in front:
      my $indent = " " x 28; say $indent,"your message";
      I used a variable to save having to change x 28 however many places around the program when the indentation gets changed.
        I understand what you mean, but it's not what I'm looking, I want to align the output. For example, suppose print "\nValue1 is $data1 Value2 is $data2"; if it's inside a loop and the size of $data1 and $data2 changes often it will get all unaligned. I want to start at a pre-defined position in a way that output of value2 will always be printed on the same place, independent of the size of $data1. Thank you
        Great, it was exactly what I wanted. Thank you
      i can't remember off the top of my head the exact perl variable, but anyhow you can just change the end of line character to any character or any number of characters you want. after it is set, print a blank line, and all your prints now default at whatever position. If you need more control over print layout, you could use the (a bit arcane) FORMAT constructs, or use some other layout module.
      the hardest line to type correctly is: stty erase ^H