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

Re: [PBML] Converting a string into a list

Expand Messages
  • Rob Biedenharn
    ... Are you expecting this: 1..10,12..20 to become the list: (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20) perl -le my $string =
    Message 1 of 4 , Aug 2, 2006
    • 0 Attachment
      On Aug 2, 2006, at 11:07 AM, Charles K. Clarkson wrote:

      > Arun Pandey wrote:
      > : "brendangibson" <brendangibson@...> wrote:
      >
      > :: If I have a string like '1..10,12..20', how can I use that as a
      > :: list?
      > ::
      > :: I want to do something like:
      > ::
      > :: my $string = '1..10,12..20'; # Is read from a file, ...
      >
      > : I think you should use eval function, i.e create a code
      > : dynamicaly using the string and then eval it.
      >
      > How well do you trust the file? Are you certain there will
      > never be anything malicious in there? It might be safer to
      > expand things yourself.
      >
      > HTH,
      >
      > Charles K. Clarkson
      > --

      Are you expecting this: '1..10,12..20'
      to become the list: (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15,
      16, 17, 18, 19, 20)

      perl -le 'my $string = "1..10,12..20";
      print join(q{,},eval($string)) if $string =~ m/^(\d+\.\.\d
      +,?)+$/xms;'

      You can take it from there, yes?

      -Rob



      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.