# Picking through a script

**URL:** <https://www.ruby-forum.com/t/picking-through-a-script/139922>\
**Category:** Ruby\
**Created:** [June 9, 2008, 6:35am UTC](https://www.ruby-forum.com/t/picking-through-a-script/139922 "2008-06-09T06:35:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gerry\_ford](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/47e85d/32.png) [@gerry\_ford](https://www.ruby-forum.com/u/gerry_ford)\
**Post date:** [June 9, 2008, 6:35am UTC](https://www.ruby-forum.com/t/picking-through-a-script/139922/1 "2008-06-09T06:35:34Z")

</div>

Hello Ruby Forum,

I’m picking through a script that will archive sent messages in my  
Dialog newsreader, written by another. He included msgfile.rb, which  
looks to be a class definition. Am I correct that ruby should throw an  
error if it can’t find iconv? As it is, the script seems to execute  
without output, warnings or errors.

#!/usr/bin/env ruby

# extr\_sent.rb

# extract all Sent messgages from all msg\*.dat in Dialog’s data

direectory into single messages

# Usage: place into data dir and run - will extract into single messages

# with parameter -m: extracts to mbox

# with parameter -r: extracts raw, mostly for debugging purposes

# Backup your files first, no guarantees.

require ‘iconv’  
require ‘msgfile’

## Is iconv something that comes already with ruby 1.8.6? Thanks,

---

<div class="post-metadata">

**Author:** ![gerry\_ford](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/47e85d/32.png) [@gerry\_ford](https://www.ruby-forum.com/u/gerry_ford)\
**Post date:** [June 9, 2008, 7:00am UTC](https://www.ruby-forum.com/t/picking-through-a-script/139922/2 "2008-06-09T07:00:36Z")

</div>

On Sunday 08 June 2008 23:34:09 Gerry F. wrote:

> Is iconv something that comes already with ruby 1.8.6?

Seems to. For what it’s worth, isn’t 1.8.7 out now?

---

<div class="post-metadata">

**Author:** ![gerry\_ford](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/47e85d/32.png) [@gerry\_ford](https://www.ruby-forum.com/u/gerry_ford)\
**Post date:** [June 9, 2008, 11:24am UTC](https://www.ruby-forum.com/t/picking-through-a-script/139922/3 "2008-06-09T11:24:27Z")

</div>

David M. wrote:

> On Sunday 08 June 2008 23:34:09 Gerry F. wrote:
> 
> > Is iconv something that comes already with ruby 1.8.6?
> 
> Seems to. For what it’s worth, isn’t 1.8.7 out now?

I’ve had this install for a while. Ruby was something I wanted to get  
to, but real life has been interfering. I might be behind one version.

Since you said you got it to work, I went ahead and looked for anything  
in ruby that had iconv in it. There was an iconv.dll and an iconv.exe.  
I’d guess ruby.exe used iconv.dll.

Here’s some more of the script:

RAW = ARGV.delete("-r")  
MBX = ARGV.delete("-m")

def output(art, counter)  
if RAW  
File.open(filename(counter), “wb”) {|out| out.puts art}  
else  
if MBX  
File.open(“sent.mbx”, “ab”) do |out|  
out.print fromline(counter), LINEBREAK  
out.print reformat(art), LINEBREAK, LINEBREAK  
end  
else  
File.open(filename(counter), “wb”) {|out| out.print reformat(art),  
LINEBREAK}  
end  
end  
end

## It looks like ARG.delete is a way to get command line args. How would this behave if no command-line args are given?

---

<div class="post-metadata">

**Author:** ![gerry\_ford](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/47e85d/32.png) [@gerry\_ford](https://www.ruby-forum.com/u/gerry_ford)\
**Post date:** [June 10, 2008, 6:53am UTC](https://www.ruby-forum.com/t/picking-through-a-script/139922/4 "2008-06-10T06:53:26Z")

</div>

On Monday 09 June 2008 04:24:25 Gerry F. wrote:

> It looks like ARG.delete is a way to get command line args. How would  
> this behave if no command-line args are given?

Well, ARGV is an array of commandline arguments – it behaves exactly  
like any  
other array. A little testing shows that calling delete from an array  
will  
either return the item asked for, or nil.

So in this case, RAW will be either ‘-r’ or nil, depending on whether  
there’s  
a -r in the commandline. Same for MBX and ‘-m’ – so with no commandline  
arguments, RAW and MBX will both be nil.
