in reply to Perl equivelant to bash '$*'

I'm sorry, but I'm finding it hard to understand what you are saying -- in other words, what you are saying makes no sense to me.

"$*" in a bash shell refers to the list of all (0 or more) white-space separated tokens that follow the name of the shell script on the command line that invokes the shell script. Things that are within quotes are treated as a single "token", and can include any sort of white-space (even LF), but all spaces and tabs between tokens are discarded once the tokenization is done, and the shell script gets the list of tokens as $* -- for example:

$ cat test.sh for i in $* do echo ==$i== done $ source test.sh one two three ==one== ==two== ==three==
That's the same behavior you get with @ARGV in perl scripts.

A shell command line cannot pass a C structure, except when either (a) the C structure is properly quoted and escaped so that the shell sees it as a single token containing literal characters, or (b) the C structure happens to be a single string of "non-shell-magic" characters -- no internal spaces or other things that the shell would interpret in some special way (e.g. angle brackets, ampersand, semicolon, etc). Either way, $* and @ARGV should be equivalent.

Elsewhere you said:

Basically the calling program passes 128 bytes of data. It so happens that the fields in the structure are strings and padded with spaces but there are no delimiters other than byte offset from the beginning. So I know the data is there I just don't know how to get at it from within perl because I don't know how to treat the command line as a large blob of binary data.

Basically the command line would look like this.

program.pl <128 bytes of data>

So, you are not able to change the calling program, but you want your "program.pl" to replace an existing C program that previously occupied the initial slot in that command line, and you believe that the C program is treating its command line arg(s) differently from how Perl treats @ARGV -- is that it? Well, maybe the C program is treating its command-line args differently... do you have the C source code to check on that? But I don't think the "(argc,argv)" things that the C program gets from the command line can be any different from what Perl gets in @ARGV

I suspect we could be more help, but IMHO, the problem as presented so far has invalid assumptions and insufficient detail.

(updated to fix syntax in middle paragraph)

Replies are listed 'Best First'.
Re^2: Perl equivelant to bash '$*'
by tillywern (Initiate) on Jul 03, 2008 at 15:11 UTC
    Thanks everyone for your comments and schooling me in *nix. Since the source example I was given was bash using "$*" as a reference to the data structure instead of $1, I assumed they really wanted me to interpret all arguments sent to the program as a single string for parsing.

    Many of you are correct in saying that the picture I gave was unclear and probably had more to do with bash and proper argument passing technique than either C or Perl. For this I am sorry.

    As it turns out, the contents can be binary in nature but I have been told that the entirety of the data structure will be passed as the first argument. I will be able to parse the C structure fields out of $ARGV[0].

    Thanks again all for helping give me the correct questions to ask to pin then down.