regexp hangs script

Discussion in 'Perl Misc' started by norfernuman, May 29, 2004.

  1. norfernuman

    norfernuman Guest

    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";
    }
    }
    }

    }
     
    norfernuman, May 29, 2004
    #1
    1. Advertising

  2. norfernuman wrote:
    > 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";
    }

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, May 29, 2004
    #2
    1. Advertising

  3. norfernuman

    norfernuman Guest

    norfernuman wrote:
    > 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
     
    norfernuman, May 29, 2004
    #3
  4. norfernuman

    Tore Aursand Guest

    On Sat, 29 May 2004 00:35:29 +0000, norfernuman wrote:
    > 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";
    }
    }
    }
    }


    --
    Tore Aursand <>
    "I know not with what weapons World War 3 will be fought, but World War
    4 will be fought with sticks and stones." (Albert Einstein)
     
    Tore Aursand, May 29, 2004
    #4
  5. norfernuman

    norfernuman Guest

    Tore Aursand wrote:
    > On Sat, 29 May 2004 00:35:29 +0000, norfernuman wrote:
    >
    >>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";
    >> }
    >> }
    >> }
    >>
    >>}


    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";
    > }
    > }
    > }
    > }
    >
    >
     
    norfernuman, May 29, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tim Shadel

    Gem hangs => TCPSocket.write hangs

    Tim Shadel, Jul 23, 2005, in forum: Ruby
    Replies:
    1
    Views:
    391
    Ville Mattila
    Jul 24, 2005
  2. Greg Hurrell
    Replies:
    4
    Views:
    164
    James Edward Gray II
    Feb 14, 2007
  3. Mikel Lindsaar
    Replies:
    0
    Views:
    492
    Mikel Lindsaar
    Mar 31, 2008
  4. Joao Silva
    Replies:
    16
    Views:
    366
    7stud --
    Aug 21, 2009
  5. Uldis  Bojars
    Replies:
    2
    Views:
    194
    Janwillem Borleffs
    Dec 17, 2006
Loading...

Share This Page