Re: sub for die?

2017-02-19 Thread Timo Paulssen
Hi,


On 19/02/17 04:48, ToddAndMargo wrote:
>"die" is not all that useful, as it always exits
> with a "1".  With "exit", you can set the exit code.

that's leaving out a whole lot of context, though. "die" is a quick way
to throw an exception. If an exception reaches the outermost part of
your program without getting handled by something, the program will
print the exception message (i.e. what its .message method generates)
and a stack trace of where the exception was thrown.

However, using "die" in the mainline of your program is "not all that
useful" as you correctly point out.

HTH
  - Timo


Re: sub for die?

2017-02-18 Thread ToddAndMargo

On 02/17/2017 06:43 PM, ToddAndMargo wrote:

Hi All,


$ cat die.pl6
#!/usr/bin/perl6

use strict;
# use warnings;
# use lib;  # fill name of lib in

die "Curses on you!";


$ die.pl6
Curses on you!
  in block  at ./die.pl6 line 7


What is the best way to exit, like "die", without
the commentary "in block " from the "die" command?
I just want my stuff to show and nothing else.


Many thanks,
-T





Hi All,

   Almost every thing you guys tell me, I write down.
This is what became of my question and die and exit.
I may be of use to others.

   "die" is not all that useful, as it always exits
with a "1".  With "exit", you can set the exit code.

   The link to exit codes is nice.

-T


"exit" and "die" in Perl 6:

EXIT:

#!/usr/bin/perl6

use strict;
# use warnings;
# use lib;  # fill name of lib in

print STDERR "Curses on you!\n";
exit 2;

print "This should not print\n";


$ exit.pl6; echo $?
Curses on you!
2



DIE:

$ cat die.pl6
#!/usr/bin/perl6

use strict;
# use warnings;
# use lib;  # fill name of lib in

die "Curses on you!";

Print "This should not print\n";


$ die.pl6
Curses on you!
  in block  at ./die.pl6 line 7

1


For a list of bash exit codes:
http://www.tldp.org/LDP/abs/html/exitcodes.html


1   Catchall for general errors
2   Misuse of shell builtins (according to Bash documentation)



--
~~
Computers are like air conditioners.
They malfunction when you open windows
~~


Re: sub for die?

2017-02-18 Thread ToddAndMargo

On 02/18/2017 03:30 AM, Timo Paulssen wrote:

It is usually considered The Right Thing to output error messages to
stderr instead of stdout; you can use "note" to output to stderr (and
it'll also put a newline at the end for you, which print doesn't do).



True.  Thank you

--
~~
Computers are like air conditioners.
They malfunction when you open windows
~~


Re: sub for die?

2017-02-18 Thread Timo Paulssen
It is usually considered The Right Thing to output error messages to
stderr instead of stdout; you can use "note" to output to stderr (and
it'll also put a newline at the end for you, which print doesn't do).


Re: sub for die?

2017-02-17 Thread ToddAndMargo

On 02/17/2017 06:43 PM, ToddAndMargo wrote:

Hi All,


$ cat die.pl6
#!/usr/bin/perl6

use strict;
# use warnings;
# use lib;  # fill name of lib in

die "Curses on you!";


$ die.pl6
Curses on you!
  in block  at ./die.pl6 line 7


What is the best way to exit, like "die", without
the commentary "in block " from the "die" command?
I just want my stuff to show and nothing else.


Many thanks,
-T





Figured it out.  Just use "exit":



#!/usr/bin/perl6

use strict;
# use warnings;
# use lib;  # fill name of lib in

print "Curses on you!\n";
exit 2;

print "This should not print\n";


$ exit.pl6; echo $?
Curses on you!
2

--
~~~
Serious error.
All shortcuts have disappeared.
Screen. Mind. Both are blank.
~~~