CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
UrGEnT: Matching against empty space between brack

 



BrightNail
Novice

Dec 24, 2000, 1:16 AM

Post #1 of 4 (1942 views)
UrGEnT: Matching against empty space between brack Can't Post

Hey,

I have a foreach loop, but since my scalar always has some value cause its a string, I want to only print it if it containt something between the brackets... for example.

<firstname>$FORM{'firstname'}</firstname>
<lastname>$FORM{'lastname'}</lastname>

If $FORM{'firstname'} contained no data, then I don't want that whole string printed... ONLY if the $FORM{'firstname'} etc.. contains some info, then I want it printed... As you can see, the XML info changes so I really need to test between the two..>testing for info here</

you know between the 2 brackets and the closing...
Any help is greatly appreciated.



japhy
Enthusiast / Moderator

Dec 24, 2000, 7:54 AM

Post #2 of 4 (1941 views)
Re: UrGEnT: Matching against empty space between brack [In reply to] Can't Post

Just check the value before you print it:


Code
@keys = qw( this that those these ); 
%hash = (
this => 'cat',
that => 'hat',
these => 'meeses',
);

for (@keys) {
next unless $hash{$_};
print "<$_>$hash{$_}</$_>\n";
}

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author


BrightNail
Novice

Dec 24, 2000, 1:26 PM

Post #3 of 4 (1939 views)
Re: UrGEnT: Matching against empty space between brack [In reply to] Can't Post

thanks, but how can that work...--->you see, the $FORM{'somevalue'} will either contain some info or not, but it still has to be associated with a XML tag....that is unique for each form element that is coming thru. in your example, i would have..

%hash = (
this => '<first>$FORM{'firstname'}</first>',
that => '<email>$FORM{'email'}</email>',
);

See, I take the incoming form value regardless if it has content or not and apply it to a XML tag....you see, so I have to check after, not before, that is why I need to check between the brackets. I don't know if I am clear or not.
thanks,



japhy
Enthusiast / Moderator

Dec 24, 2000, 3:37 PM

Post #4 of 4 (1938 views)
Re: UrGEnT: Matching against empty space between brack [In reply to] Can't Post

Oh, I see. Well, if you're sure the XML tags will look simple, you can do something like:


Code
if ($tag =~ m!^<(\w+)></\1>$!) { 
# there's nothing between <foo> and </foo>
}
else {
# there's something there
}

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives