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

Re: [PBML] Variable in split function

Expand Messages
  • Leon Peeters
    ... From: Sumit Sent: Monday, December 30, 2002 4:44 PM Subject: [PBML] Variable in split function ... tried it but was not able ...
    Message 1 of 3 , Dec 30, 2002
    • 0 Attachment
      ----- Original Message -----
      From: "Sumit" <sumit_827@...>
      Sent: Monday, December 30, 2002 4:44 PM
      Subject: [PBML] Variable in split function


      > Hi all,
      > Can we use a variable in the /PATTERN/ argument of the split function. I
      tried it but was not able
      > to get it to work. Is there something I am missing??
      >
      > $pattern = ":";

      Use single quotes:
      $pattern = ':';


      > @Arr = split(/$pattern/, $Line);
      >
      > puts the whole $Line as the first element in the array without splitting.
      >
      > Thanks in advance and a
      > Happy New Year.
      >
      >
      > [Non-text portions of this message have been removed]
      >
      >
      >
      > Unsubscribing info is here:
      http://help.yahoo.com/help/us/groups/groups-32.html
      >
      > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
      >
      >
      >
    • Jenda Krynicky
      From: Leon Peeters ... This doesn t make any difference. There is NO difference at all between these two lines. See this: C:
      Message 2 of 3 , Dec 31, 2002
      • 0 Attachment
        From: "Leon Peeters" <leonpeeters@...>
        > ----- Original Message -----
        > From: "Sumit" <sumit_827@...>
        > Sent: Monday, December 30, 2002 4:44 PM
        > Subject: [PBML] Variable in split function
        >
        >
        > > Hi all,
        > > Can we use a variable in the /PATTERN/ argument of the split
        > > function. I
        > tried it but was not able
        > > to get it to work. Is there something I am missing??
        > >
        > > $pattern = ":";
        >
        > Use single quotes:
        > $pattern = ':';

        This doesn't make any difference. There is NO difference at all
        between these two lines. See this:

        C:\> perl -MO=Deparse -e "$pattern = ':';print $pattern"
        $pattern = ':';
        print $pattern;
        -e syntax OK

        C:\> perl -MO=Deparse -e "$pattern = \":\";print $pattern"
        $pattern = ':';
        print $pattern;
        -e syntax OK

        They are even compiled the same way. (-MO=Deparse instructs Perl to
        parse and optimize the code, generate the bytecode and then turn it
        back into Perl code and print it.)

        > > @Arr = split(/$pattern/, $Line);
        > >
        > > puts the whole $Line as the first element in the array without
        > > splitting.

        Sorry it doesn't. It works all right.

        #!perl
        $Line = "asd:sdf:wer:qweq";
        $pattern = ":";
        @Arr = split(/$pattern/, $Line);
        print join("\n", @Arr),"\n";
        __END__

        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
      • Kipp, James
        ... You sure? it works fine here: $line = test:this:now ; $pattern = : ; @Arr = split(/$pattern/, $line); print $_ n for @Arr; prints: test this now
        Message 3 of 3 , Dec 31, 2002
        • 0 Attachment
          >
          > Hi all,
          > Can we use a variable in the /PATTERN/ argument of the split
          > function. I tried it but was not able
          > to get it to work. Is there something I am missing??
          >
          > $pattern = ":";
          > @Arr = split(/$pattern/, $Line);
          >
          > puts the whole $Line as the first element in the array
          > without splitting.
          >

          You sure? it works fine here:

          $line = "test:this:now";
          $pattern = ":";
          @Arr = split(/$pattern/, $line);
          print "$_\n" for @Arr;

          prints:
          test
          this
          now
        Your message has been successfully submitted and would be delivered to recipients shortly.