split problem
Eugene Tsyrklevich
eugene at securityarchitects.com
Tue Jul 4 20:46:27 CDT 2000
~sdpm~
On Tue, Jul 04, 2000 at 05:03:35PM -0700, Steve Meier wrote:
>
> I am so close to formatting this data but it's just not behaving the way I'm expecting. This is a sample of the output of what I'm formatting:
>
> [ ID] Interval Transfer Bandwidth
> [ 4] 0.0-25.0 sec 188 MBytes 60.2 Mbits/sec
> [ 6] 0.0-25.0 sec 277 MBytes 88.5 Mbits/sec
> [ 5] 0.0-25.0 sec 112 MBytes 35.7 Mbits/sec
> [ 3] 0.0-25.0 sec 195 MBytes 62.4 Mbits/sec
> [ 5] 25.0-50.0 sec 196 MBytes 62.7 Mbits/sec
>
> My split function is this:
>
> ($id, $interval, $transfer, $bandwidth) = split (/\s+/, $_);
perldoc -f split
> What I'm doing is breaking this up to out put it into a html table.
>
> Everything is good except for the first line "[ ID] Interval Transfer Bandwidth"
>
> What happens is "Interval and Transfer" end up in the same collumn and "Bandwidth" ends up in the column that "Transfer" should be in.
>
> I've tried everything I can think of!!!! If anyone has any sugestions it would most appreciated!!
using split in your case is not a very good idea since you have way too much
extra whitespace in your string. try using a regex instead.. smth like
$ perl -wle '$,=", "; $_="[ 5] 25.0-50.0 sec 196 MBytes 62.7 Mbits/sec"; print m!\[\s+(\d+)\] (.*?) sec\s+(\d+) MBytes\s+(.*?) !'
5, 25.0-50.0, 196, 62.7
for info on regular expressions see perldoc perlre
on -wle part see perldoc perlrun
and on $, see perldoc perlvar
~sdpm~
The posting address is: san-diego-pm-list at hfb.pm.org
List requests should be sent to: majordomo at hfb.pm.org
If you ever want to remove yourself from this mailing list,
you can send mail to <majordomo at happyfunball.pm.org> with the following
command in the body of your email message:
unsubscribe san-diego-pm-list
If you ever need to get in contact with the owner of the list,
(if you have trouble unsubscribing, or have questions about the
list itself) send email to <owner-san-diego-pm-list at happyfunball.pm.org> .
This is the general rule for most mailing lists when you need
to contact a human.
More information about the San-Diego-pm
mailing list