chomping $@

J

jemptymethod

The perldoc for die says: "If the last element of LIST does not end in
a newline, the current script line number and input line number (if
any) are also printed, and a newline is supplied." Is there a way,
besides appending the newline and a subsequent "chomp($@)", to suppress
this behavior? For instance such as locally re-declaring a special
variable in the same block with die. I have tracked down the docs for
every special variable mentioned in the docs for die, and none of them
seem appropriate (I have also tried to google for "chomp $@" but google
suppresses the special variable so I get far too many results).

TIA
 
D

Dr.Ruud

(e-mail address removed) schreef:
The perldoc for die says: "If the last element of LIST does not end in
a newline, the current script line number and input line number (if
any) are also printed, and a newline is supplied." Is there a way,
besides appending the newline and a subsequent "chomp($@)", to
suppress this behavior? For instance such as locally re-declaring a
special variable in the same block with die. I have tracked down the
docs for every special variable mentioned in the docs for die, and
none of them seem appropriate (I have also tried to google for "chomp
$@" but google suppresses the special variable so I get far too many
results).


Maybe you want: { print "@_"; die $! }
 
X

xhoster

The perldoc for die says: "If the last element of LIST does not end in
a newline, the current script line number and input line number (if
any) are also printed, and a newline is supplied." Is there a way,
besides appending the newline

Appending it to what?
and a subsequent "chomp($@)",

Why do that? Is that to reverse the appending mentioned above?
to suppress
this behavior?

Which behavior do you want suppressed? The one where it adds the line
number if there isn't a \n, or where it doesn't add the line number if
there is a \n?
For instance such as locally re-declaring a special
variable in the same block with die. I have tracked down the docs for
every special variable mentioned in the docs for die, and none of them
seem appropriate

How about:

die $@, "\n";

Or maybe you want the opposite, forcing the line number, etc. even if there
is a newline:

die $@, ":";
(I have also tried to google for "chomp $@" but google
suppresses the special variable so I get far too many results).

What were you hoping to find by googling for that? Doing chomp on $@ isn't
magical. If you know what chomp and $@ do individually, you know what they
do in combination.

Xho
 
J

jemptymethod

Appending it to what?


Why do that? Is that to reverse the appending mentioned above?


Which behavior do you want suppressed? The one where it adds the line
number if there isn't a \n, or where it doesn't add the line number if
there is a \n?

Sorry I wasn't clear or specific enough. I'm using eval to catch an
exception raised with die sort of as follows:

die "WTF?\n";

Where I've added the newline to suppress the line number being
appended. Just wondering if there wasn't a way to suppress this
behavior local to die rather than after eval. I googled for "chomp" &
"$@" because that is what I'm wondering if I can avoid; I would have
googled for the solution but I don't know it yet :) chomp($@) is one
way to do it, but I understand Perl's motto is there's _more_ than one
way....
 
A

Anno Siegel

Sorry I wasn't clear or specific enough. I'm using eval to catch an
exception raised with die sort of as follows:

die "WTF?\n";

Where I've added the newline to suppress the line number being
appended.

Aha. So the behavior you want to suppress is that die() adds file/line
information to the message.
Just wondering if there wasn't a way to suppress this
behavior local to die rather than after eval.

"Local to" a builtin function doesn't make sense. You can override
die() with your own function if that is what you want. See
perldoc -q builtin.
I googled for "chomp" &
"$@" because that is what I'm wondering if I can avoid; I would have
googled for the solution but I don't know it yet :) chomp($@) is one
way to do it, but I understand Perl's motto is there's _more_ than one
way....

Hmm... chomp( $@) (before calling die( $@)) would *allow* die to add
the file/line information you wanted suppressed. So once again:

What behavior of die() do you want to suppress? Please start making
some sense.

Anno
 
J

jemptymethod

Anno said:
Hmm... chomp( $@) (before calling die( $@)) would *allow* die to add
the file/line information you wanted suppressed. So once again:

What behavior of die() do you want to suppress? Please start making
some sense.

I'm sorry I'm not communicating precisely enough. To avoid the default
appending of line/file information (see my original post, I quoted from
perldoc), I'm instead appending a newline. And I'm subsequently
performing chomp($@) after die. It's been working for me and I've
moved on to other issues. Thanks though.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top