Tk Library Source Code

View Ticket
Login
Ticket UUID: 449531
Title: Package to iterate over lines of files
Type: Patch Version: None
Submitter: lingnau Created on: 2001-08-09 16:14:58
Subsystem: None Assigned To: andreas_kupries
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2001-08-25 00:03:48
Resolution: Fixed Closed By: andreas_kupries
    Closed on: 2001-08-24 17:03:48
Description:
Here is a package I've been working on that I
would like to offer for Tcllib. It is basically
a Tcl-only clone of the Python fileinput module,
i.e., it contains syntactic sugar for iterating
over the lines of a number of files, with
optional in-place editing and backups. This
allows code like

  # Number lines
  package require fileinput
  ::fileinput::foreach line $argv {
      puts [format "%d %s" [::fileinput::lineno] $line
  }

I have included a manual page for the package.
Please let me know if this is acceptable or if
there is anything I ought to change.
User Comments: andreas_kupries added on 2001-08-25 00:03:48:
Logged In: YES 
user_id=75003

Comitted attached patch (449531.diff.2) to head.

andreas_kupries added on 2001-08-22 04:31:55:
Logged In: YES 
user_id=75003

In the near future we should also add pure-tcl versions of 
the scan-commands coming with TclX.

andreas_kupries added on 2001-08-22 02:17:13:

File Added - 9797: 449531.diff.2

Logged In: YES 
user_id=75003

Added patch which adds not 'fileinput' but two lower level 
commands ripped from TclX which can be used to 
create 'fileinput'.

andreas_kupries added on 2001-08-22 00:08:39:
Logged In: YES 
user_id=75003

I had a look at some TclX commands now (for_file, 
for_recursive_glob, 'scan*'-commands) and come
to the conclusion that it might be better to take
these and include them in tcllib. Partially they
are already written in Tcl. They just need btter 
names. With them it is possible to write the 
submitted 'fileinput' in maybe 10 lines of tcl.

andreas_kupries added on 2001-08-21 06:50:54:
Logged In: YES 
user_id=75003

Is a testsuite available for this too ?

andreas_kupries added on 2001-08-21 06:45:47:

File Added - 9758: fileinput.tar.gz

Logged In: YES 
user_id=75003

Retrieved the trimmed-down version from Anselm's website 
and attached it here.

lingnau added on 2001-08-10 02:05:07:
Logged In: YES 
user_id=65359

Andreas is right. Here is a trimmed-down version that
uses »continue« in place of »fileinput::nextfile« and
»break« in place of »fileinput::close«.

Feel free to put this into the »fileutil« package if
you think it ought to go there. I think its scope is
somewhat different from the other commands in that package (which attempt to clone Unix commands) but
it's no big thing to me. Remember that you will have
to either change the name of the »foreach« command
or else change the »namespace export« in fileutil.tcl
or chaos will ensue.

ericm added on 2001-08-10 00:44:35:

File Added - 9416: fileinput.tar.gz

lingnau added on 2001-08-09 23:41:51:
Logged In: YES 
user_id=65359

For some reason SourceForge won't let me attach the
files to this report. I've put them on
http://anselm.our-isp.org/tcltk/fileinput.tar.gz
for the time being. Sorry!

Attachments: