regexp hangs script

N

norfernuman

I'm trying to clean off a few characters from the beginning of a string.
I must be looking right at the problem, and not seeing it.

I prepended the names of my form elements so I could group them at print
out. The prepended flags match the values in my @form_flags array.
I want to clean off the flags before printout. If I leave out the
substitution it works fine.

I don't get any errors, it runs without errors from the cmd line, but it
hangs from a browser.

Thanks for any help.

- NN

Here's my code:...

my @form_flags = qw(gen_ int_ kit_ bed_ ext_ loc_ utl_);

foreach my $flag (@form_flags) {

foreach $_ ($q->param()) {
if ( $_ =~ /(^\w+_)/ ) {
if ( $1 eq $flag ) {
s/^\w+_//g; #### this make script hang
print "$_ : " . $q->param($_) . "<p>\n";
}
}
}

}
 
G

Gunnar Hjalmarsson

norfernuman said:
I prepended the names of my form elements so I could group them at
print out. The prepended flags match the values in my @form_flags
array. I want to clean off the flags before printout. If I leave
out the substitution it works fine.

I don't get any errors, it runs without errors from the cmd line,
but it hangs from a browser.

I don't know why it hangs for you, but I know that you cannot alter
the keys all through the CGI object that way.
my @form_flags = qw(gen_ int_ kit_ bed_ ext_ loc_ utl_);

foreach my $flag (@form_flags) {

foreach $_ ($q->param()) {
if ( $_ =~ /(^\w+_)/ ) {
if ( $1 eq $flag ) {
s/^\w+_//g; #### this make script hang
print "$_ : " . $q->param($_) . "<p>\n";

To print the values, you need to say for instance:

print "$_ : " . $q->param("$flag$_") . "<p>\n";

but maybe something like this would make more sense:

if ( $1 eq $flag ) {
my ($shortkey) = /^\w+_(.+)/;
print "$shortkey : " . $q->param($_) . "<p>\n";
}
 
N

norfernuman

norfernuman said:
I'm trying to clean off a few characters from the beginning of a string.
I must be looking right at the problem, and not seeing it.

I prepended the names of my form elements so I could group them at print
out. The prepended flags match the values in my @form_flags array.
I want to clean off the flags before printout. If I leave out the
substitution it works fine.

I don't get any errors, it runs without errors from the cmd line, but it
hangs from a browser.

Thanks for any help.

- NN

Here's my code:...

my @form_flags = qw(gen_ int_ kit_ bed_ ext_ loc_ utl_);

foreach my $flag (@form_flags) {

foreach $_ ($q->param()) {
if ( $_ =~ /(^\w+_)/ ) {
if ( $1 eq $flag ) {
s/^\w+_//g; #### this make script hang
print "$_ : " . $q->param($_) . "<p>\n";
}
}
}

}

Come to find out, on closing the browser (Mozilla 1.7b) and coming back
to it later, the code worked. It must have been a cache problem. (duh)
Back and forth from form to display.
Although this line would not have worked:
s/^\w+_//g;
print "$_ : " . $q->param($_) . "<p>\n";

because param($_) now did not match the original param name.

now...
my $old_val = $_;
s/^\w+_//g;
print "$_ : " . $q->param($old_val) . "<p>\n";

I get the nice clean name I wanted to display.

- NN
 
T

Tore Aursand

foreach my $flag (@form_flags) {

foreach $_ ($q->param()) {
if ( $_ =~ /(^\w+_)/ ) {
if ( $1 eq $flag ) {
s/^\w+_//g; #### this make script hang
print "$_ : " . $q->param($_) . "<p>\n";
}
}
}

}

Don't set the $_ variable. Let Perl itself take care of that;

foreach my $flag ( @form_flags ) {
foreach ( $q->param() ) {
if ( /(^\w+_)/ ) {
if ( $1 eq $flag ) {
s/^\w+_//g;
print "$_ : " . $q->param( $_ ) . "<p>\n";
}
}
}
}
 
N

norfernuman

Tore said:
Thanks




Don't set the $_ variable. Let Perl itself take care of that;

foreach my $flag ( @form_flags ) {
foreach ( $q->param() ) {
if ( /(^\w+_)/ ) {
if ( $1 eq $flag ) {
s/^\w+_//g;
print "$_ : " . $q->param( $_ ) . "<p>\n";
}
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top