Ask a Question related to PERL Beginners, Design and Development.
-
Tore Aursand #1
Re: Splitting OR Regex
On Thu, 30 Oct 2003 23:37:55 -0500, Scott, Joshua wrote:
This is a FAQ:> How can I split the data in a line by a single whitespace but also keep
> portions between quotes together?
perldoc -q delimit
--
Tore Aursand <tore@aursand.no>
Tore Aursand Guest
-
splitting a PDF file
Does anyone know if or how to split a multiple page PDF file into single page PDF files in Acrobat 7? I heard this could be done without purchasing... -
Splitting a CSV list
I have the following type of data in a page and I need to be able to pull each and every CN value without the CN or anything behind it. ... -
Splitting values
Hi All... I am really stumped on something I am trying to do. I have a table named games with the following fields: gameID, homeTeam,... -
Splitting up an XML File
I have an XML file that looks like this: <root> <economist publications="true" > <name> <first>John</first> <last>Doe</last> </name>... -
splitting an array
Hi All , I have one array of numbers say (12 17 18 19 120 121 122 123 124 379 480 481). Now I want to get the starting and ending of any... -
Rob Dixon #2
Re: Splitting OR Regex
Joshua Scott wrote:
Hi Joshua.>
> How can I split the data in a line by a single whitespace but also keep
> portions between quotes together? Here is an example of a line of data I'm
> trying to parse:
>
> id=firewall time="2003-10-30 04:15:01" fw=66.74.67.229 pri=5 c=256 m=38
> msg="ICMP packet dropped" n=63211 src=1.1.1.1 dst=2.2.2.2
>
> What I would like to do is keep the data between the quotes together despite
> the spaces. This is what I'm expecting to get:
>
> Id=firewall
> Time="2003-10-30 04:15:01"
> Fw=66.74.67.229
> Msg="ICMP packet dropped"
> ...etc
>
> How should I go about doing this? What I have currently is a regex that
> splits out the entire line, but certain fields have changed so my original
> code doesn't work as well.
The 'delimited string' FAQ is really for comma-separated values rather
than the 'name=value' format you have here. It also supports escaped
quotes within quoted strings, which you probably don't have. The
regex below should do what you want.
HTH,
Rob
use strict;
use warnings;
my $string = q{id=firewall time="2003-10-30 04:15:01" fw=66.74.67.229 pri=5 c=256 m=38 msg="ICMP packet dropped" n=63211 src=1.1.1.1
dst=2.2.2.2};
my @fields = $string =~ m/\w+=(?:"[^"]+"|\S+)/g;
print map "$_\n", @fields;
*OUTPUT*
id=firewall
time="2003-10-30 04:15:01"
fw=66.74.67.229
pri=5
c=256
m=38
msg="ICMP packet dropped"
n=63211
src=1.1.1.1
dst=2.2.2.2
Rob Dixon Guest
-
R. Joseph Newton #3
Re: Splitting OR Regex
Rob Dixon wrote:
Nice!!> my @fields = $string =~ m/\w+=(?:"[^"]+"|\S+)/g;
Joseph
R. Joseph Newton Guest
-
Rob Dixon #4
Re: Splitting OR Regex
R. Joseph Newton wrote:<blush> Thanks! </blush>>
> Rob Dixon wrote:
>>> > my @fields = $string =~ m/\w+=(?:"[^"]+"|\S+)/g;
> Nice!!
Rob
Rob Dixon Guest



Reply With Quote

