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

Re: [PBML] Please help with String Manipulation issue

Expand Messages
  • Jenda Krynicky
    From: Bob Kardell ... You must be, this should work correctly. The local() will make sure the $/ gets reset to the default value at the
    Message 1 of 14 , Mar 6, 2007
      From: Bob Kardell <bobkardell@...>
      > I have tried using the paragraph mode in the past with some success,
      > but this issue brought up a question I have had - is it possible to
      > define "$/" two different ways in the same script? In the past when I
      > have tried to redefine $/ to something other than the default I have
      > had to create separate scripts. I noticed that you put the following
      > code in:
      >
      >
      > {
      >
      > local $/ = "";
      >
      > @data = <>; # slurp all input in paragraph mode
      >
      > }
      >
      > is it possible to do something like:
      >
      >
      > {
      > local $/ = "";
      > @data = <>; # slurp all input in paragraph mode
      > }
      >
      > #do some code here
      >
      > {
      > local $/ = "\n\n";
      > @data = <>; # slurp all input in paragraph mode
      > }
      >
      > #do something else here
      >
      > When I have tried this in the past, the two separate $/ have not
      > worked nicely with one another and I have to use two separate scripts
      > because of it. I am obviously missing something.

      You must be, this should work correctly. The local() will make sure
      the $/ gets reset to the default value at the end of the block:

      $a = "global value";
      print "$a\n";
      {
      local $a = "local";
      print "$a\n";
      }
      print "$a\n";
      {
      local $a = "other local";
      print "$a\n";
      }
      print "$a\n";


      Try it again and post the code if it doesn't work as expected.

      Jenda
      ===== Jenda@... === http://Jenda.Krynicky.cz =====
      When it comes to wine, women and song, wizards are allowed
      to get drunk and croon as much as they like.
      -- Terry Pratchett in Sourcery
    • a_z0_9_blah
      ... success, but this issue brought up a question I have had - is it possible to define $/ two different ways in the same script? In the past when I have
      Message 2 of 14 , Mar 6, 2007
        --- In perl-beginner@yahoogroups.com, Bob Kardell <bobkardell@...>
        wrote:
        >
        > I have tried using the paragraph mode in the past with some
        success, but this issue brought up a question I have had - is it
        possible to define "$/" two different ways in the same script? In
        the past when I have tried to redefine $/ to something other than
        the default I have had to create separate scripts. I noticed that
        you put the following code in:
        >
        >
        > {
        >
        > local $/ = "";
        >
        > @data = <>; # slurp all input in paragraph mode
        >
        > }
        >
        > is it possible to do something like:
        >
        >
        > {
        >
        > local $/ = "";
        >
        > @data = <>; # slurp all input in paragraph mode
        >
        > }
        >
        > #do some code here


        see perldoc perlfunc for the function seek().


        >
        > {
        >
        > local $/ = "\n\n";
        >
        > @data = <>; # slurp all input in paragraph mode
        >
        > }
        >
        > #do something else here
        >
        > When I have tried this in the past, the two separate $/ have not
        worked nicely with one another and I have to use two separate
        scripts because of it. I am obviously missing something.
        >
        > Thanks,
        >
        > Bob
      Your message has been successfully submitted and would be delivered to recipients shortly.