>
> Thanks, I know how to use split (I think). Since the data
> comes in any order, and I have to corellate it, I can't think
> of a way that split will fix me up - Maybe I'm missing
> something. Can you give me an example?
>
Ok I'll give her a go
my %results;
my $cnt = 1;
foreach $line(@Array) {
my %tmp;
my $switch;
my $value;
%tmp = split(/\s/, $line);
# this assumes that every piece of data has a switch so it wouldn't work on '-I love
you' because -I and love
# would be together but then you would be lonely , it would especially be bad if it
had switches after it
# '-I love you -j enny -I mforestgump'
# if this is the case you may have to put it in an array and process that somehow to
get the switch/value combos
# and then do something with the bare values ( I guess I should be calling them
arguments oh well )
foreach $switch(keys %tmp) {
$results{$cnt}{$switch} = $value;
}
$cnt++
}
print $results{'1'}{'-h'}; # would print post1 from your three line example below
Give that a go and see if it doesn't help!
DMuey
> deb
>
>
> Dan Muey <[EMAIL PROTECTED]> had this to say,
>
> > perldoc -f split
> >
> > Will fic you up!
> >
> > Dmuey
> >
> > > Hi Guys,
> > >
> > > I have an array in which each element is a line commandline
> > > data. It looks something like this -
> > >
> > > @Array contains lines:
> > >
> > > post1: -r [EMAIL PROTECTED] -x cat-100 -h post1
> > > post2: -x tel -h post2
> > > post3: -h post3 -x hifi
> > >
> > > And so on. The order of the options varies, and there may or
> > > may not be a
> > > -r $arg on the line.
> > >
> > > These lines are parsed from a file with more lines, of which
> > > I extracted all the lines with -h:
> > >
> > > open (F, "<$File");
> > >
> > > while (<F>) {
> > > if ($_ =~ / -h /) {
> > > # remove crud
> > > s/ \"\|//;
> > > s/\/some\/crud\/path argument //;
> > > s/\"$//;
> > > # store what's left
> > > push @Array, $_;
> > > }
> > > }
> > >
> > > What I really need to do is build a relationship between the
> > > first field
> > > (which is the same as the argument to -h) and the argument to
> > > -x. The -x flag can be dropped, as they're not needed.
> > >
> > > So it looks like I need to build a hash based.
> > >
> > > But I can't can't grok how to parse each line out to do what
> > > I need, then move on to the next line (all lines are
> > > unrelated to each other).
> > >
> > > I've been using shift, but then I'm doing something like,
> > > (psuedo code):
> > >
> > > if ($_[0] eq "-r") { $r = (shift);}
> > >
> > > but if sub 0 doesn't eq -r, and I shift until I get to -x,
> > > say, and use that for the $x = (shift), how can I be
> > > efficient to check again for -r, which I still haven't found?
> > >
> > > Is this making any sense?
> > >
> > > Thanks,
> > >
> > > deb
> > >
> > >
> > >
> > > --
> > > =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> > > =-=-=-=-=-=-=-=-=-
> > > There are 010 types of people in the world:
> > > those who understand binary, and those who don't.
> > > ��� 111,111,111 x 111,111,111 = 12,345,678,987,654,321 (decimal)
> > > ~
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > --
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> > >
>
> --
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> =-=-=-=-=-=-=-=-=-
> There are 010 types of people in the world:
> those who understand binary, and those who don't.
> ��� 111,111,111 x 111,111,111 = 12,345,678,987,654,321 (decimal)
> ~
>
>
>
>
>
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]