Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] SEARCH and REPLACE part 2

Expand Messages
  • Offer Kaye
    ... 0. Are you using use strict; and the -w flag in your script? If not, use them now! ... Than inside your script you can access both arguments using the
    Message 1 of 3 , Mar 22 4:03 AM
    • 0 Attachment
      On Tue, 22 Mar 2005 02:40:25 -0800 (PST), neelam wrote:
      >
      > thanks offer kaye
      > i solved one problem but my another problem is now a
      > hurdle
      > i have to search something like "searchblock" in my
      > program then using @argv i have taken one input .now i
      > have to search for this searchblock in my program
      > replace by the users input "block"the problem is :i m
      > using
      > s/$searchbloc/$block;
      > but after running it its giving problem:
      > use of uninitialized value in subsitution
      > i m trying my best to overcome it but cudn't
      > understand what to do
      >
      > plz sugest something.....
      >

      0. Are you using "use strict;" and the "-w" flag in your script? If
      not, use them now!

      1. If your script is called as:
      > my_script.pl "searchblock" "block"
      Than inside your script you can access both arguments using the @ARGV
      array. Just remember it is a Perl array like every other, so that the
      first argument will be in $ARGV[0], the second in $ARGV[1], etc. So
      you could get the values inside your script using something like:
      my ($searchbloc, $block) = @ARGV;

      2. "s/$searchbloc/$block/;" , by itself, works on $_ . If $_ isn't
      initialized, you will get an error. To solve, either place the text to
      be changed in $_ or use the "=~" operator to directly work on the
      variable holding the text to be changed:
      $text_to_be_changed =~ s/$searchbloc/$block/;

      3. Place the following line before the s/// line and run the script:
      die "I'm going to look for '$searchbloc' and replace it with '$block'\n";
      This will make sure that $searchbloc and $block are initialized before
      you try to use them. After you finish debugging, remove the "die"
      line.

      If nothing helps, please post the code and inputs. Also, please read
      perlretut , perlrequick , perlop (the section "Quote and Quote-like
      Operators") and perlre . But before all else, take the time to read
      "perlintro" from start to finish. It will save you many questions...


      --
      Offer Kaye
    Your message has been successfully submitted and would be delivered to recipients shortly.