#!/usr/bin/perl -w
use strict;
my $line = "36,'', NULL, '', 'on', '', 300";
my @tokens = split(/\,\s*/, $line);
foreach (@tokens)
{
$_ = "''" if $_ eq 'NULL';
print "$_\n";
}
__END__
36
''
''
'' ## NULL is now an empty string
'on'
''
300
####
foreach (@tokens)
{
$_ //= ''; #sets undefined value to empty string
#the // operator (new in Perl 5.10) tests
#for "defined-ness" instead of truthful-ness.
print "$_\n";
}
####
__DATA__
3, 0, 0, 3, 2, 'on', 'host_description - Hard Drive Space', '', NULL, '', 'on', '', 300, ''
4, 0, 0, 4, 1, '', 'host_description - CPU Usage - System', '', NULL, '', 'on', '', 300, ''
5, 0, 0, 5, 1, '', 'host_description - CPU Usage - User', '', NULL, '', 'on', '', 300, ''
6, 0, 0, 6, 1, '', 'host_description - CPU Usage - Nice', '', NULL, '', 'on', '', 300, ''
7, 0, 0, 7, 2, 'on', 'host_description - Noise Level', '', NULL, '', 'on', '', 300, ''
8, 0, 0, 8, 2, 'on', 'host_description - Signal Level', '', NULL, '', 'on', '', 300, ''
9, 0, 0, 9, 2, 'on', 'host_description - Wireless Transmits', '', NULL, '', 'on', '', 300, ''
10, 0, 0, 10, 2, 'on', 'host_description - Wireless Re-Transmits', '', NULL, '', 'on', '', 300, ''
####
3, 0, 0, 3, 2, 'on',
4, 0, 0, 4, 1, '', # 4, 0, 0, 4, 1, 'off'
5, 0, 0, 5, 1, '', # 5, 0, 0, 5, 1, 'off',
6, 0, 0, 6, 1, '', # 6, 0, 0, 6, 1, 'off',
7, 0, 0, 7, 2, 'on',
8, 0, 0, 8, 2, 'on',
9, 0, 0, 9, 2, 'on',
10, 0, 0, 10, 2, 'on',