For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > October 2006 > regular expression









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 regular expression
junaid

2006-10-19, 3:59 am

Hi All,

Assume that $line = " input N1,N4,N8,N11,N14,N17,N21,N24,N27,N30,
N34,N37,N40,N43,N47,N50,N53,N56,N60,N63,

N66,N69,N73,N76,N79,N82,N86,N89,N92,N95,

N99,N102,N105,N108,N112,N115;

output N223,N329,N370,N421,N430,N431,N432;

wire N118,N119,N122,N123,N126,N127,N130,N131,
N134,N135,
N138,N139,N142,N143,N146,N147,N150,N151,
N154,N157,
N158,N159,N162,N165,N168,N171,N174,N177,
N180,N183,
N184,N185,N186,N187,N188,N189,N190,N191,
N192,N193,
N194,N195,N196,N197,N198,N199,N203,N213,
N224,N227,
N230,N233,N236,N239,N242,N243,N246,N247,
N250,N251,
N254,N255,N256,N257,N258,N259,N260,N263,
N264,N267,
N270,N273,N276,N279,N282,N285,N288,N289,
N290,N291,
N292,N293,N294,N295,N296,N300,N301,N302,
N303,N304,
N305,N306,N307,N308,N309,N319,N330,N331,
N332,N333,
N334,N335,N336,N337,N338,N339,N340,N341,
N342,N343,
N344,N345,N346,N347,N348,N349,N350,N351,
N352,N353,
N354,N355,N356,N357,N360,N371,N372,N373,
N374,N375,
N376,N377,N378,N379,N380,N381,N386,N393,
N399,N404,
N407,N411,N414,N415,N416,N417,N418,N419,
N420,N422,
N425,N428,N429;

not NOT1_1 (N118, N1);
not NOT1_2 (N119, N4);
not NOT1_3 (N122, N11);
not NOT1_4 (N123, N17);
not NOT1_5 (N126, N24);
not NOT1_6 (N127, N30);"

All the lines may or not be terminated by \n.
I need reg exp to extract all the variables under input, output and
wire into seperate array.

I used like $line =~ s/\s*wire\s+((.\n)+);
but $1 returns NULL . Hence it is not wirking
Kindly help me

nikne

2006-10-19, 3:59 am

Hi

Could not understand what u meant to say.
It would be better if you could clear it much better.

What is Input?
What output is desired?
What exactly you want to match? or print?

Thanks and Regards,
NN
junaid wrote:
> Hi All,
>
> Assume that $line = " input N1,N4,N8,N11,N14,N17,N21,N24,N27,N30,
> N34,N37,N40,N43,N47,N50,N53,N56,N60,N63,

> N66,N69,N73,N76,N79,N82,N86,N89,N92,N95,

> N99,N102,N105,N108,N112,N115;
>
> output N223,N329,N370,N421,N430,N431,N432;
>
> wire N118,N119,N122,N123,N126,N127,N130,N131,
N134,N135,
> N138,N139,N142,N143,N146,N147,N150,N151,
N154,N157,
> N158,N159,N162,N165,N168,N171,N174,N177,
N180,N183,
> N184,N185,N186,N187,N188,N189,N190,N191,
N192,N193,
> N194,N195,N196,N197,N198,N199,N203,N213,
N224,N227,
> N230,N233,N236,N239,N242,N243,N246,N247,
N250,N251,
> N254,N255,N256,N257,N258,N259,N260,N263,
N264,N267,
> N270,N273,N276,N279,N282,N285,N288,N289,
N290,N291,
> N292,N293,N294,N295,N296,N300,N301,N302,
N303,N304,
> N305,N306,N307,N308,N309,N319,N330,N331,
N332,N333,
> N334,N335,N336,N337,N338,N339,N340,N341,
N342,N343,
> N344,N345,N346,N347,N348,N349,N350,N351,
N352,N353,
> N354,N355,N356,N357,N360,N371,N372,N373,
N374,N375,
> N376,N377,N378,N379,N380,N381,N386,N393,
N399,N404,
> N407,N411,N414,N415,N416,N417,N418,N419,
N420,N422,
> N425,N428,N429;
>
> not NOT1_1 (N118, N1);
> not NOT1_2 (N119, N4);
> not NOT1_3 (N122, N11);
> not NOT1_4 (N123, N17);
> not NOT1_5 (N126, N24);
> not NOT1_6 (N127, N30);"
>
> All the lines may or not be terminated by \n.
> I need reg exp to extract all the variables under input, output and
> wire into seperate array.
>
> I used like $line =~ s/\s*wire\s+((.\n)+);
> but $1 returns NULL . Hence it is not wirking
> Kindly help me


nobull67@gmail.com

2006-10-19, 6:56 pm



On Oct 19, 5:56 am, "junaid" <k.naj...@gmail.com> wrote:
> Hi All,
>
> Assume that $line = " input N1,N4,N8,N11,N14,N17,N21,N24,N27,N30,
> N34,N37,N40,N43,N47,N50,N53,N56,N60,N63,

> N66,N69,N73,N76,N79,N82,N86,N89,N92,N95,

> N99,N102,N105,N108,N112,N115;
>
> output N223,N329,N370,N421,N430,N431,N432;
>
> wire N118,N119,N122,N123,N126,N127,N130,N131,
N134,N135,
> N138,N139,N142,N143,N146,N147,N150,N151,
N154,N157,
> N158,N159,N162,N165,N168,N171,N174,N177,
N180,N183,
> N184,N185,N186,N187,N188,N189,N190,N191,
N192,N193,
> N194,N195,N196,N197,N198,N199,N203,N213,
N224,N227,
> N230,N233,N236,N239,N242,N243,N246,N247,
N250,N251,
> N254,N255,N256,N257,N258,N259,N260,N263,
N264,N267,
> N270,N273,N276,N279,N282,N285,N288,N289,
N290,N291,
> N292,N293,N294,N295,N296,N300,N301,N302,
N303,N304,
> N305,N306,N307,N308,N309,N319,N330,N331,
N332,N333,
> N334,N335,N336,N337,N338,N339,N340,N341,
N342,N343,
> N344,N345,N346,N347,N348,N349,N350,N351,
N352,N353,
> N354,N355,N356,N357,N360,N371,N372,N373,
N374,N375,
> N376,N377,N378,N379,N380,N381,N386,N393,
N399,N404,
> N407,N411,N414,N415,N416,N417,N418,N419,
N420,N422,
> N425,N428,N429;
>
> not NOT1_1 (N118, N1);
> not NOT1_2 (N119, N4);
> not NOT1_3 (N122, N11);
> not NOT1_4 (N123, N17);
> not NOT1_5 (N126, N24);
> not NOT1_6 (N127, N30);"
>
> All the lines may or not be terminated by \n.


How can a line not be terminated by \n ?

Isn't it rather consusing to use the viable name $line for a multi-line
string?

> I need reg exp to extract all the variables


What do you mean by "variables"? Do you mean words?

> under input, output and
> wire into seperate array.


What do you mean by "separate"? And why would you want it?

> I used like $line =~ s/\s*wire\s+((.\n)+);


How much effort would it have cost you to have cut-n-pasted real valid
code?

How much effort per-reader do you think it takes to guess what your
real code looked like?

How many people do you think read you post?

Combine these numbers to calculate the factor by which you are telling
us that your time is more valuable than ours.

> Kindly help me


Kindly make it as easy as possible for people to help.

Making some random guesses about what you meant...

my %data;
while ( $line =~ /^ ?(\w+) ([\w\s,]+);/gm ) {
my ($key,$values) = ($1,$2);
$data{$key} = [ $values =~ /(\w+)/g ];
}

use Data::Dumper;
print Dumper \%data;

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com