Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 633299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:10:14+00:00 2026-05-13T20:10:14+00:00

I am writing a proc to create a header in an output file. Currently

  • 0

I am writing a proc to create a header in an output file.

Currently it needs to take an optional parameter, which is a possible comment for the header.

I have ended up coding this as a single optional parameter

proc dump_header { test description {comment = ""}}

but would like to know how I can achieve the same using args

proc dump_header { test description args }

It’s quite easy to check for args being a single blank parameter ($args == “”), but doesn’t cope well if passing multiple parameters – and I need the negative check anyway.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T20:10:14+00:00Added an answer on May 13, 2026 at 8:10 pm

    Your proc definition is incorrect (you’d get the error message too many fields in argument specifier "comment = """). Should be:

    proc dump_header { test description {comment ""}} {
        puts $comment
    }
    

    If you want to use args, you could examine the llength of it:

    proc dump_header {test desc args} {
        switch -exact [llength $args] {
            0 {puts "no comment"}
            1 {puts "the comment is: $args"}
            default {
                puts "the comment is: [lindex $args 0]"
                puts "the other args are: [lrange $args 1 end]"
            }
        }
    }
    

    You might also want to pass name-value pairs in a list:

    proc dump_header {test desc options} {
        # following will error if $options is an odd-length list
        array set opts $options
    
        if {[info exists opts(comment)]} {
            puts "the comment is: $opts(comment)"
        }
        puts "here are all the options given:"
        parray opts
    }
    dump_header "test" "description" {comment "a comment" arg1 foo arg2 bar}
    

    Some prefer a combination of args and name-value pairs (a la Tk)

    proc dump_header {test desc args} {
        # following will error if $args is an odd-length list
        array set opts $args
        if {[info exists opts(-comment)]} {
            puts "the comment is: $opts(-comment)"
        }
        parray opts
    }
    dump_header "test" "description" -comment "a comment" -arg1 foo -arg2 bar
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a SQL Stored Proc which takes in a single table valued
I writing a report in Visual Studio that takes a user input parameter and
I writing a linux kernel module that does some work with /proc... I'm trying
I have been messing around with writing some stored procedures in .NET code with
I have been unsuccesfully attempting to upload an encrypted file to an FTP server,
I am writing a daemon in c++ on linux which would launch many processes.
I'm writing a program that sits in the systray. It will have a keyboard
So, I'm writing this Stored Proc and I really suck at SQL. My Question
Writing some test scripts in IronPython, I want to verify whether a window is
Writing the code for the user authentication portion of a web site (including account

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.