I know I can die but that prints out the script name and line number.
I like to do things like die 'error' if $problem;
Is there a way to do that without printing line number stuff?
It would be nice not to have to use braces if($problem){print 'error';exit}
For example, your code can be written like this: use Time::Piece; $todaydate = localtime->strftime('%Y-%m-%d-%H%M%S'); $output_file = "my_data_$todaydate. csv"; print "SQL query output file name : $output_file\n"; Time::Piece has been included with all versions of Perl since 2007.
exit() function evaluates the expression passed to it and exits from the Perl interpreter while returning the value as the exit value. The exit() function does not always exit immediately but calls the end routines before it terminates the program.
print() operator – print operator in Perl is used to print the values of the expressions in a List passed to it as an argument. Print operator prints whatever is passed to it as an argument whether it be a string, a number, a variable or anything. Double-quotes(“”) is used as a delimiter to this operator.
So the echo is running inside of a shell and in this case it just returns the one shell variable. A cleaner way to get this in Perl is to use %ENV like so: my $jobID = $ENV{'JOBID'}; This also removes the need for chomp , avoids creating an extra process, and is much more efficient.
Adding a newline to the die error message suppresses the added line number/scriptname verbage:
die "Error\n"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With