Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2003

    Unanswered: problem with the split function

    hi, I'm a newbee on perl and I have a problem using the simple function split

    I want to use a delimiter as a parameter given by a comand line( i use getopts, and it works ). I store it in the scalar $delimiter in my script, and I want to split a line with it.

    I tried several syntaxes but none is working :

    @array = split ( /$delimiter/, $line );
    @array = split ( /"$delimiter"/, $line );
    @array = split ( $delimiter, $line );
    @array = split ( '$delimiter', $line );
    @array = split ( /\$delimiter/, $line );

    when i do a print $delimiter, it prints the right thing : | (for example )

    and when I do : @array = split ( /\|/, $line ); it works well !
    but 'cause the delimiter can be different : or ; I have to pass It to my script as a parameter

    Has anybody an idea about the split syntax , in that case ?
    I've been searchin' in the perl cookbook, but nothing helps

    I need help !


  2. #2
    Join Date
    Sep 2003
    and the (easy) answer is :

    quotemeta ($delimiter);
    @array = split ( /$delimiter/, $line);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts