# Re: Search an array

**URL:** <https://www.ruby-forum.com/t/re-search-an-array/94816>\
**Category:** Ruby\
**Created:** [May 15, 2006, 6:20pm UTC](https://www.ruby-forum.com/t/re-search-an-array/94816 "2006-05-15T18:20:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [May 15, 2006, 6:20pm UTC](https://www.ruby-forum.com/t/re-search-an-array/94816/1 "2006-05-15T18:20:24Z")

</div>

> 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. 🙂

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.

---

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [May 15, 2006, 10:29pm UTC](https://www.ruby-forum.com/t/re-search-an-array/94816/2 "2006-05-15T22:29:59Z")

</div>

2006/5/15, Berger, Daniel [removed\_email\_address@domain.invalid](mailto: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:in `connect’”,  
“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
