Re: Search an array


#1

the currently running program; $0? The idea is to log all the
errors to
a SQL Server database, the name of the program, line number where the
error occurred, error message, etc.

Thanks!

Why look in $@? You already know what $0 is.

Also, it might be easier to use a library like ‘tracer’ (stdlib) or
perhaps ruby-trace (RAA).

In other other random thoughts, ruby-trace looks like a prime candidate
for a rewrite using a DSL. :slight_smile:

Regards,

Dan

This communication is the property of Qwest and may contain confidential
or
privileged information. Unauthorized use of this communication is
strictly
prohibited and may be unlawful. If you have received this communication
in error, please immediately notify the sender by reply e-mail and
destroy
all copies of the communication and any attachments.


#2

2006/5/15, Berger, Daniel removed_email_address@domain.invalid:

the currently running program; $0? The idea is to log all the
errors to
a SQL Server database, the name of the program, line number where the
error occurred, error message, etc.

Thanks!

Why look in $@? You already know what $0 is.

He needs to find the entry with the name to get the line number.
Here’s another nice solution:

prog = “C:/mhiqTest/testAdoConnection.rb”

stack = [
“c:/ruby/lib/ruby/site_ruby/1.8/DBD/ADO/ADO.rb:57:in connect'", "c:/ruby/lib/ruby/site_ruby/1.8/dbi.rb:424:inconnect’”,
“c:/ruby/lib/ruby/site_ruby/1.8/dbi.rb:215:in `connect’”,
“C:/mhiqTest/testAdoConnection.rb:16”,
]

rx = Regexp.new(Regexp.escape(prog) + “:(\d+)”)
stack.inject(nil) {|nr, frame| rx =~ frame ? $1.to_i : nr }

:-))

Kind regards

robert