in reply to it seems i don't understand =~

thanks ikegami. i don't get the " won't compile comments".. the two lines fix a bug in the script which "seems" to be working ok on my host now..?? though i can now see it's not working the way i want it too. ~frowns~ i'm curious why would the code run on a server and return errors on your machines? it worked on my box ~shruggs~
beware the farmers.

Replies are listed 'Best First'.
Re^2: it seems i don't understand =~
by ikegami (Patriarch) on Mar 30, 2009 at 04:25 UTC

    thanks ikegami. i don't get the " won't compile comments"..

    >type 754047.pl $value =~ s/\D//g; $value =~ $1 if( $value =~ /(\d+)/ ){ $value =~ $1 } else { undef $value; } >perl -c 754047.pl syntax error at 754047.pl line 3, near "){" 754047.pl had compilation errors.

    the two lines fix a bug in the script which "seems" to be working ok on my host now..??

    Seems is the operative word

    my $value = "abc456def"; $_ = $value; $value = m/(\d+)/; print "$value\n"; # Prints 1, not 456

    Fix:

    my $value = "abc456def"; $_ = $value; ($value) = m/(\d+)/; print "$value\n"; # Prints 456

    A more elegant version that doesn't clobber a global:

    my $value = "abc456def"; ($value) = $value =~ m/(\d+)/; print "$value\n"; # Prints 456
      oh.. i get it.. i thought the not working code was referring to my 2 lines, not the other segment (i didn't bother to look at it as i wanted a shorter model).

      yes my code seemed to work. but actually was not. your suggestion fixed it perfectly.

      thanks again.

      beware the farmers.