perl regexp error , I cant understand what is wrong


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl regexp error , I cant understand what is wrong
# 1  
Old 10-18-2006
perl regexp error , I cant understand what is wrong

perl regexp error , I cant understand what is wrong
Hello all
I have simple perl regexp that is searching for pattern in string and replace it with the same string + addition string
here is what I have :
Code:
my $rec =  q| new Array("Attributes Management"  ,"/ResourceManagement/Attribute/attributeFrameset.jsp","/Images/icons/attributes.gif",null,"AttributesManagement"),|;

Code:
rec =~ s/[^+\s*](\"\/.*?[jsp|gif|css|bmp|js]\")/handle_path($1,1)/gse;

and the handle_path function lookes like this :

Code:
sub handle_path {

	my $s = $_[0];
	my $type = $_[1];
	 
	if($type == 0){
		return "Env.getPath()+".$s;
	}elsif($type == 1){
		my $tmpStr = "\<\%= Env.getPath() \%\>\+".$s;
		return $tmpStr;
		
	}

}

but the result im getting is almost fine .. there is missing comma in there , and i have no idea why
the comma is missing after the switching . for example between the "Attributes Management" and <%= Env.getPath() %>
Here is the result:
new Array("Attributes Management" <%= Env.getPath() %>+"/ResourceManagement/Attribute/attributeFrameset.jsp"<%= Env.getPath() %>+"/Images/icons/attributes.gif",null,"AttributesManagement"),
can someone please tell me what im doing wrong here?
# 2  
Old 10-18-2006
What about this?

Quote:
Originally Posted by umen
Code:
rec =~ s/[^+\s*](\"\/.*?(jsp|gif|css|bmp|js)\")/handle_path($1,1)/gse;

# 3  
Old 10-19-2006
hello
and thanks for the fast reply
but it still give me the same results
what is wrong here?
# 4  
Old 10-19-2006
The presence of [^+\s*] is the cause.

Remove it.
# 5  
Old 10-19-2006
The reason its there because sometimes I have :


Code:
my $rec =  q| new Array("Attributes Management"  , "<%=  myFunc2 %>   +   "/ResourceManagement/Attribute/attributeFrameset.jsp",<%=  myFunc1 %>    + "/Images/icons/attributes.gif",null,"AttributesManagement"),|;

and then I don't what that the regexp handle it
this is why i have [^+\s*]
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Trying to understand perl error

I am trying to begin to troubleshoot this perl error that I keep getting, yet I get output is produced. The error is Use of uninitialized value in join or string line 175, <MANNO> line 7138 and below is line 175: I am not too sure what the error is but since not every line has an error on it, I... (1 Reply)
Discussion started by: cmccabe
1 Replies

2. Shell Programming and Scripting

Executing perl script in Linux gives :Exec format error. Wrong Architecture

i have perl script that used to be working great , once i edit it in windows and convert it to UTF-8 and then via FTP return it . also did: chmod +x foo.pl and then when i try to run it : ./foo.pl im getting this error: ./foo.pl: Exec format error. Wrong Architecture.... (4 Replies)
Discussion started by: umen
4 Replies

3. Shell Programming and Scripting

Perl regexp to extract first and second column

Hi, I am trying with the below Perl one-liner using regular expression to extract the first and second column of a text file: perl -p -e "s/\s*(\w+).*/$1/" perl -p -e "s/\s*.+\s(.+)\s*/$1\n/" whereas the text file's data looks like: Error: terminated 2233 Warning: reboot 3434 Warning:... (3 Replies)
Discussion started by: royalibrahim
3 Replies

4. Shell Programming and Scripting

Perl regexp help

Hi, I have file like below: 1|1212|34353|5fdf 6575||dfgdg sfsdf |afsf||4|aasfbc|~1213~~~~~ 1|1212|34353|5fdf 6575||dfgdg sfsdf |affsf| |4|abc|~rwarw~~asa~~~123~312313 1|1212|34353|5fdf 6575||dfgdg sfsdf |afasfs||4|aasfdbc|~564564~~~~ 1|1212|34353|5fdf 6575||dfgdg sfsdf... (1 Reply)
Discussion started by: sol_nov
1 Replies

5. Shell Programming and Scripting

A Perl regexp to validate arithmetic expressions

Can a Perl regexp validate arithmetic expressions? I say yes. Here is my Perl regexp to validate arifmetic expressions: #!perl -w use strict; use re 'eval'; my @testexpr=( # Valid arifmetic expressions '+3', '-(3/4+(-2-3)/3)', '(-((3)))', '-(+1+2)*(3/(1-2))/((-3))', # Invalid (from... (3 Replies)
Discussion started by: cronc
3 Replies

6. Shell Programming and Scripting

perl regexp: no match across newlines

Hi. Here's a tricky one (at least to me): I have a file named theFile.txt (UTF-8) that contains the following: a b cWhen I execute perl -pe 's|a.*c|d|sg' theFile.txtin bash 3.2 on MAC OS X 10.6, I get no match, i.e. the result is a b cagain. Any clues why? (2 Replies)
Discussion started by: BatManWSL
2 Replies

7. Shell Programming and Scripting

perl regexp matching

Hello, I cannot see what's wrong in my code. When I run code below, it just print an empty string. my $test = "SWER~~ERTGSDFGTHAS_RTAWGA_DFAS.x4-234253454.in"; if ($test = ~ m/\~{1,2}.*4/) { print "$1\n"; } else { print "No match...\n"; } Anyone know what I'm doing wrong? ... (4 Replies)
Discussion started by: urandom
4 Replies

8. Shell Programming and Scripting

perl regexp

What is the easiest way to get full address of *.jpg images from html file using perl? example: http://farm3.static.flickr.com/2397/2126443111_65a810004c.jpg (1 Reply)
Discussion started by: mirusnet
1 Replies

9. Shell Programming and Scripting

loop throw perl regexp selection

hello all i have string that i need to parse something list that : <form name="CustomerStatus" action="<% env.GetURI %>" method="post"<$if(blah)%> name="<% env.get("StatusList") %>" ><% hello %><input type="hidden" name="<% env.get("Operation") %>" value=""> now im selecting the the string... (6 Replies)
Discussion started by: umen
6 Replies

10. Shell Programming and Scripting

Need Help with Perl REGEXP

I need help with a Perl regular expression. The following string blows up my program: <david(greg jim)> If I type this string, there is no problem: <david(greg_jim)> or type david(gregjim) or type <david greg jim> the CGI program does not complain. For some reason that I do not understand the... (1 Reply)
Discussion started by: mh53j_fe
1 Replies
Login or Register to Ask a Question