Re: I think I need another regex...
I tried to do this with split(), but it's not working good at all The string: interface=something very long with spaces and all mac-address=00:02:6F:36:2D:31 ap=no wds=no rx-rate=11Mbps tx-rate=11Mbps packets=12623,18377 bytes=10829240,2009327 frames=12623,18377 (the above is one line, wrapped for email). I need to grab the values for all the options #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $data = 'your=data goes=here'; my %opts = (); $opts{$1} = $2 while $data =~ /([^= ]+)=([^=]+)(?= [\w-]+=)/g; print Dumper(\%opts); -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: I think I need another regex...
On Thu, 17 Mar 2005 11:32:23 -0500, Dave Gray [EMAIL PROTECTED] wrote: I tried to do this with split(), but it's not working good at all The string: interface=something very long with spaces and all mac-address=00:02:6F:36:2D:31 ap=no wds=no rx-rate=11Mbps tx-rate=11Mbps packets=12623,18377 bytes=10829240,2009327 frames=12623,18377 (the above is one line, wrapped for email). I need to grab the values for all the options #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $data = 'your=data goes=here'; my %opts = (); $opts{$1} = $2 while $data =~ /([^= ]+)=([^=]+)(?= [\w-]+=)/g; print Dumper(\%opts); Er, that should be: $opts{$1} = $2 while $data =~ /([^= ]+)=([^=]+)(?:(?= [\w-]+=)|$)/g -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: I think I need another regex...
Chris Knipe wrote: Lo all, Hello, I tried to do this with split(), but it's not working good at all The string: interface=something very long with spaces and all mac-address=00:02:6F:36:2D:31 ap=no wds=no rx-rate=11Mbps tx-rate=11Mbps packets=12623,18377 bytes=10829240,2009327 frames=12623,18377 (the above is one line, wrapped for email). I need to grab the values for all the options $ perl -le' use Data::Dumper; my $string = q/interface=something very long with spaces and all mac-address=00:02:6F:36:2D:31 ap=no wds=no rx-rate=11Mbps tx-rate=11Mbps packets=12623,18377 bytes=10829240,2009327 frames=12623,18377/; my %hash = $string =~ /(\S+)=([^=]+)(?:\s+|$)/g; print Dumper \%hash; ' $VAR1 = { 'bytes' = '10829240,2009327', 'mac-address' = '00:02:6F:36:2D:31', 'packets' = '12623,18377', 'frames' = '12623,18377', 'wds' = 'no', 'interface' = 'something very long with spaces and all', 'rx-rate' = '11Mbps', 'ap' = 'no', 'tx-rate' = '11Mbps' }; John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: I think I need another regex...
On Thu, 17 Mar 2005 12:55:02 -0800 John W. Krahn [EMAIL PROTECTED] wrote: Chris Knipe wrote: Lo all, Hello, I tried to do this with split(), but it's not working good at all The string: interface=something very long with spaces and all mac-address=00:02:6F:36:2D:31 ap=no wds=no rx-rate=11Mbps tx-rate=11Mbps packets=12623,18377 bytes=10829240,2009327 frames=12623,18377 (the above is one line, wrapped for email). I need to grab the values for all the options $ perl -le' use Data::Dumper; my $string = q/interface=something very long with spaces and all mac-address=00:02:6F:36:2D:31 ap=no wds=no rx-rate=11Mbps tx-rate=11Mbps packets=12623,18377 bytes=10829240,2009327 frames=12623,18377/; my %hash = $string =~ /(\S+)=([^=]+)(?:\s+|$)/g; = would you kindly explain how this (?:\s+|$) works? print Dumper \%hash; ' $VAR1 = { 'bytes' = '10829240,2009327', 'mac-address' = '00:02:6F:36:2D:31', 'packets' = '12623,18377', 'frames' = '12623,18377', 'wds' = 'no', 'interface' = 'something very long with spaces and all', 'rx-rate' = '11Mbps', 'ap' = 'no', 'tx-rate' = '11Mbps' }; John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- Whatever you do will be insignificant,but the important is you do it! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: I think I need another regex...
Renqilong wrote: On Thu, 17 Mar 2005 12:55:02 -0800 John W. Krahn [EMAIL PROTECTED] wrote: Chris Knipe wrote: I tried to do this with split(), but it's not working good at all The string: interface=something very long with spaces and all mac-address=00:02:6F:36:2D:31 ap=no wds=no rx-rate=11Mbps tx-rate=11Mbps packets=12623,18377 bytes=10829240,2009327 frames=12623,18377 (the above is one line, wrapped for email). I need to grab the values for all the options $ perl -le' use Data::Dumper; my $string = q/interface=something very long with spaces and all mac-address=00:02:6F:36:2D:31 ap=no wds=no rx-rate=11Mbps tx-rate=11Mbps packets=12623,18377 bytes=10829240,2009327 frames=12623,18377/; my %hash = $string =~ /(\S+)=([^=]+)(?:\s+|$)/g; = would you kindly explain how this (?:\s+|$) works? Sure. (?:) are non-capturing parentheses so the pattern inside will not be returned in list context like normal capturing parentheses. The pattern says to match EITHER \s+ (one or more whitespace characters) OR $ (the end of the line.) John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: I think I need another regex...
Got it!Thanks a lot,John! On Thu, 17 Mar 2005 20:38:21 -0800 John W. Krahn [EMAIL PROTECTED] wrote: Renqilong wrote: On Thu, 17 Mar 2005 12:55:02 -0800 John W. Krahn [EMAIL PROTECTED] wrote: Chris Knipe wrote: I tried to do this with split(), but it's not working good at all The string: interface=something very long with spaces and all mac-address=00:02:6F:36:2D:31 ap=no wds=no rx-rate=11Mbps tx-rate=11Mbps packets=12623,18377 bytes=10829240,2009327 frames=12623,18377 (the above is one line, wrapped for email). I need to grab the values for all the options $ perl -le' use Data::Dumper; my $string = q/interface=something very long with spaces and all mac-address=00:02:6F:36:2D:31 ap=no wds=no rx-rate=11Mbps tx-rate=11Mbps packets=12623,18377 bytes=10829240,2009327 frames=12623,18377/; my %hash = $string =~ /(\S+)=([^=]+)(?:\s+|$)/g; = would you kindly explain how this (?:\s+|$) works? Sure. (?:) are non-capturing parentheses so the pattern inside will not be returned in list context like normal capturing parentheses. The pattern says to match EITHER \s+ (one or more whitespace characters) OR $ (the end of the line.) John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- Whatever you do will be insignificant,but the important is you do it! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response