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

Converting a string into a list

Expand Messages
  • brendangibson
    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, so must
    Message 1 of 1 , Aug 2, 2006
    • 0 Attachment
      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, so must be a string
      my $value = 9;

      my @pattern = convert_string_to_list($string);

      if (grep(/^$value$/,@pattern)) {
      print "matched\n";
      }
      else {
      print "didn't match\n";
      }

      How can I do the bit of "convert_string_to_list"? I could do it with
      split if my string was just a comma separated list, but the range
      operator makes this tricky? Is there an easy way?
    Your message has been successfully submitted and would be delivered to recipients shortly.