in reply to RE: Re: @ARGV Manipulation
in thread @ARGV Manipulation

I'm lost about where you're lost. Here's the things that I think you'll need to know to do this task, but I'm not sure which of these you know and which you don't. I enjoy helping people. But I keep wondering "help you with WHAT?" on each post. Ask a more specific question, perhaps any of the above. If it's all of the above, then I suggest you need a good book or two, or spend some time with Perl tutorials.

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
RE: RE: RE: Re: @ARGV Manipulation
by Limo (Scribe) on Sep 16, 2000 at 05:42 UTC
    AHA! Thank you! I DON'T know:
    how to recognize the difference between file_1 and a b c, other than p +ositionally. Which is of no help, because a b c can change, depending on which fields I want to read!
    That's precisely it! I caan figure the rest out! I have 4 books, which have been helpful, thus far. Thank you, thank you, thankyou, for helping to extract some clarity from me! Steven L. Sesar, Perl Infant
      Well, I've got to kick that question back to you. How would you know, as a human being, which arguments on the command line are filenames, and which ones are columns within filenames?

      You can't teach a computer to do what you yourself cannot compute, or decide how to compute. So first, teach me, and I can help you figure out the code.

      For example, what rule can you use to distinguish a, the filename, from a, the column name?

      I think that the way you've stated your problem, it's intractable, which is why I keep kicking it back. You'll need to annotate the column names distinctly from the filenames somehow.

      -- Randal L. Schwartz, Perl hacker

        Ok, Merlyn, so maybe you and your book learned me something:
        #!/usr/local/bin/perl5 #I'll call this snippet exfields.pl as in "EXtractFIELDS" #zcat command for gzipped files $gzcatcmd="gunzip -c"; # I'll need this eventually # Input parameters $RegExp = ""; # Default no regexp $MatchFld = ""; # Default no field match $LastHdr = ""; # Last read header line $DbFSplit = ' '; # Need this form for split $DbOFSep = ' '; # Default output field delimiter $VBarDel = 0; # Flag default not splitting by vertical bar ($progname = $0) =~ s/^.*\/([^\/*]+)$/$1/; # name of this program while (@ARGV) { $Param = shift @ARGV; if ($Param eq "-s") { $RegExp = shift @ARGV; # Search expression } elsif ($Param eq "-f") { $MatchFld = shift @ARGV; # Search field specifier } elsif ($Param eq "-e") { $FList = shift @ARGV; # field extract list } elsif ($Param =~ /^\-/) { &ErrorExit; #I'll define this later; you get the point } else { push @FileList,$Param; } } # Flag to substitute for whitespace if the new field delimiter #includes whitespace and the old one did not. The assumption is #that if the old delimiter included whitespace, we do not need #to convert existing whitespace in fields. May be modified by # #DFD declaration.. if (($DbOFSep =~ /^ +$/) && ($DbFSplit !~ /^ +$/)){ $FixSpaces = 'Y'; # can't have Null fields or whitespace } else { $FixSpaces = ''; # can't have Null fields or whitespace } @OrigFields = split(',',$FList); unless (@FileList) {push @FileList,"-";} print " @FileList\n";
        </CODE If you run this: <CODE> exfields.pl -e Name,Rank,SerialNumber file.gz
        it will return:
        Name,Rank,SerialNumber
        Great. Now what? I've succesfully coded HALF of what I wanted to do! What I CAN'T figure out how to do, is:
        exfields.pl -e Name,Rank,SerialNumber file.gz | Who,What,Where another +file.gz
        And have it return:
        print "@FileList_1\n"; #prints "Name" "Rank" SerialNumber" print "@FileList_2\n"; #prints "Who" "What" "Where"
        How am I doing as far as explaining what I'm trying to do?
        Ok. I'm going to try and code it, as an answer to your question, then let me know your comments..