Hi fair monks!

As I was troubleshooting some old code of mine, I came to a piece of code that was somewhat similar to this test script:
use strict; # clean a directory path of extraneous '/' sub clean_path { for (my $i = 0; $i <= $#_; $i++) { # match two or more '/' between a pair of # other non '/' chars and replace the # multiple occurance of '/' with a single '/'. $_[$i] =~ s|([^/])[/]{2,}([^/])|$1/$2|g; # remove trailing garbage such as '/'... $_[$i] =~ s|[/\n\t\s]+$||; # also remove silly '/./...' things $_[$i] =~ s|\./||g; $_[$i] =~ s|/\.$||g; # some path have that wicked '/foo/bar/.' + '.' in the end! } } ### MAIN my $path_list = undef; ## a bunch of code here ## . . . . . ## ## I'm checking that if no path list was provided, ## I use at a 'blank' path so that the loop would ## execute at least once (as if for root directory). ## foreach my $some_path ( (defined $path_list && $#$path_list >= 0) ? @{ +$path_list} : "" ) { clean_path($some_path); # do stuff with path print "Working with $some_path\n"; } print "done\n";
The error I get when trying to run the script is this:
Modification of a read-only value attempted at test.pl line 10, <IN> + chunk 1. main::clean_path('') called at test.pl line 33
I can't quite understand what causes this error. I'm sure it's something simple. I'm also wondering whether it's possible to test any variable for being a 'read-only' one?

Thanks for help ;-).

"There is no system but GNU, and Linux is one of its kernels." -- Confession of Faith

In reply to How could I check if a variable is 'read-only'? by vladb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.