Home > Archive > PERL Beginners > May 2007 > missing something from regex ...
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
missing something from regex ...
|
|
| Gregory Machin 2007-05-16, 7:58 am |
| Hi i have the following string
I need to break down into usable data ...
CLIENT_LIST,tsc-odi.vpn.ct-net.org,165.146.60.29:11134,10.1.0.46,1959761,218729,Wed
May 16 11:24:37 2007,1179307477
and I dont want "Wed May 16 11:24:37 2007" cause the number at the end
is the same thing ..
this is the beginning of my code ...
$row = "CLIENT_LIST,tsc-odi.vpn.ct-net.org,165.146.60.29:11134,10.1.0.46,1959761,218729,Wed
May 16 11:24:37 2007,1179307477"
$row = ~/(\w+)\,(\w+)\,(\d+\.\d+\.\d+\.\d+\:\d+)\,(\d+\.\d+\.\d+\.\d+)\,(\d+)\,(\d+)\,\,(\d+)/
print "info $1 \n";
print "hostname $2 \n";
print "pubip $3 \n";
print "wanip $4 \n";
print "recieved $5 \n";
print "sent $6 \n";
print "time $7 \n";
and I'm getting the following error ..
[root@server ~]# ./vpninfo.pl
../vpninfo.pl: line 1: =: command not found
../vpninfo.pl: line 2: syntax error near unexpected token `('
../vpninfo.pl: line 2: `$row =
~/(\w+)\,(\w+)\,(\d+\.\d+\.\d+\.\d+\:\d+)\,(\d+\.\d+\.\d+\.\d+)\,(\d+)\,(\d+)\,\,(\d+)/'
[root@server ~]#
..... what have I missed ...
Many thanks
--
Gregory Machin
gregory.machin@gmail.com
www.linuxpro.co.za
| |
| Matthew J. Avitable 2007-05-16, 7:58 am |
| Gregory Machin wrote:
> $row =
> "CLIENT_LIST,tsc-odi.vpn.ct-net.org,165.146.60.29:11134,10.1.0.46,1959761,218729,Wed
>
> May 16 11:24:37 2007,1179307477"
> $row =
> ~/(\w+)\,(\w+)\,(\d+\.\d+\.\d+\.\d+\:\d+)\,(\d+\.\d+\.\d+\.\d+)\,(\d+)\,(\d+)\,\,(\d+)/
>
> print "info $1 \n";
> print "hostname $2 \n";
> print "pubip $3 \n";
> print "wanip $4 \n";
> print "recieved $5 \n";
> print "sent $6 \n";
> print "time $7 \n";
>
>
> and I'm getting the following error ..
>
> [root@server ~]# ./vpninfo.pl
> ./vpninfo.pl: line 1: =: command not found
> ./vpninfo.pl: line 2: syntax error near unexpected token `('
> ./vpninfo.pl: line 2: `$row =
> ~/(\w+)\,(\w+)\,(\d+\.\d+\.\d+\.\d+\:\d+)\,(\d+\.\d+\.\d+\.\d+)\,(\d+)\,(\d+)\,\,(\d+)/'
>
> [root@server ~]#
>
>
> .... what have I missed ...
Looks like you are missing semicolons after your first two lines.
-m
| |
| Chas Owens 2007-05-16, 7:58 am |
| On 5/16/07, Gregory Machin <gregory.machin@gmail.com> wrote:
> Hi i have the following string
> I need to break down into usable data ...
>
> CLIENT_LIST,tsc-odi.vpn.ct-net.org,165.146.60.29:11134,10.1.0.46,1959761,218729,Wed
> May 16 11:24:37 2007,1179307477
snip
Right, you have delimited data and it looks like there is no chance of
the delimiter being part of a field. This means you want the split
function, not a regex.
snip
> $row = "CLIENT_LIST,tsc-odi.vpn.ct-net.org,165.146.60.29:11134,10.1.0.46,1959761,218729,Wed
> May 16 11:24:37 2007,1179307477"
> $row = ~/(\w+)\,(\w+)\,(\d+\.\d+\.\d+\.\d+\:\d+)\,(\d+\.\d+\.\d+\.\d+)\,(\d+)\,(\d+)\,\,(\d+)/
snip
These lines are missing semicolons.
snip
> and I'm getting the following error ..
>
> [root@server ~]# ./vpninfo.pl
> ./vpninfo.pl: line 1: =: command not found
> ./vpninfo.pl: line 2: syntax error near unexpected token `('
> ./vpninfo.pl: line 2: `$row =
> ~/(\w+)\,(\w+)\,(\d+\.\d+\.\d+\.\d+\:\d+)\,(\d+\.\d+\.\d+\.\d+)\,(\d+)\,(\d+)\,\,(\d+)/'
> [root@server ~]#
>
>
> .... what have I missed ...
snip
It looks like you are missing the #!/usr/bin/perl at the beginning of
the script and therefore your current shell is being used as the
interpreter. Try the following instead:
#!/usr/bin/perl
use strict;
use warnings;
my $input = "CLIENT_LIST,tsc-odi.vpn.ct-net.org,165.146.60.29:11134,10.1.0.46,1959761,218729,Wed
May 16 11:24:37 2007,1179307477";
my ($info, $host, $pubid, $wanip, $recieved, $sent, undef, $time) =
split /,/, $input;
print "info = $info\nhost=$host\npubid=$pubid\nwanip=$
wanip\n",
" recieved=$recieved\nsent=$sent\ntime=$ti
me\n";
|
|
|
|
|