Wampa has asked for the wisdom of the Perl Monks concerning the following question:

I have this code
Input is /something/something/index.html

[- $script = $ENV{SCRIPT_NAME} -] [- @fields = split("/",$script) -] [+ $fields[3] +]<br /> [- $script = $fields[3] -] [+ $script +]<br />

Result is index.html
And now I need split index.html on index and html but code below dont give me this result.

[- @field = split(".",$script) -] [+ @field +] [+ $field[0] +]<br /> [+ $field[1] +]<br /> [+ $field[2] +]<br />

where is problem ???

Programing in Embperl and all questions are related to Embperl.
Excuse my bad English !!!

Replies are listed 'Best First'.
Re: Problem with Split function
by davorg (Chancellor) on Jul 28, 2004 at 08:56 UTC

    Read the documentation for split. The first argument to split is a regular expression. A dot has a special meaning in a regular expression. To use it as a real dot you need to escape it.

    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

      This is corect and work.

      @field = split(/\./,$script); $script = $field[0]

      Thanks

      Programing in Embperl and all questions are related to Embperl.
      Excuse my bad English !!!