On Sunday, April 21, 2002, at 11:41 , Jeff 'japhy' Pinyan wrote:
> On Apr 22, pat said: [..] >> $line = "Mar 17 08:48:50 msasa pppd[6404]: Connect: ppp0 <--> /dev/ttyS1" > > Well, there's no need to put them into $1, $2, etc. That can only be done > with a regex, and there's no need to do > > $line =~ /(\S+)\s+(\S+)\s+.../; but having stuffed them into $1..$9, doesn't he want to get them out of there toot sweet - or at least the ones that will need to be dealt with before doing any subseqent matching that would step over the values???? such as deconstructing the 'time' there??? > Why not just do: > > @parts = split ' ', $line; or the map to hash trick of the form: #!/usr/bin/perl -w use strict; my $line = "Mar 17 08:48:50 msasa pppd[6404]: Connect: ppp0 <--> /dev/ ttyS1"; my $count = 1 ; my %parts = map { $count++ => $_ } (split ' ', $line); my $incr = 1; print "$incr has <$parts{$incr++}> \n" while ( $incr < $count ); which would allow him to access it by numeric offset and hence would generate data of the form: jeeves:~] drieux% perl tmp/perl/silly.pl 1 has <Mar> 2 has <17> 3 has <08:48:50> 4 has <msasa> 5 has <pppd[6404]:> 6 has <Connect:> 7 has <ppp0> 8 has <<-->> 9 has </dev/ttyS1> [jeeves:~] { i put $parts{$incr++} inside the <...> to help him see that split did work the way that we all expect it... } >> Ques 2) Where in the linux documentation do I find an example? I have >> RH7.1. > > If you have perl installed, you have perldoc installed. > > japhy% perldoc -f split > [...] ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]