On Mon, 3 Mar 2003, Deb wrote:
> Here's the modified script. I made some changes, as suggested, but there
> was no change in the output. I've included my entire script. My head is
> getting mighty flat from banging it against the wall. Oh, and I added "use
> warnings;" and I haven't got a clue what I need to do to fix those. <sigh>
>
> I'd *LOVE* to be able to use GetOpt::Std - but I wasn't able to get it to
> look at something other than @ARGV - I need to process files on the fly
> that have the lines as delineated in __DATA__, below.
>
> My goals are to see if the -x option exists, and if it does get its
> argument. I also need to do certain things based on -h and -r and their
> respective arguments. This would all tied to the argument of -x (I guess
> this would be the key to everything). -x arg always exists on these lines,
> while the others may or may not. The argument to -x is the root of
> everything else.
>
> I can see how I'd do this if I could use GetOpt::Std - is this possible
> given that it is not actually coming from the commandline?
Yes this is possible, your commandline is the @ARGV array. Read the line
in, split it and store the resulting array in @ARGV like this
local @ARGV = split;
The original @ARGV will be saved and restored once the program comes out
of the while loop.
perldoc -f split
perldoc -f local
Did you look at the code that I posted at the end of my last mail?
>
> Here's my script... as it stands now:
>
> #!/bin/perl -w
>
> use warnings;
> use strict;
> my %cmdLine;
> my %newHash;
> my $DBG = 1;
> my ($onceMore, $opt, $arg);
>
> while (<DATA>) {
> chomp;
>
> my ($adx, $rest) = (split(/:/,$_));
> if ($DBG) {print "\$adx=\t<$adx>\n\$rest=\t<$rest>\n";}
>
> while (defined ($rest) && $rest ne "") {
> my ($opt, $arg, $newRest) = ($rest =~ /\s*([\-a-z]*)\s+([^ ]*)\s+(.*)/);
> $rest = $newRest;
> $cmdLine{$opt} = $arg;
> }
>
> # parse the final tuple...
> my ($opt, $arg, $newRest) = ($rest =~ /\s*([\-a-z]*)\s+([^ ]*)\s+(.*)/);
> $cmdLine{$opt} = $arg;
>
> # Build out the data structure
> my $masterKey = $cmdLine{'-x'};
>
> foreach my $opt (keys %cmdLine) {
> $newHash{$masterKey}{$opt} = $cmdLine{$opt};
> }
> }
>
> foreach my $masterKey (sort keys %newHash) {
> print "$masterKey\n";
> foreach my $opt (sort keys %{$newHash{$masterKey}}) {
> print "\t$opt\t" . $newHash{$masterKey}{$opt} . "\n";
> }
> }
>
>
> __DATA__
> ten-me-900: -r timbu -x me-900 -h ten-me-900
> hidit: -r tenbu -x networks-users -h hidit
> postal: -x direct -h postal
> pickit: -h pickit -x uncrp -r oakd
>
>
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]