Thank you, John. This code does exactly what I want. Problem is, I only
understand about 30% of what's going on. I can figure out the use of the
hash, some of the pattern matching & $1/$2. But can someone elaborate on:
@keys{ qw/P ST U SL D/ } = \( $Proc, $Start, $Url, $Sleep, $Drive );
/(\S+)=(.+?)(?=\s+\S+=|\z)/g
${$keys{uc $1}} = $2;
Again, thanks for your time...
-----Original Message-----
From: John W. Krahn [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, 23 April, 2002 17:39
To: [EMAIL PROTECTED]
Subject: Re: Parsing a line
Rich Busse wrote:
>
> I'm currently processing lines from an input file this way:
>
> $_ = "P=IcwRcsm D=D: SL=20 ST=d:\icw\rcsm\StartSv.bat
> U=http://uslv..."
> @Token = split ;
> foreach (@Token)
> {
> $Proc = $' if (/P=/i) ;
> $Start = $' if (/ST=/i) ;
> $Url = $' if (/U=/i) ;
> $Sleep = $' if (/SL=/i) ;
> $Drive = $' if (/D=/i) ;
> }
>
> Probably not very Perl-ish, but I'm ending up with
> $Start="d:\icw\rcsm\StartSv.bat" as needed.
>
> Now I'd like to pass parameters to the program in $Start. Something like:
>
> P=IcwRcsm D=D: SL=20 ST=d:\icw\rcsm\StartSv.bat Parm1 Parm2
> U=http://uslv...
>
> or even with delimiters if it helps:
>
> P=IcwRcsm D=D: SL=20 ST="d:\icw\rcsm\StartSv.bat Parm1 Parm2"
> U=http://uslv...
> P=IcwRcsm D=D: SL=20 ST='d:\icw\rcsm\StartSv.bat Parm1 Parm2'
> U=http://uslv...
>
> so I end up with $Start="d:\icw\rcsm\StartSv.bat Parm1 Parm2".
>
> Any suggestions appreciated. TIA...
Here is one way to do it:
$_ = q[P=IcwRcsm D=D: SL=20 ST=d:\icw\rcsm\StartSv.bat Parm1 Parm2
U=http://uslv...];
my ( $Proc, $Start, $Url, $Sleep, $Drive );
my %keys;
@keys{ qw/P ST U SL D/ } = \( $Proc, $Start, $Url, $Sleep, $Drive );
while ( /(\S+)=(.+?)(?=\s+\S+=|\z)/g ) {
${$keys{uc $1}} = $2;
}
print "Proc: $Proc\nStart: $Start\nUrl: $Url\nSleep: $Sleep\nDrive:
$Drive\n";
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]